Skip to content

Instantly share code, notes, and snippets.

@acoffman
Created February 13, 2019 21:13
Show Gist options
  • Save acoffman/c48a8388348fa9ae468f52f8a51d731e to your computer and use it in GitHub Desktop.
Save acoffman/c48a8388348fa9ae468f52f8a51d731e to your computer and use it in GitHub Desktop.
Get all variants in CIViC for a specific entrez symbol
import requests
entrez_symbol = 'BRAF'
gene_url = 'https://civicdb.org/api/genes/{}?identifier_type=entrez_symbol'.format(entrez_symbol)
gene_response = requests.get(gene_url)
gene_body = gene_response.json()
variant_details = []
variants_with_evidence = [variant for variant in gene_body['variants'] if variant['evidence_items']['accepted_count'] > 0]
for variant in variants_with_evidence:
variant_detail_url = 'https://civicdb.org/api/variants/{}'.format(variant['id'])
variant_detail_response = requests.get(variant_detail_url)
variant_detail_body = variant_detail_response.json()
variant_details.append(variant_detail_body)
print('Retrieved {} variants for gene {}, the last of which is named {}.'
.format(len(variant_details), entrez_symbol, variant_details[-1]['name']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment