-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathcli.py
More file actions
200 lines (170 loc) · 5.84 KB
/
Copy pathcli.py
File metadata and controls
200 lines (170 loc) · 5.84 KB
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
#!python
import click
import os
from alphabase.yaml_utils import save_yaml
from click.core import Context
from click.formatting import HelpFormatter
import peptdeep
from peptdeep.settings import global_settings, load_global_settings
from .cli_argparse import get_parser, parse_args_to_global_settings
@click.group(
context_settings=dict(
help_option_names=["-h", "--help"],
),
invoke_without_command=True,
)
@click.pass_context
@click.version_option(peptdeep.__version__, "-v", "--version")
def run(ctx, **kwargs):
click.echo(
r"""
____ __ ____
/ __ \___ ____ / /_/ __ \___ ___ ____
/ /_/ / _ \/ __ \/ __/ / / / _ \/ _ \/ __ \
/ ____/ __/ /_/ / /_/ /_/ / __/ __/ /_/ /
/_/ \___/ .___/\__/_____/\___/\___/ .___/
/_/ /_/
....................................................
.{version}.
.{url}.
.{license}.
....................................................
""".format(
version=peptdeep.__version__.center(50),
url=peptdeep.__github__.center(50),
license=peptdeep.__license__.center(50),
)
)
if ctx.invoked_subcommand is None:
click.echo(run.get_help(ctx))
@run.command("gui", help="Start graphical user interface.")
@click.option(
"--port", default=10077, type=int, show_default=True, help="The web server port."
)
@click.option(
"--settings_yaml",
default="",
type=str,
show_default=True,
help="Load default settings yaml file.",
)
def _gui(port, settings_yaml):
import peptdeep.gui
from peptdeep.webui.server import _server
if os.path.isfile(settings_yaml):
load_global_settings(settings_yaml)
# start the server to run tasks
_server.start()
peptdeep.gui.run(port)
@run.command("install-models", help="Install or update peptdeep pre-trained models.")
@click.option(
"--model-file",
default=None,
type=str,
show_default=True,
help="The model .zip file to install. "
"If not set, peptdeep will download the model file from GitHub.",
)
@click.option(
"--overwrite",
default=True,
type=bool,
show_default=True,
help="If overwrite existing model file.",
)
def _install_model(model_file, overwrite):
from peptdeep.pretrained_models import download_models, MODEL_URL
if not model_file:
download_models(MODEL_URL, overwrite=overwrite)
else:
download_models(model_file, overwrite=overwrite)
_help_str = (
"\n\nTo get the settings_yaml file,"
" you can either export from the GUI,"
" or use `peptdeep export-settings`."
" Visit https://github.com/mannlabs/alphapeptdeep/#cli"
" for detailed usages."
)
# @run.command("rescore", help=
# "Rescore PSMs using Percolator."+_help_str
# )
# @click.argument("settings_yaml", type=str)
# def _rescore(settings_yaml:str):
# from peptdeep.pipeline_api import rescore
# load_global_settings(settings_yaml)
# rescore()
@run.command("library", help="Predict library for DIA search." + _help_str)
@click.argument("settings_yaml", type=str)
def _library(settings_yaml: str):
from peptdeep.pipeline_api import generate_library
load_global_settings(settings_yaml)
generate_library()
@run.command("transfer", help="Transfer learning for different data types." + _help_str)
@click.argument("settings_yaml", type=str)
def _transfer(settings_yaml: str):
from peptdeep.pipeline_api import transfer_learn
load_global_settings(settings_yaml)
transfer_learn()
@run.command(
"export-settings",
help="Export the default settings to a yaml file. It can be used as the template setting.",
)
@click.argument("yaml_file", type=str)
def _export_settings(yaml_file: str):
save_yaml(yaml_file, global_settings)
class ParserHelper(click.Command):
def format_help(self, ctx: Context, formatter: HelpFormatter) -> None:
parser = get_parser()
formatter.write(parser.format_help())
@run.command(
"cmd-flow",
help="Using command line arguments to control the settings",
cls=ParserHelper,
context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
),
)
@click.pass_context
def _cmd_flow(ctx):
parser = get_parser()
if len(ctx.args) == 0:
parser.print_help()
else:
parse_args_to_global_settings(parser, ctx.args)
if "train" in global_settings["task_workflow"]:
from peptdeep.pipeline_api import transfer_learn
transfer_learn()
if os.path.isfile(
os.path.join(
global_settings["model_mgr"]["transfer"]["model_output_folder"],
"ms2.pth",
)
):
global_settings["model_mgr"]["external_ms2_model"] = os.path.join(
global_settings["model_mgr"]["transfer"]["model_output_folder"],
"ms2.pth",
)
if os.path.isfile(
os.path.join(
global_settings["model_mgr"]["transfer"]["model_output_folder"],
"rt.pth",
)
):
global_settings["model_mgr"]["external_rt_model"] = os.path.join(
global_settings["model_mgr"]["transfer"]["model_output_folder"],
"rt.pth",
)
if os.path.isfile(
os.path.join(
global_settings["model_mgr"]["transfer"]["model_output_folder"],
"ccs.pth",
)
):
global_settings["model_mgr"]["external_ccs_model"] = os.path.join(
global_settings["model_mgr"]["transfer"]["model_output_folder"],
"ccs.pth",
)
if "library" in global_settings["task_workflow"]:
from peptdeep.pipeline_api import generate_library
generate_library()