def test_no_evidence(self):
        with self.assertRaises(SystemExit) as se:
            # empty response
            reasoner_std = { "query_graph": dict(),
                             "knowledge_graph": dict(),
                             "response": dict()
                           }
            # empty query graph
            reasoner_std["query_graph"] = { "edges": [],
                                            "nodes": []
                                          }
            # empty knowledge graph
            reasoner_std["knowledge_graph"] = { "edges": [],
                                                "nodes": []
                                              }
            # empty response graph
            reasoner_std["results"] = { "node_bindings": [],
                                        "edge_bindings": []
                                      }

            # add target survival node
            reasoner_std['query_graph']['nodes'].append({ 'id': 'n{}'.format('2'),
                                                          'type': 'PhenotypicFeature',
                                                          'curie': 'UBERON:0000071',
                                                       })
            handler = ReasonerStdHandler(source_ara='ranking',
                                         dict_query=reasoner_std)
            queries = handler.buildChpQueries()
Exemple #2
0
    def test_no_disease(self):
        """ Test with no disease
        """
        with self.assertRaises(SystemExit) as se:

            # empty response
            reasoner_std = { "query_graph": dict(),
                             "knowledge_graph": dict(),
                             "results": list()
                           }
            # empty query graph
            reasoner_std["query_graph"] = { "edges": dict(),
                                            "nodes": dict()
                                          }
            # empty knowledge graph
            reasoner_std["knowledge_graph"] = { "edges": dict(),
                                                "nodes": dict()
                                              }
            # add target survival node
            phenotype = ('Survival_Time', 'EFO:0000714')
            reasoner_std['query_graph']['nodes']['n2'] = { 'category': 'biolink:PhenotypicFeature',
                                                           'id': '{}'.format(phenotype[1]),
                                                         }
            handler = ReasonerStdHandler(source_ara='default',
                                         dict_query=reasoner_std)
            queries = handler.buildChpQueries()
        self.assertEqual(se.exception.code, 'Disease node not found. Node type must be \'biolink:Disease\' and curie must be in: MONDO:0007254')
 def test_no_disease(self):
     with self.assertRaises(SystemExit) as se:
         # empty response
         reasoner_std = {
             "query_graph": dict(),
             "knowledge_graph": dict(),
             "response": dict()
         }
         # empty query graph
         reasoner_std["query_graph"] = {"edges": [], "nodes": []}
         # empty knowledge graph
         reasoner_std["knowledge_graph"] = {"edges": [], "nodes": []}
         # empty response graph
         reasoner_std["results"] = {
             "node_bindings": [],
             "edge_bindings": []
         }
         # add target survival node
         phenotype = ('Survival_Time', 'EFO:0000714')
         reasoner_std['query_graph']['nodes'].append({
             'id':
             'n{}'.format('1'),
             'type':
             'PhenotypicFeature',
             'curie':
             '{}'.format(phenotype[1]),
         })
         handler = ReasonerStdHandler(source_ara='exploring',
                                      dict_query=reasoner_std)
         queries = handler.buildChpQueries()
     self.assertEqual(
         se.exception.code,
         'Disease node not found. Node type must be \'disease\' and curie must be in: MONDO:0007254'
     )
