By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

How to split a list file

P: 1
I have a huge gene blast file, It looks like
gene1 40 0.5 1 20
gene2 30 0.4 3 30

I want to make it like this
I am a really a python newbie,so I don't know how to make it.

After this step, I want to filter the second value, if it larger than 20, I will output it.How could I do it in Python?
I am not quite sure my thinking is right or not.
Thanks a lot!
Feb 13 '11 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 2.5K+
P: 2,851
A file can be read one line at a time. Each line is read as a string. The line "gene1 40 0.5 1 20" can be split into a list with the string method split(). The second element in the list (list index 1) can then easily be evaluated for your output.
Expand|Select|Wrap|Line Numbers
  1. >>> line = "gene1 40 0.5 1 20\n"
  2. >>> lineList = line.strip().split()
  3. >>> int(lineList[1]) > 20
  4. True
  5. >>> 
Feb 13 '11 #2

Post your reply

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