Mercurial > repos > miller-lab > genome_diversity
comparison draw_variants.py @ 24:248b06e86022
Added gd_genotype datatype. Modified tools to support new datatype.
author | Richard Burhans <burhans@bx.psu.edu> |
---|---|
date | Tue, 28 May 2013 16:24:19 -0400 |
parents | |
children | 8997f2ca8c7a |
comparison
equal
deleted
inserted
replaced
23:66a183c44dd5 | 24:248b06e86022 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import sys | |
4 import subprocess | |
5 from Population import Population | |
6 | |
7 def run_program(prog, args, stdout_file=None, space_to_tab=False): | |
8 #print "args: ", ' '.join(args) | |
9 p = subprocess.Popen(args, bufsize=-1, executable=prog, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
10 (stdoutdata, stderrdata) = p.communicate() | |
11 rc = p.returncode | |
12 | |
13 if stdout_file is not None: | |
14 with open(stdout_file, 'w') as ofh: | |
15 lines = stdoutdata.split('\n') | |
16 for line in lines: | |
17 line = line.strip() | |
18 if line: | |
19 if space_to_tab: | |
20 line = line.replace(' ', '\t') | |
21 print >> ofh, line | |
22 | |
23 if rc != 0: | |
24 print >> sys.stderr, "FAILED: rc={0}: {1}".format(rc, ' '.join(args)) | |
25 print >> sys.stderr, stderrdata | |
26 sys.exit(1) | |
27 | |
28 ################################################################################ | |
29 | |
30 if len(sys.argv) < 10: | |
31 print >> sys.stderr, "Usage" | |
32 sys.exit(1) | |
33 | |
34 snp_input, indel_input, coverage_input, annotation_input, indiv_input, ref_name, min_coverage, output = sys.argv[1:9] | |
35 individual_metadata = sys.argv[9:] | |
36 | |
37 p_total = Population() | |
38 p_total.from_tag_list(individual_metadata) | |
39 | |
40 p1 = Population() | |
41 p1.from_population_file(indiv_input) | |
42 if not p_total.is_superset(p1): | |
43 print >> sys.stderr, 'There is an individual in the population individuals that is not in the SNP table' | |
44 sys.exit(1) | |
45 | |
46 ################################################################################ | |
47 | |
48 prog = 'mk_Ji' | |
49 | |
50 args = [ prog ] | |
51 | |
52 args.append(snp_input) | |
53 args.append(indel_input) | |
54 args.append(coverage_input) | |
55 args.append(annotation_input) | |
56 args.append(min_coverage) | |
57 args.append(ref_name) | |
58 | |
59 for tag in p1.tag_list(): | |
60 args.append(tag) | |
61 | |
62 run_program(prog, args, stdout_file='mk_Ji.out') | |
63 | |
64 ################################################################################ | |
65 | |
66 prog = 'varplot' | |
67 | |
68 args = [ prog ] | |
69 args.append('-w') | |
70 args.append('3') | |
71 args.append('-s') | |
72 args.append('0.3') | |
73 args.append('-g') | |
74 args.append('0.2') | |
75 args.append('mk_Ji.out') | |
76 | |
77 run_program(prog, args, stdout_file=output) | |
78 sys.exit(0) |