Last active
February 19, 2016 18:32
-
-
Save tbrittoborges/316180231298cf909eb0 to your computer and use it in GitHub Desktop.
Load an Uniprot GFF directly to a pandas.DataFrame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urlparse import parse_qs | |
import pandas as pd | |
def _fetch_uniprot_gff(identifier): | |
""" | |
Retrieve UniProt data from the GFF file | |
:param identifier: UniProt accession identifier | |
:type identifier: str | |
:return: table | |
:return type: pandas.DataFrame | |
""" | |
url = defaults.api_uniprot + identifier + ".gff" | |
cols = "NAME SOURCE TYPE START END SCORE STRAND FRAME GROUP empty".split() | |
data = pd.read_table(url, skiprows=2, names=cols) | |
groups = data.GROUP.apply(parse_qs) | |
groups = pd.DataFrame.from_records(groups) | |
data = data.merge(groups, left_index=True, right_index=True) | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment