示例#1
0
def tests():
    print("Running tests on DNAMapper.")
    import re, random
    testsequence = sequtils.bioseq(sequtils.random_dna(100))
    maptargets = [sequtils.random_iupac_dna(random.randint(2,10)) for x in range(2,7)]
    mapper = DNAMapper(maptargets,verbose=True)

    def verify_stringmap():
        result = True
        string_map = mapper.map_string(testsequence)
        print("\t ----- Checking Hits for Consistency ----- ")
        for x in string_map:
            x_dict = string_map[x]
            for pattern in x_dict['patterns']:
                thisre = re.compile(pattern)
                if not thisre.match(testsequence[x:x+x_dict['span']]):
                    print("\tFailed to match",pattern,"with substring",testsequence[x:])
                    result = False
                else:
                    print("\tMatched",pattern,"successfully at target site.")
        return result

    def verify_framemap(frame):
        result = True
        #mycodons = testsequence.as_codon_list(trailing=True)
        mycodons = testsequence.codons(leading=False,trailing=True) # Leading?
        codon_map = mapper.codon_indices(testsequence,frame)
        print("\t ----- Checking Hits for Consistency ----- ")
        for indexC in sorted(codon_map.keys()):
            region = ''.join(mycodons[indexC:indexC+codon_map[indexC]['span']])
            for pattern in codon_map[indexC]["patterns"]:
                thisre = re.compile(pattern)
                if not thisre.findall(region):
                    print("\tNon-match with pattern",thisre.pattern,"in string",region)
                    print("\t\tDebug dict:",codon_map[indexC]['debug'])
                    result = False
                else:
                    pass
                    #print("\tMatch with pattern",thisre.pattern,"in string",region)
        return result

    allpassing = True
    if verify_stringmap():
        print("Passed stringmap tests.\n","==============================\n")
    else:
        print("Failed stringmap tests.\n","==============================\n")
        allpassing = False
    for x in range(0,3):
        if verify_framemap(x):
            print("Passed framemap test at frame",str(x)+".\n","==============================\n")
        else:
            print("Failed framemap test at frame",str(x)+".\n","==============================\n")
            allpassing = False
    if allpassing: print("\n >>> All Tests Passed! <<<")
    else: print("\n >>> Tests Failed <<<")
示例#2
0
def tests(aminos):
    ecoli_table='{"A": {"GCA": 0.24242424242424243, "GCC": 0.1919191919191919, "GCT": 0.12121212121212122, "GCG": 0.4444444444444444}, "C": {"TGC": 0.5772005772005773, "TGT": 0.42279942279942284}, "E": {"GAG": 0.29558634020618557, "GAA": 0.7044136597938144}, "D": {"GAT": 0.46, "GAC": 0.54}, "G": {"GGT": 0.6060606060606061, "GGG": 0.0, "GGA": 0.0, "GGC": 0.3939393939393939}, "F": {"TTC": 0.55, "TTT": 0.45}, "I": {"ATT": 0.5820752914198357, "ATC": 0.34702847315115615, "ATA": 0.07089623542900822}, "H": {"CAC": 0.45275181723779856, "CAT": 0.5472481827622014}, "K": {"AAG": 0.49, "AAA": 0.51}, "M": {"ATG": 1.0}, "L": {"CTT": 0.02, "CTG": 0.78, "CTA": 0.0, "CTC": 0.03, "TTA": 0.03, "TTG": 0.14}, "N": {"AAT": 0.4726604711476119, "AAC": 0.5273395288523882}, "Q": {"CAA": 0.45, "CAG": 0.55}, "P": {"CCT": 0.09, "CCG": 0.81, "CCA": 0.1, "CCC": 0.0}, "S": {"TCT": 0.10204081632653061, "AGC": 0.6938775510204082, "TCG": 0.05102040816326531, "AGT": 0.0, "TCC": 0.1326530612244898, "TCA": 0.02040816326530612}, "R": {"AGG": 0.02671690357938003, "CGC": 0.4447679397157047, "CGG": 0.07021750299708854, "CGA": 0.073642747045727, "AGA": 0.023462921733173492, "CGT": 0.3611919849289262}, "T": {"ACC": 0.57, "ACA": 0.0, "ACG": 0.33, "ACT": 0.09999999999999999}, "W": {"TGG": 1.0}, "V": {"GTA": 0.1735462488701416, "GTC": 0.17640855679421516, "GTT": 0.2529376318168123, "GTG": 0.397107562518831}, "Y": {"TAT": 0.5342029907731467, "TAC": 0.46579700922685335}, "*": {"TAG": 0.0, "TGA": 0.3576642335766423, "TAA": 0.6423357664233577}}'
    import DNAMapper
    import translators
    import random
    print("\nRunning tests for Splicer object and splice_amino_to_codons function.")
    testtable = translators.ReverseTranslator(ecoli_table)
    testtable.set_
    maptargets = [sequtils.random_iupac_dna(random.randint(6,10)) for x in range(2,7)]
    print("Using the optimised E.coli table as default.")
    print("Targeted sites to splice around are:",'; '.join(maptargets))
    testmapper = DNAMapper.DNAMapper(maptargets)
    print(''.join(splice_aminos_to_codons(aminos, testtable, testmapper, 100, verbose=True)),"\n")
