<jupyter_start><jupyter_text>Import api_crawler [Code for api_crawler](https://github.com/biothings/JSON-LD_BioThings_API_DEMO/blob/master/src/api_crawler.py)<jupyter_code>from api_crawler import uri_query<jupyter_output><empty_output><jupyter_text>Given a variant hgvs id, looking for ncbi gene id related to it<jupyter_code>uri_query(input_value='chr12:g.103234255C>T', input_name='http://identifiers.org/hgvs/', output_name='http://identifiers.org/ncbigene/')<jupyter_output>1 api(s) could be utilized based on the input_type, output_type you provided: ['myvariant.info']
myvariant.info returns the following results based on your query: 5053<jupyter_text>From the ncbi gene we found in previous query, get all wikipathways ids related<jupyter_code>uri_query(input_value='5053', input_name='http://identifiers.org/ncbigene/', output_name='http://identifiers.org/wikipathways/')<jupyter_output>1 api(s) could be utilized based on the input_type, output_type you provided: ['mygene.info']
mygene.info returns the following results based on your query: ['WP706', 'WP550']<jupyter_text>Breakdown of uri_query function The following code shows each step involved in uri_query function demonstrated above.  [Metadata information about BioThings API(config)](https://github.com/biothings/JSON-LD_BioThings_API_DEMO/blob/master/src/config.py)[code for biothings_helper](https://github.com/biothings/JSON-LD_BioThings_API_DEMO/blob/master/src/biothings_helper.py)  Step 1: Specify input and output<jupyter_code>input_value = '5053'
input_name='http://identifiers.org/ncbigene/'
output_name='http://identifiers.org/wikipathways/'<jupyter_output><empty_output><jupyter_text>Step 2: Iterate through API metadata info, and find corresponding API based on input & output<jupyter_code>from config import AVAILABLE_API_SOURCES
from biothings_helper import find_value_from_output_type, query_ids_from_output_type
from api_crawler import api_lookup
# look up api in api metadata info
api_results = api_lookup(input_name, output_name)
print(api_results)<jupyter_output>[{'jsonld': 'context/mygene_context.json', 'api': 'mygene.info', 'output': ['http://identifiers.org/uniprot/', 'http://identifiers.org/ensembl.gene/', 'http://identifiers.org/hgnc.symbol/', 'http://identifiers.org/wikipathways/', 'http://identifiers.org/pubmed/'], 'type': 'annotate', 'url_syntax': 'http://mygene.info/v3/gene/{{input}}', 'input': ['http://identifiers.org/ncbigene/']}]<jupyter_text>Step 3: Make API call<jupyter_code>import requests
# construct url based on metadata info
url = api_results[0]['url_syntax'].replace('{{input}}', input_value)
# make API call
doc = requests.get(url).json()
#for better display in ipython notebook, we are not printing the whole json doc here
#the following code could be used to display the json_doc returned from api call
# print(doc)<jupyter_output><empty_output><jupyter_text>Step 4: Transform JSON doc to JSON-LD doc and Nquads format<jupyter_code>from jsonld_processor import flatten_doc
# flatten the json doc
doc = flatten_doc(doc)
import json
# load context file
context = json.load(open(api_results[0]['jsonld']))
# construct json-ld doc
doc.update(context)
# transform json-ld doc to nquads format
from pyld import jsonld
t = jsonld.JsonLdProcessor()
nquads = t.parse_nquads(jsonld.to_rdf(doc, {'format': 'application/nquads'}))['@default']
print(nquads[1])
# for better display in ipython notebook, we are not printing the whole nquads doc here\
# the following code could be used to display the whole nquads doc
# print(nquads)<jupyter_output>{'predicate': {'value': 'http://identifiers.org/ensembl.protein/', 'type': 'IRI'}, 'subject': {'value': '_:b0', 'type': 'blank node'}, 'object': {'value': 'ENSP00000303500', 'datatype': 'http://www.w3.org/2001/XMLSchema#string', 'type': 'literal'}}<jupyter_text>Step 5: Fetch value using URI from Nquads format<jupyter_code>value_list = []
for item in nquads:
    if item['predicate']['value'] == output_name:
        value_list.append(item['object']['value'])
value = list(set(value_list))
print(value)<jupyter_output>['WP706', 'WP550']
{'fraction_non_alphanumeric': 0.1321446018563752, 'fraction_numerical': 0.015388373229115779, 'mean_word_length': 7.19, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 29, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '16341', 'license': 'Apache-2.0', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1366, 'n_words': 326, 'path': 'src/Crawl APIs based on URI.ipynb', 'repo_name': 'kevinxin90/JSON-LD_BioThings_API_DEMO', 'size': '4094'}