Skip to content

Commit

Permalink
increase coverage of API lib tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saapooch committed Oct 16, 2018
1 parent 1cd5c9c commit 3d514b7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 14 deletions.
1 change: 0 additions & 1 deletion datanator/api/lib/search/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def search(self, string):
subunit = subunit_manager._search_simple(string)

rxns = []
print(metabolite[:METABOLITE_REACTION_LIMIT])
for _metabolite in metabolite[:METABOLITE_REACTION_LIMIT]:
rxn_list = reaction_manager.get_reaction_by_metabolite(_metabolite)
if rxn_list:
Expand Down
26 changes: 13 additions & 13 deletions datanator/api/lib/subunit/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,19 @@ def get_abundance_by_sequence(self, sequence, select=models.AbundanceData):
condition = models.ProteinSubunit.canonical_sequence == sequence
return q.filter(condition)

def get_abundance_by_entrez(self, entrez_id, select=models.AbundanceData):
""" Find the abundance from uniprot
Args:
entrez_id (:obj:`str`): NCBI entrez id for a given protein
Returns:
:obj:`sqlalchemy.orm.query.Query`: query for matching abundance rows
"""
q = self.data_source.session.query(select).join(
models.ProteinSubunit, models.AbundanceData.subunit)
condition = models.ProteinSubunit.entrez_id == entrez_id
return q.filter(condition)
# def get_abundance_by_entrez(self, entrez_id, select=models.AbundanceData):
# """ Find the abundance from uniprot
#
# Args:
# entrez_id (:obj:`str`): NCBI entrez id for a given protein
#
# Returns:
# :obj:`sqlalchemy.orm.query.Query`: query for matching abundance rows
# """
# q = self.data_source.session.query(select).join(
# models.ProteinSubunit, models.AbundanceData.subunit)
# condition = models.ProteinSubunit.entrez_id == entrez_id
# return q.filter(condition)

def get_abundance_by_mass(self, mass, select=models.AbundanceData):
""" Find the abundance from uniprot
Expand Down
19 changes: 19 additions & 0 deletions tests/api/lib/test_complex_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class TestProteinComplexManager(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.signal_peptidase = complex_manager.data_source.session.query(models.ProteinComplex).filter_by(complex_name = 'signal peptidase I').first()
cls.rhino_complex = complex_manager.data_source.session.query(models.ProteinComplex).filter_by(complex_name = 'Rhino-Deadlock-Cutoff Complex').first()



def test_get_complex_by_id(self):
prot = complex_manager.get_complex_by_id(self.signal_peptidase.id)
Expand All @@ -29,3 +32,19 @@ def test__port(self):
ported_prot = complex_manager._port(self.signal_peptidase)
self.assertEqual(ported_prot.name, 'signal peptidase I')
self.assertEqual(ported_prot.cross_references, [])


def test_get_observable_subunits(self):
observed_subunits = complex_manager.get_observable_subunits(self.rhino_complex)
self.assertEqual(set(['Q9VIF5', 'Q9V629', 'Q7JXA8']), set([subunit.specie.uniprot_id for subunit in observed_subunits]))

def test_get_subunits_by_known_complex(self):
subunits = complex_manager.get_subunits_by_known_complex(self.rhino_complex.complex_name)
self.assertEqual(set(['Q9VIF5', 'Q9V629', 'Q7JXA8']), set([subunit.uniprot_id for subunit in subunits]))

def test_get_known_complex_by_subunit(self):
complex = complex_manager.get_known_complex_by_subunit('Q9CWF2').all()

self.assertEqual(len(complex), 1)
self.assertEqual(complex[0].complex_name, 'Profilin 1 complex')
self.assertEqual(complex[0].go_id, 'GO:0006461;GO:0006897;GO:0030036')
8 changes: 8 additions & 0 deletions tests/api/lib/test_metabolite_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ def test__port(self):
self.assertEqual(ported_specie.name, self.proline.metabolite_name)
self.assertEqual(ported_specie.structure, self.proline.structure._value_inchi)
self.assertGreater(len(ported_specie.cross_references), 0)


def test_get_metabolite_by_structure(self):
metabolites = metabolite_manager.get_metabolite_by_structure(self.proline.structure._value_inchi)
self.assertIn(self.proline, metabolites)

metabolites = metabolite_manager.get_metabolite_by_structure(self.proline.structure._value_inchi, only_formula_and_connectivity=True)
self.assertIn(self.proline, metabolites)
4 changes: 4 additions & 0 deletions tests/api/lib/test_search_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ def test_search(self):
self.assertGreater(len(dict['Reaction']), 0)
self.assertEqual(len(dict['ProteinSubunit']), 0)
self.assertEqual(len(dict['ProteinComplex']), 0)

def test_get_object_by_id(self):
obj = search_manager.get_object_by_id(5)
self.assertTrue(obj)
11 changes: 11 additions & 0 deletions tests/api/lib/test_subunit_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TestProteinSubunitManager(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.protein_P00323 = subunit_manager.data_source.session.query(models.ProteinSubunit).filter_by(uniprot_id = 'P00323').first()
cls.protein_P49418 = subunit_manager.data_source.session.query(models.ProteinSubunit).filter_by(uniprot_id = 'P49418').first()
cls.protein_O15169 = subunit_manager.data_source.session.query(models.ProteinSubunit).filter_by(uniprot_id = 'O15169').first()

def test_get_abundance_by_uniprot(self):
uniprot = self.protein_P00323.uniprot_id
Expand Down Expand Up @@ -61,3 +63,12 @@ def test_get_abundance_by_length(self):
models.AbundanceData.pax_load.in_([1, 2])).all()
self.assertEqual(set(c.abundance for c in abundances),
set([1003.0, 1336.0, 1027.0, 1861.0]))


def test_get_observable_interactions(self):
interactions = subunit_manager.get_observable_interactions(self.protein_P49418)
self.assertGreater(len(interactions), 0)

def test_get_observable_complex(self):
complexes = subunit_manager.get_observable_complex(self.protein_O15169)
self.assertGreater(len(complexes), 0)

0 comments on commit 3d514b7

Please sign in to comment.