Skip to content Skip to sidebar Skip to footer

Loops For Sequence Output - Python

I've been struggling to figure out a way to get my sequence printed out with a 6-mer in the sequence on separate lines. As so (note the spacing of each line): atgctagtcatc tgctag

Solution 1:

This should work:

width = 6for i in range(len(sequence) - width):
    print" " * i + sequence[i:i+width]

Solution 2:

You could try the following (as far as I see you're using python2)

seq = "atgctagtcatc"
spaces = " "for i in range(0, len(seq)):
    print spaces*i+seq[i:i+6]

Output:

atgcta
 tgctag
  gctagt
   ctagtc
    tagtca
     agtcat
      gtcatc
       tcatc
        catc
         atc
          tc
           c

Post a Comment for "Loops For Sequence Output - Python"