Beispiel #1
0
 def get(self):
     input_cls = self.get_query_argument('input_cls', None)
     input_id = self.get_query_argument('input_id', None)
     input_obj = self.get_query_argument('input_obj', None)
     output_cls = self.get_query_argument('output_cls', None)
     output_id = self.get_query_argument('output_id', None)
     pred = self.get_query_argument('predicate', None)
     if input_obj:
         input_obj = ast.literal_eval(input_obj)
     if output_cls:
         output_cls = ast.literal_eval(output_cls)[0]
     if input_id:
         _id, _value = input_id.split(':', 1)
         _id = "bts:" + _id
     else:
         _id = None,
         _value = None
     print(input_cls, _id, input_obj, output_cls, output_id, pred, _value)
     seqd = SingleEdgeQueryDispatcher(input_cls=input_cls,
                                      input_id=_id,
                                      input_obj=input_obj,
                                      output_cls=output_cls,
                                      output_id=output_id,
                                      pred=pred,
                                      values=_value,
                                      registry=reg)
     seqd.query()
     res = json_graph.node_link_data(seqd.G)
     if res:
         self.set_status(200)
         self.write(json.dumps(networkx_json_to_visjs(res)))
         self.finish()
         return
Beispiel #2
0
    def _answer_query_using_bte(self, input_qnode, output_qnode, qedge, answer_kg, valid_bte_inputs_dict):
        accepted_curies = set()
        # Send this single-edge query to BTE, once per input curie (adding findings to our answer KG as we go)
        for curie in input_qnode.curie:
            if eu.get_curie_prefix(curie) in valid_bte_inputs_dict['curie_prefixes']:
                accepted_curies.add(curie)
                try:
                    loop = asyncio.new_event_loop()
                    seqd = SingleEdgeQueryDispatcher(input_cls=input_qnode.type,
                                                     output_cls=output_qnode.type,
                                                     pred=qedge.type,
                                                     input_id=eu.get_curie_prefix(curie),
                                                     values=eu.get_curie_local_id(curie),
                                                     loop=loop)
                    self.response.debug(f"Sending query to BTE: {curie}-{qedge.type if qedge.type else ''}->{output_qnode.type}")
                    seqd.query()
                    reasoner_std_response = seqd.to_reasoner_std()
                except Exception:
                    trace_back = traceback.format_exc()
                    error_type, error, _ = sys.exc_info()
                    self.response.error(f"Encountered a problem while using BioThings Explorer. {trace_back}",
                                        error_code=error_type.__name__)
                    return answer_kg, accepted_curies
                else:
                    answer_kg = self._add_answers_to_kg(answer_kg, reasoner_std_response, input_qnode.id, output_qnode.id, qedge.id)

        return answer_kg, accepted_curies
