Skip to content

Commit

Permalink
get_kinlawid_by_rxn in query sabiork odl
Browse files Browse the repository at this point in the history
  • Loading branch information
lzy7071 committed Oct 21, 2019
1 parent 11518bb commit d4c22bf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
31 changes: 25 additions & 6 deletions datanator_query_python/query/query_sabiork_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ def get_kinlaw_by_environment(self, taxon=None, taxon_wildtype=None, ph_range=No

return docs, count

def get_kinlaw_by_rxn(self):
'''Place holder
'''
pass

def get_reaction_doc(self, kinlaw_id, projection={'_id': 0}):
'''Find a document on reaction with the kinlaw_id
Args:
Expand All @@ -78,4 +73,28 @@ def get_reaction_doc(self, kinlaw_id, projection={'_id': 0}):
query = {'kinlaw_id': {'$in': kinlaw_id}}
docs = self.collection.find(filter=query, projection=projection)
count = self.collection.count_documents(query)
return docs, count
return docs, count

def get_kinlawid_by_rxn(self, substrates, products):
''' Find the kinlaw_id defined in sabio_rk using
rxn participants' inchi string
Args:
substrates: list of substrates' inchi
products: list of products' inchi
Return:
rxns: list of kinlaw_ids that satisfy the condition
[id0, id1, id2,..., ]
'''
result = []
substrate = 'reaction_participant.substrate.substrate_structure.inchi_structure'
product = 'reaction_participant.product.product_structure.inchi_structure'
projection = {'kinlaw_id': 1, '_id': 0}
constraint_0 = {substrate: {'$in': substrates}}
constraint_1 = {product: {'$in': products}}
query = {'$and': [constraint_0, constraint_1]}
docs = self.collection.find(filter=query, projection=projection)
for doc in docs:
result.append(doc['kinlaw_id'])
return result
10 changes: 9 additions & 1 deletion tests/query/test_query_sabiork_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ def test_get_reaction_doc(self):
_id = [31, 32]
result, count = self.src.get_reaction_doc(_id)
self.assertEqual(count, 2)
self.assertTrue('kinlaw_id' in result[0])
self.assertTrue('kinlaw_id' in result[0])

def test_get_kinlawid_by_rxn(self):
substrate_0 = 'InChI=1S/C21H28N7O17P3/c22-17-12-19(25-7-24-17)28(8-26-12)21-16(44-46(33,34)35)14(30)11(43-21)6-41-48(38,39)45-47(36,37)40-5-10-13(29)15(31)20(42-10)27-3-1-2-9(4-27)18(23)32/h1-4,7-8,10-11,13-16,20-21,29-31H,5-6H2,(H7-,22,23,24,25,32,33,34,35,36,37,38,39)/t10-,11-,13-,14-,15-,16-,20-,21-/m1/s1'
substrate_1 = 'InChI=1S/C6H8O7/c7-3(8)1-2(5(10)11)4(9)6(12)13/h2,4,9H,1H2,(H,7,8)(H,10,11)(H,12,13)'
product_0 = 'InChI=1S/C5H6O5/c6-3(5(9)10)1-2-4(7)8/h1-2H2,(H,7,8)(H,9,10)'
product_1 = 'InChI=1S/CO2/c2-1-3'
result = self.src.get_kinlawid_by_rxn([substrate_0, substrate_1], [product_0, product_1])
self.assertTrue(7923 in result)

0 comments on commit d4c22bf

Please sign in to comment.