<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Annotations in NCBI's gene2go file
1) Download the NCBI annotations
The NCBI annotations are stored in the file named "gene2go".
Step1:  2) Read NCBI annotation file, "gene2go"
2a) Read one taxid
Step2:  2b) Read all taxids
Step4:  3) Get associations, split by namespace (Only human annotations loaded)
Namespaces include biological_process (BP), molecular_function (MF), cellular_component (CC).
The taxid argument in function, get_ns2assc, is ignored if there only one taxid is loaded.
Step5:  4) Get associations, split by namespace (Many taxids loaded)
4a) Get associations for one species (human)
Step6:  4b) Get associations for one species (mouse)
Step7:  4c) Combine associations for multiple species (human and mouse)
Step8:  4d) Combine all associations
Step9:  4e) Try getting unspecified taxids
If annotations have been loaded for multiple or all taxids, the taxid argument is required.
If the taxid arg is unused, an error will be printed and an empty dict will be returned.
<ASSISTANT_TASK:>
Python Code:
from goatools.base import download_ncbi_associations
# fin -> Filename of input file (file to be read)
fin_gene2go = download_ncbi_associations()
Explanation: Annotations in NCBI's gene2go file
1) Download the NCBI annotations
The NCBI annotations are stored in the file named "gene2go".
End of explanation
from goatools.anno.genetogo_reader import Gene2GoReader
objanno_hsa = Gene2GoReader(fin_gene2go, taxids=[9606])
Explanation: 2) Read NCBI annotation file, "gene2go"
2a) Read one taxid: human
End of explanation
objanno_all = Gene2GoReader(fin_gene2go, taxids=True)
Explanation: 2b) Read all taxids
End of explanation
ns2assc_hsa1 = objanno_hsa.get_ns2assc()
from itertools import chain
def prt_assc_counts(ns2assc):
    Print the number of genes and GO IDs in an association
    for nspc, gene2goids in sorted(ns2assc.items()):
        print("{NS} {N:6,} genes, {GOs:6,} GOs".format(
            NS=nspc, N=len(gene2goids), GOs=len(set.union(*gene2goids.values()))))
prt_assc_counts(ns2assc_hsa1)
Explanation: 3) Get associations, split by namespace (Only human annotations loaded)
Namespaces include biological_process (BP), molecular_function (MF), cellular_component (CC).
The taxid argument in function, get_ns2assc, is ignored if there only one taxid is loaded.
End of explanation
ns2assc_hsa2 = objanno_all.get_ns2assc(9606)
prt_assc_counts(ns2assc_hsa2)
Explanation: 4) Get associations, split by namespace (Many taxids loaded)
4a) Get associations for one species (human)
End of explanation
ns2assc_mmu = objanno_all.get_ns2assc(10090)
prt_assc_counts(ns2assc_mmu)
Explanation: 4b) Get associations for one species (mouse)
End of explanation
ns2assc_two = objanno_all.get_ns2assc({9606, 10090})
prt_assc_counts(ns2assc_two)
Explanation: 4c) Combine associations for multiple species (human and mouse)
End of explanation
ns2assc_all = objanno_all.get_ns2assc(True)
prt_assc_counts(ns2assc_all)
Explanation: 4d) Combine all associations
End of explanation
ns2assc_all = objanno_all.get_ns2assc()
print(ns2assc_all)
Explanation: 4e) Try getting unspecified taxids
If annotations have been loaded for multiple or all taxids, the taxid argument is required.
If the taxid arg is unused, an error will be printed and an empty dict will be returned.
End of explanation
<END_TASK>