Skip to content

Instantly share code, notes, and snippets.

@tbrittoborges
Last active February 19, 2016 18:32
Show Gist options
  • Save tbrittoborges/316180231298cf909eb0 to your computer and use it in GitHub Desktop.
Save tbrittoborges/316180231298cf909eb0 to your computer and use it in GitHub Desktop.
Load an Uniprot GFF directly to a pandas.DataFrame
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