Skip to content

Commit

Permalink
Merge pull request #383 from ChristopherBradley/376
Browse files Browse the repository at this point in the history
SequenceCollection.annotate_from_gff works in Alignment subclass, but not in the generic SequenceCollection class
  • Loading branch information
GavinHuttley committed Nov 14, 2019
2 parents 28e17b5 + a8eff66 commit 3947582
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/cogent3/core/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4007,6 +4007,10 @@ def get_identical_sets(self, mask_degen=False):

return identical_sets

def annotate_from_gff(self, f):
"""Override annotate_from_gff since an ArrayAlignment cannot be annotated"""
raise TypeError("not supported on ArrayAlignment, use to_type(array_align=True) to convert")


class CodonArrayAlignment(ArrayAlignment):
"""Stores alignment of gapped codons, no degenerate symbols."""
Expand Down
13 changes: 12 additions & 1 deletion tests/test_core/test_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,12 +871,18 @@ def test_copy_annotations(self):

def test_annotate_from_gff(self):
"""SequenceCollection.annotate_from_gff should read gff features"""
aln = self.Class({"seq1": "ACGU", "seq2": "CGUA", "seq3": "CCGU"})
aln = self.Class({"seq1": "ACGU", "seq2": "CGUA", "seq3": "C-GU"})
gff = [
["seq1", "prog1", "snp", "1", "2", "1.0", "+", "1", '"abc"'],
["seq3", "prog2", "del", "1", "3", "1.0", "+", "1", '"xyz"'],
["seq5", "prog2", "snp", "2", "3", "1.0", "+", "1", '"yyy"'],
]
gff = list(map("\t".join, gff))
if self.Class == ArrayAlignment:
with self.assertRaises(TypeError):
aln.annotate_from_gff(gff)
return

aln.annotate_from_gff(gff)
aln_seq_1 = aln.named_seqs["seq1"]
if not hasattr(aln_seq_1, "annotations"):
Expand All @@ -888,6 +894,11 @@ def test_annotate_from_gff(self):
self.assertEqual(aln_seq_1.annotations[0].name, "abc")
self.assertEqual(len(aln_seq_2.annotations), 0)

if self.Class == Alignment:
aln_seq_3 = aln.get_seq("seq3")
matches = [m for m in aln_seq_3.get_annotations_matching("*")]
self.assertFalse("-" in matches[0].get_slice())

def test_add(self):
"""__add__ should concatenate sequence data, by name"""
align1 = self.Class({"a": "AAAA", "b": "TTTT", "c": "CCCC"})
Expand Down

0 comments on commit 3947582

Please sign in to comment.