annotate spotyping_postprocess.py @ 1:fcfd1e66edf9 draft default tip

planemo upload
author jowong
date Tue, 13 Nov 2018 10:47:19 -0500
parents 7412632c7b0e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7412632c7b0e planemo upload
jowong
parents:
diff changeset
1 #!/usr/bin/env python
7412632c7b0e planemo upload
jowong
parents:
diff changeset
2
7412632c7b0e planemo upload
jowong
parents:
diff changeset
3 import sys
7412632c7b0e planemo upload
jowong
parents:
diff changeset
4 import argparse as ap
7412632c7b0e planemo upload
jowong
parents:
diff changeset
5 import re
7412632c7b0e planemo upload
jowong
parents:
diff changeset
6 parser = ap.ArgumentParser(prog='spotyping_postprocess', conflict_handler='resolve',
7412632c7b0e planemo upload
jowong
parents:
diff changeset
7 description="Postprocess galaxy spotyping output")
7412632c7b0e planemo upload
jowong
parents:
diff changeset
8
7412632c7b0e planemo upload
jowong
parents:
diff changeset
9 input = parser.add_argument_group('Input', '')
7412632c7b0e planemo upload
jowong
parents:
diff changeset
10 input.add_argument('-s', '--sample', nargs='+', required=True, help="Sample names")
7412632c7b0e planemo upload
jowong
parents:
diff changeset
11 input.add_argument('-f', '--file', nargs='+', required=True, help="File of spotyping in galaxy convention")
7412632c7b0e planemo upload
jowong
parents:
diff changeset
12 if len(sys.argv) == 0:
7412632c7b0e planemo upload
jowong
parents:
diff changeset
13 parser.print_usage()
7412632c7b0e planemo upload
jowong
parents:
diff changeset
14 sys.exit(1)
7412632c7b0e planemo upload
jowong
parents:
diff changeset
15
7412632c7b0e planemo upload
jowong
parents:
diff changeset
16 args = parser.parse_args()
7412632c7b0e planemo upload
jowong
parents:
diff changeset
17
7412632c7b0e planemo upload
jowong
parents:
diff changeset
18
7412632c7b0e planemo upload
jowong
parents:
diff changeset
19 sample_dict={}
7412632c7b0e planemo upload
jowong
parents:
diff changeset
20
7412632c7b0e planemo upload
jowong
parents:
diff changeset
21
7412632c7b0e planemo upload
jowong
parents:
diff changeset
22 with open('spotyping_postprocess_output.txt', 'w') as output:
7412632c7b0e planemo upload
jowong
parents:
diff changeset
23 index = 0
7412632c7b0e planemo upload
jowong
parents:
diff changeset
24 for path in args.file:
7412632c7b0e planemo upload
jowong
parents:
diff changeset
25 with open(path) as f:
7412632c7b0e planemo upload
jowong
parents:
diff changeset
26 for line in f:
7412632c7b0e planemo upload
jowong
parents:
diff changeset
27 #sample_dict[re.sub(".*/","",line.rstrip())] = args.sample[path_index]
7412632c7b0e planemo upload
jowong
parents:
diff changeset
28 sample = re.sub('(_1.fastq(.gz)*|_2.fastq(.gz)*|.fastq(.gz)*)', '', args.sample[index].rstrip().lstrip())
7412632c7b0e planemo upload
jowong
parents:
diff changeset
29 output.write(re.sub(".*.dat", sample, line))
7412632c7b0e planemo upload
jowong
parents:
diff changeset
30 index += 1
7412632c7b0e planemo upload
jowong
parents:
diff changeset
31