Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix GTDB database setup #329

Merged
merged 15 commits into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions autometa/taxonomy/gtdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
File containing definition of the GTDB class and containing functions useful for handling GTDB taxonomy databases
"""


import gzip
import logging
import os
import re
import string
import tarfile
import glob
from pathlib import Path

from typing import Dict, List, Set, Tuple
from typing import Dict, Set, Tuple
from itertools import chain
from tqdm import tqdm
from typing import Dict
Expand All @@ -25,7 +24,6 @@
from autometa.common.utilities import file_length, is_gz_file
from autometa.common.external import diamond
from autometa.taxonomy.database import TaxonomyDatabase
from autometa.common.exceptions import DatabaseOutOfSyncError


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -59,7 +57,9 @@ def create_gtdb_db(reps_faa: str, dbdir: str) -> str:
reps_faa = dbdir

genome_protein_faa_filepaths = glob.glob(
os.path.join(reps_faa, "**", "*_protein.faa"), recursive=True
os.path.join(reps_faa, "**", "*_protein.faa*"),
recursive=True
# To find *_protein.faa and *_protein.faa.gz files
)

faa_index: Dict[str, str] = {}
Expand All @@ -79,12 +79,15 @@ def create_gtdb_db(reps_faa: str, dbdir: str) -> str:
combined_faa = os.path.join(dbdir, "gtdb.faa")
with open(combined_faa, "w") as f_out:
for faa_file, acc in faa_index.items():
with open(faa_file) as f_in:
with gzip.open(faa_file, "rb") as f_in:
evanroyrees marked this conversation as resolved.
Show resolved Hide resolved
for line in f_in:
line = line.decode("utf-8")
if line.startswith(">"):
seqheader = line.lstrip(">")
line = f"\n>{acc} {seqheader}"
f_out.write(line)
seqheader = line.lstrip(">").strip()
outline = f">{acc} {seqheader}\n"
else:
outline = line
f_out.write(outline)
logger.debug(f"Combined GTDB faa file written to {combined_faa}")
return combined_faa

Expand Down