Exemple #1
0
 def test_compound_reverse(self):
     self.feature.location = CompoundLocation([
         FeatureLocation(21, 27, -1),
         FeatureLocation(12, 15, -1),
         FeatureLocation(0, 6, -1)
     ])
     assert self.get_sub(2, 3) == FeatureLocation(12, 15, -1)
Exemple #2
0
 def test_string_conversion(self):
     for feature_type in ["protocluster", "cds_motif", "test"]:
         for start, end in [(1, 5), (3, 8), (10, 15)]:
             feature = Feature(FeatureLocation(start, end, strand=1),
                               feature_type=feature_type)
             assert str(feature) == "%s([%d:%d](+))" % (feature_type, start, end)
             feature = Feature(FeatureLocation(start, end, strand=-1),
                               feature_type=feature_type)
             assert str(feature) == "%s([%d:%d](-))" % (feature_type, start, end)
Exemple #3
0
 def test_bridging_fails(self):
     parts = [
         FeatureLocation(9, 12, strand=1),
         FeatureLocation(0, 3, strand=1)
     ]
     with self.assertRaisesRegex(ValueError, "bridge the record origin"):
         Feature(CompoundLocation(parts, operator="join"),
                 feature_type="test")
     Feature(CompoundLocation(parts[::-1], operator="join"),
             feature_type="test")
Exemple #4
0
 def test_compound_forward(self):
     for position_type in self.position_types:
         old = CompoundLocation([FeatureLocation(position_type(5), 12, 1),
                                 FeatureLocation(15, 17, 1)])
         for offset in range(-2, 3):
             new = adjust(old, offset)
             assert isinstance(new.start, position_type)
             assert new.start == old.start + offset
             assert new.parts[0].end is old.parts[0].end
             for old_part, new_part in zip(old.parts[1:], new.parts[1:]):
                 assert old_part is new_part
Exemple #5
0
 def test_compound_reverse(self):
     for position_type in self.position_types:
         old = CompoundLocation([FeatureLocation(15, position_type(17), -1),
                                 FeatureLocation(5, 12, -1)])
         for offset in range(-2, 3):
             new = adjust(old, offset)
             assert isinstance(new.end, position_type)
             assert new.end == old.end + offset
             assert new.parts[0].start is old.parts[0].start
             for old_part, new_part in zip(old.parts[1:], new.parts[1:]):
                 assert old_part is new_part
Exemple #6
0
    def test_ordering(self):
        feature = Feature(FeatureLocation(10, 40), feature_type="test")
        before = Feature(FeatureLocation(5, 30), feature_type="test")
        after = Feature(FeatureLocation(20, 40), feature_type="test")
        longer = Feature(FeatureLocation(10, 70), feature_type="test")

        def check(first, second):
            assert first < second
            assert first < second.location
            assert sorted([second, first]) == [first, second]

        check(before, feature)
        check(feature, after)
        check(feature, longer)

        assert sorted([feature, before, after, longer]) == [before, feature, longer, after]
Exemple #7
0
 def test_invalid_codon_start(self):
     seqf = SeqFeature(FeatureLocation(5, AfterPosition(12), -1))
     seqf.type = "test"
     for codon_start in ["-1", "4", "NA"]:
         seqf.qualifiers["codon_start"] = [codon_start]
         with self.assertRaisesRegex(ValueError, "invalid codon_start"):
             Feature.from_biopython(seqf)
Exemple #8
0
 def test_single_reverse(self):
     for position_type in self.position_types:
         old = FeatureLocation(5, position_type(12), -1)
         for offset in range(-2, 3):
             new = adjust(old, offset)
             assert isinstance(new.end, position_type)
             assert new.end == old.end + offset
             assert new.start is old.start
Exemple #9
0
 def test_single_forward(self):
     for position_type in self.position_types:
         old = FeatureLocation(position_type(5), 12, 1)
         for offset in range(-2, 3):
             new = adjust(old, offset)
             assert isinstance(new.start, position_type)
             assert new.start == old.start + offset
             assert new.end is old.end