Exemple #4
0
    def test_contribution_property(self):
        """ check if the contribution property returns contributions
        """

        # empty response
        reasoner_std = { "query_graph": dict(),
                         "knowledge_graph": dict(),
                         "results": list()
                       }
        # empty query graph
        reasoner_std["query_graph"] = { "edges": dict(),
                                        "nodes": dict()
                                      }
        # empty knowledge graph
        reasoner_std["knowledge_graph"] = { "edges": dict(),
                                            "nodes": dict()
                                          }

        # add in evidence gene
        gene1 = ('RAF1', 'ENSEMBL:ENSG00000132155')
        reasoner_std['query_graph']['nodes']['n0'] = { 'category':'biolink:Gene',
                                                       'id':'{}'.format(gene1[1])
                                                     }
        # add in disease node
        disease = ('Breast_Cancer', 'MONDO:0007254')
        reasoner_std['query_graph']['nodes']['n1'] = { 'category':'biolink:Disease',
                                                       'id':'{}'.format(disease[1])
                                                     }
        # add target survival node
        phenotype = ('Survival_Time', 'EFO:0000714')
        reasoner_std['query_graph']['nodes']['n2'] = { 'category': 'biolink:PhenotypicFeature',
                                                       'id': '{}'.format(phenotype[1]),
                                                     }
        # link genes/drugs to disease
        reasoner_std['query_graph']['edges']['e0'] = { 'predicate':'biolink:GeneToDiseaseAssociation',
                                                       'subject': 'n0',
                                                       'object': 'n1'
                                                     }
        # link disease to target
        reasoner_std['query_graph']['edges']['e1'] = { 'predicate':'biolink:DiseaseToPhenotypicFeatureAssociation',
                                                       'subject': 'n1',
                                                       'object': 'n2',
                                                       'properties': { 'qualifier':'>=',
                                                                       'days':970,
                                                                       'contributions':True
                                                                     }
                                                     }
        handler = ReasonerStdHandler(source_ara='default',
                                     dict_query=reasoner_std)
        queries = handler.buildChpQueries()
        queries = handler.runChpQueries()
        reasoner_std_final = handler.constructDecoratedKG()
        KG = reasoner_std_final['message']['knowledge_graph']
        for edge_key in KG['edges'].keys():
            edge = KG['edges'][edge_key]
            if edge['predicate'] == 'biolink:DiseaseToPhenotypicFeatureAssociation':
                p_survival = edge['has_confidence_level']
                report = edge['properties']['contributions']
        print("probability of survival:",p_survival)
    def test_negative(self):
        # empty response
        reasoner_std = { "query_graph": dict(),
                         "knowledge_graph": dict(),
                         "response": dict()
                       }
        # empty query graph
        reasoner_std["query_graph"] = { "edges": [],
                                        "nodes": []
                                      }
        # empty knowledge graph
        reasoner_std["knowledge_graph"] = { "edges": [],
                                            "nodes": []
                                          }
        # empty response graph
        reasoner_std["results"] = { "node_bindings": [],
                                    "edge_bindings": []
                                  }

        # add in evidence drug
        drug = ('CYCLOPHOSPHAMIDE', 'CHEMBL:CHEMBL88')
        reasoner_std['query_graph']['nodes'].append({ 'id':'n{}'.format('0'),
                                                      'type':'Drug',
                                                      'curie':'{}'.format(drug[1])
                                                   })

        # add target survival node
        phenotype = ('Survival_Time', 'EFO:0000714')
        reasoner_std['query_graph']['nodes'].append({ 'id': 'n{}'.format('1'),
                                                      'type': 'PhenotypicFeature',
                                                      'curie': '{}'.format(phenotype[1]),
                                                   })

        # link evidence to target survival node
        reasoner_std['query_graph']['edges'].append({ 'id':'e{}'.format('0'),
                                                      'type':'chemical_to_disease_or_phenotypic_feature_association',
                                                      'value':1000,
                                                      'source_id':'n{}'.format('0'),
                                                      'target_id':'n{}'.format('1')
                                                   })


        handler = ReasonerStdHandler(source_ara='relay9_22',
                                     dict_query=reasoner_std)
        queries = handler.buildChpQueries()
        queries = handler.runChpQueries()
        reasoner_std_final = handler.constructDecoratedKG()

        KG = reasoner_std_final['knowledge_graph']
        res = reasoner_std_final['results']

        # extract probability
        KG_result_edge = res['edge_bindings'][0]['kg_id']
        for edge in KG['edges']:
            if edge['type'] == 'chemical_to_disease_or_phenotypic_feature_association':
                p_survival = edge['has_confidence_level']
                gene_contribs = edge['Description']
        print("probability of survival:",p_survival)
        print(gene_contribs)
