Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
Fix error caused by exessive trimming by trimal (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
moshi4 committed Sep 4, 2022
1 parent 1e085a5 commit b7ae6b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/fastdtlmapper/scripts/FastDTLmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,19 @@ def trimal_run(outpath: OutPath, cmd: Cmd) -> None:
trimal_cmd_list, outpath.tmp_parallel_cmds_file, outpath.trimal_log_file
)

# If trimal removed sequence, use raw mafft alignment in next step
# If trimal removed sequence or exessive trimming
# use raw mafft alignment in next step
for aln_file in sorted(outpath.dtl_rec_dir.glob("**/*_aln.fa")):
group_id = aln_file.parent.name
aln_trim_file = aln_file.parent / (group_id + "_aln_trim.fa")
if UtilFasta(aln_file).seq_num > UtilFasta(aln_trim_file).seq_num:
shutil.copy(aln_file, aln_trim_file)

aln_length = UtilFasta.get_aln_length(aln_file)
aln_trim_length = UtilFasta.get_aln_length(aln_trim_file)
if aln_trim_length < 5 or aln_length > aln_trim_length * 10:
shutil.copy(aln_file, aln_trim_file)


@print_runtime
def iqtree_run(outpath: OutPath, cmd: Cmd) -> None:
Expand Down
14 changes: 13 additions & 1 deletion src/fastdtlmapper/util/fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import Dict, List, Union

from Bio import SeqIO
from Bio import AlignIO, SeqIO


@dataclass
Expand Down Expand Up @@ -72,3 +72,15 @@ def add_serial_id(
record.id = f"{id_prefix}_GENE{cnt:06d}_{record_id}"
fix_records.append(record)
SeqIO.write(fix_records, fasta_outfile, "fasta-2line")

@classmethod
def get_aln_length(cls, aln_file: Union[str, Path]) -> int:
"""Get alignment length
Args:
aln_file (Union[str, Path]): Alignment file
Returns:
int: alignment length
"""
return AlignIO.read(aln_file, "fasta").get_alignment_length()

0 comments on commit b7ae6b5

Please sign in to comment.