Skip to content

Commit

Permalink
Fix Log Entry to Config File Bug (#406)
Browse files Browse the repository at this point in the history
* log entry to config file bug fix

* Generate new screengrabs with rich-codex

* file suffix fix

* comprehensive configure integration test, shared file io commands\

* Generate new screengrabs with rich-codex

* Minor simplification

* Update changelog

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Wout Bittremieux <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent 17bb3f2 commit ea0a82c
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 291 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed

- Precursor charges are exported as integers instead of floats in the mzTab output file, in compliance with the mzTab specification.
- Fixed log entries written to the config file instead of the log file when running the `configure` command.

### Removed

Expand Down
86 changes: 47 additions & 39 deletions casanovo/casanovo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,23 @@
import tqdm
from lightning.pytorch import seed_everything

from . import __version__
from . import utils
from .denovo import ModelRunner
from . import __version__, utils
from .config import Config
from .denovo import ModelRunner

logger = logging.getLogger("casanovo")
click.rich_click.USE_MARKDOWN = True
click.rich_click.STYLE_HELPTEXT = ""
click.rich_click.SHOW_ARGUMENTS = True


class _SharedParams(click.RichCommand):
"""Options shared between most Casanovo commands"""
class _SharedFileIOParams(click.RichCommand):
"""File IO options shared between most Casanovo commands"""

def __init__(self, *args, **kwargs) -> None:
"""Define shared options."""
super().__init__(*args, **kwargs)
self.params += [
click.Option(
("-m", "--model"),
help="""
Either the model weights (.ckpt file) or a URL pointing to the
model weights file. If not provided, Casanovo will try to
download the latest release automatically.
""",
),
click.Option(
("-d", "--output_dir"),
help="The destination directory for output files.",
Expand All @@ -78,30 +69,44 @@ def __init__(self, *args, **kwargs) -> None:
type=click.Path(dir_okay=False),
),
click.Option(
("-c", "--config"),
help="""
The YAML configuration file overriding the default options.
""",
type=click.Path(exists=True, dir_okay=False),
("-f", "--force_overwrite"),
help="Whether to overwrite output files.",
is_flag=True,
show_default=True,
default=False,
),
click.Option(
("-v", "--verbosity"),
help="""
Set the verbosity of console logging messages. Log files are
always set to 'debug'.
""",
help=(
"Set the verbosity of console logging messages."
" Log files are always set to 'debug'."
),
type=click.Choice(
["debug", "info", "warning", "error"],
case_sensitive=False,
),
default="info",
),
]


class _SharedParams(_SharedFileIOParams):
"""Options shared between main Casanovo commands"""

def __init__(self, *args, **kwargs) -> None:
"""Define shared options."""
super().__init__(*args, **kwargs)
self.params += [
click.Option(
("-f", "--force_overwrite"),
help="Whether to overwrite output files.",
is_flag=True,
show_default=True,
default=False,
("-m", "--model"),
help="""Either the model weights (.ckpt file) or a URL pointing to
the model weights file. If not provided, Casanovo will try to
download the latest release automatically.""",
),
click.Option(
("-c", "--config"),
help="The YAML configuration file overriding the default options.",
type=click.Path(exists=True, dir_okay=False),
),
]

Expand Down Expand Up @@ -336,22 +341,25 @@ def version() -> None:
sys.stdout.write("\n".join(versions) + "\n")


@main.command()
@click.option(
"-o",
"--output",
help="The output configuration file.",
default="casanovo.yaml",
type=click.Path(dir_okay=False),
)
def configure(output: Path) -> None:
@main.command(cls=_SharedFileIOParams)
def configure(
output_dir: str, output_root: str, verbosity: str, force_overwrite: bool
) -> None:
"""Generate a Casanovo configuration file to customize.
The casanovo configuration file is in the YAML format.
"""
Config.copy_default(str(output))
setup_logging(output, "info")
logger.info(f"Wrote {output}\n")
output_path, _ = _setup_output(
output_dir, output_root, force_overwrite, verbosity
)
config_fname = output_root if output_root is not None else "casanovo"
config_fname = Path(config_fname).with_suffix(".yaml")
if not force_overwrite:
utils.check_dir_file_exists(output_path, str(config_fname))

config_path = str(output_path / config_fname)
Config.copy_default(config_path)
logger.info(f"Wrote {config_path}")


def setup_logging(
Expand Down
Loading

0 comments on commit ea0a82c

Please sign in to comment.