annotate tools/hyphy/hyphy_dnds_wrapper.py @ 0:9071e359b9a3

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