annotate name_affixer.py @ 34:91996b991991 draft default tip

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