Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply ruff formatting #182

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
# - repo: https://github.com/astral-sh/ruff-pre-commit
# rev: v0.4.0
# hooks:
# - id: ruff-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff-format
# - id: ruff

exclude: .bumpversion.cfg
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,21 @@ clone the repository and create a [pull
request](https://github.com/MannLabs/alphapeptdeep/pulls) with a new
branch. For an even more interactive participation, check out the
[discussions](https://github.com/MannLabs/alphapeptdeep/discussions) and
the [the Contributors License Agreement](misc/CLA.md).
the [Contributors License Agreement](misc/CLA.md).

### Notes for developers
#### pre-commit hooks
It is highly recommended to use the provided pre-commit hooks, as the CI pipeline enforces all checks therein to
pass in order to merge a branch.

The hooks need to be installed once by
```bash
pre-commit install
```
You can run the checks yourself using:
```bash
pre-commit run --all-files
```
------------------------------------------------------------------------

## Changelog
Expand Down
42 changes: 21 additions & 21 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import sys
import importlib
import inspect
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))


# -- Project information -----------------------------------------------------

project = 'peptdeep'
copyright = '2022, Mann Labs, MPIB'
author = 'Mann Labs, MPIB'
project = "peptdeep"
copyright = "2022, Mann Labs, MPIB"
author = "Mann Labs, MPIB"

release = "1.2.1"

Expand All @@ -31,34 +32,33 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.napoleon',
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"sphinx.ext.linkcode",
'sphinx.ext.viewcode',
'autodocsumm',
'nbsphinx',
'myst_parser',
"sphinx.ext.viewcode",
"autodocsumm",
"nbsphinx",
"myst_parser",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
'_build', 'Thumbs.db', '.DS_Store',
'_modidx,py'
]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "_modidx,py"]

code_url = f"https://github.com/mannlabs/alphapeptdeep/blob/main"


def linkcode_resolve(domain, info):
# Non-linkable objects from the starter kit in the tutorial.
if domain == "js" or info["module"] == "connect4":
return

if domain != "py": return
if domain != "py":
return

mod = importlib.import_module(info["module"])
if "." in info["fullname"]:
Expand Down Expand Up @@ -93,16 +93,16 @@ def linkcode_resolve(domain, info):
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'furo'
html_logo = '_static/peptdeep.png'
html_favicon = '_static/peptdeep.png'
html_theme = "furo"
html_logo = "_static/peptdeep.png"
html_favicon = "_static/peptdeep.png"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

autodoc_default_options = {
'autosummary': True,
'special-members': '__init__', # Include __init__ methods.
"autosummary": True,
"special-members": "__init__", # Include __init__ methods.
}
3 changes: 1 addition & 2 deletions peptdeep/_modidx.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
d = { 'settings': { },
'syms': { }}
d = {"settings": {}, "syms": {}}
130 changes: 84 additions & 46 deletions peptdeep/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
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'],
help_option_names=["-h", "--help"],
),
invoke_without_command=True
invoke_without_command=True,
)
@click.pass_context
@click.version_option(peptdeep.__version__, "-v", "--version")
def run(ctx, **kwargs):
click.echo(
r'''
r"""
____ __ ____
/ __ \___ ____ / /_/ __ \___ ___ ____
/ /_/ / _ \/ __ \/ __/ / / / _ \/ _ \/ __ \
Expand All @@ -35,48 +36,63 @@ def run(ctx, **kwargs):
.{url}.
.{license}.
....................................................
'''.format(
version=peptdeep.__version__.center(50),
url=peptdeep.__github__.center(50),
license=peptdeep.__license__.center(50),
""".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(
"--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."
@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(
"--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."
@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
)
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,"
Expand All @@ -94,41 +110,49 @@ def _install_model(model_file, overwrite):
# load_global_settings(settings_yaml)
# rescore()

@run.command("library", help=
"Predict library for DIA search."+_help_str
)

@run.command("library", help="Predict library for DIA search." + _help_str)
@click.argument("settings_yaml", type=str)
def _library(settings_yaml: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
)

@run.command("transfer", help="Transfer learning for different data types." + _help_str)
@click.argument("settings_yaml", type=str)
def _transfer(settings_yaml: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.")

@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):
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",

@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,
))
ignore_unknown_options=True,
allow_extra_args=True,
),
)
@click.pass_context
def _cmd_flow(ctx):
parser = get_parser()
Expand All @@ -138,25 +162,39 @@ def _cmd_flow(ctx):
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"
)):
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"
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"
)):
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"
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",
)
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"
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()
Loading
Loading