[Tutor] extract information from txtfile
Anna Olofsson
olofsson_anna585 at hotmail.com
Tue Oct 4 22:00:05 CEST 2011
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.
Best,
Anna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111004/d307765c/attachment.html>
More information about the Tutor
mailing list