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

augur align: Ensure reference sequence is removed when no gaps are present #456

Closed
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion augur/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,33 @@ def strip_non_reference(alignment_fname, reference, keep_reference=False):
-------
list
list of trimmed sequences, effectively a multiple alignment

Tests
-----
>>> [s.name for s in strip_non_reference("tests/data/align/test_aligned_sequences.fasta", "with_gaps", keep_reference=False)]
Trimmed gaps in with_gaps from the alignment
['no_gaps', 'some_other_seq']
>>> [s.name for s in strip_non_reference("tests/data/align/test_aligned_sequences.fasta", "with_gaps", keep_reference=True)]
Trimmed gaps in with_gaps from the alignment
['with_gaps', 'no_gaps', 'some_other_seq']
>>> [s.name for s in strip_non_reference("tests/data/align/test_aligned_sequences.fasta", "no_gaps", keep_reference=True)]
No gaps in alignment to trim (with respect to the reference, no_gaps)
['with_gaps', 'no_gaps', 'some_other_seq']
>>> [s.name for s in strip_non_reference("tests/data/align/test_aligned_sequences.fasta", "no_gaps", keep_reference=False)]
No gaps in alignment to trim (with respect to the reference, no_gaps)
['with_gaps', 'some_other_seq']
>>> [s.name for s in strip_non_reference("tests/data/align/test_aligned_sequences.fasta", "missing", keep_reference=False)]
Traceback (most recent call last):
...
augur.align.AlignmentError: ERROR: reference missing not found in alignment
'''
aln = AlignIO.read(alignment_fname, 'fasta')
seqs = {s.name:s for s in aln}
if reference in seqs:
ref_array = np.array(seqs[reference])
if "-" not in ref_array:
print("No gaps in alignment to trim (with respect to the reference, %s)"%reference)
return aln
return [seq for seq in aln if (keep_reference or seq.name != reference)]
ungapped = ref_array!='-'
ref_aln_array = np.array(aln)[:,ungapped]
else:
Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/data/align/test_aligned_sequences.fasta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
>with_gaps
---ATATA---
>no_gaps
GGGATATAGGG
>some_other_seq
--GATCTAGGG