统计碱基序列中ATCG出现的个数

统计碱基序列中ATCG出现的个数

题目

Given: A DNA string “s” of length at most 1000 nt.

Return: Four integers (separated by spaces) counting the respective number of times that the symbols ‘A’, ‘C’, ‘G’, and ‘T’ occur in “s”.

Example input:
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC

Should output:
20 12 17 21

Now input:
TCCCTCGAAAACTAGAGGACGCCGTCAAAGTAAGTTGCGTTCTCGTTGACTATAGGCTGCGGTCCCGCCTTACACTGCTTTTGAACATACCTCAGAACACTCTCTATCCCTGGTGTTTACAGGTATTTCGCACGCTTTAACACTAGCCCCTTCAAAACTCCACCTGCTCTTGGATATACCGTAGATGAGACGATTGAGTTATGTTCTCAGCACAAGAGGATAGGTTTGCGAAGAGCGTGGCCTCTACCAAGACCTCGCGAAAGATAGTCGTTGAGGAATAGGTCGCTATTGTCCTGCCGAGCACGTGTAATATTTTAATCGTGGATCCGGAGTCAGACGGGACTGGTCTCTTCTATTGGCCCTCCCTGTTAGCATGCGCAAAAAGTAACGCCCTCGGCAGCGCATAGCGTGATATTGTTGTAACACTGGCTAGCGATCGCGCCATTATCCTTGGCTCAAAGTCTGTCCCTTTCAATACTTACATCAATGAGCCGACATCTAAAGATATGCCCTTGTTCCTTCCGCGTATACTTCGGCGGGGTACAACGGTGAGGCAAGGATTGTCACGCCATGGCGACCTTTGGTCCCCAGTGCAGCCGCCAATCACCTGGGACATGCCAGGAGCCAGCCTGCAGTTTGGTACCTAACCTGTAGGTAAGGGCGGCGCCCGAACCAGCCCTATCTCTGGGTACCGGAGGTTCATTTAGCACGCTAGGTTCCCGTGGAACGGTGTGGAACCCTGCTCTTCCACTGCAGTGTATGATGGTCTGTTGATTGTACCCCACCGACGCCGAAAGTGTAATAAAGCCCACGATTCGCCTGTATCAT

代码

def count(DNA):
    a_count, c_count, g_count, t_count = 0,0,0,0
    for char in DNA:
        if char == 'A':
            a_count += 1
        elif char == 'C':
            c_count += 1
        elif char == 'G':
            g_count += 1
        elif char == 'T':
            t_count += 1
        else:
            continue
    return a_count, c_count, g_count, t_count
q1_input = "TCCCTCGAAAACTAGAGGACGCCGTCAAAGTAAGTTGCGTTCTCGTTGACTATAGGCTGCGGTCCCGCCTTACACTGCTTTTGAACATACCTCAGAACACTCTCTATCCCTGGTGTTTACAGGTATTTCGCACGCTTTAACACTAGCCCCTTCAAAACTCCACCTGCTCTTGGATATACCGTAGATGAGACGATTGAGTTATGTTCTCAGCACAAGAGGATAGGTTTGCGAAGAGCGTGGCCTCTACCAAGACCTCGCGAAAGATAGTCGTTGAGGAATAGGTCGCTATTGTCCTGCCGAGCACGTGTAATATTTTAATCGTGGATCCGGAGTCAGACGGGACTGGTCTCTTCTATTGGCCCTCCCTGTTAGCATGCGCAAAAAGTAACGCCCTCGGCAGCGCATAGCGTGATATTGTTGTAACACTGGCTAGCGATCGCGCCATTATCCTTGGCTCAAAGTCTGTCCCTTTCAATACTTACATCAATGAGCCGACATCTAAAGATATGCCCTTGTTCCTTCCGCGTATACTTCGGCGGGGTACAACGGTGAGGCAAGGATTGTCACGCCATGGCGACCTTTGGTCCCCAGTGCAGCCGCCAATCACCTGGGACATGCCAGGAGCCAGCCTGCAGTTTGGTACCTAACCTGTAGGTAAGGGCGGCGCCCGAACCAGCCCTATCTCTGGGTACCGGAGGTTCATTTAGCACGCTAGGTTCCCGTGGAACGGTGTGGAACCCTGCTCTTCCACTGCAGTGTATGATGGTCTGTTGATTGTACCCCACCGACGCCGAAAGTGTAATAAAGCCCACGATTCGCCTGTATCAT"
print(count(q1_input))

你可能感兴趣的:(ROSALIND_BI,Stronghold,python)