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)
def test_within(self): """Features: write/read simple within locations.""" f = SeqFeature(FeatureLocation(WithinPosition(2,6),10), \ strand=+1, type="CDS") self.assertEqual(_insdc_feature_location_string(f), "(3.9)..10") self.record.features.append(f) f = SeqFeature(FeatureLocation(WithinPosition(12,6), WithinPosition(20,8)), \ strand=+1, type="CDS") self.assertEqual(_insdc_feature_location_string(f), "(13.19)..(20.28)") self.record.features.append(f) f = SeqFeature(FeatureLocation(25,WithinPosition(30,3)), \ strand=+1, type="misc_feature") self.assertEqual(_insdc_feature_location_string(f), "26..(30.33)") self.record.features.append(f) f = SeqFeature(FeatureLocation(WithinPosition(35,4),40), \ strand=-1, type="rRNA") self.assertEqual(_insdc_feature_location_string(f), "complement((36.40)..40)") self.record.features.append(f) f = SeqFeature(FeatureLocation(WithinPosition(45,2), WithinPosition(50,3)), \ strand=-1, type="repeat_region") self.assertEqual(_insdc_feature_location_string(f), "complement((46.48)..(50.53))") self.record.features.append(f) f = SeqFeature(FeatureLocation(55,WithinPosition(60,5)), \ strand=-1, type="CDS") self.assertEqual(_insdc_feature_location_string(f), "complement(56..(60.65))") self.record.features.append(f) self.write_read_check()
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], )
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()
def test_fuzzy(self): """Test fuzzy representations.""" # check the positions alone exact_pos = ExactPosition(5) within_pos_s = WithinPosition(10, left=10, right=13) within_pos_e = WithinPosition(13, left=10, right=13) between_pos_e = BetweenPosition(24, left=20, right=24) before_pos = BeforePosition(15) after_pos = AfterPosition(40) self.assertEqual(int(within_pos_s), 10) self.assertEqual(str(within_pos_s), "(10.13)") self.assertEqual(int(within_pos_e), 13) self.assertEqual(str(within_pos_e), "(10.13)") self.assertEqual(int(between_pos_e), 24) self.assertEqual(str(between_pos_e), "(20^24)") self.assertEqual(str(before_pos), "<15") self.assertEqual(str(after_pos), ">40") # put these into Locations location1 = FeatureLocation(exact_pos, within_pos_e) location2 = FeatureLocation(before_pos, between_pos_e) location3 = FeatureLocation(within_pos_s, after_pos) self.assertEqual(str(location1), "[5:(10.13)]") self.assertEqual(str(location1.start), "5") self.assertEqual(str(location1.end), "(10.13)") self.assertEqual(str(location2), "[<15:(20^24)]") self.assertEqual(str(location2.start), "<15") self.assertEqual(str(location2.end), "(20^24)") self.assertEqual(str(location3), "[(10.13):>40]") self.assertEqual(str(location3.start), "(10.13)") self.assertEqual(str(location3.end), ">40") # --- test non-fuzzy representations self.assertEqual(location1.nofuzzy_start, 5) self.assertEqual(location1.nofuzzy_end, 13) self.assertEqual(location2.nofuzzy_start, 15) self.assertEqual(location2.nofuzzy_end, 24) self.assertEqual(location3.nofuzzy_start, 10) self.assertEqual(location3.nofuzzy_end, 40)