annotate fastq_name_affixer.py @ 27:eefed7a82001 draft

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