Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_i147_all_taxids():
"""Work with all taxids using Gene2GoReader"""
# 1. Download Ontologies and Associations
# 1a. Download Ontologies, if necessary
# Get http://geneontology.org/ontology/go-basic.obo
download_go_basic_obo()
# 1b. Download Associations, if necessary
# Get ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/gene2go.gz
fin_gene2go = download_ncbi_associations()
# 2. Load Ontologies, Associations and Background gene set
# 2a. Load Ontologies
godag = GODag("go-basic.obo")
# 2b. Load Associations for all species
# Read NCBI's gene2go. Store annotations in a list of namedtuples
objanno_all = Gene2GoReader(fin_gene2go, godag=godag, taxids=True)
objanno_mmu = Gene2GoReader(fin_gene2go, godag=godag, taxids=[10090])
objanno_mmuhsa = Gene2GoReader(fin_gene2go, godag=godag, taxids=[10090, 9606])
# Get associations
def get_genes_cell_cycle(taxid=9606, log=sys.stdout):
"""Test GOEA with local multipletest correction methods for cell cycle."""
# Download ontologies and annotations, if necessary
fin_go_obo = os.path.join(os.getcwd(), "go-basic.obo")
download_go_basic_obo(fin_go_obo, loading_bar=None)
# Because get_assoc_ncbi_taxids returns id2gos, we will opt to
# use the (optional) multi-level dictionary separate associations by taxid
# taxid2asscs contains both GO2IDs and ID2GOs.
taxid2asscs = defaultdict(lambda: defaultdict(lambda: defaultdict(set)))
get_assoc_ncbi_taxids([taxid], taxid2asscs=taxid2asscs, loading_bar=None)
# Initialize GO-search helper object with obo and annotations(go2items)
srch = GoSearch(fin_go_obo, go2items=taxid2asscs[taxid]['GO2IDs'])
# Compile search pattern for 'cell cycle'
cell_cycle = re.compile(r'cell cycle', flags=re.IGNORECASE)
# Find ALL GOs that have 'cell cycle'. Store results in file.
fout_allgos = "cell_cycle_gos_{TAXID}.log".format(TAXID=taxid)
with open(fout_allgos, "w") as prt:
# Search for 'cell cycle' in GO terms
gos_cc_all = srch.get_matching_gos(cell_cycle, prt=prt)
# Researcher carefully reviews GO results and finds GO:0005764(lysosome)
def test_go_print(prt=sys.stdout):
"""Test that all GO Terms can be printed, even if level/depth are not assigned."""
prt_pypath(prt)
file_obo = os.path.join(os.getcwd(), "go-basic.obo")
obo_file = download_go_basic_obo(file_obo, prt=prt, loading_bar=None)
reader = goatools.obo_parser.OBOReader(obo_file)
go_terms = list(reader)
prt.write("Python Version: {VER}\n\n".format(VER=sys.version))
prt.write("\nOBOReader: {OBJ}\n\n".format(OBJ=reader))
prt.write("format-version: {VER}\n".format(VER=reader.format_version))
prt.write("data-version: {VER}\n\n".format(VER=reader.data_version))
prt.write("Found {N} GO Records:\n".format(N=len(go_terms)))
for idx, go_rec in enumerate(go_terms):
prt.write("{I:>7,} {RECORD}\n".format(I=idx, RECORD=go_rec))
def dnld_ontology(filename):
"""Test downloading of ontologies."""
# download_go_basic_obo(filename, loading_bar=None)
os.system("rm -f {FILE}".format(FILE=filename))
download_go_basic_obo(filename, loading_bar=None)
download_go_basic_obo(filename, loading_bar=None)
assert os.path.isfile(filename), "FILE({F}) EXPECTED TO EXIST".format(F=filename)
def _init_dnld_dag(self):
"""If dag does not exist, download it."""
if not os.path.exists(self.obo):
download_go_basic_obo(self.obo, loading_bar=None)