Exemple #6
0
    def test_gene_request(self):

        # empty response
        reasoner_std = {
            "query_graph": dict(),
            "knowledge_graph": dict(),
            "response": dict()
        }
        # empty query graph
        reasoner_std["query_graph"] = {"edges": [], "nodes": []}
        # empty knowledge graph
        reasoner_std["knowledge_graph"] = {"edges": [], "nodes": []}
        # empty response graph
        reasoner_std["results"] = {"node_bindings": [], "edge_bindings": []}
        # add in evidence genes
        gene = ('RAF1', 'ENSEMBL:ENSG00000132155')
        reasoner_std['query_graph']['nodes'].append({
            'id':
            'n{}'.format('0'),
            'type':
            'Gene',
            'curie':
            '{}'.format(gene[1])
        })
        # add target survival node
        reasoner_std['query_graph']['nodes'].append({
            'id': 'n{}'.format('1'),
            'type': 'PhenotypicFeature',
            'curie': 'UBERON:0000071',
        })
        # link evidence to target survival node
        reasoner_std['query_graph']['edges'].append({
            'id':
            'e{}'.format('0'),
            'type':
            'causes',
            'onset_qualifier':
            1000,
            'source_id':
            'n{}'.format('0'),
            'target_id':
            'n{}'.format('1')
        })
        handler = ReasonerStdHandler(source_ara='ranking',
                                     dict_query=reasoner_std)
        queries = handler.buildChpQueries()
        queries = handler.runChpQueries()
        reasoner_std_final = handler.constructDecoratedKG()

        KG = reasoner_std_final['knowledge_graph']
        res = reasoner_std_final['results']

        # extract probability
        KG_result_edge = res['edge_bindings'][0]['kg_id']
        for edge in KG['edges']:
            if edge['id'] == KG_result_edge:
                p_survival = edge['has_confidence_level']
        print("probability of survival:", p_survival)
Exemple #7
0
    def test_one_drug(self):
        """ Test with one drug
        """
        # empty response
        reasoner_std = { "query_graph": dict(),
                         "knowledge_graph": dict(),
                         "results": list()
                       }
        # empty query graph
        reasoner_std["query_graph"] = { "edges": dict(),
                                        "nodes": dict()
                                      }
        # empty knowledge graph
        reasoner_std["knowledge_graph"] = { "edges": dict(),
                                            "nodes": dict()
                                          }

        # add in evidence drug
        drug = ('CYCLOPHOSPHAMIDE', 'CHEMBL:CHEMBL88')
        reasoner_std['query_graph']['nodes']['n0'] = { 'category':'biolink:Drug',
                                                       'id':'{}'.format(drug[1])
                                                     }
         # add in disease node
        disease = ('Breast_Cancer', 'MONDO:0007254')
        reasoner_std['query_graph']['nodes']['n1'] = { 'category':'biolink:Disease',
                                                       'id':'{}'.format(disease[1])
                                                     }
        # add target survival node
        phenotype = ('Survival_Time', 'EFO:0000714')
        reasoner_std['query_graph']['nodes']['n2'] = { 'category': 'biolink:PhenotypicFeature',
                                                       'id': '{}'.format(phenotype[1]),
                                                     }
        # link genes/drugs to disease
        reasoner_std['query_graph']['edges']['e0'] = { 'predicate':'biolink:ChemicalToDiseaseOrPhenotypicFeatureAssociation',
                                                       'subject': 'n0',
                                                       'object': 'n1'
                                                     }

        # link disease to target
        reasoner_std['query_graph']['edges']['e1'] = { 'predicate':'biolink:DiseaseToPhenotypicFeatureAssociation',
                                                       'subject': 'n1',
                                                       'object': 'n2',
                                                       'properties': { 'qualifier':'>=',
                                                                       'days':970
                                                                     }
                                                     }
        handler = ReasonerStdHandler(source_ara='default',
                                     dict_query=reasoner_std)
        queries = handler.buildChpQueries()
        queries = handler.runChpQueries()
        reasoner_std_final = handler.constructDecoratedKG()
        KG = reasoner_std_final['message']['knowledge_graph']
        for edge_key in KG['edges'].keys():
            edge = KG['edges'][edge_key]
            if edge['predicate'] == 'biolink:DiseaseToPhenotypicFeatureAssociation':
                p_survival = edge['has_confidence_level']
        print("probability of survival:",p_survival)
 def test_no_evidence(self):
     # empty response
     reasoner_std = {
         "query_graph": dict(),
         "knowledge_graph": dict(),
         "response": dict()
     }
     # empty query graph
     reasoner_std["query_graph"] = {"edges": [], "nodes": []}
     # empty knowledge graph
     reasoner_std["knowledge_graph"] = {"edges": [], "nodes": []}
     # empty response graph
     reasoner_std["results"] = {"node_bindings": [], "edge_bindings": []}
     # add in disease node
     disease = ('Breast_Cancer', 'MONDO:0007254')
     reasoner_std['query_graph']['nodes'].append({
         'id':
         'n{}'.format('0'),
         'type':
         'disease',
         'curie':
         '{}'.format(disease[1])
     })
     # add target survival node
     phenotype = ('Survival_Time', 'EFO:0000714')
     reasoner_std['query_graph']['nodes'].append({
         'id':
         'n{}'.format('1'),
         'type':
         'PhenotypicFeature',
         'curie':
         '{}'.format(phenotype[1]),
     })
     # link disease to target
     reasoner_std['query_graph']['edges'].append({
         'id':
         'e{}'.format('0'),
         'type':
         'disease_to_phenotype_association',
         'value':
         970,
         'source_id':
         'n{}'.format('0'),
         'target_id':
         'n{}'.format('1')
     })
     handler = ReasonerStdHandler(source_ara='exploring',
                                  dict_query=reasoner_std)
     queries = handler.buildChpQueries()
     queries = handler.runChpQueries()
     reasoner_std_final = handler.constructDecoratedKG()
     KG = reasoner_std_final['knowledge_graph']
     for edge in KG['edges']:
         if edge['type'] == 'disease_to_phenotype_association':
             p_survival = edge['has_confidence_level']
     print("probability of survival:", p_survival)
    def test_too_much_evidence(self):
        with self.assertRaises(SystemExit) as se:
            # empty response
            reasoner_std = { "query_graph": dict(),
                             "knowledge_graph": dict(),
                             "response": dict()
                           }
            # empty query graph
            reasoner_std["query_graph"] = { "edges": [],
                                            "nodes": []
                                          }
            # empty knowledge graph
            reasoner_std["knowledge_graph"] = { "edges": [],
                                                "nodes": []
                                              }
            # empty response graph
            reasoner_std["results"] = { "node_bindings": [],
                                        "edge_bindings": []
                                      }
            # add in evidence gene
            gene1 = ('RAF1', 'ENSEMBL:ENSG00000132155')
            reasoner_std['query_graph']['nodes'].append({ 'id':'n{}'.format('0'),
                                                          'type':'Gene',
                                                          'curie':'{}'.format(gene1[1])
                                                       })
            # add in second evidence gene
            gene2 = ('TTN', 'ENSEMBL:ENSG00000155657')
            reasoner_std['query_graph']['nodes'].append({ 'id':'n{}'.format('1'),
                                                          'type':'Gene',
                                                          'curie':'{}'.format(gene2[1])
                                                       })

            # add target survival node
            reasoner_std['query_graph']['nodes'].append({ 'id': 'n{}'.format('2'),
                                                          'type': 'PhenotypicFeature',
                                                          'curie': 'UBERON:0000071',
                                                       })
            # link evidence to target survival node
            reasoner_std['query_graph']['edges'].append({ 'id':'e{}'.format('0'),
                                                          'type':'causes',
                                                          'onset_qualifier':1000,
                                                          'source_id':'n{}'.format('0'),
                                                          'target_id':'n{}'.format('2')
                                                       })
            # link evidence to target survival node
            reasoner_std['query_graph']['edges'].append({ 'id':'e{}'.format('1'),
                                                          'type':'causes',
                                                          'onset_qualifier':1000,
                                                          'source_id':'n{}'.format('1'),
                                                          'target_id':'n{}'.format('2')
                                                       })
            handler = ReasonerStdHandler(source_ara='ranking',
                                         dict_query=reasoner_std)
            queries = handler.buildChpQueries()
        self.assertEqual(se.exception.code, 'More than 1 piece of evidence')
