|
0
|
1 import argparse
|
|
|
2 import sys
|
|
|
3 import re
|
|
|
4
|
|
|
5 if __name__ == '__main__':
|
|
|
6
|
|
|
7 desc = "Convert Strelka Makefile into a sub-Makefile used STRICTLY for parallelization by chromosome in Galaxy"
|
|
|
8 parser = argparse.ArgumentParser(description=desc)
|
|
|
9 parser.add_argument(
|
|
|
10 "-m", "--makefile",
|
|
|
11 required=True,
|
|
|
12 help="Input Must be a Strelka Makefile"
|
|
|
13 )
|
|
|
14 parser.add_argument(
|
|
|
15 "-c", "--chrom",
|
|
|
16 type=str,
|
|
|
17 required=False,
|
|
|
18 help="Chromosome present in the Strelka Makefile"
|
|
|
19 )
|
|
|
20 parser.add_argument(
|
|
|
21 "-cf", "--chrom_file",
|
|
|
22 required=False,
|
|
|
23 help="Chromosome File separated by newline"
|
|
|
24 )
|
|
|
25 parser.add_argument(
|
|
|
26 '-o', '--output',
|
|
|
27 required=True,
|
|
|
28 help="Output Makefile"
|
|
|
29 )
|
|
|
30 args = parser.parse_args()
|
|
|
31
|
|
|
32 if (not args.chrom and not args.chrom_file) or (args.chrom and args.chrom_file):
|
|
|
33 sys.exit('Must define a single chromosome entry or a single chromosome file')
|
|
|
34
|
|
|
35 chromosomes = [];
|
|
|
36
|
|
|
37 if args.chrom_file:
|
|
|
38 chromosomes = open(args.chrom_file).read().splitlines()
|
|
|
39
|
|
|
40 if args.chrom:
|
|
|
41 chromosomes = [args.chrom]
|
|
|
42 add_at_end = []
|
|
|
43 makefile_in = open(args.makefile, 'r')
|
|
|
44 makefile_out = open(args.output, 'w')
|
|
|
45
|
|
|
46 for line in makefile_in:
|
|
|
47 if line.startswith('script_dir'):
|
|
|
48 makefile_out.write(line)
|
|
|
49 elif line.startswith('call_script'):
|
|
|
50 makefile_out.write(line)
|
|
|
51 elif line.startswith('filter_script'):
|
|
|
52 makefile_out.write(line)
|
|
|
53 elif line.startswith('finish_script'):
|
|
|
54 makefile_out.write(line)
|
|
|
55 elif line.startswith('script_dir'):
|
|
|
56 makefile_out.write(line)
|
|
|
57 elif line.startswith('config_file'):
|
|
|
58 makefile_out.write(line)
|
|
|
59 elif line.startswith('analysis_dir'):
|
|
|
60 makefile_out.write(line)
|
|
|
61 elif line.startswith('results_dir'):
|
|
|
62 makefile_out.write(line)
|
|
|
63 elif line.startswith('get_chrom_dir'):
|
|
|
64 makefile_out.write(line)
|
|
|
65 elif line.startswith('get_chrom_task'):
|
|
|
66 makefile_out.write(line)
|
|
|
67 elif line.startswith('get_bin_task'):
|
|
|
68 makefile_out.write(line)
|
|
|
69 makefile_out.write('\n')
|
|
|
70 elif line.startswith('all:'):
|
|
|
71 makefile_out.write('all:\n')
|
|
|
72 elif re.search("--chrom=", line):
|
|
|
73 if re.search(''.join(["\s|".join(chromosomes),'\s']), line):
|
|
|
74 if re.search('bin', line):
|
|
|
75 makefile_out.write(line)
|
|
|
76 else:
|
|
|
77 add_at_end.append(line)
|
|
|
78
|
|
|
79 makefile_in.close()
|
|
|
80 for line in add_at_end:
|
|
|
81 makefile_out.write(line)
|
|
|
82 makefile_out.close()
|