Exemple #10
0
 def test_feature_type(self):
     loc = FeatureLocation(1, 4, strand=1)
     with self.assertRaisesRegex(ValueError, "invalid length"):
         Feature(loc, feature_type="")
     assert Feature(loc, feature_type="A")
     assert Feature(loc, feature_type="A"*15)
     with self.assertRaisesRegex(ValueError, "invalid length"):
         Feature(loc, feature_type="A"*16)
Exemple #11
0
    def test_created_by_antismash_conversion(self):
        for created in [True, False]:
            old = Feature(FeatureLocation(1, 5), feature_type="testtype", created_by_antismash=created)
            assert old.created_by_antismash == created
            assert old.type == "testtype"

            new = Feature.from_biopython(old.to_biopython()[0])
            assert new.created_by_antismash == old.created_by_antismash == created
            assert new.type == old.type == "testtype"
Exemple #12
0
 def test_biopython_conversion(self):
     bio = SeqFeature(FeatureLocation(1, 5))
     bio.qualifiers["foo"] = ["bar"]
     bio.qualifiers["key_only"] = None
     # check that features without types are caught
     with self.assertRaisesRegex(ValueError, "invalid length"):
         sec = Feature.from_biopython(bio)
     bio.type = "test"
     sec = Feature.from_biopython(bio)
     assert sec.get_qualifier("foo") == tuple(["bar"])
     assert sec.get_qualifier("bar") is None
     assert sec.get_qualifier("key_only") is True
Exemple #13
0
 def test_conversion_with_codon_start_reverse(self):
     seqf = SeqFeature(FeatureLocation(5, AfterPosition(12), -1))
     seqf.type = "test"
     for codon_start in "123":
         seqf.qualifiers["codon_start"] = [codon_start]
         feature = Feature.from_biopython(seqf)
         assert feature._original_codon_start == int(codon_start) - 1
         assert feature.location.end == AfterPosition(12 - feature._original_codon_start)
         new = feature.to_biopython()[0]
         assert new.qualifiers["codon_start"] == [codon_start]
         assert new.location.start == seqf.location.start
         assert new.location.end == seqf.location.end
Exemple #14
0
 def test_compound_overlap_reverse(self):
     self.feature.location = CompoundLocation([FeatureLocation(15, 24, -1),
                                               FeatureLocation(10, 16, -1)])
     assert self.get_sub(0, 1) == FeatureLocation(21, 24, -1)
     assert self.get_sub(2, 4) == CompoundLocation([FeatureLocation(15, 18, -1),
                                                    FeatureLocation(13, 16, -1)])
     assert self.get_sub(4, 5) == FeatureLocation(10, 13, -1)
Exemple #15
0
 def test_compound_overlap_forward(self):
     self.feature.location = CompoundLocation([FeatureLocation(10, 16, 1),
                                               FeatureLocation(15, 24, 1)])
     assert self.get_sub(0, 1) == FeatureLocation(10, 13, 1)
     assert self.get_sub(1, 3) == CompoundLocation([FeatureLocation(13, 16, 1),
                                                    FeatureLocation(15, 18, 1)])
     assert self.get_sub(4, 5) == FeatureLocation(21, 24, 1)
Exemple #16
0
 def test_simple_reverse(self):
     self.feature.location = FeatureLocation(10, 40, -1)
     assert self.get_sub(0, 1) == FeatureLocation(37, 40, -1)
     assert self.get_sub(2, 4) == FeatureLocation(28, 34, -1)
     assert self.get_sub(9, 10) == FeatureLocation(10, 13, -1)
Exemple #17
0
 def test_simple_forward(self):
     assert self.get_sub(0, 1) == FeatureLocation(10, 13, 1)
     assert self.get_sub(2, 4) == FeatureLocation(16, 22, 1)
     assert self.get_sub(9, 10) == FeatureLocation(37, 40, 1)
Exemple #18
0
 def setUp(self):
     self.feature = Feature(FeatureLocation(10, 40, 1), feature_type="test")
     self.get_sub = self.feature.get_sub_location_from_protein_coordinates
Exemple #19
0
 def test_negative_locations(self):
     loc = FeatureLocation(-2, 500, strand=1)
     with self.assertRaisesRegex(ValueError, "negative coordinate"):
         Feature(loc, feature_type="")