<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Introduction
This notebook demonstrates basic usage of BioThings Explorer, an engine for autonomously querying a distributed knowledge graph. BioThings Explorer can answer two classes of queries -- "EXPLAIN" and "PREDICT".  EXPLAIN queries are described in EXPLAIN_demo.ipynb. Here, we describe PREDICT queries and how to use BioThings Explorer to execute them.  A more detailed overview of the BioThings Explorer systems is provided in these slides.
PREDICT queries are designed to predict plausible relationships between one entity and an entity class.  For example, in this notebook, we explore the question
Step1:  Next, import the relevant modules
Step2:  Step 1
Step3:  Step 2
Step4:  Here, we formulate a FindConnection query with "hyperphenylalaninemia" as the input_ojb, "ChemicalSubstance" as the output_obj (which corresponds to a Biolink Entity type).  We further specify with the intermediate_nodes parameter that we are looking for paths joining hyperphenylalaninemia and chemical compounds with one intermediate node that is a Gene.  (The ability to search for longer reasoning paths that include additional intermediate nodes will be added shortly.)
Step5:  We next execute the connect method, which performs the query path planning and query path execution process.  In short, BioThings Explorer is deconstructing the query into individual API calls, executing those API calls, then assembling the results.
A verbose log of this process is displayed below
Step6:  Step 3
Step7:  While most results are based on edges from semmed, edges from DGIdb, biolink, disgenet, and mychem.info were also retrieved from their respective APIs. 
Next, let's examine which chemical compounds were most frequently mentioned.
Step8:  Hyperphenylalaninemia is a condition characterized by elevated levels of phenylalanine in the blood. This phenotype is strongly associated with phenylketonuria (PKU), an inherited, genetic disorder that affects the ability to metabolize phenylalanine.  Sapropterin is a naturally-occurring cofactor associated with several enzymatic processes, including the metabolism of phenylalanine to tyrosine. It has been FDA-approved as a treatment for PKU patients.  Tyrosine is also a precursor to several neurotransmitters, including norepinephrine and dopamine.
While several of the listed compounds would be considered positive controls, others on the list could be viewed as testable hypotheses and discovery opportunities to be evaluated by domain experts. For example, let's examine which genes link hyperphenylalaninemia to nitric oxide.
<ASSISTANT_TASK:>
Python Code:
%%capture
!pip install git+https://github.com/biothings/biothings_explorer#egg=biothings_explorer
Explanation: Introduction
This notebook demonstrates basic usage of BioThings Explorer, an engine for autonomously querying a distributed knowledge graph. BioThings Explorer can answer two classes of queries -- "EXPLAIN" and "PREDICT".  EXPLAIN queries are described in EXPLAIN_demo.ipynb. Here, we describe PREDICT queries and how to use BioThings Explorer to execute them.  A more detailed overview of the BioThings Explorer systems is provided in these slides.
PREDICT queries are designed to predict plausible relationships between one entity and an entity class.  For example, in this notebook, we explore the question:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"What drugs might be used to treat hyperphenylalaninemia?"
To experiment with an executable version of this notebook, load it in Google Colaboratory.
Step 0: Load BioThings Explorer modules
First, install the biothings_explorer and biothings_schema packages, as described in this README.  This only needs to be done once (but including it here for compability with colab).
End of explanation
# import modules from biothings_explorer
from biothings_explorer.hint import Hint
from biothings_explorer.user_query_dispatcher import FindConnection
import nest_asyncio
nest_asyncio.apply()
Explanation: Next, import the relevant modules:
Hint: Find corresponding bio-entity representation used in BioThings Explorer based on user input (could be any database IDs, symbols, names)
FindConnection: Find intermediate bio-entities which connects user specified input and output
End of explanation
ht = Hint()
# find all potential representations of hyperphenylalaninemia
hyperphenylalaninemia_hint = ht.query("hyperphenylalaninemia")
# select the correct representation of hyperphenylalaninemia
hyperphenylalaninemia = hyperphenylalaninemia_hint['Disease'][0]
hyperphenylalaninemia
Explanation: Step 1: Find representation of "hyperphenylalaninemia" in BTE
In this step, BioThings Explorer translates our query string "hyperphenylalaninemia"  into BioThings objects, which contain mappings to many common identifiers.  Generally, the top result returned by the Hint module will be the correct item, but you should confirm that using the identifiers shown.
Search terms can correspond to any child of BiologicalEntity from the Biolink Model, including DiseaseOrPhenotypicFeature (e.g., "lupus"), ChemicalSubstance (e.g., "acetaminophen"), Gene (e.g., "CDK2"), BiologicalProcess (e.g., "T cell differentiation"), and Pathway (e.g., "Citric acid cycle").
End of explanation
help(FindConnection.__init__)
Explanation: Step 2: Find drugs that are associated with genes which invovled in hyperphenylalaninemia
In this section, we find all paths in the knowledge graph that connect hyperphenylalaninemia to any entity that is a chemical compound.  To do that, we will use FindConnection.  This class is a convenient wrapper around two advanced functions for query path planning and query path execution. More advanced features for both query path planning and query path execution are in development and will be documented in the coming months. 
The parameters for FindConnection are described below:
End of explanation
fc = FindConnection(input_obj=hyperphenylalaninemia, output_obj='ChemicalSubstance', intermediate_nodes=['Gene'])
Explanation: Here, we formulate a FindConnection query with "hyperphenylalaninemia" as the input_ojb, "ChemicalSubstance" as the output_obj (which corresponds to a Biolink Entity type).  We further specify with the intermediate_nodes parameter that we are looking for paths joining hyperphenylalaninemia and chemical compounds with one intermediate node that is a Gene.  (The ability to search for longer reasoning paths that include additional intermediate nodes will be added shortly.)
End of explanation
# set verbose=True will display all steps which BTE takes to find the connection
fc.connect(verbose=True)
Explanation: We next execute the connect method, which performs the query path planning and query path execution process.  In short, BioThings Explorer is deconstructing the query into individual API calls, executing those API calls, then assembling the results.
A verbose log of this process is displayed below:
End of explanation
df = fc.display_table_view()
# because UMLS is not currently well-integrated in our ID-to-object translation system, removing UMLS-only outputs here
patternDel = "^UMLS:C\d+"
filter = df.output_id.str.contains(patternDel)
df = df[~filter]
patternDel2 = "^InChI="
filter2 = df.output_name.str.contains(patternDel2)
df = df[~filter2]
patternDel3 = "^umls:C\d+"
filter3 = df.node1_id.str.contains(patternDel3)
df = df[~filter3]
print(df.shape)
df.sample(10)
Explanation: Step 3: Display and Filter results
This section demonstrates post-query filtering done in Python. Later, more advanced filtering functions will be added to the query path execution module for interleaved filtering, thereby enabling longer query paths. More details to come...
First, all matching paths can be exported to a data frame. Let's examine a sample of those results.
End of explanation
df.output_name.value_counts().head(20)
Explanation: While most results are based on edges from semmed, edges from DGIdb, biolink, disgenet, and mychem.info were also retrieved from their respective APIs. 
Next, let's examine which chemical compounds were most frequently mentioned.
End of explanation
df[df.output_name=="NITRIC OXIDE"]
Explanation: Hyperphenylalaninemia is a condition characterized by elevated levels of phenylalanine in the blood. This phenotype is strongly associated with phenylketonuria (PKU), an inherited, genetic disorder that affects the ability to metabolize phenylalanine.  Sapropterin is a naturally-occurring cofactor associated with several enzymatic processes, including the metabolism of phenylalanine to tyrosine. It has been FDA-approved as a treatment for PKU patients.  Tyrosine is also a precursor to several neurotransmitters, including norepinephrine and dopamine.
While several of the listed compounds would be considered positive controls, others on the list could be viewed as testable hypotheses and discovery opportunities to be evaluated by domain experts. For example, let's examine which genes link hyperphenylalaninemia to nitric oxide.
End of explanation
<END_TASK>