annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
1 #!/usr/bin/env python
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
2
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
3 def exec_before_job(app, inp_data=None, out_data=None, tool=None, param_dict=None):
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
4 pass
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
5
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
6 def exec_after_process(app, inp_data=None, out_data=None, param_dict=None, tool=None, stdout=None, stderr=None):
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
7 output_name = 'output1'
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
8
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
9 ## check for output
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
10 try:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
11 first_output = out_data[output_name]
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
12 except:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
13 return
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
14
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
15 ## check for collected datasets
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
16 try:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
17 collected_dict = param_dict['__collected_datasets__']['primary'][output_name]
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
18 except:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
19 return
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
20
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
21 if len(collected_dict.keys()) == 0:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
22 return
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
23
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
24 ## check for fasta file
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
25 try:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
26 fasta_file = inp_data['fasta_input']
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
27 except:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
28 return
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
29
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
30 ## find missing fasta header
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
31 first_output_name = None
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
32 with open(fasta_file.get_file_name()) as fh:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
33 for line in fh:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
34 if line[0] != '>':
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
35 continue
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
36 name = line[1:]
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
37 name = name.strip()
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
38 name = name.split()[0]
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
39 name = name.replace('_', '-')
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
40 if name not in collected_dict:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
41 first_output_name = name
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
42 break
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
43
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
44 ## fix name
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
45 if first_output_name is not None:
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
46 first_output.name = '%s (%s)' % (first_output.name, first_output_name)
ea52b23f1141 Bug fixes for Draw variants, Phylip, and gd_d_tools
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
47