Reading a Gene Product Association Data (GPAD) file¶
Download a GPAD file
Load the GPAD file into the GpadReader
Get Annotations
Bonus: Each line in the GPAD file is stored in a namedtuple:
Namedtuple fields
Print a subset of the namedtuple fields
1) Download a GPAD file and GO Dag file¶
from os.path import exists
if not exists('goa_human.gpad'):
!rm -f goa_human.gpad.gz
!wget http://current.geneontology.org/annotations/goa_human.gpad.gz
!gunzip goa_human.gpad.gz
if not exists('go-basic.obo'):
!wget http://geneontology.org/ontology/go-basic.obo
2) Load the GPAD file into the GpadReader¶
from goatools.base import get_godag
from goatools.anno.gpad_reader import GpadReader
godag = get_godag("go-basic.obo")
anno = GpadReader("goa_human.gpad", godag=godag)
EXISTS: go-basic.obo
go-basic.obo: fmt(1.2) rel(2022-11-03) 46,800 Terms
HMS:0:00:16.880690 635,765 annotations READ: goa_human.gpad
3) Get Annotations¶
The annotations will be stored in three dicts, one for each GODAG branch, where:
the key is the protein ID and
the value is a list of GO IDs associated with the protein.
ns2assc = anno.get_ns2assc()
for namespace, associations in ns2assc.items():
for protein_id, go_ids in sorted(associations.items())[:3]:
print("{NS} {PROT:7} : {GOs}".format(
NS=namespace,
PROT=protein_id,
GOs=' '.join(sorted(go_ids))))
MF A0A024RBG1 : GO:0000298 GO:0008486 GO:0034431 GO:0034432 GO:0046872 GO:0050072
MF A0A075B6Q5 : GO:0003823 GO:0034987
MF A0A075B6R2 : GO:0003823 GO:0034987
CC A0A024RBG1 : GO:0005634 GO:0005737 GO:0005829
CC A0A075B6H5 : GO:0005886
CC A0A075B6H7 : GO:0005615 GO:0005886 GO:0019814
BP A0A024RBG1 : GO:0071543 GO:1901907 GO:1901909 GO:1901911
BP A0A075B6H5 : GO:0007166
BP A0A075B6H7 : GO:0002250 GO:0002377 GO:0006955
Bonus: The GPAD is stored as a list of named tuples¶
The list of namedtuples is stored in the GpadReader data member named associations.
Each namedtuple stores data for one line in the GPAD file.
# Sort the list of GPAD namedtuples by ID
nts = sorted(anno.associations, key=lambda nt:nt.DB_ID)
# Print one namedtuple
print(nts[0])
ntgpadobj(DB='UniProtKB', DB_ID='A0A024RBG1', Qualifier={'enables'}, GO_ID='GO:0046872', DB_Reference={'GO_REF:0000043'}, ECO='ECO:0000501', Evidence_Code='IEA', With_From={'UniProtKB-KW:KW-0479'}, Taxon=None, Date=datetime.date(2022, 9, 7), Assigned_By='UniProt', Extension=None, Properties={}, NS='MF')
Namedtuple fields¶
DB # 0 required 1 UniProtKB
DB_ID # 1 required 1 P12345
DB_Symbol # 2 required 1 PHO3
Qualifier # 3 optional 0 or greater NOT
GO_ID # 4 required 1 GO:0003993
DB_Reference # 5 required 1 or greater PMID:2676709
Evidence_Code # 6 required 1 IMP
With_From # 7 optional 0 or greater GO:0000346
Aspect # 8 required 1 F
DB_Name # 9 optional 0 or 1 Toll-like receptor 4
DB_Synonym # 10 optional 0 or greater hToll|Tollbooth
DB_Type # 11 required 1 protein
Taxon # 12 required 1 or 2 taxon:9606
Date # 13 required 1 20090118
Assigned_By # 14 required 1 SGD
Annotation_Extension # 15 optional 0 or greater part_of(CL:0000576)
Gene_Product_Form_ID # 16 optional 0 or 1 UniProtKB:P12345-2
Print a subset of the namedtuple fields¶
fmtpat = '{NS} {DB_ID} {GO_ID} {Evidence_Code} {Date} {Assigned_By}'
for nt_line in nts[:10]:
print(fmtpat.format(**nt_line._asdict()))
MF A0A024RBG1 GO:0046872 IEA 2022-09-07 UniProt
CC A0A024RBG1 GO:0005829 IDA 2016-12-04 HPA
BP A0A024RBG1 GO:1901907 IBA 2017-02-28 GO_Central
MF A0A024RBG1 GO:0000298 IBA 2017-02-28 GO_Central
MF A0A024RBG1 GO:0008486 IBA 2021-05-30 GO_Central
CC A0A024RBG1 GO:0005634 IBA 2017-02-28 GO_Central
BP A0A024RBG1 GO:1901911 IBA 2017-02-28 GO_Central
BP A0A024RBG1 GO:1901909 IBA 2017-02-28 GO_Central
MF A0A024RBG1 GO:0034432 IBA 2017-02-28 GO_Central
CC A0A024RBG1 GO:0005737 IBA 2017-02-28 GO_Central
Copyright (C) 2010-present, DV Klopfenstein PhD, Haibao Tang. All rights reserved.