reading a file a printing a list of values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aboxylica
    New Member
    • Jul 2007
    • 111

    reading a file a printing a list of values

    I have a file like this!Sequence Header: >Sbay YOR009W c606:3651..4650

    Sequence = CCTAATCTTGAAAAA A Calculation = 1
    Sequence = CTAATCTTGAAAAAA A Calculation = 1
    Sequence = TAATCTTGAAAAAAA A Calculation = 1
    Sequence = AATCTTGAAAAAAAA A Calculation = 1
    Sequence = ATCTTGAAAAAAAAA A Calculation = 1
    Sequence = TCTTGAAAAAAAAAA A Calculation = 1
    Sequence = CTTGAAAAAAAAAAA A Calculation = 1
    Sequence = TTGAAAAAAAAAAAA A Calculation = 1
    Sequence = TGAAAAAAAAAAAAA A Calculation = 1
    Sequence = GAAAAAAAAAAAAAA A Calculation = 1
    Sequence = AAAAAAAAAAAAAAA A Calculation = 1
    Sequence = AAAAAAAAAAAAAAA A Calculation = 1
    Sequence = AAAAAAAAAAAAAAA A Calculation = 1
    Sequence = AAAAAAAAAAAAAAA A Calculation = 1
    Array set # = 32
    Sequence set # = 1
    Sequence Header: >Sbay YOR009W c606:3651..4650


    Array set # = 33
    Sequence set # = 1
    Sequence Header: >Sbay YOR009W c606:3651..4650

    Sequence = CCTAATC Calculation = 1
    Array set # = 34
    Sequence set # = 1
    Sequence Header: >Sbay YOR009W c606:3651..4650

    Sequence = CCTAATCTTGAAAAA A Calculation = 1
    Sequence = CTAATCTTGAAAAAA A Calculation = 1
    Sequence = TAATCTTGAAAAAAA A Calculation = 1
    Sequence = AATCTTGAAAAAAAA A Calculation = 1
    i want to create a function that reads this file
    so i want to create a list that reads the lines and print something like this
    sbay=[14,4]
    14 because there are 14 ones and then 4 ones.. like this and then i want to compute average of these numbers.. how i exactly do??
  • STM
    New Member
    • Dec 2007
    • 4

    #2
    those really look like base sequences from a nucleic acid. are they? maybe knowing what is it that you really need to do and why would help.

    Comment

    • ghostdog74
      Recognized Expert Contributor
      • Apr 2006
      • 511

      #3
      you should be familiar with how Python works by now, since you have so many posts.
      Code:
      n=0
      m=0
      for line in open("file"):
          if line.startswith("Sequence ="):
              n += int(line.split()[-1])
          elif line.startswith("Sequence set # ="):
              m += int(line.split("=")[-1])
      print n,m
      the above prints out all the sums . I leave it to you to find a way to take the total of a block of them.

      Comment

      Working...