Writing to a file in python -


i have been receiving indexing errors in python. got code work correctly through reading in file , printing desired output, trying write output file. seem having problem indexing when trying write it. i've tried couple different things, left attempt commented out. either way keep getting indexing error. edit original error may caused error in eclipse, when running on server, having new issue*

i can run , produce output .txt file, prints single output

with open("blast.txt") blast_output: line in blast_output:     subfields = [item.split('|') item in line.split()]     #transid = str(subfields[0][0])     #iso = str(subfields[0][1])     #sp = str(subfields[1][3])     #identity = str(subfields[2][0])     out = open("parsed_blast.txt", "w")     #out.write(transid + "\t" + iso + "\t" + sp + "\t" + identity)     out.write((str(subfields[0][0]) + "\t" + str(subfields[0][1]) + "\t" + str(subfields[1][3]) + "\t" + str(subfields[2][0])))     out.close()   indexerror: list index out of range 

input file looks like:

c0_g1_i1|m.1    gi|74665200|sp|q9hgp0.1|pvg4_schpo      100.00  372     0       0       1       372     1       372     0.0       754 c1002_g1_i1|m.801       gi|1723464|sp|q10302.1|yd49_schpo       100.00  646     0       0       1       646     1       646     0.0      1310 c1003_g1_i1|m.803       gi|74631197|sp|q6bdr8.1|nse4_schpo      100.00  246     0       0       1       246     1       246     1e-179    502 c1004_g1_i1|m.804       gi|74676184|sp|o94325.1|pex5_schpo      100.00  598     0       0       1       598     1       598     0.0      1227 c1005_g1_i1|m.805       gi|9910811|sp|o42832.2|spb1_schpo       100.00  802     0       0       1       802     1       802     0.0      1644 c1006_g1_i1|m.806       gi|74627042|sp|o94631.1|mrm1_schpo      100.00  255     0       0       1       255     47      301     0.0       525 

expected output

c0_g1_i1    m.1 q9hgp0.1    100.00 c1002_g1_i1 m.801   q10302.1    100.00 c1003_g1_i1 m.803   q6bdr8.1    100.00 c1004_g1_i1 m.804   o94325.1    100.00 c1005_g1_i1 m.805   o42832.2    100.00 c1006_g1_i1 m.806   o94631.1    100.00 

my output instead 1 of lines instead of of lines

you overwriting same file again , again. open file outside loop or open in append mode 'a'


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -