<jupyter_start><jupyter_text>Step 1: Find representation of a patient gene in BTEIn this step, BioThings Explorer translates our query string "CACNA1H"  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](https://biolink.github.io/biolink-model/docs/BiologicalEntity.html) from the [Biolink Model](https://biolink.github.io/biolink-model/docs/), 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").<jupyter_code>ht = Hint()
cacna1h = ht.query("CACNA1H")<jupyter_output><empty_output><jupyter_text>The hint object will output results of the search into a few different biolink categories, i.e.<jupyter_code>list(cacna1h.keys())<jupyter_output><empty_output><jupyter_text>Naturally, we care about the gene categories:<jupyter_code>cacna1h['Gene']<jupyter_output><empty_output><jupyter_text>Step 2: Import a patient data file and find curies for all supported genes. The general organization of the Connections Hypothesis Provider (CHP) is to ingest a TCGA dataset, e.g. Breast Cancer and created BKB Fragments and a patient_data.pk file that contains all patient data in a consistent format. In this section, we will read in a sample patient data file and find get the curies for all the genes that exist in this data file, i.e. supported by the CHP.<jupyter_code>with open('data/patient_data.pk', 'rb') as f_:
    patient_data = pickle.load(f_)<jupyter_output><empty_output><jupyter_text>Inspecting the patient data of a single patient (classified by a unique ID key) we see that there are 13 categories:<jupyter_code>list(patient_data[list(patient_data.keys())[0]].keys())<jupyter_output><empty_output><jupyter_text>Now we'll collect all the genes and grab their associated curies using the BTE hint module.<jupyter_code>genes = set()
for patient_id, data in patient_data.items():
    genes.update(data['Patient_Genes'])
gene_hints = {}
for gene in tqdm.tqdm(list(genes)[:10], leave=False):
    gene_ht = ht.query(gene)
    if len(gene_ht['Gene']) == 0:
        print("Couldn't find a hint for {}".format(gene))
    gene_hints[gene] = gene_ht['Gene']<jupyter_output><jupyter_text>The code above only collects the hints for the first 10 genes in the set and takes about ~55 seconds to run. If we want to do this for ~15,000 genes it is going to take a while. Since, these requests are just API calls we can easily parrellize the execution.<jupyter_code>def getGeneHints(gene):
    hint = Hint()
    ht = hint.query(gene)
    return {gene: ht['Gene']}
start_time = time.time()
pool = Pool(10)
async_resp = pool.map(getGeneHints, list(genes)[:10])
pool.close()
pool.join()
print('Pool time = {}'.format(time.time() - start_time))
#-- Collect gene hints into one dictionary
gene_hints = {}
for resp in async_resp:
    gene_hints.update(resp)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10917721518987342, 'fraction_numerical': 0.008544303797468355, 'mean_word_length': 5.711252653927813, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '575843', 'license': 'Apache-2.0', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1004, 'n_words': 339, 'path': 'notebooks/babel/curie_mapping.ipynb', 'repo_name': 'NCATSTranslator/connections_hypothesis_provider', 'size': '3160'}