3
|
1 #!/usr/bin/env python
|
|
2 import sys
|
|
3
|
|
4 from optparse import OptionParser
|
|
5
|
|
6 parser = OptionParser()
|
|
7 parser.add_option("-f", "--fastq", dest="fastq", help="fastq file")
|
|
8 parser.add_option("-p", "--prefix", dest="prefix", help="prefix to be added to names")
|
|
9 parser.add_option("-s", "--suffix", dest="suffix", help="suffix to be added",default='')
|
|
10 parser.add_option("-n", "--nspace", dest="nspace", help="number of spaces to ignore",default='0')
|
|
11 options, args = parser.parse_args()
|
|
12 nspace=int(options.nspace)
|
|
13
|
|
14 f=open(options.fastq,"r")
|
|
15 j=0
|
|
16 for oneline in f:
|
|
17 if oneline=="":
|
|
18 continue
|
|
19 j+=1
|
|
20 if j==5:
|
|
21 j=1
|
|
22 if not oneline:
|
|
23 break
|
|
24
|
|
25 if (oneline[0]=="@" and j==1) or (oneline[0]=="+" and len(oneline)>2 and j==3):
|
|
26 header=" ".join(oneline.split()[:1+nspace])
|
|
27 header_out=header[0]+options.prefix+header[1:]+options.suffix+"\n"
|
|
28 sys.stdout.write(header_out)
|
|
29 else:
|
|
30 sys.stdout.write(oneline)
|
|
31
|