[Tutor] searching for data in one file from another

Rich Krauter rmkrauter at yahoo.com
Fri Nov 5 15:08:22 CET 2004


Hi Scott,
I think it's probably just that the lines don't really start with '>'. 
In the post in which you originally showed the file format, it looked to 
me like lines started with '>'. In the last email I don't see any '>'. 
Do you think you can check for this, and modify the code to suit the 
actual file format?

If you still have trouble, can you send me a file containing the first 
500 or so lines of the fasta file, so I can check what is going wrong?

(You may want to just send the truncated file to me and I can summarize 
it in my reply to the list. Ideally posting the files to the web and 
including the url in the posted question lets people interested in 
helping retrieve the files, without filling the inboxes of those who 
don't. I don't mind getting attachments in mail from this list, but I'm 
not sure about others.)

Something like the code below will dump the first 500 lines of files 
passed in on command line.

import sys

for fname in sys.argv[1:]:
     infile = open(fname)
     outfile = '%s.trunc'%fname
     out = open(outfile,'w+')
     # enumerate() requires python 2.3
     for n,line in enumerate(infile):
         if n >= 500:
             break
         else:
             out.write(line)


Thanks.
Rich


More information about the Tutor mailing list