Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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"
Exemplo n.º 5
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")
Exemplo n.º 6
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
Exemplo n.º 7
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]
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
0
 def test_negative_locations(self):
     loc = FeatureLocation(-2, 500, strand=1)
     with self.assertRaisesRegex(ValueError, "negative coordinate"):
         Feature(loc, feature_type="")