annotate tools/hyphy/hyphy_branch_lengths_wrapper.py @ 2:c2a356708570

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:42 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #Dan Blankenberg
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 #takes commandline tree def and input multiple fasta alignment file and runs the branch length ananlysis
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 import os, sys
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 from galaxy import eggs
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 from galaxy.tools.util import hyphy_util
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 #Retrieve hyphy path, this will need to be the same across the cluster
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 tool_data = sys.argv.pop()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 HYPHY_PATH = os.path.join( tool_data, "HYPHY" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 HYPHY_EXECUTABLE = os.path.join( HYPHY_PATH, "HYPHY" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 #Read command line arguments
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 input_filename = os.path.abspath(sys.argv[1].strip())
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 output_filename = os.path.abspath(sys.argv[2].strip())
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 tree_contents = sys.argv[3].strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 nuc_model = sys.argv[4].strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 base_freq = sys.argv[5].strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 model_options = sys.argv[6].strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 #Set up Temporary files for hyphy run
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 #set up tree file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 tree_filename = hyphy_util.get_filled_temp_filename(tree_contents)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 #Guess if this is a single or multiple FASTA input file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 found_blank = False
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 is_multiple = False
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 for line in open(input_filename):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 line = line.strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 if line == "": found_blank = True
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 elif line.startswith(">") and found_blank:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 is_multiple = True
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 else: found_blank = False
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 #set up BranchLengths file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 BranchLengths_filename = hyphy_util.get_filled_temp_filename(hyphy_util.BranchLengths)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 if is_multiple:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 os.unlink(BranchLengths_filename)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 BranchLengths_filename = hyphy_util.get_filled_temp_filename(hyphy_util.BranchLengthsMF)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 print "Multiple Alignment Analyses"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 else: print "Single Alignment Analyses"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 #setup Config file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 config_filename = hyphy_util.get_branch_lengths_config_filename(input_filename, nuc_model, model_options, base_freq, tree_filename, output_filename, BranchLengths_filename)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 #Run Hyphy
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 hyphy_cmd = "%s BASEPATH=%s USEPATH=/dev/null %s" % (HYPHY_EXECUTABLE, HYPHY_PATH, config_filename)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 hyphy = os.popen(hyphy_cmd, 'r')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 #print hyphy.read()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 hyphy.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 #remove temporary files
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 os.unlink(BranchLengths_filename)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 os.unlink(tree_filename)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 os.unlink(config_filename)