Beispiel #3
0
 def _answer_query_using_bte(self, input_qnode_key: str, output_qnode_key: str, qg: QueryGraph,
                             answer_kg: QGOrganizedKnowledgeGraph, valid_bte_inputs_dict: Dict[str, Set[str]],
                             log: ARAXResponse) -> Tuple[QGOrganizedKnowledgeGraph, Set[str]]:
     accepted_curies = set()
     qedge_key = next(qedge_key for qedge_key in qg.edges)
     qedge = qg.edges[qedge_key]
     input_qnode = qg.nodes[input_qnode_key]
     output_qnode = qg.nodes[output_qnode_key]
     # Send this single-edge query to BTE, input curie by input curie (adding findings to our answer KG as we go)
     for curie in input_qnode.id:
         # Consider all different combinations of qnode types (can be multiple if gene/protein)
         for input_qnode_category, output_qnode_category in itertools.product(input_qnode.category, output_qnode.category):
             if eu.get_curie_prefix(curie) in valid_bte_inputs_dict['curie_prefixes']:
                 accepted_curies.add(curie)
                 try:
                     loop = asyncio.new_event_loop()
                     seqd = SingleEdgeQueryDispatcher(input_cls=input_qnode_category,
                                                      output_cls=output_qnode_category,
                                                      pred=qedge.predicate,
                                                      input_id=eu.get_curie_prefix(curie),
                                                      values=eu.get_curie_local_id(curie),
                                                      loop=loop)
                     log.debug(f"Sending query to BTE: {curie}-{qedge.predicate if qedge.predicate else ''}->{output_qnode_category}")
                     seqd.query()
                     reasoner_std_response = seqd.to_reasoner_std()
                 except Exception:
                     trace_back = traceback.format_exc()
                     error_type, error, _ = sys.exc_info()
                     log.error(f"Encountered a problem while using BioThings Explorer. {trace_back}",
                               error_code=error_type.__name__)
                     return answer_kg, accepted_curies
                 else:
                     answer_kg = self._add_answers_to_kg(answer_kg, reasoner_std_response, input_qnode_key, output_qnode_key, qedge_key, log)
     return answer_kg, accepted_curies
 def test_protein2disease(self):
     """Test protein-disease"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Disease',
                                      input_cls='Protein',
                                      input_id='PR',
                                      values='PR:000008999')
     seqd.query()
     self.assertTrue('DOID:0111550' in seqd.G)
 def test_protein2cell(self):
     """Test protein-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='Protein',
                                      input_id='PR',
                                      values='PR:000008999')
     seqd.query()
     self.assertTrue('CL:0000094' in seqd.G)
 def test_protein2cc(self):
     """Test protein-cellular_component"""
     seqd = SingleEdgeQueryDispatcher(output_cls='CellularComponent',
                                      input_cls='Protein',
                                      input_id='PR',
                                      values='PR:000008999')
     seqd.query()
     self.assertTrue('membrane attack complex'.upper() in seqd.G)
 def test_protein2bp(self):
     """Test protein-biological_process"""
     seqd = SingleEdgeQueryDispatcher(output_cls='BiologicalProcess',
                                      input_cls='Protein',
                                      input_id='PR',
                                      values='PR:000008999')
     seqd.query()
     self.assertTrue('gene expression'.upper() in seqd.G)
 def test_bp2cell(self):
     """Test gene-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='CellularComponent',
                                      input_id='GO',
                                      values='GO:0001891')
     seqd.query()
     self.assertTrue('CL:0000234' in seqd.G)
 def test_ma2cell(self):
     """Test gene-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='MolecularActivity',
                                      input_id='GO',
                                      values='GO:0050626')
     seqd.query()
     self.assertTrue('CL:0000097' in seqd.G)