Exemple #10
0
 def test_no_evidence_omitting_KG_and_results(self):
     with self.assertRaises(SystemExit) as se:
         # empty response
         reasoner_std = {
             "query_graph": dict(),
         }
         # empty query graph
         reasoner_std["query_graph"] = {"edges": [], "nodes": []}
         # add in disease node
         disease = ('Breast_Cancer', 'MONDO:0007254')
         reasoner_std['query_graph']['nodes'].append({
             'id':
             'n{}'.format('0'),
             'type':
             'disease',
             'curie':
             '{}'.format(disease[1])
         })
         # add target survival node
         phenotype = ('Survival_Time', 'EFO:0000714')
         reasoner_std['query_graph']['nodes'].append({
             'id':
             'n{}'.format('1'),
             'type':
             'PhenotypicFeature',
             'curie':
             '{}'.format(phenotype[1]),
         })
         # link disease to target
         reasoner_std['query_graph']['edges'].append({
             'id':
             'e{}'.format('0'),
             'type':
             'disease_to_phenotype_association',
             'value':
             970,
             'source_id':
             'n{}'.format('0'),
             'target_id':
             'n{}'.format('1')
         })
         handler = ReasonerStdHandler(source_ara='unsecret',
                                      dict_query=reasoner_std)
         queries = handler.buildChpQueries()
         queries = handler.runChpQueries()
         reasoner_std_final = handler.constructDecoratedKG()
         KG = reasoner_std_final['knowledge_graph']
         for edge in KG['edges']:
             if edge['type'] == 'disease_to_phenotype_association':
                 p_survival = edge['has_confidence_level']
         print("probability of survival:", p_survival)
     self.assertEqual(se.exception.code, 'Needs at least 1 gene')
    def test_sparse_drug(self):
        """ queries the drug Gemzar which has a sparsity issue. Used to throw an error.
            Should be handled.
        """

        # empty response
        reasoner_std = {
            "query_graph": {},
            "knowledge_graph": {},
            "results": []
        }
        # empty query graph
        reasoner_std["query_graph"] = {"edges": {}, "nodes": {}}
        # empty knowledge graph
        reasoner_std["knowledge_graph"] = {"edges": {}, "nodes": {}}

        # add in evidence drug
        drug = ('GEMZAR', 'CHEMBL:CHEMBL888')
        reasoner_std['query_graph']['nodes']['n{}'.format('0')] = {
            'category': 'biolink:Drug',
            'id': '{}'.format(drug[1])
        }

        # add in gene node (to be filled by contribution analysis
        reasoner_std['query_graph']['nodes']['n{}'.format('1')] = {
            'category': 'biolink:Gene',
        }

        # link genes/drugs to disease
        reasoner_std['query_graph']['edges']['e{}'.format(0)] = {
            'predicate': 'biolink:chemical_to_gene_association',
            'subject': 'n0',
            'object': 'n1'
        }

        handler = ReasonerStdHandler(source_ara='default',
                                     dict_query=reasoner_std,
                                     max_results=5)
        queries = handler.buildChpQueries()
        queries = handler.runChpQueries()
        reasoner_std_final = handler.constructDecoratedKG()

        KG = reasoner_std_final["message"]['knowledge_graph']
        res = reasoner_std_final["message"]['results']

        res_pretty = json.dumps(reasoner_std_final, indent=2)
        print(res_pretty)
