コード例 #1
0
ファイル: test_SeqFeature.py プロジェクト: wenh06/biopython
    def test_pickle(self):
        """Test pickle behaviour of position instances."""
        # setup
        import pickle

        within_pos = WithinPosition(10, left=10, right=13)
        between_pos = BetweenPosition(24, left=20, right=24)
        oneof_pos = OneOfPosition(
            1888,
            [ExactPosition(1888), ExactPosition(1901)])
        # test __getnewargs__
        self.assertEqual(within_pos.__getnewargs__(), (10, 10, 13))
        self.assertEqual(between_pos.__getnewargs__(), (24, 20, 24))
        self.assertEqual(
            oneof_pos.__getnewargs__(),
            (1888, [ExactPosition(1888),
                    ExactPosition(1901)]),
        )
        # test pickle behaviour
        within_pos2 = pickle.loads(pickle.dumps(within_pos))
        between_pos2 = pickle.loads(pickle.dumps(between_pos))
        oneof_pos2 = pickle.loads(pickle.dumps(oneof_pos))
        self.assertEqual(within_pos, within_pos2)
        self.assertEqual(between_pos, between_pos2)
        self.assertEqual(oneof_pos, oneof_pos2)
        self.assertEqual(within_pos._left, within_pos2._left)
        self.assertEqual(within_pos._right, within_pos2._right)
        self.assertEqual(between_pos._left, between_pos2._left)
        self.assertEqual(between_pos._right, between_pos2._right)
        self.assertEqual(oneof_pos.position_choices,
                         oneof_pos2.position_choices)
コード例 #2
0
ファイル: test_SeqRecord.py プロジェクト: tulw4r/biopython
 def setUp(self):
     f0 = SeqFeature(
         FeatureLocation(0, 26),
         type="source",
         qualifiers={"mol_type": ["fake protein"]},
     )
     f1 = SeqFeature(FeatureLocation(0, ExactPosition(10)))
     f2 = SeqFeature(
         FeatureLocation(WithinPosition(12, left=12, right=15),
                         BeforePosition(22)))
     f3 = SeqFeature(
         FeatureLocation(
             AfterPosition(16),
             OneOfPosition(
                 26,
                 [ExactPosition(25), AfterPosition(26)]),
         ))
     self.record = SeqRecord(
         Seq("ABCDEFGHIJKLMNOPQRSTUVWZYX", generic_protein),
         id="TestID",
         name="TestName",
         description="TestDescr",
         dbxrefs=["TestXRef"],
         annotations={"k": "v"},
         letter_annotations={"fake": "X" * 26},
         features=[f0, f1, f2, f3],
     )
コード例 #3
0
 def test_fuzzy_join(self):
     """Features: write/read fuzzy join locations."""
     f1 = SeqFeature(FeatureLocation(BeforePosition(10), 20), strand=+1)
     f2 = SeqFeature(FeatureLocation(25, AfterPosition(40)), strand=+1)
     f = self.make_join_feature([f1, f2])
     self.record.features.append(f)
     self.assertEqual(_insdc_feature_location_string(f),
                      "join(<11..20,26..>40)")
     f1 = SeqFeature(FeatureLocation(
         OneOfPosition([ExactPosition(107),
                        ExactPosition(110)]), 120),
                     strand=+1)
     f2 = SeqFeature(FeatureLocation(125, 140), strand=+1)
     f3 = SeqFeature(FeatureLocation(145, WithinPosition(150, 10)),
                     strand=+1)
     f = self.make_join_feature([f1, f2, f3], "CDS")
     self.assertEqual(_insdc_feature_location_string(f),
                      "join(one-of(108,111)..120,126..140,146..(150.160))")
     self.record.features.append(f)
     f1 = SeqFeature(FeatureLocation(BeforePosition(210), 220), strand=-1)
     f2 = SeqFeature(FeatureLocation(225, WithinPosition(240, 4)),
                     strand=-1)
     f = self.make_join_feature([f1, f2], "gene")
     self.assertEqual(_insdc_feature_location_string(f),
                      "complement(join(<211..220,226..(240.244)))")
     self.record.features.append(f)
     f1 = SeqFeature(FeatureLocation(AfterPosition(310), 320), strand=-1)
     f2 = SeqFeature(FeatureLocation(
         325, OneOfPosition([ExactPosition(340),
                             ExactPosition(337)])),
                     strand=-1)
     f3 = SeqFeature(FeatureLocation(345, WithinPosition(350, 5)),
                     strand=-1)
     f = self.make_join_feature([f1, f2, f3], "CDS")
     self.assertEqual(
         _insdc_feature_location_string(f),
         "complement(join(>311..320,326..one-of(340,337),346..(350.355)))")
     self.record.features.append(f)
     self.write_read_check()
コード例 #4
0
 def test_oneof(self):
     """Features: write/read simple one-of locations."""
     start = OneOfPosition(
         [ExactPosition(0),
          ExactPosition(3),
          ExactPosition(6)])
     f = SeqFeature(FeatureLocation(start, 21), strand=+1, type="CDS")
     self.assertEqual(_insdc_feature_location_string(f),
                      "one-of(1,4,7)..21")
     self.record.features.append(f)
     start = OneOfPosition([ExactPosition(x) for x in [10, 13, 16]])
     end = OneOfPosition([ExactPosition(x) for x in [41, 44, 50]])
     f = SeqFeature(FeatureLocation(start, end), strand=+1, type="gene")
     self.assertEqual(_insdc_feature_location_string(f),
                      "one-of(11,14,17)..one-of(41,44,50)")
     self.record.features.append(f)
     end = OneOfPosition([ExactPosition(x) for x in [30, 33]])
     f = SeqFeature(FeatureLocation(27, end), strand=+1, type="gene")
     self.assertEqual(_insdc_feature_location_string(f),
                      "28..one-of(30,33)")
     self.record.features.append(f)
     start = OneOfPosition([ExactPosition(x) for x in [36, 40]])
     f = SeqFeature(FeatureLocation(start, 46), strand=-1, type="CDS")
     self.assertEqual(_insdc_feature_location_string(f),
                      "complement(one-of(37,41)..46)")
     self.record.features.append(f)
     start = OneOfPosition([ExactPosition(x) for x in [45, 60]])
     end = OneOfPosition([ExactPosition(x) for x in [70, 90]])
     f = SeqFeature(FeatureLocation(start, end), strand=-1, type="CDS")
     self.assertEqual(_insdc_feature_location_string(f),
                      "complement(one-of(46,61)..one-of(70,90))")
     self.record.features.append(f)
     end = OneOfPosition([ExactPosition(x) for x in [60, 63]])
     f = SeqFeature(FeatureLocation(55, end), strand=-1, type="tRNA")
     self.assertEqual(_insdc_feature_location_string(f),
                      "complement(56..one-of(60,63))")
     self.record.features.append(f)
     self.write_read_check()