Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions KEGGutils/KEGGapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ def get_organism_codes(force_download=False):
org_filename = "organism_code_list"

org_codes = []
org_codespath = RES_PATH.joinpath("org_codes.txt")

if force_download:
organism_fulltext = download_textfile(
Expand All @@ -997,13 +998,27 @@ def get_organism_codes(force_download=False):
org_codes.append(kegg_code)

else:
org_codespath = RES_PATH.joinpath("org_codes.txt")
# with open("./res/org_codes.txt", "r+") as org_file:
# organism_fulltext = org_file.read()
organism_fulltext = org_codespath.read_text()
# Check if file exists. if it does not, download it and save it
if not os.path.exists(org_codespath):
if not os.path.isdir(RES_PATH):
os.mkdir(RES_PATH)

for line in organism_fulltext.splitlines():
org_codes.append(line)
organism_fulltext = download_textfile(
org_url, org_filename, verbose=False, force_download=force_download
)
for line in organism_fulltext.splitlines():
_, kegg_code, _, _ = line.strip().split("\t")
org_codes.append(kegg_code)

with open(org_codespath, "w") as f:
f.write('\n'.join(org_codes))
else:
# with open("./res/org_codes.txt", "r+") as org_file:
# organism_fulltext = org_file.read()
organism_fulltext = org_codespath.read_text()

for line in organism_fulltext.splitlines():
org_codes.append(line)

return org_codes

Expand Down