Mercurial > repos > miller-lab > genome_diversity
diff make_phylip_hooks.py @ 35:ea52b23f1141
Bug fixes for Draw variants, Phylip, and gd_d_tools
author | Richard Burhans <burhans@bx.psu.edu> |
---|---|
date | Wed, 20 Nov 2013 13:46:10 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/make_phylip_hooks.py Wed Nov 20 13:46:10 2013 -0500 @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +def exec_before_job(app, inp_data=None, out_data=None, tool=None, param_dict=None): + pass + +def exec_after_process(app, inp_data=None, out_data=None, param_dict=None, tool=None, stdout=None, stderr=None): + output_name = 'output1' + + ## check for output + try: + first_output = out_data[output_name] + except: + return + + ## check for collected datasets + try: + collected_dict = param_dict['__collected_datasets__']['primary'][output_name] + except: + return + + if len(collected_dict.keys()) == 0: + return + + ## check for fasta file + try: + fasta_file = inp_data['fasta_input'] + except: + return + + ## find missing fasta header + first_output_name = None + with open(fasta_file.get_file_name()) as fh: + for line in fh: + if line[0] != '>': + continue + name = line[1:] + name = name.strip() + name = name.split()[0] + name = name.replace('_', '-') + if name not in collected_dict: + first_output_name = name + break + + ## fix name + if first_output_name is not None: + first_output.name = '%s (%s)' % (first_output.name, first_output_name) +