root/galaxy-central/tools/hyphy/hyphy_nj_tree_wrapper.py @ 3

リビジョン 2, 2.2 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#Dan Blankenberg
2#takes fasta alignments, a distance metric and builds neighbor joining trees
3import os, sys
4from galaxy import eggs
5from galaxy.tools.util import hyphy_util
6
7#Retrieve hyphy path, this will need to be the same across the cluster
8tool_data = sys.argv.pop()
9HYPHY_PATH = os.path.join( tool_data, "HYPHY" )
10HYPHY_EXECUTABLE = os.path.join( HYPHY_PATH, "HYPHY" )
11
12#Read command line arguments
13input_filename = os.path.abspath(sys.argv[1].strip())
14output_filename1 = os.path.abspath(sys.argv[2].strip())
15output_filename2 = os.path.abspath(sys.argv[3].strip())
16distance_metric = sys.argv[4].strip()
17temp_ps_filename = hyphy_util.get_filled_temp_filename("")
18
19#Guess if this is a single or multiple FASTA input file
20found_blank = False
21is_multiple = False
22for line in open(input_filename):
23    line = line.strip()
24    if line == "": found_blank = True
25    elif line.startswith(">") and found_blank:
26        is_multiple = True
27        break
28    else: found_blank = False
29
30NJ_tree_shared_ibf = hyphy_util.get_filled_temp_filename(hyphy_util.NJ_tree_shared_ibf)
31
32#set up NJ_tree file
33NJ_tree_filename = hyphy_util.get_filled_temp_filename(hyphy_util.get_NJ_tree(NJ_tree_shared_ibf))
34#setup Config file
35config_filename = hyphy_util.get_nj_tree_config_filename(input_filename, distance_metric, output_filename1, temp_ps_filename, NJ_tree_filename)
36if is_multiple:
37    os.unlink(NJ_tree_filename)
38    os.unlink(config_filename)
39    NJ_tree_filename = hyphy_util.get_filled_temp_filename(hyphy_util.get_NJ_treeMF(NJ_tree_shared_ibf))
40    config_filename = hyphy_util.get_nj_treeMF_config_filename(input_filename, output_filename1, temp_ps_filename, distance_metric, NJ_tree_filename)
41    print "Multiple Alignment Analyses"
42else: print "Single Alignment Analyses"
43
44
45#Run Hyphy
46hyphy_cmd = "%s BASEPATH=%s USEPATH=/dev/null %s" % (HYPHY_EXECUTABLE, HYPHY_PATH, config_filename)
47hyphy = os.popen(hyphy_cmd, 'r')
48#print hyphy.read()
49hyphy.close()
50
51#remove temporary files
52os.unlink(NJ_tree_filename)
53os.unlink(config_filename)
54
55
56#Convert PS to PDF
57if os.path.getsize(temp_ps_filename)>0: temp = os.popen("ps2pdf %s %s" % (temp_ps_filename, output_filename2), 'r').close()
58os.unlink(temp_ps_filename)
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。