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