View Single Post
Old 07-04-2013, 10:19 AM   #7
Heisman
Senior Member
 
Location: St. Louis

Join Date: Dec 2010
Posts: 534
Default

Quote:
Originally Posted by wieni View Post
Here a quick and dirty solution in python - was still missing :-)


#!/usr/bin/env python

import re
import string
import sys


infile = open(sys.argv[1])
data = infile.readlines()
infile.close()

outfile = open(sys.argv[2], "w")
c = 1
l = 1
for i in data:
i = re.sub("\n|\r", "", i)
if c%2 != 0:
outfile.write(i+"_" +str(l) +"\n")
l+=1
else:
outfile.write(i +"\n")
c += 1
outfile.close()


save the upper code in a file called for example "numberFasta.py"
on a terminal call the program with: python numberFasta.py <yourInfile> <outfilename>
You can use the "code" tags to make this work (surround the code with [code ] and [/code ] (but no spaces):

Code:
#!/usr/bin/env python

import re
import string
import sys


infile = open(sys.argv[1])
data = infile.readlines()
infile.close()

outfile = open(sys.argv[2], "w")
c = 1
l = 1
for i in data:
    i = re.sub("\n|\r", "", i)
    if c%2 != 0:
        outfile.write(i+"_" +str(l) +"\n")
        l+=1
    else:
        outfile.write(i +"\n")
    c += 1
outfile.close()
Heisman is offline   Reply With Quote