示例#3
0
def tests(aminos):
    ecoli_table='{"A": {"GCA": 0.24242424242424243, "GCC": 0.1919191919191919, "GCT": 0.12121212121212122, "GCG": 0.4444444444444444}, "C": {"TGC": 0.5772005772005773, "TGT": 0.42279942279942284}, "E": {"GAG": 0.29558634020618557, "GAA": 0.7044136597938144}, "D": {"GAT": 0.46, "GAC": 0.54}, "G": {"GGT": 0.6060606060606061, "GGG": 0.0, "GGA": 0.0, "GGC": 0.3939393939393939}, "F": {"TTC": 0.55, "TTT": 0.45}, "I": {"ATT": 0.5820752914198357, "ATC": 0.34702847315115615, "ATA": 0.07089623542900822}, "H": {"CAC": 0.45275181723779856, "CAT": 0.5472481827622014}, "K": {"AAG": 0.49, "AAA": 0.51}, "M": {"ATG": 1.0}, "L": {"CTT": 0.02, "CTG": 0.78, "CTA": 0.0, "CTC": 0.03, "TTA": 0.03, "TTG": 0.14}, "N": {"AAT": 0.4726604711476119, "AAC": 0.5273395288523882}, "Q": {"CAA": 0.45, "CAG": 0.55}, "P": {"CCT": 0.09, "CCG": 0.81, "CCA": 0.1, "CCC": 0.0}, "S": {"TCT": 0.10204081632653061, "AGC": 0.6938775510204082, "TCG": 0.05102040816326531, "AGT": 0.0, "TCC": 0.1326530612244898, "TCA": 0.02040816326530612}, "R": {"AGG": 0.02671690357938003, "CGC": 0.4447679397157047, "CGG": 0.07021750299708854, "CGA": 0.073642747045727, "AGA": 0.023462921733173492, "CGT": 0.3611919849289262}, "T": {"ACC": 0.57, "ACA": 0.0, "ACG": 0.33, "ACT": 0.09999999999999999}, "W": {"TGG": 1.0}, "V": {"GTA": 0.1735462488701416, "GTC": 0.17640855679421516, "GTT": 0.2529376318168123, "GTG": 0.397107562518831}, "Y": {"TAT": 0.5342029907731467, "TAC": 0.46579700922685335}, "*": {"TAG": 0.0, "TGA": 0.3576642335766423, "TAA": 0.6423357664233577}}'
    import random
    print("\nRunning tests for Substitutor.")
    testtable = translators.ReverseTranslator(ecoli_table)
    maptargets = [sequtils.random_iupac_dna(random.randint(5,7)) for x in range(2,10)]
    print("Using the optimised E.coli table as default.")
    print("Targeted sites to edit away are:",'; '.join(maptargets))
    testmapper = DNAMapper.DNAMapper(maptargets)
    Subber = Substitutor(table=testtable, mapper=testmapper, verbose=True)
    test_codon_list = testtable.get_codons(aminos)
    scrubbed_codons = Subber.remove_mapped(test_codon_list)
    print("Final codon list:",scrubbed_codons)
    print("Translates to:",testtable.for_table.translate_codon_list_to_str(scrubbed_codons))
    print("Original Heatmap:\t",'-'.join([str(int(x*100)).zfill(2) for x in testtable.heat_map(test_codon_list)]))
    print("Heatmap:\t\t",'-'.join([str(int(x*100)).zfill(2) for x in testtable.heat_map(scrubbed_codons)]))