【问题标题】:How to properly generate a DNA sequence from user input?如何根据用户输入正确生成 DNA 序列?
【发布时间】:2021-03-18 20:48:20
【问题描述】:

我正在为“软件”创建一个代码,该代码会询问用户他们想要多少个 DNA 条形码 (n) 序列以及他想要的 DNA 条形码的长度(大小)是多少。并且根据用户参数,它必须生成一个文本文件,其中包含总共 n 个大小核苷酸长的 DNA 条形码序列。生成的文件必须遵循 EXACT 格式显示-> 条形码(序列号):DNA 条形码。我遇到的麻烦是创建一个用户输入来询问他们想要多少个序列,他们想要什么大小的序列。

    import io
#given a DNA(A,C,T,G) string and a 1-letter base string,
#returns number of occurences of base in the sequence
def dna_sequence():
    base_counter=0
    seq_len=len(seq)

    for index in range(0,seq_len):
        seq_base=seq[index]
        if seq_base==query_base:
            base_counter=base_counter+1
    return base_counter
#given a DNA(A,C,T,G) sequence string and returns GC content as float
def GC_content(seq):
    g_content=dna_sequence(seq,"G")
    c_content=dna_sequence(seq,"C")
    seq_len=len(seq)
    GC=(g_content+c_content)/float(seq_len)
    return GC
#opens file I want to create and loop over lines
f=io.open("barcode_generator.txt","rU")

for line in f:
    linestripped=line.strip()
    linelist=line.split("\t")
    id=linelist[0]
    sequence=linelist[1]
    seqgc=gc_content(sequence)
    print(id+"\t"+str(seqgc))
f.close()

【问题讨论】:

    标签: python file generated-code


    【解决方案1】:

    我刚刚开始使用 python,目前还没有掌握最新的 Python,但您是否需要代码行 choice=input("How many sequences do you want to generate?")choice2=input("What is the size that you want your sequence?") 才能为您的文本文件获得所需的两个结果?

    【讨论】:

    • 哇,谢谢,这确实有帮助,但我不知道该放在哪里,也不知道它在这段代码中的位置,但这似乎是朝着正确方向迈出的一步!
    猜你喜欢
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-23
    • 2014-04-16
    • 1970-01-01
    • 2014-04-08
    • 2014-02-11
    相关资源
    最近更新 更多