473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

reading a file a printing a list of values

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

Sequence = CCTAATCTTGAAAAAA Calculation = 1
Sequence = CTAATCTTGAAAAAAA Calculation = 1
Sequence = TAATCTTGAAAAAAAA Calculation = 1
Sequence = AATCTTGAAAAAAAAA Calculation = 1
Sequence = ATCTTGAAAAAAAAAA Calculation = 1
Sequence = TCTTGAAAAAAAAAAA Calculation = 1
Sequence = CTTGAAAAAAAAAAAA Calculation = 1
Sequence = TTGAAAAAAAAAAAAA Calculation = 1
Sequence = TGAAAAAAAAAAAAAA Calculation = 1
Sequence = GAAAAAAAAAAAAAAA Calculation = 1
Sequence = AAAAAAAAAAAAAAAA Calculation = 1
Sequence = AAAAAAAAAAAAAAAA Calculation = 1
Sequence = AAAAAAAAAAAAAAAA Calculation = 1
Sequence = AAAAAAAAAAAAAAAA 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 = CCTAATCTTGAAAAAA Calculation = 1
Sequence = CTAATCTTGAAAAAAA Calculation = 1
Sequence = TAATCTTGAAAAAAAA Calculation = 1
Sequence = AATCTTGAAAAAAAAA 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??
Dec 17 '07 #1
2 1289
STM
4
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.
Dec 22 '07 #2
ghostdog74
511 Expert 256MB
you should be familiar with how Python works by now, since you have so many posts.
Expand|Select|Wrap|Line Numbers
  1. n=0
  2. m=0
  3. for line in open("file"):
  4.     if line.startswith("Sequence ="):
  5.         n += int(line.split()[-1])
  6.     elif line.startswith("Sequence set # ="):
  7.         m += int(line.split("=")[-1])
  8. print n,m
  9.  
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.
Dec 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
4
by: flgeyer | last post by:
Hello all, I'm trying to read in a binary file in C. I have the specification of the file format and everything. I can parse the file with a software called "010 Editor". This way I can check if...
29
by: Jerim79 | last post by:
I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a...
0
by: Anish G | last post by:
Hi, I have an issue with reading CSV files. I am to reading CSV file and putting it in a Datatable in C#. I am using a regular expression to read the values. Below is the code. Now, it reads...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.