Skip to content

Instantly share code, notes, and snippets.

@ahwagner
Last active July 24, 2018 15:30
Show Gist options
  • Save ahwagner/d1f7da8aa2ba294d201864e52cf87ca8 to your computer and use it in GitHub Desktop.
Save ahwagner/d1f7da8aa2ba294d201864e52cf87ca8 to your computer and use it in GitHub Desktop.
All CIViC variants with merged suggested HPO terms
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from civicpy import civic, recipes\n",
"import csv"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# get all variant ids\n",
"variant_ids = civic.get_all_variant_ids()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# get all merged HPO terms for variants\n",
"evidence_hpo = dict()\n",
"for evidence, phenotypes in recipes.get_variant_phenotypes_with_suggested_changes_merged(variant_ids):\n",
" hpo_records = civic.get_HPO_by_ids(phenotypes)\n",
" hpo_ids = [x['hpo_id'] for x in hpo_records]\n",
" evidence_hpo[evidence] = hpo_ids"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Write variant and HPO info to file\n",
"\n",
"with open('variant_hpo_merged.csv', 'w', newline='') as f:\n",
" w = csv.writer(f)\n",
" w.writerow([\n",
" 'evidence_id',\n",
" 'variant_id',\n",
" 'variant_gene',\n",
" 'variant_name',\n",
" 'variant_origin',\n",
" 'hpo_ids'\n",
" ])\n",
" for evidence, hpo_ids in evidence_hpo.items():\n",
" variant = evidence.variant\n",
" origin = evidence.variant_origin\n",
" if origin is None or 'Germline' not in origin:\n",
" continue\n",
" w.writerow((\n",
" evidence.id,\n",
" variant.id, \n",
" variant.entrez_name, \n",
" variant.name, \n",
" origin,\n",
" '|'.join(hpo_ids)))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [civicpy]",
"language": "python",
"name": "Python [civicpy]"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment