Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
catch alignment error
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Sep 16, 2023
1 parent 0a4e958 commit 6c6730c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
38 changes: 22 additions & 16 deletions intact/intact.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@
from util.blastrow import BlastRow


WRONGORFNUMBER_ERROR = "WrongORFNumber"
MISPLACEDORF_ERROR = "MisplacedORF"
LONGDELETION_ERROR = "LongDeletion"
DELETIONINORF_ERROR = "DeletionInOrf"
INSERTIONINORF_ERROR = "InsertionInOrf"
INTERNALSTOP_ERROR = "InternalStopInOrf"
SCRAMBLE_ERROR = "Scramble"
NONHIV_ERROR = "NonHIV"
WRONGORFNUMBER_ERROR = "WrongORFNumber"
MISPLACEDORF_ERROR = "MisplacedORF"
LONGDELETION_ERROR = "LongDeletion"
DELETIONINORF_ERROR = "DeletionInOrf"
INSERTIONINORF_ERROR = "InsertionInOrf"
INTERNALSTOP_ERROR = "InternalStopInOrf"
SCRAMBLE_ERROR = "Scramble"
NONHIV_ERROR = "NonHIV"
INTERNALINVERSION_ERROR = "InternalInversion"
ALIGNMENT_FAILED = "AlignmentFailed" # Happens when mafft process fails

FRAMESHIFTINORF_ERROR = "FrameshiftInOrf"
MSDMUTATED_ERROR = "MajorSpliceDonorSiteMutated"
PSIDELETION_ERROR = "PackagingSignalDeletion"
PSINOTFOUND_ERROR = "PackagingSignalNotComplete"
RREDELETION_ERROR = "RevResponseElementDeletion"
HYPERMUTATION_ERROR = "APOBECHypermutationDetected"
FRAMESHIFTINORF_ERROR = "FrameshiftInOrf"
MSDMUTATED_ERROR = "MajorSpliceDonorSiteMutated"
PSIDELETION_ERROR = "PackagingSignalDeletion"
PSINOTFOUND_ERROR = "PackagingSignalNotComplete"
RREDELETION_ERROR = "RevResponseElementDeletion"
HYPERMUTATION_ERROR = "APOBECHypermutationDetected"


@dataclass
Expand Down Expand Up @@ -832,8 +833,13 @@ def intact( working_dir,
name = sequence.name
)

alignment = wrappers.mafft([reference, sequence])
reverse_alignment = wrappers.mafft([reference, reverse_sequence])
try:
alignment = wrappers.mafft([reference, sequence])
reverse_alignment = wrappers.mafft([reference, reverse_sequence])
except wrappers.AlignmentFailure:
err = IntactnessError(sequence.id, ALIGNMENT_FAILED, "Alignment failed for this sequence. It probably contains unallowed symbols.")
sequence_errors.append(err)
continue

forward_score = alignment_score(alignment)
reverse_score = alignment_score(reverse_alignment)
Expand Down
10 changes: 9 additions & 1 deletion util/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from util.blastrow import BlastRow

class AlignmentFailure(Exception):
pass

def mafft(sequences):
'''
Call mafft on a set of sequences and return the resulting alignment.
Expand All @@ -19,7 +22,12 @@ def mafft(sequences):

with tempfile.NamedTemporaryFile() as alignment_input, tempfile.NamedTemporaryFile() as alignment_output:
SeqIO.write(sequences, alignment_input.name, "fasta")
subprocess.call(["mafft", "--quiet", alignment_input.name], shell=False, stdout=alignment_output)

try:
subprocess.run(["mafft", "--quiet", alignment_input.name], shell=False, stdout=alignment_output, check=True)
except subprocess.CalledProcessError:
raise AlignmentFailure()

alignment = AlignIO.read(alignment_output.name, "fasta")
return alignment

Expand Down

0 comments on commit 6c6730c

Please sign in to comment.