Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

biosustain / cameo / 963

15 Feb 2016 - 14:59 coverage decreased (-4.3%) to 62.885%
963

Pull #41

travis-ci

Daaf0308d36e60bacd269a6f70b6dd70?size=18&default=identiconphantomas1234
Merge branch 'devel' into structural_analysis_2
Pull Request #41: Second try on implementing the enumeration of shortest elementary flux modes and MCS

431 of 908 new or added lines in 38 files covered. (47.47%)

678 existing lines in 28 files now uncovered.

3143 of 4998 relevant lines covered (62.89%)

1.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.0
/cameo/api/products.py
1
# Copyright 2014 Novo Nordisk Foundation Center for Biosustainability, DTU.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#   http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
from __future__ import absolute_import, print_function
2×
16

17
__all__ = ['products']
2×
18

19
import difflib
2×
20
from pandas import DataFrame
2×
21
from cameo.data import metanetx
2×
22
from cameo.visualization import inchi_to_svg
2×
23

24

25
class Compound(object):
2×
26
    def __init__(self, inchi):
2×
UNCOV
27
        self.InChI = inchi
!
28

29
    def _repr_svg_(self):
2×
UNCOV
30
        try:
!
UNCOV
31
            return inchi_to_svg(self.InChI)
!
32
        except ImportError:
!
33
            return self.__repr__()
!
34

35
    def _repr_html_(self):
2×
UNCOV
36
        return self._repr_svg_()
!
37

38

39
class Products(object):
2×
40
    def __init__(self):
2×
41
        self.data_frame = metanetx.chem_prop
2×
42

43
    def search(self, query):
2×
44
        matches = self._search_by_source(query)
2×
45
        if len(matches) > 0:
2×
UNCOV
46
            return matches
!
47
        matches = self._search_by_inchi(query)
2×
48
        if len(matches) > 0:
2×
NEW
49
            return matches
!
50
        matches = self._search_by_name_fuzzy(query)
2×
51
        if len(matches) > 0:
2×
52
            return matches
2×
53
        matches = self._search_by_inchi_fuzzy(query)
2×
54
        if len(matches) > 0:
2×
NEW
55
            return matches
!
56
        else:
57
            raise Exception("No compound matches found for query %s" % query)
2×
58

59
    def _search_by_name_fuzzy(self, name):
2×
60
        matches = difflib.get_close_matches(name, self.data_frame.name.dropna(), n=5, cutoff=.8)
2×
61
        ranks = dict([(match, i) for i, match in enumerate(matches)])
2×
62
        selection = DataFrame(self.data_frame[self.data_frame.name.isin(matches)])
2×
63
        selection['search_rank'] = selection.name.map(ranks)
2×
64
        return selection.sort('search_rank')
2×
65

66
    def _search_by_source(self, source_id):
2×
67
        return self.data_frame[self.data_frame.source == source_id.lower()]
2×
68

69
    def _search_by_inchi(self, inchi):
2×
70
        return self.data_frame[self.data_frame.InChI == inchi]
2×
71

72
    def _search_by_inchi_fuzzy(self, inchi):
2×
73
        # TODO: use openbabel if available
74
        matches = difflib.get_close_matches(inchi, self.data_frame.InChI.dropna(), n=5, cutoff=.8)
2×
75
        ranks = dict([(match, i) for i, match in enumerate(matches)])
2×
76
        selection = DataFrame(self.data_frame[self.data_frame.InChI.isin(matches)])
2×
77
        selection['search_rank'] = selection.name.map(ranks)
2×
78
        return selection.sort('search_rank')
2×
79

80

81
products = Products()
2×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2021 Coveralls, Inc