def setUpClass(cls): ht = Hint() cxcr4 = ht.query("CXCR4")["Gene"][0] fc = FindConnection(input_obj=cxcr4, output_obj="ChemicalSubstance", intermediate_nodes=None) fc.connect(verbose=True) cls.response = fc.to_reasoner_std()
def setUp(self): ht = Hint() cxcr4 = ht.query('CXCR4')['Gene'][0] fc = FindConnection(input_obj=cxcr4, output_obj='ChemicalSubstance', intermediate_nodes=None) fc.connect(verbose=True) self.response = fc.to_reasoner_std()
def test_one_filt(self): ht = Hint() input = ht.query('hyperphenylalaninemia')['Disease'][0] filt = [{}, {'name': 'NodeDegree', 'count': 25}] fc = FindConnection(input_obj=input, output_obj='ChemicalSubstance', intermediate_nodes=['Gene'], filters=filt) fc.connect() self.assertEqual(27, len(fc.fc.G.nodes))
def test_no_filter(self): ht = Hint() input = ht.query('hyperphenylalaninemia')['Disease'][0] filt = [] fc = FindConnection(input_obj=input, output_obj='ChemicalSubstance', intermediate_nodes=['Gene'], filters=filt) fc.connect() for node, y in fc.fc.G.nodes(data=True): self.assertTrue('filteredBy' not in y.keys())
class TestHint(unittest.TestCase): def setUp(self): self.ht = Hint() def test_gene_entrez_id_as_input(self): """test the output of Hint query when providing gene entrez id as input""" res = self.ht.query('1017') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['entrez'], '1017') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'entrez') self.assertEqual(bioentity['primary']['value'], '1017') self.assertEqual(bioentity['symbol'], 'CDK2') def test_gene_symbol_as_input(self): """test the output of Hint query when providing gene symbol as input""" res = self.ht.query('CDK2') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['entrez'], '1017') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'entrez') self.assertEqual(bioentity['primary']['value'], '1017') self.assertEqual(bioentity['symbol'], 'CDK2') def test_gene_umls_id_as_input(self): """test the output of Hint query when providing gene umls id as input""" res = self.ht.query('C1332823') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['entrez'], '7852') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'entrez') self.assertEqual(bioentity['primary']['value'], '7852') self.assertEqual(bioentity['symbol'], 'CXCR4')
def test_two_filt(self): ht = Hint() input = ht.query('hyperphenylalaninemia')['Disease'][0] filt = [{ 'name': 'NodeDegree', 'count': 20 }, { 'name': 'EdgeLabel', 'label': 'related_to' }] fc = FindConnection(input_obj=input, output_obj='ChemicalSubstance', intermediate_nodes=['Gene'], filters=filt) fc.connect() self.assertEqual(52, len(fc.fc.G.nodes)) for node, y in fc.fc.G.nodes(data=True): if node != 'mild hyperphenylalaninemia': if y['type'] == 'Gene': self.assertEqual('NodeDegree', y['filteredBy']) elif y['type'] == 'ChemicalSubstance': self.assertEqual('EdgeLabel', y['filteredBy'])
class TestHint(unittest.TestCase): def setUp(self): self.ht = Hint() def mygene_test(self, res): self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['NCBIGene'], '1017') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'NCBIGene') self.assertEqual(bioentity['primary']['value'], '1017') self.assertEqual(bioentity['SYMBOL'], 'CDK2') def myvariant_test(self, res): self.assertIsNotNone(res) self.assertIsNotNone(res.get('SequenceVariant')) self.assertIsNotNone(res.get('SequenceVariant')[0]) bioentity = res.get('SequenceVariant')[0] self.assertEqual(bioentity['DBSNP'], 'rs12190874') self.assertEqual(bioentity['type'], 'SequenceVariant') self.assertEqual(bioentity['primary']['identifier'], 'DBSNP') self.assertEqual(bioentity['primary']['value'], 'rs12190874') def test_gene_NCBIGene_id_as_input(self): """Test the output of Hint query when providing gene NCBIGene id as input.""" res = self.ht.query('1017') self.mygene_test(res) def test_gene_SYMBOL_as_input(self): """Test the output of Hint query when providing gene SYMBOL as input.""" res = self.ht.query('CDK2') self.mygene_test(res) def test_gene_UMLS_id_as_input(self): """Test the output of Hint query when providing gene UMLS id as input.""" res = self.ht.query('C1332823') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['UMLS'], 'C1332823') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'NCBIGene') self.assertEqual(bioentity['primary']['value'], '7852') self.assertEqual(bioentity['SYMBOL'], 'CXCR4') def test_gene_hgnc_id_as_input(self): """Test the output of Hint query when providing gene hgnc id as input.""" res = self.ht.query('1771') self.mygene_test(res) def test_gene_uniprot_id_as_input(self): """Test the output of Hint query when providing gene uniprot id as input.""" res = self.ht.query('P24941') self.mygene_test(res) def test_variant_rsid_as_input(self): """Test the output of Hint query when providing variant dbsnp id as input.""" res = self.ht.query('rs12190874') self.myvariant_test(res) def test_variant_hgvs_as_input(self): """Test the output of Hint query when providing variant hgvs id as input.""" res = self.ht.query('chr6:g.42454850G>A') self.myvariant_test(res) def test_chemical(self): """Test the output of Hint query when providing chemical drugbank ID as input.""" res = self.ht.query("DB01926") bioentity = res.get('ChemicalSubstance')[0] self.assertIsNotNone(res) self.assertEqual(bioentity['name'], 'Carboxymycobactin S')
def step_impl(context, name): ht = Hint() disease_hint = ht.query(name) context.disease = disease_hint['DiseaseOrPhenotypicFeature'][0]
class TestHint(unittest.TestCase): def setUp(self): self.ht = Hint() def mygene_test(self, res): self.assertIsNotNone(res) self.assertIsNotNone(res.get("Gene")) self.assertIsNotNone(res.get("Gene")[0]) bioentity = res.get("Gene")[0] self.assertEqual(bioentity["NCBIGene"], "1017") self.assertEqual(bioentity["type"], "Gene") self.assertEqual(bioentity["primary"]["identifier"], "NCBIGene") self.assertEqual(bioentity["primary"]["value"], "1017") self.assertEqual(bioentity["SYMBOL"], "CDK2") def myvariant_test(self, res): self.assertIsNotNone(res) self.assertIsNotNone(res.get("SequenceVariant")) self.assertIsNotNone(res.get("SequenceVariant")[0]) bioentity = res.get("SequenceVariant")[0] self.assertEqual(bioentity["DBSNP"], "rs12190874") self.assertEqual(bioentity["type"], "SequenceVariant") self.assertEqual(bioentity["primary"]["identifier"], "DBSNP") self.assertEqual(bioentity["primary"]["value"], "rs12190874") def test_gene_NCBIGene_id_as_input(self): """Test the output of Hint query when providing gene NCBIGene id as input.""" res = self.ht.query("1017") self.mygene_test(res) def test_gene_SYMBOL_as_input(self): """Test the output of Hint query when providing gene SYMBOL as input.""" res = self.ht.query("CDK2") self.mygene_test(res) def test_gene_UMLS_id_as_input(self): """Test the output of Hint query when providing gene UMLS id as input.""" res = self.ht.query("C1332823") self.assertIsNotNone(res) self.assertIsNotNone(res.get("Gene")) self.assertIsNotNone(res.get("Gene")[0]) bioentity = res.get("Gene")[0] self.assertEqual(bioentity["UMLS"], "C1332823") self.assertEqual(bioentity["type"], "Gene") self.assertEqual(bioentity["primary"]["identifier"], "NCBIGene") self.assertEqual(bioentity["primary"]["value"], "7852") self.assertEqual(bioentity["SYMBOL"], "CXCR4") def test_gene_hgnc_id_as_input(self): """Test the output of Hint query when providing gene hgnc id as input.""" res = self.ht.query("1771") self.assertIsNotNone(res) self.assertIsNotNone(res.get("Gene")) self.assertIsNotNone(res.get("Gene")[0]) bioentity = [ item for item in res.get("Gene") if item.get("HGNC") == "1771" ][0] self.assertEqual(bioentity["type"], "Gene") self.assertEqual(bioentity["primary"]["identifier"], "NCBIGene") self.assertEqual(bioentity["primary"]["value"], "1017") def test_gene_uniprot_id_as_input(self): """Test the output of Hint query when providing gene uniprot id as input.""" res = self.ht.query("P24941") self.mygene_test(res) def test_variant_rsid_as_input(self): """Test the output of Hint query when providing variant dbsnp id as input.""" res = self.ht.query("rs12190874") self.myvariant_test(res) def test_chemical(self): """Test the output of Hint query when providing chemical drugbank ID as input.""" res = self.ht.query("DB01926") bioentity = res.get("ChemicalSubstance")[0] self.assertIsNotNone(res) self.assertEqual(bioentity["name"], "Carboxymycobactin S") def test_chemical_with_cas_id(self): """Test the output of Hint query when providing chemical CAS ID as input.""" res = self.ht.query("1744-22-5") bioentity = res.get("ChemicalSubstance")[0] self.assertIsNotNone(res) self.assertEqual(bioentity["CHEMBL.COMPOUND"], "CHEMBL744") def test_chemical_with_iupac_id(self): """Test the output of Hint query when providing chemical IUPAC ID as input.""" res = self.ht.query( "[6-(trifluoromethoxy)-1,3-benzothiazol-2-yl]amine") bioentity = res.get("ChemicalSubstance")[0] self.assertIsNotNone(res) self.assertEqual(bioentity["IUPAC"], "[6-(trifluoromethoxy)-1,3-benzothiazol-2-yl]amine") def test_chemical_with_formula(self): """Test the output of Hint query when providing chemical formula as input.""" res = self.ht.query("H2O") bioentity = res.get("ChemicalSubstance")[0] self.assertIsNotNone(res) self.assertEqual(bioentity["formula"], "H2O") def test_chemical_with_abbreviations(self): """Test the output of Hint query when providing chemical abbreviations as input.""" res = self.ht.query("AZT") names = [item.get("name") for item in res.get("ChemicalSubstance")] self.assertIsNotNone(res) self.assertIn("zidovudine", names) def test_chemical_with_international_brand_names(self): """Test the output of Hint query when providing drug international brand name as input.""" res = self.ht.query("Dulane") names = [item.get("name") for item in res.get("ChemicalSubstance")] self.assertIsNotNone(res) self.assertIn("DULOXETINE", names) def test_mf_with_lowercase_go_term(self): """Test the output of Hint query when providing lower case go term as input.""" res = self.ht.query("go:0001790") bioentity = res.get("MolecularActivity")[0] self.assertIsNotNone(res) self.assertEqual(bioentity["GO"], "GO:0001790") def test_bp_with_lowercase_go_term(self): """Test the output of Hint query when providing lower case go term as input.""" res = self.ht.query("go:0002354") bioentity = res.get("BiologicalProcess")[0] self.assertIsNotNone(res) self.assertEqual(bioentity["GO"], "GO:0002354") def test_cc_with_lowercase_go_term(self): """Test the output of Hint query when providing lower case go term as input.""" res = self.ht.query("go:1903503") bioentity = res.get("CellularComponent")[0] self.assertIsNotNone(res) self.assertEqual(bioentity["GO"], "GO:1903503") def test_anatomy_with_uberon_id(self): """Test the output of Hint query when providing UBERON ID as input.""" res = self.ht.query("UBERON:0035924") bioentity = res.get("AnatomicalEntity")[0] self.assertIsNotNone(res) self.assertEqual(bioentity["UBERON"], "UBERON:0035924") def test_resolving_by_synonyms(self): """Test the output of Hint query when providing disease synonyms""" res = self.ht.query("GIST") bioentity = res.get("Disease") ids = [item.get("MONDO") for item in bioentity] self.assertIsNotNone(res) self.assertIn("MONDO:0011719", ids)
from biothings_explorer.hint import Hint import json from .base import BaseHandler ht = Hint() class HintHandler(BaseHandler): def get(self): _input = self.get_query_argument('q', None) print('input is {}'.format(_input)) if _input: result = ht.query(_input) self.set_status(200) self.write(json.dumps(result)) self.finish() else: self.set_status(400) self.write(json.dumps({'No input is found'}))
def getDrugHints(drug): hint = Hint() ht = hint.query(drug) return {ImmutableHint(ht): drug}
def getGeneHints(gene): hint = Hint() ht = hint.query(gene) return {ImmutableHint(ht): gene}
def getCancerHints(cancer): hint = Hint() ht = hint.query(cancer) return {ImmutableHint(ht): cancer}
def step_impl(context, disease, chemical): ht = Hint() context.disease = ht.query(disease)['DiseaseOrPhenotypicFeature'][0] context.chemical = ht.query(chemical)['ChemicalSubstance'][0]
class TestHint(unittest.TestCase): def setUp(self): self.ht = Hint() def test_gene_entrez_id_as_input(self): """Test the output of Hint query when providing gene entrez id as input.""" res = self.ht.query('1017') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['entrez'], '1017') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'entrez') self.assertEqual(bioentity['primary']['value'], '1017') self.assertEqual(bioentity['symbol'], 'CDK2') def test_gene_symbol_as_input(self): """Test the output of Hint query when providing gene symbol as input.""" res = self.ht.query('CDK2') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['entrez'], '1017') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'entrez') self.assertEqual(bioentity['primary']['value'], '1017') self.assertEqual(bioentity['symbol'], 'CDK2') def test_gene_umls_id_as_input(self): """Test the output of Hint query when providing gene umls id as input.""" res = self.ht.query('C1332823') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['umls'], 'C1332823') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'entrez') self.assertEqual(bioentity['primary']['value'], '7852') self.assertEqual(bioentity['symbol'], 'CXCR4') def test_gene_hgnc_id_as_input(self): """Test the output of Hint query when providing gene hgnc id as input.""" res = self.ht.query('1771') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['hgnc'], '1771') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'entrez') self.assertEqual(bioentity['primary']['value'], '1017') self.assertEqual(bioentity['symbol'], 'CDK2') def test_gene_uniprot_id_as_input(self): """Test the output of Hint query when providing gene uniprot id as input.""" res = self.ht.query('P24941') self.assertIsNotNone(res) self.assertIsNotNone(res.get('Gene')) self.assertIsNotNone(res.get('Gene')[0]) bioentity = res.get('Gene')[0] self.assertEqual(bioentity['uniprot'], 'P24941') self.assertEqual(bioentity['type'], 'Gene') self.assertEqual(bioentity['primary']['identifier'], 'entrez') self.assertEqual(bioentity['primary']['value'], '1017') self.assertEqual(bioentity['symbol'], 'CDK2') def test_variant_rsid_as_input(self): """Test the output of Hint query when providing variant dbsnp id as input.""" res = self.ht.query('rs12190874') self.assertIsNotNone(res) self.assertIsNotNone(res.get('SequenceVariant')) self.assertIsNotNone(res.get('SequenceVariant')[0]) bioentity = res.get('SequenceVariant')[0] self.assertEqual(bioentity['dbsnp'], 'rs12190874') self.assertEqual(bioentity['type'], 'SequenceVariant') self.assertEqual(bioentity['primary']['identifier'], 'dbsnp') self.assertEqual(bioentity['primary']['value'], 'rs12190874') self.assertEqual(bioentity['hgvs'], 'chr6:g.42454850G>A') def test_variant_hgvs_as_input(self): """Test the output of Hint query when providing variant hgvs id as input.""" res = self.ht.query('chr6:g.42454850G>A') self.assertIsNotNone(res) self.assertIsNotNone(res.get('SequenceVariant')) self.assertIsNotNone(res.get('SequenceVariant')[0]) bioentity = res.get('SequenceVariant')[0] self.assertEqual(bioentity['hgvs'], 'chr6:g.42454850G>A') self.assertEqual(bioentity['type'], 'SequenceVariant') self.assertEqual(bioentity['primary']['identifier'], 'dbsnp') self.assertEqual(bioentity['primary']['value'], 'rs12190874')
from biothings_explorer.hint import Hint from biothings_explorer.user_query_dispatcher import FindConnection ht = Hint() ace2 = ht.query("ACE2")['Gene'][0] # print(ace2) fc = FindConnection(input_obj=ace2, output_obj='DiseaseOrPhenotypicFeature', intermediate_nodes='ChemicalSubstance') fc.connect(verbose=True) # save graphml file to test.graphml output = fc.to_graphml("test.graphml")
import numpy as np import pickle import os from biothings_explorer.hint import Hint from biothings_explorer.user_query_dispatcher import FindConnection from chp.core.query import Query from chp.core.reasoner_std import ReasonerStdHandler query_path = '/home/cyakaboski/src/python/projects/bkb-pathway-provider/tests/reasonerStdTests/sample_query.pk' if os.path.exists(query_path): with open(query_path, 'rb') as f_: reasoner_std = pickle.load(f_) else: ht = Hint() breast_cancer = ht.query('breast cancer')['Disease'][0] tamoxifin = ht.query('tamoxifen')['ChemicalSubstance'][0] fc = FindConnection(input_obj=breast_cancer, output_obj=tamoxifin, intermediate_nodes='Gene') fc.connect(verbose=True) reasoner_std = fc.to_reasoner_std() #-- Add target node and edge to Query Graph reasoner_std['query_graph']['nodes'].append({ 'id': 't1', 'type': 'PhenotypicFeature',
from biothings_explorer.hint import Hint ht = Hint() # produce a python dictionary containing covid related information covid_hint = ht.query('covid-19') # they keys to access the dictionary - most are empty except for the Disease tab print(covid_hint.keys()) # covid disease information print(covid_hint['Disease']) # iterate the items under the disease tab for h_t in covid_hint['Disease']: print(h_t) # Each h_t is in of itself a dictionary object that can be indexed with its own set of keys. # What might be confusing is what 'MONDO' is. This is what is called a curie identifier. # Curie identifiers are unique names within some dataase or ontology. In this case MONDO is # an ontology. For example the unique curie identifier that map to the ontology names are: for h_t in covid_hint['Disease']: print("Printing Mondo:") print(h_t['MONDO'] + "\n") print("Printing name") print(h_t['name'])
# import modules from biothings_explorer from biothings_explorer.hint import Hint from biothings_explorer.user_query_dispatcher import FindConnection ht = Hint() # Find all potential representations of TBI tbi_hint = ht.query("traumatic brain injury") print(tbi_hint) print() # Select the correct representation of TBI tbi = tbi_hint["Disease"][0] print(tbi) print() # Find all potential representations of unipolar depression depression_hint = ht.query("unipolar depression") print(depression_hint) print() # Select the correct representation of depression depression = depression_hint["Disease"][0] print(depression) print() # help(FindConnection.__init__) fc = FindConnection(input_obj=depression, output_obj=tbi, intermediate_nodes="BiologicalEntity") # BTE finding connection fc.connect(verbose=True) print()
def setUp(self): self.ht = Hint()
def step_impl(context, symbol): ht = Hint() gene_hint = ht.query(symbol) context.gene = gene_hint['Gene'][0]