numbering sequence

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DARFOUR
    New Member
    • Jun 2011
    • 2

    numbering sequence

    I want additional python codes that will help me generate the second column (the column with numbers) of the output under the
    codes. The codes here only generate the first column
    by breaking the sequence in cds into threes. Thank you.

    >>> cds = "atgagtgaacgtct gagcattaccccgct ggggccgtatatcgg cgcacaataa"

    >>> 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
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Use built-in function enumerate() in conjunction with range(). Also, I would use string formatting for the output.
    Code:
    >>> cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"
    >>> for j,i in enumerate(range(0,len(cds),3)):
    ... 	print "%s %2s" % (cds[i:i+3], j+1)
    ... 	
    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
    >>>

    Comment

    • DARFOUR
      New Member
      • Jun 2011
      • 2

      #3
      Thanks bvdet. I have used your codes and the actually did what I wanted

      Comment

      Working...