<jupyter_start><jupyter_text>Important prerequisite1. The package doesn't work with the newest version of Jupyter Notebook, run the following commands in your terminal before initiating the Notebook2. pip install notebook==5.7.53. pip install tornado==4.5.3  Install dependencies Don't worry about the error messages during installation, you will be fine.<jupyter_code># uncomment the following line if you haven't installed bte_schema
# !pip install git+https://github.com/kevinxin90/bte_schema#egg=bte_schema
# uncomment the following line if you haven't installed biothings_schema
#pip install git+https://github.com/biothings/biothings_schema.py#egg=biothings_schema.py<jupyter_output><empty_output><jupyter_text>Initiating the package<jupyter_code># import the query module
from biothings_explorer.user_query_dispatcher import SingleEdgeQueryDispatcher
# import the hint module (suggest hits based on your input)
from biothings_explorer.hint import Hint
# import the registry module
from biothings_explorer.registry import Registry
reg = Registry()
ht = Hint()<jupyter_output><empty_output><jupyter_text>Feature 1: Single Hop QueryQuery from a specific biological entity (e.g. entrezgene 1017) to other semantic types (e.g. ChemicalSubstance)  The example below will query all ChemicalSubstances related to Entrezgene 1017  Step1: Get your input<jupyter_code># use the hint the module to let BioThings Explorer suggest the inputs for you
a = ht.query('1019')
# the output of the hint module is grouped by semantic types
a
# select your input object
input_obj = a['Gene'][0]
input_obj<jupyter_output><empty_output><jupyter_text>Step2: Make Single Hop Query A couple required parameters in order to perform the query:1. input_obj: This is the object which serves as the start point of your query.2. output_cls: This is the output class which serves as the end point of your query. If you don't specify this parameter, this tool will automatically search all possible output classes for you.3. output_id: This is optional. The identifier type you want the output to be.4. pred: This is also optional. The predicate linking your input and output. If you don't specify, this tool will automatically search all possible linkages.<jupyter_code>seqd = SingleEdgeQueryDispatcher(input_obj=input_obj,
                                 output_cls='ChemicalSubstance',
                                 output_id='bts:chembl',
                                 registry=reg)
seqd.query()<jupyter_output><empty_output><jupyter_text>Step3: Understand the results The result of the query would be a networkx MultiDiGraph connecting from your input to all possible outputs.  Show results in JSON format nodes: All nodes in the graphlinks: All edges in the graph<jupyter_code>seqd.to_json()<jupyter_output><empty_output><jupyter_text>List all output ids<jupyter_code>seqd.output_ids<jupyter_output><empty_output><jupyter_text>Dig deep into the network<jupyter_code># List all nodes
seqd.show_all_nodes()
# list all edges
seqd.show_all_edges()
# see details of a specific edge
seqd.display_edge_info('1019', 'CHEMBL448')
# see details of a specific node
seqd.display_node_info('CHEMBL448')<jupyter_output><empty_output><jupyter_text>(Optional) Do it the hard way You can still use this tool without the hint module. In this case, specify your parameters as the following:1. input_cls: required, The semantic type of your input2. input_id: required, The identifier type of your input3. values: required, The input value4. output_cls: required, The semantic type of your output5. output_id: optional, the identifier type of your output<jupyter_code>seqd = SingleEdgeQueryDispatcher(input_cls="Gene",
                                 input_id="bts:entrez",
                                 values="1019",
                                 output_cls="ChemicalSubstance",
                                 output_id="bts:chembl",
                                 registry=reg)
seqd.query()
seqd.G.nodes()<jupyter_output><empty_output><jupyter_text>Feature 2: Multi Hop Query Query from a specific biological entity (e.g. entrezgene 1017) to other semantic types (e.g. ChemicalSubstance) through multiple hops, e.g. ChemicalSubstance -> Gene -> Disease<jupyter_code># Initiate the multi hop module
from biothings_explorer.user_query_dispatcher import MultiEdgeQueryDispatcher<jupyter_output><empty_output><jupyter_text>The tutorial below create edges from Riluzole(ChemicalSubstance) to Gene, then to Disease, which is to first find genes related to riluzole, and then find diseases related to genes  Step1: Decide on your input<jupyter_code>a = ht.query('riluzole')
a
input_obj = a['ChemicalSubstance'][0]
input_obj<jupyter_output><empty_output><jupyter_text>Step2: Construct your edges the format of edges should be like [(subject1, pred1, object1), (subject2, pred2, object2), ...]The object of an edge should always be the same as the subject of its proceeding edge Note: You can leave pred as None. In this case, the tool will search for all potential edges<jupyter_code>edges = [('ChemicalSubstance', None, 'Gene'), ('Gene', None, 'DiseaseOrPhenotypicFeature')]<jupyter_output><empty_output><jupyter_text>Step3: Execute the query<jupyter_code>meqd = MultiEdgeQueryDispatcher(input_obj=input_obj,
                                edges=edges,
                                registry=reg)
meqd.query()<jupyter_output>start to query for associations between ChemicalSubstance and Gene...
finished! Find 23 hits.
start to query for associations between Gene and DiseaseOrPhenotypicFeature...
finished! Find 741 hits.<jupyter_text>Step4: Explore the results<jupyter_code># show all nodes in the graph
meqd.show_all_nodes()
# Display the path connecting two nodes in the graph
meqd.show_path('CHEMBL744', 'MONDO:0011376')
# Display detailed edge information
meqd.display_edge_info('CHEMBL744', '6331')
# display detailed edge information
meqd.display_edge_info('6331', 'MONDO:0011376')
meqd.display_node_info('MONDO:0011376')<jupyter_output><empty_output><jupyter_text>Feature3: Discover connections between two bio-entitiesFind connections between two bio-entities through one or more intermediate nodes<jupyter_code># initialize the connect module
from biothings_explorer.user_query_dispatcher import Connect<jupyter_output><empty_output><jupyter_text>Step 1: Decide on your input and output<jupyter_code># search for riluzole
a = ht.query("riluzole")
a
# select the input object from the hint results
input_obj = a['ChemicalSubstance'][0]
input_obj
# search for "Amyotrophic Lateral Sclerosis"
b = ht.query("Amyotrophic Lateral Sclerosis")
b
# select the output object from the hint results
output_obj = b['DiseaseOrPhenotypicFeature'][0]
output_obj<jupyter_output><empty_output><jupyter_text>Step2: Find connections between your input and output<jupyter_code>cc = Connect(input_obj=input_obj, output_obj=output_obj, registry=reg)
cc.connect()<jupyter_output>processing step 1 ...
processing step 2 ...
query completed
Find connection<jupyter_text>Step3: Find how your input and output is connected<jupyter_code># find the path connecting from your input to output
cc.show_path()
# show detailed edge information
cc.display_edge_info(start_node='CHEMBL744', end_node="6332")
# show detailed edge information
cc.display_edge_info(start_node="6332", end_node="MONDO:0004976")
# return the graph connectin from input to output in JSON
cc.to_json()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup