-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathksrates_cli.py
269 lines (227 loc) · 13.1 KB
/
ksrates_cli.py
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import click
import logging
from sys import argv
from ksrates._version import __version__
@click.group(context_settings={'help_option_names': ['-h', '--help']})
@click.version_option(__version__, prog_name="ksrates", help="Print version number.")
def cli():
"""
Welcome to ksrates!
"""
@cli.command(context_settings={'help_option_names': ['-h', '--help']}, short_help="Generates configuration file.")
@click.argument('filename')
def generate_config(filename):
"""
Generates the configuration file for the rate-adjustment.
The configuration file name is given by argument FILENAME.
FILENAME: configuration file name
"""
from ksrates.generate_configfile import generate_configfile
generate_configfile(filename)
@cli.command(context_settings={'help_option_names': ['-h', '--help']}, short_help="Initializes rate-adjustment.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
@click.option("-n", "--nextflow", is_flag=True, help="Flag for Nextflow pipeline (Default: False)")
def init(config_file, expert, nextflow):
"""
Initializes rate-adjustment from CONFIG_FILE.
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
"""
from ksrates.setup_correction import setup_correction
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
setup_correction(config_file, expert, nextflow)
@cli.command(context_settings={'help_option_names': ['-h', '--help']}, short_help="Performs paralog Ks estimation.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option("--n-threads", type=int, default=4, help="Number of threads (default: 4)")
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
def paralogs_ks(config_file, expert, n_threads):
"""
Performs paralog Ks estimation for the focal species through wgd.
Takes parameters from CONFIG_FILE.
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
"""
from ksrates.wgd_paralogs import wgd_paralogs
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
wgd_paralogs(config_file, expert, n_threads)
@cli.command(context_settings={'help_option_names': ['-h', '--help']}, short_help="Performs ortholog Ks estimation.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
@click.argument("species1")
@click.argument("species2")
@click.option("--n-threads", type=int, default=4, help="Number of threads (default: 4)")
def orthologs_ks(config_file, expert, species1, species2, n_threads):
"""
Performs ortholog Ks estimation for SPECIES1 and SPECIES2 through wgd.
Takes parameters from CONFIG_FILE.
\b
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
SPECIES1: first of the two species involved in the ortholog Ks estimation
SPECIES2: second of the two species involved in the ortholog Ks estimation
"""
from ksrates.wgd_orthologs import wgd_orthologs
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
wgd_orthologs(config_file, expert, species1, species2, n_threads)
@cli.command(context_settings={'help_option_names': ['-h', '--help']},
short_help="Computes ortholog divergence times Ks estimates.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
@click.option('--ortholog-pairs', type=click.Path(exists=True), help="User-defined path to file containing the ortholog pairs with missing ortholog Ks peak in database (default: rate_adjustment/species/ortholog_pairs_species.tsv)")
def orthologs_analysis(config_file, expert, ortholog_pairs):
"""
Computes ortholog Ks distribution mode (or median) and updates the ortholog databases.
Takes parameters from CONFIG_FILE.
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
"""
from ksrates.compute_peaks import compute_peaks
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
if ortholog_pairs:
click.format_filename(ortholog_pairs)
compute_peaks(config_file, expert, ortholog_pairs)
@cli.command(context_settings={'help_option_names': ['-h', '--help']},
short_help="Performs ortholog substitution rate-adjustment.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
@click.option("--trios", type=click.Path(exists=True), help="User-defined path to file containing the ortholog trios (default: rate_adjustment/species/orthologs_trios_species.tsv)")
def orthologs_adjustment(config_file, expert, trios):
"""
Performs substitution rate-adjustment relative to the focal species.
Takes parameters from CONFIG_FILE.
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
"""
from ksrates.correct import correct
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
if trios:
click.format_filename(trios)
correct(config_file, expert, trios)
@cli.command(context_settings={'help_option_names': ['-h', '--help']}, short_help="Generates rate-adjusted mixed Ks plot.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
@click.option("--adjustment-table", type=click.Path(exists=True), help="User-defined path to file containing adjustment results (default: rate_adjustment/species/adjustment_table_species.tsv)")
@click.option("--paranome-table", type=click.Path(exists=True), help="User-defined path to file containing paranome Ks (default: paralog_distributions/wgd_species/species.ks.tsv)")
@click.option("--anchors-table", type=click.Path(exists=True), help="User-defined path to file containing anchor pair Ks (default: paralog_distribution/wgd_species/species.ks_anchors.tsv)")
def plot_paralogs(config_file, expert, adjustment_table, paranome_table, anchors_table):
"""
Plots rate-adjusted mixed paralog-ortholog Ks distribution.
Takes parameters from CONFIG_FILE.
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
"""
from ksrates.plot_paralogs import plot_paralogs_distr
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
if adjustment_table:
click.format_filename(adjustment_table)
if paranome_table:
click.format_filename(paranome_table)
if anchors_table:
click.format_filename(anchors_table)
plot_paralogs_distr(config_file, expert, adjustment_table, paranome_table, anchors_table)
@cli.command(context_settings={'help_option_names': ['-h', '--help']}, short_help="Generates phylogram with Ks-unit branch lengths.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
@click.option("--adjustment-table", type=click.Path(exists=True), help="User-defined path to file containing adjustment results (default: rate_adjustment/species/adjustment_table_species.tsv)")
@click.option("-n", "--nextflow", is_flag=True, help="Flag for Nextflow pipeline (Default: False)")
def plot_tree(config_file, expert, adjustment_table, nextflow):
"""
Generates a phylogram of the input dataset with branch lengths set to\
Ks distances estimated from ortholog KS distributions.
Takes parameters from CONFIG_FILE.
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
"""
from ksrates.plot_tree import plot_tree_rates
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
if adjustment_table:
click.format_filename(adjustment_table)
plot_tree_rates(config_file, expert, adjustment_table, nextflow)
@cli.command(context_settings={'help_option_names': ['-h', '--help']}, short_help="Generates ortholog Ks distributions plot.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
@click.option("--trios", type=click.Path(exists=True), help="User-defined path to file containing the ortholog trios (default: rate_adjustment/species/orthologs_trios_species.tsv)")
def plot_orthologs(config_file, expert, trios):
"""
Plots ortholog Ks distributions used for rate-adjustment.
Takes parameters from CONFIG_FILE.
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
"""
from ksrates.plot_orthologs import plot_orthologs_distr
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
if trios:
click.format_filename(trios)
plot_orthologs_distr(config_file, expert, trios)
@cli.command(context_settings={'help_option_names': ['-h', '--help']}, short_help="Detects WGD signatures in paralog Ks distribution.")
@click.argument('config_file', type=click.Path(exists=True))
@click.option('-e', '--expert', type=click.Path(exists=True), help="User-defined path to the expert configuration file")
@click.option("--paranome-table", type=click.Path(exists=True), help="User-defined path to file containing paranome Ks (default: paralog_distributions/wgd_species/species.ks.tsv)")
@click.option("--anchors-table", type=click.Path(exists=True), help="User-defined path to file containing anchor pair Ks (default: paralog_distribution/wgd_species/species.ks_anchors.tsv)")
@click.option("--adjustment-table", type=click.Path(exists=True), help="User-defined path to file containing adjustment results (default: rate_adjustment/species/adjustment_table_species.tsv)")
@click.option("--anchorpoints", type=click.Path(exists=True), help="User-defined path to i-ADHoRe file anchorpoints.txt (default: paralog_distributions/wgd_species/species_i-adhore/anchorpoints.txt)")
@click.option("--multiplicons", type=click.Path(exists=True), help="User-defined path to i-ADHoRe file multiplicons.txt (default: paralog_distributions/wgd_species/species_i-adhore/multiplicons.txt)")
@click.option("--segments", type=click.Path(exists=True), help="User-defined path to i-ADHoRe file segments.txt (default: paralog_distributions/wgd_species/species_i-adhore/segments.txt)")
@click.option("--list-elements", type=click.Path(exists=True), help="User-defined path to i-ADHoRe file list_elements.txt (default: paralog_distributions/wgd_species/species_i-adhore/list_elements.txt)")
@click.option("--multiplicon-pairs", type=click.Path(exists=True), help="User-defined path to i-ADHoRe file multiplicons_pairs.txt (default: paralog_distributions/wgd_species/species_i-adhore/multiplicons_pairs.txt)")
def paralogs_analyses(config_file, expert, paranome_table, anchors_table, adjustment_table, anchorpoints, multiplicons, segments, list_elements, multiplicon_pairs):
"""
Reconstructs potential WGD peaks in the paralog Ks distributions.
Performs anchor Ks clustering if "collinearity" analysis is switched on, otherwise performs exponential-lognormal mixture model on paranome.
If extra methods are asked through the expert configuration file, performs all methods available for the analysis type(s) selected.
Takes parameters from CONFIG_FILE.
CONFIG_FILE: configuration file to set up the rate-adjustment relative to the focal species
"""
from ksrates.paralogs_analyses import paralogs_analyses_methods
click.format_filename(config_file)
if expert:
click.format_filename(expert)
else:
expert = ""
if paranome_table:
click.format_filename(paranome_table)
if anchors_table:
click.format_filename(anchors_table)
if adjustment_table:
click.format_filename(adjustment_table)
if anchorpoints:
click.format_filename(anchorpoints)
if multiplicons:
click.format_filename(multiplicons)
if segments:
click.format_filename(segments)
if list_elements:
click.format_filename(list_elements)
if multiplicon_pairs:
click.format_filename(multiplicon_pairs)
paralogs_analyses_methods(config_file, expert, paranome_table, anchors_table, adjustment_table,
anchorpoints, multiplicons, segments, list_elements, multiplicon_pairs)
# For debugging
# Syntax: python3 ksrates_cli.py [command] [args]
if __name__ == "__main__":
cli(argv[1:])