如何在给定宽度后插入'\n',将DNA链格式化为给定宽度?

2024-09-30 04:29:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要知道如何将一行代码中的单链DNA格式化为给定的宽度,这样它就可以读取多行。我要做的是在给定的宽度插入一个换行符。这是我迄今为止的代码:

def formatSeq(dna, width):  #dna strand and given width passed to fucntion
    seq =[]
    start =0

    while start < len(dna):
        if start + width < len(dna):
            seq = seq + dna[start:start+width]]
            start = start + width
        else:
            seq += dna[start:]
        seq.append('\n')

    return seq

执行时,程序不终止,输出文件为空。你知道吗


Tags: and代码len宽度defwidthstartseq

热门问题