0

I need additional python codes that will number the left column of the output below like I have shown in the right column: The codes here just divides the sequence into 3s. Now I want to number them from 1 to the last as I have done manually in the right column.

cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"

for i in range(0,len(cds),3):
     print cds[i:i+3],
... 
Atg 1
Agt 2
Gaa 3
Cgt 4
Ctg 5
Agc 6
Att 7
Acc 8
Ccg 9
Ctg 10
Ggg 11
Ccg 12
Tat 13
Atc 14
Ggc 15
Gca 16
Caa 17
Taa 18
Taa 19
Mat
  • 188,820
  • 38
  • 367
  • 383

4 Answers4

3
cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"

for num, i in enumerate(range(0,len(cds),3)):
    print cds[i:i+3], num + 1
DrTyrsa
  • 27,759
  • 7
  • 79
  • 83
1

Not sure that this is what you want, but:

cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"
for data in ((i+1, cds[i:i+3], i+1) for i in xrange(0, len(cds), 3)):
    #do something
    print data
Artsiom Rudzenka
  • 24,197
  • 3
  • 30
  • 49
0

Here you may read about this way

>>> cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"
>>> for ind, val in enumerate(range(0,len(cds),3), start=1):
...     print cds[val:val+3].capitalize(), ind
...
Atg 1
Agt 2
Gaa 3
Cgt 4
Ctg 5
Agc 6
Att 7
Acc 8
Ccg 9
Ctg 10
Ggg 11
Ccg 12
Tat 13
Atc 14
Ggc 15
Gca 16
Caa 17
Taa 18
>>>
Community
  • 1
  • 1
tony
  • 1,406
  • 2
  • 21
  • 27
0
for item in map(lambda x,y,z: [z[0]+1,"".join([x,y,z[1]])], list(cds)[::3],list(cds)[1::3],enumerate(list(cds)[2::3])):
    print item[1].capitalize(), item[0]
Vader
  • 3,085
  • 21
  • 37
  • `print '\n'.join('%s %s' % (cds[y:y+3], x) for x, y in enumerate(xrange(0, len(cds), 3), start=1))` And your variation return list of lists which can't be printed directly. – DrTyrsa Jun 14 '11 at 10:29
  • Thank you all for your responding to my question – Kwame Oduro Jun 14 '11 at 20:13