def test_repr(): 'It test the repr reader' assert u'a (h)' == _cast_to_class("u'a (h)'") assert ('adios',) == _cast_to_class("('adios',)") assert ['arab1', 'arab2'] == _cast_to_class("['arab1', 'arab2']") assert ('arab1', 'arab2') == _cast_to_class("('arab1', 'arab2')") result = _cast_to_class("{1: 2}") assert {1: 2} == result assert {'al': {'c': 1}, 'T': 2} == _cast_to_class("{'al': {'c': 1}, 'T': 2}") seq1 = SeqWithQuality(seq=Seq('ATCT')) seq2 = SeqWithQuality(seq=Seq('AAAA')) fcontent = repr(seq1) + '\n' + repr(seq2) + '\n' fhand = StringIO.StringIO(fcontent) seqs = list(seqs_in_file(fhand, format='repr')) assert repr(seqs[0]) == repr(seq1) assert repr(seqs[1]) == repr(seq2) #with quality seq1 = SeqWithQuality(seq=Seq('ATCT'), qual=[10, 2, 3, 4]) fcontent = repr(seq1) + '\n' fhand = StringIO.StringIO(fcontent) seqs = list(seqs_in_file(fhand, format='repr')) assert repr(seqs[0]) == repr(seq1) #a seq with features seq1 = SeqWithQuality(seq=Seq('GAAAAGATGTG', SingleLetterAlphabet()), id='seq', name='seq', description='', dbxrefs=[], features=[SeqFeature(FeatureLocation(ExactPosition(478), ExactPosition(478)), type='intron', qualifiers={'db': 'tomato'} ), SeqFeature(FeatureLocation(ExactPosition(572), ExactPosition(572)), type='intron', qualifiers={'db': 'tomato'} )], annotations={}, qual=None) fcontent = repr(seq1) + '\n' fhand = StringIO.StringIO(fcontent) seq0 = list(seqs_in_file(fhand, format='repr'))[0] assert seq0.seq == seq1.seq assert seq0.qual == seq1.qual assert seq0.description == seq1.description assert seq0.annotations == seq1.annotations feat0 = seq0.features[0] feat1 = seq1.features[0] assert feat0.type == feat1.type assert feat0.qualifiers == feat1.qualifiers assert str(feat0.location) == str(feat1.location) #some more qualifiers fhand = tempfile.NamedTemporaryFile(suffix='.repr') seq1 = SeqWithQuality(id='seqid', name='seqname', description='seqdescription', seq=Seq('ATGAT')) seq1.letter_annotations["phred_quality"] = [40, 40, 38, 30, 30] seq1.annotations['source'] = 'ara1' seqfeature = SeqFeature(location=FeatureLocation(5, 8), type='orthologs', qualifiers={'arabidposis':['arab1', 'arab2']}) seq1.features.append(seqfeature) fcontent = repr(seq1) + '\n' fhand = StringIO.StringIO(fcontent) seq0 = list(seqs_in_file(fhand, format='repr'))[0] assert seq0.seq == seq1.seq assert seq0.qual == seq1.qual assert seq0.description == seq1.description assert seq0.annotations == seq1.annotations feat0 = seq0.features[0] feat1 = seq1.features[0] assert feat0.type == feat1.type assert feat0.qualifiers == feat1.qualifiers assert str(feat0.location) == str(feat1.location) #with snps repr_ = "SeqWithQuality(seq=Seq('GGGGATTTG', Alphabet()), features=[SeqFeature(FeatureLocation(ExactPosition(213),ExactPosition(213)), type='snv', qualifiers={'alleles': {('C', 3): {'read_groups': ['group1+454', 'group1+454', 'group1+454'], 'qualities': [44.0, 44.0, 44.0], 'libraries': ['group1', 'group1', 'group1'], 'read_names': ['seq1', 'seq4', 'seq7'], 'orientations': [True, True, True], 'samples': ['group1+454', 'group1+454', 'group1+454'], 'quality': 66.0, 'mapping_qualities': [149, 149, 149]}, ('T', 0): {'read_groups': ['group1+454', 'group1+454', 'group1+454', 'group1+454', 'group1+454', 'group1+454'], 'qualities': [44.0, 44.0, 44.0, 44.0, 44.0, 44.0], 'libraries': ['group1', 'group1', 'group1', 'group1', 'group1', 'group1'], 'read_names': ['seq2', 'seq3', 'seq5', 'seq6', 'seq8', 'seq9'], 'orientations': [True, True, True, True, True, True], 'samples': ['group1+454', 'group1+454', 'group1+454', 'group1+454', 'group1+454', 'group1+454'], 'quality': 66.0, 'mapping_qualities': [28, 28, 28, 28, 28, 28]}}, 'reference_allele': 'C'} )])\n" alleles = {('C', 3): {'read_groups': ['group1+454', 'group1+454', 'group1+454'], 'qualities': [44.0, 44.0, 44.0], 'libraries': ['group1', 'group1', 'group1'], 'read_names': ['seq1', 'seq4', 'seq7'], 'orientations': [True, True, True], 'samples': ['group1+454', 'group1+454', 'group1+454'], 'quality': 66.0, 'mapping_qualities': [149, 149, 149]}, ('T', 0): {'read_groups': ['group1+454', 'group1+454', 'group1+454', 'group1+454', 'group1+454', 'group1+454'], 'qualities': [44.0, 44.0, 44.0, 44.0, 44.0, 44.0], 'libraries': ['group1', 'group1', 'group1', 'group1', 'group1', 'group1'], 'read_names': ['seq2', 'seq3', 'seq5', 'seq6', 'seq8', 'seq9'], 'orientations': [True, True, True, True, True, True], 'samples': ['group1+454', 'group1+454', 'group1+454', 'group1+454', 'group1+454', 'group1+454'], 'quality': 66.0, 'mapping_qualities': [28, 28, 28, 28, 28, 28]} } fcontent = repr_ fhand = StringIO.StringIO(fcontent) seq0 = list(seqs_in_file(fhand, format='repr'))[0] alleles0 = seq0.features[0].qualifiers['alleles'] assert alleles == alleles0