Exemple #12
0
    def test_no_evidence_omitting_KG_and_results(self):
        """ Test with no evidence, but omitting KG and Results (should be handled by handler)
        """
        # empty response
        reasoner_std = { "query_graph": dict(),
                       }

        # empty query graph
        reasoner_std["query_graph"] = { "edges": dict(),
                                        "nodes": dict()
                                      }
        # add in disease node
        disease = ('Breast_Cancer', 'MONDO:0007254')
        reasoner_std['query_graph']['nodes']['n0'] = { 'category':'biolink:Disease',
                                                       'id':'{}'.format(disease[1])
                                                     }
        # add target survival node
        phenotype = ('Survival_Time', 'EFO:0000714')
        reasoner_std['query_graph']['nodes']['n1'] = { 'category': 'biolink:PhenotypicFeature',
                                                       'id': '{}'.format(phenotype[1]),
                                                     }
        # link disease to target
        reasoner_std['query_graph']['edges']['e0'] = { 'predicate':'biolink:DiseaseToPhenotypicFeatureAssociation',
                                                       'subject': 'n0',
                                                       'object': 'n1',
                                                       'properties': { 'qualifier':'>=',
                                                                       'days':970
                                                                     }
                                                     }

        handler = ReasonerStdHandler(source_ara='default',
                                     dict_query=reasoner_std)
        queries = handler.buildChpQueries()
        queries = handler.runChpQueries()
        reasoner_std_final = handler.constructDecoratedKG()
        KG = reasoner_std_final['message']['knowledge_graph']
        for edge_key in KG['edges'].keys():
            edge = KG['edges'][edge_key]
            if edge['predicate'] == 'biolink:DiseaseToPhenotypicFeatureAssociation':
                p_survival = edge['has_confidence_level']
        print("probability of survival:",p_survival)
