Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
单字符串的多行输入[python]_Python_String_Replace_Biopython - Fatal编程技术网

单字符串的多行输入[python]

单字符串的多行输入[python],python,string,replace,biopython,Python,String,Replace,Biopython,我希望能够允许我的用户从ncbi复制和粘贴基因组序列,如下所示: 1 CataacGCG gcctgccggg ccgataaaaa gaaaccgcgg CGCCCCCG GACACCAC 61 actggctctc GAACCCGGA CGCGCAGAG ggacccgggc gcgggtccgc cggtaagagc 我试图让我的程序接受任何大小的输入,并将其作为单个字符串使用(在过程中删除空格和数字)。当我目前尝试它时,它会分别运行每一行,这并不理想 bad_chars = [' ','

我希望能够允许我的用户从ncbi复制和粘贴基因组序列,如下所示:

1 CataacGCG gcctgccggg ccgataaaaa gaaaccgcgg CGCCCCCG GACACCAC 61 actggctctc GAACCCGGA CGCGCAGAG ggacccgggc gcgggtccgc cggtaagagc

我试图让我的程序接受任何大小的输入,并将其作为单个字符串使用(在过程中删除空格和数字)。当我目前尝试它时,它会分别运行每一行,这并不理想

bad_chars = [' ','0', '1', '2', '3', '4', '5', '6', '7', '8', '9','\n', '\t']
dna = str(input("please enter your DNA sequence \n")).lower()
while dna != "end":
    for y in bad_chars :
        dna = dna.replace(y, '')
    print("input: \n", dna)

    replication = dna.maketrans("tcga", "agct")
    print("Your complimentary sequence is shown below: \n", dna.translate(replication))
    answer = dna.translate(replication)
    transcription = answer.maketrans("tcga", "ucga")
    print("The RNA sequence is shown below: \n", answer.translate(transcription))
    mRNA = answer.translate(transcription)
    n = 3
    codons = [mRNA[i:i+n] for i in range (0, len(mRNA), n)]


    protein = {"uuu" : "Phe-", "cuu" : "Leu-", "auu" : "Ile-", "guu" : "Val-",
               "uuc" : "Phe-", "cuc" : "Leu-", "auc" : "Ile-", "guc" : "Val-",
               "uua" : "Leu-", "cua" : "Leu-", "aua" : "Ile-", "gua" : "Val-",
               "uug" : "Leu-", "cug" : "Leu-", "aug" : "Met-", "gug" : "Val-",
               "ucu" : "Ser-", "ccu" : "Pro-", "acu" : "Thr-", "gcu" : "Ala-",
               "ucc" : "Ser-", "ccc" : "Pro-", "acc" : "Thr-", "gcc" : "Ala-",
               "uca" : "Ser-", "cca" : "Pro-", "aca" : "Thr-", "gca" : "Ala-",
               "ucg" : "Ser-", "ccg" : "Pro-", "acg" : "Thr-", "gcg" : "Ala-",
               "uau" : "Tyr-", "cau" : "His-", "aau" : "Asn-", "gau" : "Asp-",
               "uac" : "Tyr-", "cac" : "His-", "aac" : "Asn-", "gac" : "Asp-",
               "uaa" : "STOP", "caa" : "Gin-", "aaa" : "Lys-", "gaa" : "Glu-",
               "uag" : "STOP", "cag" : "Gin-", "aag" : "Lys-", "gag" : "Glu-",
               "ugu" : "Cys-", "cgu" : "Arg-", "agu" : "Ser-", "ggu" : "Gly-",
               "ugc" : "Cys-", "cgc" : "Arg-", "agc" : "Ser-", "ggc" : "Gly-",
               "uga" : "STOP", "cga" : "Arg-", "aga" : "Arg-", "gga" : "Gly-",
               "ugg" : "Trp-", "cgg" : "Arg-", "agg" : "Arg-", "ggg" : "Gly-" 
               }
    protein_sequence = ""

    for x in codons:
        if x in protein:
            protein_sequence += protein[x]
        else:
            protein_sequence += x
    print("translation: ", protein_sequence)
    dna = str(input("please enter your DNA sequence or 'end' to quit \n")).lower()
    if dna == "end":
        print ("thank you.")

关于如何做到这一点有什么想法吗?

这类应用的惯例是听EOF(CTRL-D)

有了这段代码,你就可以做到

print("Paste your DNA and hit CTRL-D.")

lines = []
while True:
    try:
        line = input()
        lines.append(line)
    except EOFError:
        break

all_lines = "".join(lines)

print("Got your DNA:")    
print(all_lines)

您可以收集列表中的输入,直到输入“结束”。然后使用“str.join”从列表字符串中创建一个字符串并处理它。我不确定我是否理解正确。。。您想收集多个DNA字符串的输入并同时处理它们吗?