1 | #Guru
|
---|
2 | #takes fasta alignments, a distance metric and builds neighbor joining trees
|
---|
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 | analysis = sys.argv[5].strip()
|
---|
18 |
|
---|
19 | if tree_contents == "":
|
---|
20 | print >> sys.stderr, "Please specify a valid tree definition."
|
---|
21 | sys.exit()
|
---|
22 |
|
---|
23 | tree_filename = hyphy_util.get_filled_temp_filename(tree_contents)
|
---|
24 |
|
---|
25 | if analysis == "local":
|
---|
26 | fitter_filename = hyphy_util.get_filled_temp_filename(hyphy_util.SimpleLocalFitter)
|
---|
27 | else:
|
---|
28 | fitter_filename = hyphy_util.get_filled_temp_filename(hyphy_util.SimpleGlobalFitter)
|
---|
29 |
|
---|
30 | tabwriter_filename = hyphy_util.get_filled_temp_filename(hyphy_util.TabWriter)
|
---|
31 | FastaReader_filename = hyphy_util.get_filled_temp_filename(hyphy_util.FastaReader)
|
---|
32 | #setup Config file
|
---|
33 | config_filename = hyphy_util.get_dnds_config_filename(fitter_filename, tabwriter_filename, "Universal", tree_filename, input_filename, nuc_model, output_filename, FastaReader_filename)
|
---|
34 |
|
---|
35 | #Run Hyphy
|
---|
36 | hyphy_cmd = "%s BASEPATH=%s USEPATH=/dev/null %s" % (HYPHY_EXECUTABLE, HYPHY_PATH, config_filename)
|
---|
37 | hyphy = os.popen(hyphy_cmd, 'r')
|
---|
38 | #print hyphy.read()
|
---|
39 | hyphy.close()
|
---|
40 |
|
---|
41 | #remove temporary files
|
---|
42 | os.unlink(fitter_filename)
|
---|
43 | os.unlink(tabwriter_filename)
|
---|
44 | os.unlink(tree_filename)
|
---|
45 | os.unlink(FastaReader_filename)
|
---|
46 | os.unlink(config_filename)
|
---|
47 |
|
---|
48 | if nuc_model == "000000":
|
---|
49 | model = "F81"
|
---|
50 | elif nuc_model == "010010":
|
---|
51 | model = "HKY85"
|
---|
52 | else:
|
---|
53 | model = "REV"
|
---|
54 |
|
---|
55 | print "Analysis: %s; Model: %s; Tree: %s" %(analysis, model, tree_contents)
|
---|