/
runSchism
executable file
·156 lines (137 loc) · 7.27 KB
/
runSchism
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
#=========================================================================#
import os
import sys
import yaml
from argparse import ArgumentParser as argument_parser
import SCHISM
__version__ = SCHISM.__version__
from SCHISM.HT import prep_hypothesis_test
from SCHISM.HT import hypothesis_test
from SCHISM.CL import cluster_muts
from SCHISM.CL import integrate_cluster_metrics
from SCHISM.GA import run_ga
from SCHISM.GA import ga_summary
from SCHISM.GA import generate_consensus_tree
from SCHISM.visualize import plot_cpov
from SCHISM.visualize import plot_pov
from SCHISM.visualize import plot_mut_clust_cellularity
from SCHISM.utils import Config
#--------------------------------------------------------------------#
class CMDParser():
# command line parser
usage = '\n python schism.py --help\n'
def __init__(self):
parser = argument_parser(description = CMDParser.usage)
parser.add_argument('--version',action ='version', version='curr_dev')
subparsers = parser.add_subparsers(dest = 'task',\
title = 'analysis_type',\
help = 'SCHISM analysis type')
# runner script executing steps in sequence
#----------------------------------------------------#
runner_parser = subparsers.add_parser('analyze',\
help = 'run schism analysis steps in sequence')
runner_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
runner_parser.set_defaults(func = run_schism)
# task specific subparsers
#----------------------------------------------------#
pht_parser = subparsers.add_parser('prepare_for_hypothesis_test',\
help = 'prepare cellularity input for hypothesis test')
pht_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
pht_parser.set_defaults(func = prep_hypothesis_test)
#----------------------------------------------------#
ht_parser = subparsers.add_parser('hypothesis_test',\
help = 'Perform SCHISM hypothesis test')
ht_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
ht_parser.set_defaults(func = hypothesis_test)
#----------------------------------------------------#
cl_parser = subparsers.add_parser('cluster_mutations',\
help = 'cluster mutations based on their hypothesis test results')
cl_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
cl_parser.set_defaults(func = cluster_muts)
#----------------------------------------------------#
icm_parser = subparsers.add_parser('confirm_clusters',\
help = 'integrate cluster metrics (cellularity, and HT) over confirmed cluster definitions')
icm_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
icm_parser.set_defaults(func = integrate_cluster_metrics)
#----------------------------------------------------#
viz_parser = subparsers.add_parser('plot_cpov',\
help = 'plot CPOV heatmap')
viz_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
viz_parser.set_defaults(func = plot_cpov)
#----------------------------------------------------#
pviz_parser = subparsers.add_parser('plot_pov',\
help = 'plot POV heatmap')
pviz_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
pviz_parser.set_defaults(func = plot_pov)
#----------------------------------------------------#
clv_parser = subparsers.add_parser('plot_cellularity',\
help = 'plot mutation and cluster cellularities')
clv_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
clv_parser.set_defaults(func = plot_mut_clust_cellularity)
#----------------------------------------------------#
ga_parser = subparsers.add_parser('run_ga',\
help = 'run genetic algorithm')
ga_parser.add_argument('-m', '--mode',type= str,\
help = 'GA run mode: serial or parallel')
ga_parser.add_argument('-r', '--runID',type= int,\
help = 'GA run id to run')
ga_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
ga_parser.set_defaults(func = run_ga)
#----------------------------------------------------#
ga_summary_parser = subparsers.add_parser('summarize_ga_results',\
help='generate summary ga table and plots')
ga_summary_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
ga_summary_parser.set_defaults(func = ga_summary)
#----------------------------------------------------#
ct_parser = subparsers.add_parser('consensus_tree',\
help = 'construct and plot consensus tree from the fittest')
ct_parser.add_argument('-c','--config_file',\
help = 'path to SCHISM configuration file')
ct_parser.set_defaults(func = generate_consensus_tree)
#----------------------------------------------------#
args = parser.parse_args()
self.__dict__.update(args.__dict__)
return
#--------------------------------------------------------------------#
def run_schism(args):
config = Config(args.config_file)
print >>sys.stderr, 'Preparing hypothesis test input...'
prep_hypothesis_test(args)
print >>sys.stderr, 'Performing hypothesis input...'
hypothesis_test(args)
if hasattr(config, 'cluster_analysis') and config.cluster_analysis == 'schism':
print >>sys.stderr, 'clustering mutations...'
cluster_muts(args)
print >>sys.stderr, 'integrating cluster metrics ...'
integrate_cluster_metrics(args)
print >>sys.stderr, 'Visualizing test results...'
plot_cpov(args)
print >>sys.stderr, 'Visualizing mutation and cluster cellularity estimates ...'
plot_mut_clust_cellularity(args)
args.mode = 'serial'
print >>sys.stderr, 'Performing independent runs of' + \
' genetic algorithm in serial mode ...'
run_ga(args)
print >>sys.stderr, 'Merging results from independent GA runs' +\
' and generating summary plots...'
ga_summary(args)
print >>sys.stderr, 'generating the consensus of maximum fitness trees'
generate_consensus_tree(args)
#--------------------------------------------------------------------#
def main():
# call the appropriate function to carry out the selected task
args = CMDParser()
args.func(args)
if __name__ == '__main__':
main()