def test_reverse_complements(self): """Test double reverse complement preserves the sequence.""" sorted_amb_rna = sorted(ambiguous_rna_values) sorted_amb_dna = sorted(ambiguous_dna_values) for sequence in [ Seq.Seq("".join(sorted_amb_rna)), Seq.Seq("".join(sorted_amb_dna)), Seq.Seq("".join(sorted_amb_rna), Alphabet.generic_rna), Seq.Seq("".join(sorted_amb_dna), Alphabet.generic_dna), Seq.Seq("".join(sorted_amb_rna).replace("X", ""), IUPAC.IUPACAmbiguousRNA()), Seq.Seq("".join(sorted_amb_dna).replace("X", ""), IUPAC.IUPACAmbiguousDNA()), Seq.Seq("AWGAARCKG"), ]: # Note no U or T reversed_sequence = sequence.reverse_complement() self.assertEqual(str(sequence), str(reversed_sequence.reverse_complement()))
def setUp(self): self.test_seqs = [ Seq.Seq("TCAAAAGGATGCATCATG", IUPAC.unambiguous_dna), Seq.Seq("ATGAAACTG"), Seq.Seq("ATGAARCTG"), Seq.Seq("AWGAARCKG"), # Note no U or T Seq.Seq("".join(ambiguous_rna_values)), Seq.Seq("".join(ambiguous_dna_values)), Seq.Seq("".join(ambiguous_rna_values), Alphabet.generic_rna), Seq.Seq("".join(ambiguous_dna_values), Alphabet.generic_dna), Seq.Seq("".join(ambiguous_rna_values), IUPAC.IUPACAmbiguousRNA()), Seq.Seq("".join(ambiguous_dna_values), IUPAC.IUPACAmbiguousDNA()), Seq.Seq("AWGAARCKG", Alphabet.generic_dna), Seq.Seq("AUGAAACUG", Alphabet.generic_rna), Seq.Seq("ATGAAACTG", IUPAC.unambiguous_dna), Seq.Seq("ATGAAACTGWN", IUPAC.ambiguous_dna), Seq.Seq("AUGAAACUG", Alphabet.generic_rna), Seq.Seq("AUGAAACUG", IUPAC.unambiguous_rna), Seq.Seq("AUGAAACUGWN", IUPAC.ambiguous_rna), Seq.Seq("ATGAAACTG", Alphabet.generic_nucleotide), Seq.MutableSeq("ATGAAACTG", Alphabet.generic_dna), Seq.MutableSeq("AUGaaaCUG", IUPAC.unambiguous_rna), ]
compl_values = complement(values).replace( "T", "U") # need to help as no alphabet print "%s={%s} --> {%s}=%s" % \ (ambig_char, values, compl_values, ambiguous_rna_complement[ambig_char]) assert set(compl_values) == set( ambiguous_rna_values[ambiguous_rna_complement[ambig_char]]) print print "Reverse complements:" for sequence in [ Seq.Seq("".join(sorted(ambiguous_rna_values))), Seq.Seq("".join(sorted(ambiguous_dna_values))), Seq.Seq("".join(sorted(ambiguous_rna_values)), Alphabet.generic_rna), Seq.Seq("".join(sorted(ambiguous_dna_values)), Alphabet.generic_dna), Seq.Seq("".join(sorted(ambiguous_rna_values)).replace("X", ""), IUPAC.IUPACAmbiguousRNA()), Seq.Seq("".join(sorted(ambiguous_dna_values)).replace("X", ""), IUPAC.IUPACAmbiguousDNA()), Seq.Seq("AWGAARCKG") ]: # Note no U or T print "%s -> %s" \ % (repr(sequence), repr(Seq.reverse_complement(sequence))) assert str(sequence) \ == str(Seq.reverse_complement(Seq.reverse_complement(sequence))), \ "Dobule reverse complement didn't preserve the sequence!" print ########################################################################### test_seqs = [ s,
ambiguous_rna_values, ) from Bio.Data.CodonTable import TranslationError, standard_dna_table from Bio.Seq import MutableSeq test_seqs = [ Seq.Seq("TCAAAAGGATGCATCATG", IUPAC.unambiguous_dna), Seq.Seq("T", IUPAC.ambiguous_dna), Seq.Seq("ATGAAACTG"), Seq.Seq("ATGAARCTG"), Seq.Seq("AWGAARCKG"), # Note no U or T Seq.Seq("".join(ambiguous_rna_values)), Seq.Seq("".join(ambiguous_dna_values)), Seq.Seq("".join(ambiguous_rna_values), Alphabet.generic_rna), Seq.Seq("".join(ambiguous_dna_values), Alphabet.generic_dna), Seq.Seq("".join(ambiguous_rna_values), IUPAC.IUPACAmbiguousRNA()), Seq.Seq("".join(ambiguous_dna_values), IUPAC.IUPACAmbiguousDNA()), Seq.Seq("AWGAARCKG", Alphabet.generic_dna), Seq.Seq("AUGAAACUG", Alphabet.generic_rna), Seq.Seq("ATGAAACTG", IUPAC.unambiguous_dna), Seq.Seq("ATGAAA-CTG", Alphabet.generic_dna), Seq.Seq("ATGAAACTGWN", IUPAC.ambiguous_dna), Seq.Seq("AUGAAACUG", Alphabet.generic_rna), Seq.Seq("AUGAAA==CUG", Alphabet.generic_rna), Seq.Seq("AUGAAACUG", IUPAC.unambiguous_rna), Seq.Seq("AUGAAACUGWN", IUPAC.ambiguous_rna), Seq.Seq("ATGAAACTG", Alphabet.generic_nucleotide), Seq.Seq("AUGAAACTG", Alphabet.generic_nucleotide), # U and T Seq.MutableSeq("ATGAAACTG", Alphabet.generic_dna), Seq.MutableSeq("AUGaaaCUG", IUPAC.unambiguous_rna), Seq.Seq("ACTGTCGTCT", Alphabet.generic_protein),
print print "RNA Ambiguity mapping:", sorted_dict(ambiguous_rna_values) print "RNA Complement mapping:", sorted_dict(ambiguous_rna_complement) for ambig_char, values in sorted(ambiguous_rna_values.iteritems()): compl_values = complement(values).replace("T","U") # need to help as no alphabet print("%s={%s} --> {%s}=%s" % \ (ambig_char, values, compl_values, ambiguous_rna_complement[ambig_char])) assert set(compl_values) == set(ambiguous_rna_values[ambiguous_rna_complement[ambig_char]]) print print("Reverse complements:") for sequence in [Seq.Seq("".join(sorted(ambiguous_rna_values))), Seq.Seq("".join(sorted(ambiguous_dna_values))), Seq.Seq("".join(sorted(ambiguous_rna_values)), Alphabet.generic_rna), Seq.Seq("".join(sorted(ambiguous_dna_values)), Alphabet.generic_dna), Seq.Seq("".join(sorted(ambiguous_rna_values)).replace("X",""), IUPAC.IUPACAmbiguousRNA()), Seq.Seq("".join(sorted(ambiguous_dna_values)).replace("X",""), IUPAC.IUPACAmbiguousDNA()), Seq.Seq("AWGAARCKG")]: # Note no U or T print("%s -> %s" \ % (repr(sequence), repr(Seq.reverse_complement(sequence)))) assert str(sequence) \ == str(Seq.reverse_complement(Seq.reverse_complement(sequence))), \ "Dobule reverse complement didn't preserve the sequence!" print ########################################################################### test_seqs = [s,t,u, Seq.Seq("ATGAAACTG"), "ATGAAACtg", #TODO - Fix ambiguous translation