Skip to content

Instantly share code, notes, and snippets.

@bow
Last active November 23, 2021 09:52
Show Gist options
  • Save bow/3626c5b834a44fe7fed8 to your computer and use it in GitHub Desktop.
Save bow/3626c5b834a44fe7fed8 to your computer and use it in GitHub Desktop.
Extract VEP consequence table
name: vep-consequence-extract
dependencies:
- beautifulsoup4=4.4.1=py35_0
- libxml2=2.9.3=0
- libxslt=1.1.28=0
- lxml=3.6.0=py35_0
- openssl=1.0.2h=1
- pip=8.1.2=py35_0
- python=3.5.1=0
- readline=6.2=2
- requests=2.10.0=py35_0
- setuptools=23.0.0=py35_0
- sqlite=3.13.0=0
- tk=8.5.18=0
- wheel=0.29.0=py35_0
- xz=5.0.5=1
- zlib=1.2.8=3
#!/usr/bin/env python
"""
Quick and dirty script for extracting VEP consequence table, creating a JSON
that maps the VEP consequence to its predicted impact level.
Requirements:
* Python 3.x
* requests library
* BeautifulSoup library
* lxml library
No Rights Reserved. This script is in the public domain.
"""
__author__ = "Wibowo Arindrarto"
URL = "http://www.ensembl.org/info/genome/variation/predicted_data.html"
import json
import sys
import requests
from bs4 import BeautifulSoup
if __name__ == "__main__":
res = {}
html = requests.get(URL).text
soup = BeautifulSoup(html, "lxml")
tbody = soup.find(attrs={"id": "consequence_type_table"}).contents[3]
for table_row in tbody.children:
cols = list(table_row.children)
vep_cons = cols[1].text
impact = cols[5].text.split(".")[-1]
res[vep_cons] = impact
json.dump(res, sys.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment