Mercurial > repos > miller-lab > genome_diversity
diff nucleotide_diversity_pi.py @ 27:8997f2ca8c7a
Update to Miller Lab devshed revision bae0d3306d3b
author | Richard Burhans <burhans@bx.psu.edu> |
---|---|
date | Mon, 15 Jul 2013 10:47:35 -0400 |
parents | 95a05c1ef5d5 |
children |
line wrap: on
line diff
--- a/nucleotide_diversity_pi.py Mon Jun 03 12:29:29 2013 -0400 +++ b/nucleotide_diversity_pi.py Mon Jul 15 10:47:35 2013 -0400 @@ -1,49 +1,23 @@ #!/usr/bin/env python +import gd_util import sys -import subprocess from Population import Population ################################################################################ -def run_program(prog, args, stdout_file=None, space_to_tab=False): - #print "args: ", ' '.join(args) - p = subprocess.Popen(args, bufsize=-1, executable=prog, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdoutdata, stderrdata) = p.communicate() - rc = p.returncode +if len(sys.argv) != 7: + gd_util.die('Usage') - if stdout_file is not None: - with open(stdout_file, 'w') as ofh: - lines = stdoutdata.split('\n') - for line in lines: - line = line.strip() - if line: - if space_to_tab: - line = line.replace(' ', '\t') - print >> ofh, line - - if rc != 0: - print >> sys.stderr, "FAILED: rc={0}: {1}".format(rc, ' '.join(args)) - print >> sys.stderr, stderrdata - sys.exit(1) - -################################################################################ - -if len(sys.argv) < 8: - print >> sys.stderr, "Usage" - sys.exit(1) - -gd_saps_file, gd_snps_file, covered_intervals_file, gd_indivs_file, output_file = sys.argv[1:6] -individual_metadata = sys.argv[6:] +gd_saps_file, gd_snps_file, covered_intervals_file, gd_indivs_file, output_file, ind_arg = sys.argv[1:] p_total = Population() -p_total.from_tag_list(individual_metadata) +p_total.from_wrapped_dict(ind_arg) p1 = Population() p1.from_population_file(gd_indivs_file) if not p_total.is_superset(p1): - print >> sys.stderr, 'There is an individual in the population individuals that is not in the SNP table' - sys.exit(1) + gd_util.die('There is an individual in the population individuals that is not in the SNP table') ################################################################################ @@ -56,9 +30,10 @@ columns = p1.column_list() for column in columns: - args.append('{0}'.format(column)) + args.append(column) -run_program(None, args, stdout_file=output_file) +with open(output_file, 'w') as fh: + gd_util.run_program(prog, args, stdout=fh) sys.exit(0)