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