<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
<img src="img/tidbit2.png" width=300 style="float
Step1:  Then import the relevant modules
Step2:  Step 1
Step3:  Step 2
Step4:  The df object contains the full output from BioThings Explorer. Each row shows one path that joins the input node (Parkinson's disease) to an intermediate node (a gene or protein) to an ending node (a chemical compound). The data frame includes a set of columns with additional details on each node and edge (including human-readable labels, identifiers, and sources). Let's remove all examples where the output_name (the compound label) is None, and specifically focus on paths with specific mechanistic predicates causedBy and targetedBy.
Step5:  Let's examine how many unique Parkinsons - GENE - DRUG paths there are
Step6:  Results
Finally, let's examine the list of genes identified as intermediates between Parkinson's Disease and some chemical compound, sorted by the frequency of occurrence
Step7:  Within this list, we found a number of genes associated with therapies for Parkinson's Disease that are either approved or in development, including DRD2, COMT, LRRK2, and SNCA.  We can also view the many chemical compounds that are known to modulate those genes using the query below
Step8:  The other genes in that list all have some link to Parkinson's Disease and have known chemical modulators.  In some cases, these genes reflect relatively recent findings that may represent novel therapeutic candidates.  For example, BTE found a link between the gene LCN2 and Parkinson's Disease based on both on upregulation in the brains of PD patients, and based on genetic evidence in mouse models (PMID
<ASSISTANT_TASK:>
Python Code:
!pip install git+https://github.com/biothings/biothings_explorer#egg=biothings_explorer
Explanation: Introduction
<img src="img/tidbit2.png" width=300 style="float: right;"/>
This notebook demonstrates how BioThings Explorer can be used to answer the following query:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"What drugs might be used to treat Parkinson's disease?"
This query corresponds to Tidbit 2 which was formulated as a demonstration of the NCATS Translator program.
To experiment with an executable version of this notebook, load it in Google Colaboratory.
Background: BioThings Explorer can answer two classes of queries -- "EXPLAIN" and "PREDICT".  EXPLAIN queries are described in EXPLAIN_demo.ipynb, and PREDICT queries are described in PREDICT_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.
Step 0: Load BioThings Explorer modules
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
Explanation: Then import the relevant modules:
End of explanation
from biothings_explorer.hint import Hint
ht = Hint()
parkDis = ht.query("Parkinson disease")['DiseaseOrPhenotypicFeature'][0]
parkDis
Explanation: Step 1: Find representation of "Parkinson disease" in BTE
In this step, BioThings Explorer translates our query string "Parkinson disease"  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
from biothings_explorer.user_query_dispatcher import FindConnection
fc = FindConnection(input_obj=parkDis, output_obj='ChemicalSubstance', intermediate_nodes=['Gene'])
fc.connect(verbose=True)
df = fc.display_table_view()
Explanation: Step 2: Find drugs that are associated with genes which invovled in Parkinson disease
In this section, we find all paths in the knowledge graph that connect Parkinson disease 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
dfFilt = df.loc[df['output_name'].notnull()].query('pred1 == "causedBy" and pred2 == "targetedBy"')
dfFilt
Explanation: The df object contains the full output from BioThings Explorer. Each row shows one path that joins the input node (Parkinson's disease) to an intermediate node (a gene or protein) to an ending node (a chemical compound). The data frame includes a set of columns with additional details on each node and edge (including human-readable labels, identifiers, and sources). Let's remove all examples where the output_name (the compound label) is None, and specifically focus on paths with specific mechanistic predicates causedBy and targetedBy.
End of explanation
dfFiltUnique = dfFilt[["input","node1_name","output_name"]].drop_duplicates()
dfFiltUnique
Explanation: Let's examine how many unique Parkinsons - GENE - DRUG paths there are:
End of explanation
import pandas as pd
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_colwidth', 2000)
print("Num genes: "+str(len(dfFiltUnique["node1_name"].value_counts()))+"\n")
print(dfFiltUnique["node1_name"].value_counts())
Explanation: Results
Finally, let's examine the list of genes identified as intermediates between Parkinson's Disease and some chemical compound, sorted by the frequency of occurrence:
End of explanation
knownPDgenes = dfFilt[dfFilt["node1_name"].isin(["LRRK2","COMT","DRD2","SNCA"])][["input","node1_name","output_name"]].drop_duplicates().sort_values("node1_name")
compounds = knownPDgenes.groupby(['node1_name'])['output_name'].apply(','.join)
count = knownPDgenes.groupby(['node1_name'])['output_name'].count()
result = pd.DataFrame({ 'count': count, 'compounds': compounds } )
result
Explanation: Within this list, we found a number of genes associated with therapies for Parkinson's Disease that are either approved or in development, including DRD2, COMT, LRRK2, and SNCA.  We can also view the many chemical compounds that are known to modulate those genes using the query below:
End of explanation
dfFilt.query('node1_name == "LCN2"')[["output_id","output_name"]].drop_duplicates()
Explanation: The other genes in that list all have some link to Parkinson's Disease and have known chemical modulators.  In some cases, these genes reflect relatively recent findings that may represent novel therapeutic candidates.  For example, BTE found a link between the gene LCN2 and Parkinson's Disease based on both on upregulation in the brains of PD patients, and based on genetic evidence in mouse models (PMID:27194339).  This association was found through SemMedDB.
<img src="img/lcn2_27194339.png" width="700px" />
Through two other APIs (mychem.info and DGIdb), BTE discovered six compounds that target LCN2:
End of explanation
<END_TASK>