1

I need to know how to format a single strand of DNA in one line of code into a given width so it reads as multiple lines. What I am trying to do is insert a newline character at a given width. This is my code thus far:

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

When executed the program does not terminate and the output file is blank.

Tagc
  • 8,736
  • 7
  • 61
  • 114
aschenk04
  • 21
  • 3
  • 1
    Why you do not use `biopython` http://biopython.org/ ? – Jose Ricardo Bustos M. Jan 27 '17 at 18:19
  • without attempting to address the problem in the OP, I would strongly suggest looking into Biopython and the `SeqIO` package instead of trying to manipulate this manually. The `SeqIO` package ( [overview here](http://biopython.org/wiki/SeqIO), and [tutorial here](http://biopython.org/DIST/docs/tutorial/Tutorial.html) with the section on sequence manipulation [here](http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc16)) is specifically designed for manipulation of DNA data. – user5359531 Jan 27 '17 at 18:20

0 Answers0