Skip to content

Commit

Permalink
Add nextflow workflow stub runs for tower runs (#3763) | major
Browse files Browse the repository at this point in the history
### Added

- Add nextflow workflow stub-run option for tower runs

### Changed

- Removed log option for nextflow workflow start and run commands to keep option number under 13

### Fixed

-
  • Loading branch information
rannick authored Sep 25, 2024
1 parent 08878a5 commit 97035c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
25 changes: 13 additions & 12 deletions cg/cli/workflow/nf_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
help="Choose a configuration profile",
)

OPTION_LOG = click.option(
"--log",
type=click.Path(),
help="Set nextflow log file path",
)

OPTION_CONFIG = click.option(
"--config",
type=click.Path(),
Expand Down Expand Up @@ -88,6 +82,13 @@
show_default=True,
help="Start workflow from start without resuming execution",
)
OPTION_STUB = click.option(
"--stub-run",
is_flag=True,
default=False,
show_default=True,
help="Start a stub workflow",
)


@click.command("config-case")
Expand All @@ -106,7 +107,6 @@ def config_case(context: CGConfig, case_id: str, dry_run: bool) -> None:

@click.command("run")
@ARGUMENT_CASE_ID
@OPTION_LOG
@OPTION_WORKDIR
@OPTION_FROM_START
@OPTION_PROFILE
Expand All @@ -116,12 +116,12 @@ def config_case(context: CGConfig, case_id: str, dry_run: bool) -> None:
@OPTION_COMPUTE_ENV
@OPTION_USE_NEXTFLOW
@OPTION_TOWER_RUN_ID
@OPTION_STUB
@DRY_RUN
@click.pass_obj
def run(
context: CGConfig,
case_id: str,
log: str,
work_dir: str,
from_start: bool,
profile: str,
Expand All @@ -131,6 +131,7 @@ def run(
compute_env: str,
use_nextflow: bool,
nf_tower_id: str | None,
stub_run: bool,
dry_run: bool,
) -> None:
"""Run analysis for a case."""
Expand All @@ -139,7 +140,6 @@ def run(
analysis_api.run_nextflow_analysis(
case_id=case_id,
dry_run=dry_run,
log=log,
work_dir=work_dir,
from_start=from_start,
profile=profile,
Expand All @@ -149,6 +149,7 @@ def run(
compute_env=compute_env,
use_nextflow=use_nextflow,
nf_tower_id=nf_tower_id,
stub_run=stub_run,
)
except Exception as error:
LOG.error(f"Unspecified error occurred: {error}")
Expand All @@ -157,27 +158,27 @@ def run(

@click.command("start")
@ARGUMENT_CASE_ID
@OPTION_LOG
@OPTION_WORKDIR
@OPTION_PROFILE
@OPTION_CONFIG
@OPTION_PARAMS_FILE
@OPTION_REVISION
@OPTION_COMPUTE_ENV
@OPTION_USE_NEXTFLOW
@OPTION_STUB
@DRY_RUN
@click.pass_obj
def start(
context: CGConfig,
case_id: str,
log: str,
work_dir: str,
profile: str,
config: str,
params_file: str,
revision: str,
compute_env: str,
use_nextflow: bool,
stub_run: bool,
dry_run: bool,
) -> None:
"""Start workflow for a case."""
Expand All @@ -190,7 +191,6 @@ def start(
analysis_api.run_nextflow_analysis(
case_id=case_id,
dry_run=dry_run,
log=log,
work_dir=work_dir,
from_start=True,
profile=profile,
Expand All @@ -199,6 +199,7 @@ def start(
revision=revision,
compute_env=compute_env,
use_nextflow=use_nextflow,
stub_run=stub_run,
)
except Exception as error:
LOG.error(f"Unexpected error occurred: {error}")
Expand Down
13 changes: 6 additions & 7 deletions cg/meta/workflow/nf_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,8 @@ def create_case_directory(self, case_id: str, dry_run: bool = False) -> None:
if not dry_run:
Path(self.get_case_path(case_id=case_id)).mkdir(parents=True, exist_ok=True)

def get_log_path(self, case_id: str, workflow: str, log: str = None) -> Path:
def get_log_path(self, case_id: str, workflow: str) -> Path:
"""Path to NF log."""
if log:
return log
launch_time: str = datetime.now().strftime("%Y-%m-%d_%H.%M.%S")
return Path(
self.get_case_path(case_id),
Expand Down Expand Up @@ -453,7 +451,6 @@ def _run_analysis_with_tower(
def get_command_args(
self,
case_id: str,
log: str,
work_dir: str,
from_start: bool,
profile: str,
Expand All @@ -462,10 +459,11 @@ def get_command_args(
revision: str,
compute_env: str,
nf_tower_id: str | None,
stub_run: bool,
) -> NfCommandArgs:
command_args: NfCommandArgs = NfCommandArgs(
**{
"log": self.get_log_path(case_id=case_id, workflow=self.workflow, log=log),
"log": self.get_log_path(case_id=case_id, workflow=self.workflow),
"work_dir": self.get_workdir_path(case_id=case_id, work_dir=work_dir),
"resume": not from_start,
"profile": self.get_profile(profile=profile),
Expand All @@ -476,6 +474,7 @@ def get_command_args(
"revision": revision or self.revision,
"wait": NfTowerStatus.SUBMITTED,
"id": nf_tower_id,
"stub_run": stub_run,
}
)
return command_args
Expand All @@ -484,14 +483,14 @@ def run_nextflow_analysis(
self,
case_id: str,
use_nextflow: bool,
log: str,
work_dir: str,
from_start: bool,
profile: str,
config: str,
params_file: str | None,
revision: str,
compute_env: str,
stub_run: bool,
nf_tower_id: str | None = None,
dry_run: bool = False,
) -> None:
Expand All @@ -500,7 +499,6 @@ def run_nextflow_analysis(

command_args = self.get_command_args(
case_id=case_id,
log=log,
work_dir=work_dir,
from_start=from_start,
profile=profile,
Expand All @@ -509,6 +507,7 @@ def run_nextflow_analysis(
revision=revision,
compute_env=compute_env,
nf_tower_id=nf_tower_id,
stub_run=stub_run,
)

try:
Expand Down
2 changes: 2 additions & 0 deletions cg/meta/workflow/nf_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_tower_launch_parameters(cls, tower_workflow: str, command_args: dict) ->
"name",
"revision",
"compute_env",
"stub_run",
)
},
exclude_true=True,
Expand All @@ -62,6 +63,7 @@ def get_tower_relaunch_parameters(cls, from_tower_id: int, command_args: dict) -
"params_file",
"config",
"compute_env",
"stub_run",
)
},
exclude_true=True,
Expand Down
2 changes: 1 addition & 1 deletion cg/models/nf_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NfCommandArgs(BaseModel):
log: str | Path | None
resume: bool | None
profile: str | None
stub: bool | None
stub_run: bool | None
config: str | Path | None
name: str | None
revision: str | None
Expand Down

0 comments on commit 97035c9

Please sign in to comment.