Beispiel #10
0
 def test_chemical2cell(self):
     """Test gene-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='ChemicalSubstance',
                                      input_id='CHEBI',
                                      values='CHEBI:28640')
     seqd.query()
     self.assertTrue('CL:0000990' in seqd.G)
 def test_gene2bp(self):
     """Test gene-biological_process"""
     seqd = SingleEdgeQueryDispatcher(output_cls='BiologicalProcess',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='1139')
     seqd.query()
     self.assertTrue('ADAPTIVE IMMUNE RESPONSE' in seqd.G)
 def test_gene2cc(self):
     """Test gene-cellular_component"""
     seqd = SingleEdgeQueryDispatcher(output_cls='CellularComponent',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='1139')
     seqd.query()
     self.assertTrue('CHROMATIN' in seqd.G)
 def test_gene2anatomy(self):
     """Test gene-anatomy"""
     seqd = SingleEdgeQueryDispatcher(output_cls='AnatomicalEntity',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='7890')
     seqd.query()
     self.assertTrue("UBERON:0001844" in seqd.G)
Beispiel #14
0
 def test_bp2cell(self):
     """Test gene-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='BiologicalProcess',
                                      input_id='GO',
                                      values='GO:0019369')
     seqd.query()
     self.assertTrue('CL:0000097' in seqd.G)
 def test_protein2ma(self):
     """Test protein-molecular_activity"""
     seqd = SingleEdgeQueryDispatcher(output_cls='MolecularActivity',
                                      input_cls='Protein',
                                      input_id='PR',
                                      values='PR:000008999')
     seqd.query()
     self.assertTrue("cytokine activity".upper() in seqd.G)
 def test_genomicentity2cell(self):
     """Test gene-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='GenomicEntity',
                                      input_id='SO',
                                      values='SO:0001860')
     seqd.query()
     self.assertTrue('CL:0000037' in seqd.G)
Beispiel #17
0
 def test_cell2cell(self):
     """Test gene-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='Cell',
                                      input_id='CL',
                                      values='CL:0000040')
     seqd.query()
     self.assertTrue('CL:0000988' in seqd.G)
 def test_gene2cell(self):
     """Test gene-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='3684')
     seqd.query()
     self.assertTrue('CL:0000057' in seqd.G)
Beispiel #19
0
 def test_disease2cell(self):
     """Test gene-cell"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Cell',
                                      input_cls='Disease',
                                      input_id='DOID',
                                      values='DOID:12143')
     seqd.query()
     self.assertTrue('CL:0000731' in seqd.G)
 def test_gene2protein(self):
     """Test gene-protein"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Protein',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='7890')
     seqd.query()
     self.assertTrue('PR:000016253' in seqd.G)
     self.assertTrue('PR:000001825' in seqd.G)
 def test_gene2ma(self):
     """Test gene-molecular_activity"""
     seqd = SingleEdgeQueryDispatcher(output_cls='MolecularActivity',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='10115')
     seqd.query()
     self.assertTrue("MOP:0000030" in seqd.G)
     self.assertTrue("ACETYL-COA CARBOXYLASE ACTIVITY" in seqd.G)
Beispiel #22
0
 def test_no_count(self):
     filter = {'name':'NodeDegree'}
     seqd = SingleEdgeQueryDispatcher(input_cls='Gene',
                                      output_cls='ChemicalSubstance',
                                      input_id='NCBIGene',
                                      values='1017',
                                      filter=filter)
     seqd.query()
     self.assertEqual(seqd.G.number_of_nodes(), 51)
 def test_protein2protein(self):
     """Test protein-protein"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Protein',
                                      input_cls='Protein',
                                      input_id='PR',
                                      values='PR:000008999')
     seqd.query()
     self.assertTrue('PR:000017296' in seqd.G)
     self.assertTrue('PR:000007563' in seqd.G)
 def test_gene2genomicentity(self):
     """Test gene-protein"""
     seqd = SingleEdgeQueryDispatcher(output_cls='GenomicEntity',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='7890')
     seqd.query()
     self.assertTrue('SO:0000704' in seqd.G)
     self.assertTrue('SO:0001853' in seqd.G)
Beispiel #25
0
 def test_label_F(self):
     filter = {'name':'EdgeLabel', 'count':60}
     seqd = SingleEdgeQueryDispatcher(input_cls='Gene',
                                      output_cls='ChemicalSubstance',
                                      input_id='NCBIGene',
                                      values='1017',
                                      filter=filter)
     seqd.query()
     self.assertEqual(seqd.G.number_of_nodes(), 859)
 def test_no_filter(self):
     seqd = SingleEdgeQueryDispatcher(input_cls='Gene',
                                      output_cls='ChemicalSubstance',
                                      input_id='NCBIGene',
                                      values='1017')
     seqd.query()
     newG = Filter(seqd.G).filter_results()
     self.assertEqual(seqd.G, newG)
     self.assertEqual(seqd.G.number_of_nodes(), newG.number_of_nodes())
 def test_gene2disease(self):
     """Test gene-disease"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Disease',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      output_id='DOID',
                                      values='10115')
     seqd.query()
     self.assertTrue('DOID:0060731' in seqd.G)
 def test_gene2chemicalsubstance(self):
     """Test gene-genomic entity"""
     seqd = SingleEdgeQueryDispatcher(output_cls='ChemicalSubstance',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='7890')
     seqd.query()
     self.assertTrue('CHEBI:22260' in seqd.G)
     self.assertTrue('CISPLATIN' in seqd.G)
 def test_gene2gene(self):
     """Test gene-gene"""
     seqd = SingleEdgeQueryDispatcher(output_cls='Gene',
                                      input_cls='Gene',
                                      input_id='HGNC',
                                      values='7890')
     seqd.query()
     self.assertTrue('CALB1' in seqd.G)
     self.assertTrue('ADORA1' in seqd.G)
 def test_protein2gene(self):
     """Test protein-gene"""
     seqd = SingleEdgeQueryDispatcher(output_cls="Gene",
                                      input_cls="Protein",
                                      input_id="PR",
                                      values="PR:000008999")
     seqd.query()
     self.assertTrue("GAPDH" in seqd.G)
     self.assertTrue("ATM" in seqd.G)