Exemple #13
0
    def test_no_target(self):
        """ Test with no target (should crash)
        """
        with self.assertRaises(SystemExit) as se:

            # empty response
            reasoner_std = { "query_graph": dict(),
                             "knowledge_graph": dict(),
                             "results": list()
                           }
            # empty query graph
            reasoner_std["query_graph"] = { "edges": dict(),
                                            "nodes": dict()
                                          }
            # empty knowledge graph
            reasoner_std["knowledge_graph"] = { "edges": dict(),
                                                "nodes": dict()
                                              }

            handler = ReasonerStdHandler(source_ara='default',
                                         dict_query=reasoner_std)
            queries = handler.buildChpQueries()
        self.assertEqual(se.exception.code, 'Survival Node not found. Node category must be \'biolink:PhenotypicFeature\' and id must be in: EFO:0000714')
 def test_no_target(self):
     with self.assertRaises(SystemExit) as se:
         # empty response
         reasoner_std = {
             "query_graph": dict(),
             "knowledge_graph": dict(),
             "response": dict()
         }
         # empty query graph
         reasoner_std["query_graph"] = {"edges": [], "nodes": []}
         # empty knowledge graph
         reasoner_std["knowledge_graph"] = {"edges": [], "nodes": []}
         # empty response graph
         reasoner_std["results"] = {
             "node_bindings": [],
             "edge_bindings": []
         }
         handler = ReasonerStdHandler(source_ara='exploring',
                                      dict_query=reasoner_std)
         queries = handler.buildChpQueries()
     self.assertEqual(
         se.exception.code,
         'Survival Node not found. Node type muse be \'PhenotypicFeature\' and curie must be in: EFO:0000714'
     )
    def test_drug(self):
        """ queries Cyclophosphamide which has no sparsity issue. Should return
            top 5 genes and a probability of survival
        """

        # empty response
        reasoner_std = {
            "query_graph": {},
            "knowledge_graph": {},
            "results": []
        }
        # empty query graph
        reasoner_std["query_graph"] = {"edges": {}, "nodes": {}}
        # empty knowledge graph
        reasoner_std["knowledge_graph"] = {"edges": {}, "nodes": {}}

        # add in evidence drug
        drug = ('CYCLOPHOSPHAMIDE', 'CHEMBL:CHEMBL88')
        reasoner_std['query_graph']['nodes']['n0'] = {
            'category': 'biolink:Drug',
            'id': '{}'.format(drug[1])
        }

        # add in gene node (to be filled by contribution analysis
        reasoner_std['query_graph']['nodes']['n1'] = {
            'category': 'biolink:Gene'
        }

        #add in disease node
        disease = ('Breast_Cancer', 'MONDO:0007254')
        reasoner_std['query_graph']['nodes']['n2'] = {
            'category': 'biolink:Disease',
            'id': '{}'.format(disease[1])
        }

        # add target survival node
        phenotype = ('Survival_Time', 'EFO:0000714')
        reasoner_std['query_graph']['nodes']['n3'] = {
            'category': 'biolink:PhenotypicFeature',
            'id': '{}'.format(phenotype[1]),
        }

        # link disease to target survival node
        reasoner_std['query_graph']['edges']['e0'] = {
            'predicate': 'biolink:DiseaseToPhenotypicFeatureAssociation',
            'subject': 'n2',
            'object': 'n3',
            'properties': {
                'qualifier': '>=',
                'days': 940
            }
        }

        # link genes/drugs to disease
        reasoner_std['query_graph']['edges']['e1'] = {
            'predicate': 'biolink:GeneToDiseaseAssociation',
            'subject': 'n1',
            'object': 'n2'
        }
        reasoner_std['query_graph']['edges']['e2'] = {
            'predicate':
            'biolink:ChemicalToDiseaseOrPhenotypicFeatureAssociation',
            'subject': 'n0',
            'object': 'n2'
        }

        handler = ReasonerStdHandler(source_ara='default',
                                     dict_query=reasoner_std,
                                     max_results=5)
        queries = handler.buildChpQueries()
        queries = handler.runChpQueries()
        reasoner_std_final = handler.constructDecoratedKG()

        KG = reasoner_std_final["message"]['knowledge_graph']

        res_pretty = json.dumps(reasoner_std_final, indent=2)
        print(res_pretty)

        # extract probability
        for _, edge in KG['edges'].items():
            if edge['predicate'] == 'biolink:DiseaseToPhenotypicFeatureAssociation':
                p_survival = edge['has_confidence_level']
                #gene_contribs = edge['Description']
                break
        print("probability of survival:", p_survival)
 def test_normal_two_genes_and_drug(self):
     # empty response
     reasoner_std = {
         "query_graph": dict(),
         "knowledge_graph": dict(),
         "response": dict()
     }
     # empty query graph
     reasoner_std["query_graph"] = {"edges": [], "nodes": []}
     # empty knowledge graph
     reasoner_std["knowledge_graph"] = {"edges": [], "nodes": []}
     # empty response graph
     reasoner_std["results"] = {"node_bindings": [], "edge_bindings": []}
     # add in evidence gene
     gene1 = ('RAF1', 'ENSEMBL:ENSG00000132155')
     reasoner_std['query_graph']['nodes'].append({
         'id':
         'n{}'.format('0'),
         'type':
         'Gene',
         'curie':
         '{}'.format(gene1[1])
     })
     # add in second evidence gene
     gene2 = ('BRCA1', 'ENSEMBL:ENSG00000012048')
     reasoner_std['query_graph']['nodes'].append({
         'id':
         'n{}'.format('1'),
         'type':
         'Gene',
         'curie':
         '{}'.format(gene2[1])
     })
     # add in evidence drug
     drug = ('CYCLOPHOSPHAMIDE', 'CHEMBL:CHEMBL88')
     reasoner_std['query_graph']['nodes'].append({
         'id':
         'n{}'.format('2'),
         'type':
         'Drug',
         'curie':
         '{}'.format(drug[1])
     })
     # add in disease node
     disease = ('Breast_Cancer', 'MONDO:0007254')
     reasoner_std['query_graph']['nodes'].append({
         'id':
         'n{}'.format('3'),
         'type':
         'disease',
         'curie':
         '{}'.format(disease[1])
     })
     # add target survival node
     phenotype = ('Survival_Time', 'EFO:0000714')
     reasoner_std['query_graph']['nodes'].append({
         'id':
         'n{}'.format('4'),
         'type':
         'PhenotypicFeature',
         'curie':
         '{}'.format(phenotype[1]),
     })
     # link genes/drugs to disease
     reasoner_std['query_graph']['edges'].append({
         'id':
         'e{}'.format('0'),
         'type':
         'gene_to_disease_association',
         'source_id':
         'n{}'.format('0'),
         'target_id':
         'n{}'.format('3')
     })
     reasoner_std['query_graph']['edges'].append({
         'id':
         'e{}'.format('1'),
         'type':
         'gene_to_disease_association',
         'source_id':
         'n{}'.format('1'),
         'target_id':
         'n{}'.format('3')
     })
     reasoner_std['query_graph']['edges'].append({
         'id':
         'e{}'.format('2'),
         'type':
         'chemical_to_disease_or_phenotypic_feature_association',
         'source_id':
         'n{}'.format('2'),
         'target_id':
         'n{}'.format('3')
     })
     # link disease to target
     reasoner_std['query_graph']['edges'].append({
         'id':
         'e{}'.format('3'),
         'type':
         'disease_to_phenotype_association',
         'value':
         970,
         'source_id':
         'n{}'.format('3'),
         'target_id':
         'n{}'.format('4')
     })
     handler = ReasonerStdHandler(source_ara='exploring',
                                  dict_query=reasoner_std)
     queries = handler.buildChpQueries()
     queries = handler.runChpQueries()
     reasoner_std_final = handler.constructDecoratedKG()
     KG = reasoner_std_final['knowledge_graph']
     for edge in KG['edges']:
         if edge['type'] == 'disease_to_phenotype_association':
             p_survival = edge['has_confidence_level']
     print("probability of survival:", p_survival)
        'source_id':
        'n{}'.format(nodeCount - 2),
        'target_id':
        'n{}'.format(nodeCount - 1)
    })
    edgeCount += 1

    # BKB target
    response['probability_targets'] = [('Survival_Time', '>=', 1000)]

    with open('sample_query1.pk', 'wb') as f_:
        pickle.dump(response, f_)

handler = ReasonerStdHandler(source_ara='unsecret', dict_query=response)

queries = handler.buildChpQueries()
queries = handler.runChpQueries()
reasoner_std_final = handler.constructDecoratedKG()
#print(reasoner_std_final)
'''
#-- Get all options to fill query graph edges
options = dict()
for edge in reasoner_std['query_graph']['edges']:
    options[edge['id']] = []
for result in reasoner_std['results']['edge_bindings']:
    for qg_id, kg_ids in result.items():
        options[qg_id].append(kg_ids[0])

#-- Hash edges by ID
edges = {edge['id']: edge for edge in reasoner_std['knowledge_graph']['edges']}
nodes = {node['id']: node for node in reasoner_std['knowledge_graph']['nodes']}