annotate prince_postprocess.py @ 4:82569b47df8d draft

planemo upload
author jowong
date Mon, 29 Oct 2018 07:52:12 -0400
parents
children 63f3743c2ae4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
82569b47df8d planemo upload
jowong
parents:
diff changeset
1 #!/usr/bin/env python
82569b47df8d planemo upload
jowong
parents:
diff changeset
2
82569b47df8d planemo upload
jowong
parents:
diff changeset
3 import sys
82569b47df8d planemo upload
jowong
parents:
diff changeset
4 import argparse as ap
82569b47df8d planemo upload
jowong
parents:
diff changeset
5 import re
82569b47df8d planemo upload
jowong
parents:
diff changeset
6 parser = ap.ArgumentParser(prog='prince_postprocess', conflict_handler='resolve',
82569b47df8d planemo upload
jowong
parents:
diff changeset
7 description="Postprocess galaxy PRINCE output")
82569b47df8d planemo upload
jowong
parents:
diff changeset
8
82569b47df8d planemo upload
jowong
parents:
diff changeset
9 input = parser.add_argument_group('Input', '')
82569b47df8d planemo upload
jowong
parents:
diff changeset
10 input.add_argument('-i', '--input', nargs=1, required=True, help="PRINCE OUTPUT")
82569b47df8d planemo upload
jowong
parents:
diff changeset
11 input.add_argument('-s', '--sample', nargs='*', required=True, help="Sample names")
82569b47df8d planemo upload
jowong
parents:
diff changeset
12
82569b47df8d planemo upload
jowong
parents:
diff changeset
13 if len(sys.argv) == 0:
82569b47df8d planemo upload
jowong
parents:
diff changeset
14 parser.print_usage()
82569b47df8d planemo upload
jowong
parents:
diff changeset
15 sys.exit(1)
82569b47df8d planemo upload
jowong
parents:
diff changeset
16
82569b47df8d planemo upload
jowong
parents:
diff changeset
17 args = parser.parse_args()
82569b47df8d planemo upload
jowong
parents:
diff changeset
18
82569b47df8d planemo upload
jowong
parents:
diff changeset
19 #print(args.input)
82569b47df8d planemo upload
jowong
parents:
diff changeset
20 #sample_name = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.label.rstrip().lstrip())
82569b47df8d planemo upload
jowong
parents:
diff changeset
21
82569b47df8d planemo upload
jowong
parents:
diff changeset
22 with open(args.input[0]) as prince_output:
82569b47df8d planemo upload
jowong
parents:
diff changeset
23 with open('prince_postprocess_output.txt', 'w') as output:
82569b47df8d planemo upload
jowong
parents:
diff changeset
24 x = 1
82569b47df8d planemo upload
jowong
parents:
diff changeset
25 index = 0
82569b47df8d planemo upload
jowong
parents:
diff changeset
26 for line in prince_output:
82569b47df8d planemo upload
jowong
parents:
diff changeset
27 if x%2 == 0:
82569b47df8d planemo upload
jowong
parents:
diff changeset
28 sample = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.sample[index])
82569b47df8d planemo upload
jowong
parents:
diff changeset
29 output.write(re.sub('.*.dat', sample, line))
82569b47df8d planemo upload
jowong
parents:
diff changeset
30 index += 1
82569b47df8d planemo upload
jowong
parents:
diff changeset
31 else:
82569b47df8d planemo upload
jowong
parents:
diff changeset
32 output.write(line)
82569b47df8d planemo upload
jowong
parents:
diff changeset
33 x += 1
82569b47df8d planemo upload
jowong
parents:
diff changeset
34 #output.write("\n")
82569b47df8d planemo upload
jowong
parents:
diff changeset
35
82569b47df8d planemo upload
jowong
parents:
diff changeset
36