On 10/4/2011 4:00 PM, Anna Olofsson wrote:
Hi,
I'm a beginner at Python and I'm trying to extract some information
from a textfile where I have a lot of data.
The table looks something like this, but with many more columns and rows:
# chr Pos ID REF ALT . . . . . . . . . . .
1 13645 - C T
. . . . .
. . . . .
I want to extract certain data from this table above and make it to a
sentence looking something like this: chr1:13645 C/T
I have created a pseudo code, just to get an overview of want I want
to do, looking like this:
import OS
open vcf_file.vcf
for each line
words =
split(line)
# words[0] = 1 , words[1]=Pos , words[3]=REF , words[4]=ALT
if(words[0] not
"#"):
#Sometimes the word starts with a hash and I don't want that to be
included.
str="chr" + words[0] + ":" + words[1] + "\t" + words[3] +
"/" + words[4]
score = OS.system(str)
vcf_file.close()
print result
return score
I'm not exactly sure how to proceed from here.
I suggest you convert the pseudo-code into a Pythin program, then run it.
If that gives you grief then tackle it one task at a time. For example,
open, read, print, close a file. Then add another level of complication,
for example open, read, split, print, close a file.
The part that makes no sense to me is score = OS.system(str). What will
str be and what do you want system to return?
--
Bob Gailer
919-636-4239
Chapel Hill NC
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor