| 1 | package NBI::Launcher; | ||||||||||||||||||||||||||||||||||||||||
| 2 | #ABSTRACT: Base class for nbilaunch tool wrappers | ||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||
| 4 | # NBI::Launcher - Declarative base class for HPC tool launchers. | ||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||
| 6 | # DESCRIPTION: | ||||||||||||||||||||||||||||||||||||||||
| 7 | # Every tool wrapper inherits from this class. Subclasses provide: | ||||||||||||||||||||||||||||||||||||||||
| 8 | # - A constructor that calls SUPER::new() with the launcher spec | ||||||||||||||||||||||||||||||||||||||||
| 9 | # - make_command(%args) - the tool invocation string (only override needed | ||||||||||||||||||||||||||||||||||||||||
| 10 | # for most tools) | ||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||
| 12 | # The base class provides everything else: | ||||||||||||||||||||||||||||||||||||||||
| 13 | # - Spec storage and introspection (arg_spec, input_mode, sample_name) | ||||||||||||||||||||||||||||||||||||||||
| 14 | # - Input / param / output validation | ||||||||||||||||||||||||||||||||||||||||
| 15 | # - Shell script generation (generate_script) | ||||||||||||||||||||||||||||||||||||||||
| 16 | # - NBI::Job construction and NBI::Manifest creation (build) | ||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||
| 18 | # RELATIONSHIPS: | ||||||||||||||||||||||||||||||||||||||||
| 19 | # - Subclasses live in NBI::Launcher::*, ./launchers/, or ~/.nbi/launchers/. | ||||||||||||||||||||||||||||||||||||||||
| 20 | # - build() returns (NBI::Job, NBI::Manifest) - consumed by bin/nbilaunch. | ||||||||||||||||||||||||||||||||||||||||
| 21 | # - NBI::Pipeline wraps multiple NBI::Job objects for multi-step launchers. | ||||||||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use 5.012; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Carp qw(confess croak); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use Cwd qw(realpath); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | $NBI::Launcher::VERSION = $NBI::Slurm::VERSION; | |||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||
| 34 | # ── Constructor ─────────────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 35 | # All parameters are named (not the -param style used by NBI::Opts/NBI::Job). | ||||||||||||||||||||||||||||||||||||||||
| 36 | # | ||||||||||||||||||||||||||||||||||||||||
| 37 | # Required: name, activate, inputs, outputs, outdir | ||||||||||||||||||||||||||||||||||||||||
| 38 | # Optional: description, version, slurm_defaults, params, scratch, success_check | ||||||||||||||||||||||||||||||||||||||||
| 39 | 10 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 40 | 10 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||
| 42 | # ── Validate activate spec ──────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 43 | my $activate = $args{activate} | ||||||||||||||||||||||||||||||||||||||||
| 44 | 10 | ▶ | or confess "ERROR NBI::Launcher: 'activate' is required\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | ▶ | ref $activate eq 'HASH' | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 46 | or confess "ERROR NBI::Launcher: 'activate' must be a hashref\n"; | ||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | my @act_keys = keys %$activate; | |||||||||||||||||||||||||||||||||||||||
| 48 | confess "ERROR NBI::Launcher: 'activate' must have exactly one key (module|singularity|conda), got: @act_keys\n" | ||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | ▶ | unless @act_keys == 1 && grep { /^(module|singularity|conda)$/ } @act_keys; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@act_keys == 1 and grep {/^(module|singularity|conda)$/u;} @act_keys
MC/DC100%2/2
@act_keys == 1 and grep {/^(module|singularity|conda)$/u;} @act_keys
@act_keys == 1
grep {/^(module|singularity|conda)$/u;} @act_keys
Truth table100%3/3
A and B
A= @act_keys == 1B= grep {/^(module|singularity|conda)$/u;} @act_keys
| |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||
| 51 | # ── Validate slurm_defaults ─────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | ▶ | my $slurm_defaults = $args{slurm_defaults} // {}; | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"slurm_defaults"} // {}
MC/DC100%1/1
$args{"slurm_defaults"} // {}
$args{"slurm_defaults"}
Truth table100%2/2
A
A= $args{"slurm_defaults"}
| |||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | for my $k (keys %$slurm_defaults) { | |||||||||||||||||||||||||||||||||||||||
| 54 | 8 | ▶ | confess "ERROR NBI::Launcher: unknown slurm_defaults key '$k'\n" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 55 | unless $k =~ /^(queue|threads|memory|runtime)$/; | ||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | ▶ | $self->{name} = $args{name} or confess "ERROR NBI::Launcher: 'name' is required\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | $self->{description} = $args{description} // ''; | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"description"} // ""
MC/DC100%1/1
$args{"description"} // ""
$args{"description"}
Truth table100%2/2
A
A= $args{"description"}
| |||||||||||||||||||||||||||||||||||||||||
| 62 | 5 | ▶ | $self->{version} = $args{version} // 'unknown'; | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"version"} // "unknown"
MC/DC100%1/1
$args{"version"} // "unknown"
$args{"version"}
Truth table100%2/2
A
A= $args{"version"}
| |||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | $self->{activate} = $activate; | |||||||||||||||||||||||||||||||||||||||
| 64 | $self->{slurm_defaults} = { | ||||||||||||||||||||||||||||||||||||||||
| 65 | 5 | queue => 'qib-short', | |||||||||||||||||||||||||||||||||||||||
| 66 | threads => 1, | ||||||||||||||||||||||||||||||||||||||||
| 67 | memory => 4, # GB | ||||||||||||||||||||||||||||||||||||||||
| 68 | runtime => '01:00:00', | ||||||||||||||||||||||||||||||||||||||||
| 69 | %$slurm_defaults, # caller overrides | ||||||||||||||||||||||||||||||||||||||||
| 70 | }; | ||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | ▶ | $self->{inputs} = $args{inputs} // []; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"inputs"} // []
MC/DC0%0/1
$args{"inputs"} // []
$args{"inputs"}
Truth table50%1/2
A
A= $args{"inputs"}
| |||||||||||||||||||||||||||||||||||||||||
| 72 | 5 | ▶ | $self->{params} = $args{params} // []; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"params"} // []
MC/DC0%0/1
$args{"params"} // []
$args{"params"}
Truth table50%1/2
A
A= $args{"params"}
| |||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | ▶ | $self->{outputs} = $args{outputs} // []; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"outputs"} // []
MC/DC0%0/1
$args{"outputs"} // []
$args{"outputs"}
Truth table50%1/2
A
A= $args{"outputs"}
| |||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | ▶ | $self->{outdir} = $args{outdir} // { flag => '--outdir', short => '-o', required => 1 }; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"outdir"} // {"flag", "--outdir", "short", "-o", "required", 1}
MC/DC0%0/1
$args{"outdir"} // {"flag", "--outdir", "short", "-o", "required", 1}
$args{"outdir"}
Truth table50%1/2
A
A= $args{"outdir"}
| |||||||||||||||||||||||||||||||||||||||||
| 75 | 5 | ▶ | $self->{scratch} = $args{scratch} // { use_tmpdir => 0, cleanup_on_failure => 0 }; | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"scratch"} // {"use_tmpdir", 0, "cleanup_on_failure", 0}
MC/DC100%1/1
$args{"scratch"} // {"use_tmpdir", 0, "cleanup_on_failure", 0}
$args{"scratch"}
Truth table100%2/2
A
A= $args{"scratch"}
| |||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | $self->{success_check} = $args{success_check}; # optional coderef | |||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||
| 81 | # ── activation_lines() ──────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 82 | # Returns the shell snippet that loads the tool environment. | ||||||||||||||||||||||||||||||||||||||||
| 83 | # For singularity: returns "" because the prefix goes into make_command() | ||||||||||||||||||||||||||||||||||||||||
| 84 | # via singularity_prefix(). | ||||||||||||||||||||||||||||||||||||||||
| 85 | 5 | ▶ | sub activation_lines { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
activation_lines: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 86 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 87 | 5 | my ($type, $value) = each %{ $self->{activate} }; | |||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||
| 89 | 5 | ▶ | if ($type eq 'module') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | return "module load $value\n"; | |||||||||||||||||||||||||||||||||||||||
| 91 | } elsif ($type eq 'conda') { | ||||||||||||||||||||||||||||||||||||||||
| 92 | # Use 'source activate' for broadest HPC compatibility. | ||||||||||||||||||||||||||||||||||||||||
| 93 | # On systems with conda >= 4.4, 'conda activate' also works. | ||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | return "source activate $value\n"; | |||||||||||||||||||||||||||||||||||||||
| 95 | } elsif ($type eq 'singularity') { | ||||||||||||||||||||||||||||||||||||||||
| 96 | # Singularity prefix is applied per-command in make_command() | ||||||||||||||||||||||||||||||||||||||||
| 97 | # via singularity_prefix(). Nothing needed here. | ||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | return ''; | |||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||
| 103 | # ── singularity_prefix() ────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 104 | # Helper for make_command() overrides: returns "singularity exec $image " | ||||||||||||||||||||||||||||||||||||||||
| 105 | # when the launcher uses singularity activation, empty string otherwise. | ||||||||||||||||||||||||||||||||||||||||
| 106 | # Subclass make_command() calls this and prepends it to the tool invocation. | ||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | ▶ | sub singularity_prefix { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
singularity_prefix: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 109 | 2 | my $img = $self->{activate}{singularity}; | |||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | return defined $img ? "singularity exec $img " : ''; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||
| 113 | # ── sample_name(%args) ──────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 114 | # Derives the sample name from the first file-type required input (usually r1). | ||||||||||||||||||||||||||||||||||||||||
| 115 | # Strips known FASTQ extensions in order: .gz .fastq .fq _R1 _R2 _1 _2 | ||||||||||||||||||||||||||||||||||||||||
| 116 | # Override with --sample-name on the nbilaunch command line. | ||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | ▶ | sub sample_name { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
sample_name: called CC=9 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||
| 120 | # Explicit override takes priority | ||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | ▶ | return $args{sample_name} if defined $args{sample_name}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||
| 123 | # Find the first required file-type input | ||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | my $source; | |||||||||||||||||||||||||||||||||||||||
| 125 | 5 | for my $inp (@{ $self->{inputs} }) { | |||||||||||||||||||||||||||||||||||||||
| 126 | 5 | ▶ | if (($inp->{type} // '') eq 'file' && ($inp->{required} // 0)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition42%3/7
($inp->{"type"} // "") eq "file" and $inp->{"required"} // 0
$inp->{"type"} // ""
$inp->{"required"} // 0
MC/DC0%0/2
($inp->{"type"} // "") eq "file" and $inp->{"required"} // 0
$inp->{"type"}
$inp->{"required"}
Truth table33%1/3
A and B
A= $inp->{"type"}B= $inp->{"required"}
| |||||||||||||||||||||||||||||||||||||||||
| 127 | 5 | $source = $args{ $inp->{name} }; | |||||||||||||||||||||||||||||||||||||||
| 128 | 5 | ▶ | last if defined $source; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | ▶ | confess "ERROR NBI::Launcher ($self->{name}): cannot derive sample name - no file input found\n" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 132 | unless defined $source; | ||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | my $name = basename($source); | |||||||||||||||||||||||||||||||||||||||
| 135 | # Strip extensions from right to left | ||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | $name =~ s/\.gz$//i; | |||||||||||||||||||||||||||||||||||||||
| 137 | 5 | $name =~ s/\.(fastq|fq)$//i; | |||||||||||||||||||||||||||||||||||||||
| 138 | 5 | $name =~ s/_R[12]$//; | |||||||||||||||||||||||||||||||||||||||
| 139 | 5 | $name =~ s/_[12]$//; | |||||||||||||||||||||||||||||||||||||||
| 140 | 5 | return $name; | |||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||
| 143 | # ── input_mode(%args) ──────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 144 | # Returns "paired" if both r1 and r2 are defined, "single" otherwise. | ||||||||||||||||||||||||||||||||||||||||
| 145 | # Subclasses may override for tools with different pairing logic. | ||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | sub input_mode { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
input_mode: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ▶ | return (defined $args{r1} && defined $args{r2}) ? 'paired' : 'single'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $args{"r1"} and defined $args{"r2"}
MC/DC50%1/2
defined $args{"r1"} and defined $args{"r2"}
defined $args{"r1"}
defined $args{"r2"}
Truth table66%2/3
A and B
A= defined $args{"r1"}B= defined $args{"r2"}
| |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||
| 151 | # ── arg_spec() ──────────────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 152 | # Returns the full CLI surface of this launcher for nbilaunch to use when | ||||||||||||||||||||||||||||||||||||||||
| 153 | # generating --help text and parsing command-line arguments. | ||||||||||||||||||||||||||||||||||||||||
| 154 | # slurm_sync params are excluded (they are derived, not user-settable). | ||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | ▶ | sub arg_spec { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
arg_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 157 | return { | ||||||||||||||||||||||||||||||||||||||||
| 158 | name => $self->{name}, | ||||||||||||||||||||||||||||||||||||||||
| 159 | description => $self->{description}, | ||||||||||||||||||||||||||||||||||||||||
| 160 | version => $self->{version}, | ||||||||||||||||||||||||||||||||||||||||
| 161 | activate => $self->{activate}, | ||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | inputs => [ grep { !$_->{slurm_sync} } @{ $self->{inputs} } ], | |||||||||||||||||||||||||||||||||||||||
| 163 | 5 | params => [ grep { !$_->{slurm_sync} } @{ $self->{params} } ], | |||||||||||||||||||||||||||||||||||||||
| 164 | outputs => $self->{outputs}, | ||||||||||||||||||||||||||||||||||||||||
| 165 | outdir => $self->{outdir}, | ||||||||||||||||||||||||||||||||||||||||
| 166 | slurm_defaults => $self->{slurm_defaults}, | ||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | }; | |||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||
| 170 | # ── validate(%args) ─────────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 171 | # Dies with a helpful message if required inputs/params are missing or if | ||||||||||||||||||||||||||||||||||||||||
| 172 | # file/dir values do not exist on disk. | ||||||||||||||||||||||||||||||||||||||||
| 173 | 7 | ▶ | sub validate { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=30 SCAR=38.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 174 | 7 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||
| 176 | # Check inputs | ||||||||||||||||||||||||||||||||||||||||
| 177 | 7 | for my $inp (@{ $self->{inputs} }) { | |||||||||||||||||||||||||||||||||||||||
| 178 | 12 | ▶ | next if $inp->{slurm_sync}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 179 | 12 | my $name = $inp->{name}; | |||||||||||||||||||||||||||||||||||||||
| 180 | 12 | my $val = $args{$name}; | |||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||
| 182 | 12 | ▶ | if ($inp->{required} && !defined $val) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$inp->{"required"} and not defined $val
MC/DC100%2/2
$inp->{"required"} and not defined $val
$inp->{"required"}
not defined $val
Truth table100%3/3
A and not(B)
A= $inp->{"required"}B= not defined $val
| |||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | confess "ERROR NBI::Launcher ($self->{name}): missing required input '--$name'\n"; | |||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||
| 185 | 11 | ▶ | next unless defined $val; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | ▶ | my $type = $inp->{type} // 'string'; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$inp->{"type"} // "string"
MC/DC0%0/1
$inp->{"type"} // "string"
$inp->{"type"}
Truth table50%1/2
A
A= $inp->{"type"}
| |||||||||||||||||||||||||||||||||||||||||
| 188 | 6 | ▶ | if ($type eq 'file' && !-f $val) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$type eq "file" and not -f $val
MC/DC50%1/2
$type eq "file" and not -f $val
$type eq "file"
not -f $val
Truth table66%2/3
A and not(B)
A= $type eq "file"B= not -f $val
| |||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | confess "ERROR NBI::Launcher ($self->{name}): input '$name' - file not found: $val\n"; | |||||||||||||||||||||||||||||||||||||||
| 190 | ▶ | } elsif ($type eq 'dir' && !-d $val) { | |||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "dir" and not -d $val
MC/DC0%0/2
$type eq "dir" and not -d $val
$type eq "dir"
not -d $val
Truth table33%1/3
A and not(B)
A= $type eq "dir"B= not -d $val
| |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | confess "ERROR NBI::Launcher ($self->{name}): input '$name' - directory not found: $val\n"; | |||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||
| 195 | # Check params (with default_env and default fallback) | ||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | for my $p (@{ $self->{params} }) { | |||||||||||||||||||||||||||||||||||||||
| 197 | 11 | ▶ | next if $p->{slurm_sync}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | my $name = $p->{name}; | |||||||||||||||||||||||||||||||||||||||
| 199 | 7 | my $val = $args{$name}; | |||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||
| 201 | # Try default_env, then default | ||||||||||||||||||||||||||||||||||||||||
| 202 | 7 | ▶ | if (!defined $val && $p->{default_env}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $val and $p->{"default_env"}
MC/DC100%2/2
not defined $val and $p->{"default_env"}
not defined $val
$p->{"default_env"}
Truth table100%3/3
not(A) and B
A= not defined $valB= $p->{"default_env"}
| |||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | $val = $ENV{ $p->{default_env} }; | |||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||
| 205 | 7 | ▶ | $val //= $p->{default}; | ||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$val //= $p->{"default"}
MC/DC0%0/2
$val //= $p->{"default"}
$val
$p->{"default"}
Truth table66%2/3
A //= B
A= $valB= $p->{"default"}
| |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||
| 207 | 7 | ▶ | if ($p->{required} && !defined $val) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$p->{"required"} and not defined $val
MC/DC0%0/2
$p->{"required"} and not defined $val
$p->{"required"}
not defined $val
Truth table66%2/3
A and not(B)
A= $p->{"required"}B= not defined $val
| |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | confess "ERROR NBI::Launcher ($self->{name}): missing required param '--$name'\n"; | |||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||
| 210 | 7 | ▶ | next unless defined $val; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||
| 212 | 7 | ▶ | my $type = $p->{type} // 'string'; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$p->{"type"} // "string"
MC/DC0%0/1
$p->{"type"} // "string"
$p->{"type"}
Truth table50%1/2
A
A= $p->{"type"}
| |||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | ▶ | if ($type eq 'int' && $val !~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%1/3
$type eq "int" and not $val =~ /^\d+$/u
MC/DC0%0/2
$type eq "int" and not $val =~ /^\d+$/u
$type eq "int"
not $val =~ /^\d+$/u
Truth table33%1/3
A and not(B)
A= $type eq "int"B= not $val =~ /^\d+$/u
| |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | confess "ERROR NBI::Launcher ($self->{name}): param '$name' must be an integer, got: $val\n"; | |||||||||||||||||||||||||||||||||||||||
| 215 | ▶ | } elsif ($type eq 'float' && $val !~ /^[\d.]+$/) { | |||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type eq "float" and not $val =~ /^[\d.]+$/u
MC/DC0%0/2
$type eq "float" and not $val =~ /^[\d.]+$/u
$type eq "float"
not $val =~ /^[\d.]+$/u
Truth table66%2/3
A and not(B)
A= $type eq "float"B= not $val =~ /^[\d.]+$/u
| |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | confess "ERROR NBI::Launcher ($self->{name}): param '$name' must be a number, got: $val\n"; | |||||||||||||||||||||||||||||||||||||||
| 217 | ▶ | } elsif ($type eq 'file' && !-f $val) { | |||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "file" and not -f $val
MC/DC0%0/2
$type eq "file" and not -f $val
$type eq "file"
not -f $val
Truth table33%1/3
A and not(B)
A= $type eq "file"B= not -f $val
| |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | confess "ERROR NBI::Launcher ($self->{name}): param '$name' - file not found: $val\n"; | |||||||||||||||||||||||||||||||||||||||
| 219 | ▶ | } elsif ($type eq 'dir' && !-d $val) { | |||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$type eq "dir" and not -d $val
MC/DC100%2/2
$type eq "dir" and not -d $val
$type eq "dir"
not -d $val
Truth table100%3/3
A and not(B)
A= $type eq "dir"B= not -d $val
| |||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | confess "ERROR NBI::Launcher ($self->{name}): param '$name' - directory not found: $val\n"; | |||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||
| 224 | # Check outdir is provided | ||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | ▶ | if ($self->{outdir}{required} && !defined $args{outdir}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"outdir"}{"required"} and not defined $args{"outdir"}
MC/DC50%1/2
$self->{"outdir"}{"required"} and not defined $args{"outdir"}
$self->{"outdir"}{"required"}
not defined $args{"outdir"}
Truth table66%2/3
A and not(B)
A= $self->{"outdir"}{"required"}B= not defined $args{"outdir"}
| |||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | confess "ERROR NBI::Launcher ($self->{name}): missing required '--outdir'\n"; | |||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||
| 232 | # ── make_command(%args) ─────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 233 | # Returns the tool invocation string to embed in the job script. | ||||||||||||||||||||||||||||||||||||||||
| 234 | # Subclasses SHOULD override this method. | ||||||||||||||||||||||||||||||||||||||||
| 235 | # The default implementation raises an error - every launcher needs a command. | ||||||||||||||||||||||||||||||||||||||||
| 236 | # | ||||||||||||||||||||||||||||||||||||||||
| 237 | # %args contains all resolved inputs, params, and derived keys: | ||||||||||||||||||||||||||||||||||||||||
| 238 | # $args{sample} - derived sample name | ||||||||||||||||||||||||||||||||||||||||
| 239 | # $args{threads} - from slurm_sync or slurm_defaults | ||||||||||||||||||||||||||||||||||||||||
| 240 | # For scratch paths, use literal \$SCRATCH (shell variable). | ||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | sub make_command { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_command: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 243 | 0 | confess "ERROR NBI::Launcher ($self->{name}): make_command() not implemented\n"; | |||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||
| 246 | # ── generate_script(%args) ─────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 247 | # Assembles the script body (everything after the #SBATCH header generated by | ||||||||||||||||||||||||||||||||||||||||
| 248 | # NBI::Opts->header()). Returns a single string. | ||||||||||||||||||||||||||||||||||||||||
| 249 | # | ||||||||||||||||||||||||||||||||||||||||
| 250 | # Sections (in order): | ||||||||||||||||||||||||||||||||||||||||
| 251 | # 1. set -euo pipefail + metadata comment | ||||||||||||||||||||||||||||||||||||||||
| 252 | # 2. Manifest update shell functions + ERR trap | ||||||||||||||||||||||||||||||||||||||||
| 253 | # 3. Activation (module load / conda / empty for singularity) | ||||||||||||||||||||||||||||||||||||||||
| 254 | # 4. SAMPLE, OUTDIR, SCRATCH variables | ||||||||||||||||||||||||||||||||||||||||
| 255 | # 5. EXIT trap (scratch cleanup) | ||||||||||||||||||||||||||||||||||||||||
| 256 | # 6. Tool command from make_command() | ||||||||||||||||||||||||||||||||||||||||
| 257 | # 7. Required-output validation | ||||||||||||||||||||||||||||||||||||||||
| 258 | # 8. Promote from scratch to outdir + success update | ||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | ▶ | sub generate_script { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_script: called CC=19 SCAR=33.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | my $tool = $self->{name}; | |||||||||||||||||||||||||||||||||||||||
| 263 | 2 | my $version = $self->{version}; | |||||||||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | my $sample = $args{sample} or confess "generate_script: 'sample' required\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | ▶ | my $outdir = $args{outdir} or confess "generate_script: 'outdir' required\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | ▶ | my $manifest_rel = $args{manifest_path} // ".nbilaunch/$sample.manifest.json"; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"manifest_path"} // ".nbilaunch/$sample.manifest.json"
MC/DC0%0/1
$args{"manifest_path"} // ".nbilaunch/$sample.manifest.json"
$args{"manifest_path"}
Truth table50%1/2
A
A= $args{"manifest_path"}
| |||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | my $submitted_at = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime()); | |||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | my $launcher_class = ref($self); | |||||||||||||||||||||||||||||||||||||||
| 270 | 2 | ▶ | my $nbi_version = $NBI::Slurm::VERSION // 'unknown'; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$NBI::Slurm::VERSION // "unknown"
MC/DC0%0/1
$NBI::Slurm::VERSION // "unknown"
$NBI::Slurm::VERSION
Truth table50%1/2
A
A= $NBI::Slurm::VERSION
| |||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | ▶ | my $nbi_l_version = $NBI::Launcher::VERSION // '0.1.0'; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$NBI::Launcher::VERSION // "0.1.0"
MC/DC0%0/1
$NBI::Launcher::VERSION // "0.1.0"
$NBI::Launcher::VERSION
Truth table50%1/2
A
A= $NBI::Launcher::VERSION
| |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||
| 273 | # ── Resolve %args for make_command ─────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 274 | # Apply default_env / default fallbacks for params before calling make_command | ||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | my %cmd_args = %args; | |||||||||||||||||||||||||||||||||||||||
| 276 | 2 | for my $p (@{ $self->{params} }) { | |||||||||||||||||||||||||||||||||||||||
| 277 | 5 | my $name = $p->{name}; | |||||||||||||||||||||||||||||||||||||||
| 278 | 5 | ▶ | next if defined $cmd_args{$name}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ($p->{default_env} && defined $ENV{ $p->{default_env} }) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$p->{"default_env"} and defined $ENV{$p->{"default_env"}}
MC/DC0%0/2
$p->{"default_env"} and defined $ENV{$p->{"default_env"}}
$p->{"default_env"}
defined $ENV{$p->{"default_env"}}
Truth table0%0/3
A and B
A= $p->{"default_env"}B= defined $ENV{$p->{"default_env"}}
| |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $cmd_args{$name} = $ENV{ $p->{default_env} }; | |||||||||||||||||||||||||||||||||||||||
| 281 | } elsif (defined $p->{default}) { | ||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $cmd_args{$name} = $p->{default}; | |||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | my $tool_command = $self->make_command(%cmd_args); | |||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||
| 288 | # ── Output validation checks ────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | my $validation = ''; | |||||||||||||||||||||||||||||||||||||||
| 290 | 2 | for my $out (@{ $self->{outputs} }) { | |||||||||||||||||||||||||||||||||||||||
| 291 | 3 | ▶ | next unless $out->{required}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | ▶ | my $pat = $out->{pattern} // next; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$out->{"pattern"} // (next)
MC/DC0%0/1
$out->{"pattern"} // (next)
$out->{"pattern"}
Truth table50%1/2
A
A= $out->{"pattern"}
| |||||||||||||||||||||||||||||||||||||||||
| 293 | # Substitute {sample} with shell variable reference | ||||||||||||||||||||||||||||||||||||||||
| 294 | 2 | (my $shell_pat = $pat) =~ s/\{sample\}/\${SAMPLE}/g; | |||||||||||||||||||||||||||||||||||||||
| 295 | 2 | $validation .= <<" BASH"; | |||||||||||||||||||||||||||||||||||||||
| 296 | if [[ ! -s "\$SCRATCH/$shell_pat" ]]; then | ||||||||||||||||||||||||||||||||||||||||
| 297 | echo "[nbilaunch] ERROR: required output not found or empty: $shell_pat" >&2 | ||||||||||||||||||||||||||||||||||||||||
| 298 | exit 1 | ||||||||||||||||||||||||||||||||||||||||
| 299 | fi | ||||||||||||||||||||||||||||||||||||||||
| 300 | BASH | ||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | my $activation = $self->activation_lines(); | |||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||
| 305 | # ── Scratch setup ───────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 306 | # Priority: explicit scratch_dir arg > $TMPDIR (use_tmpdir) > /tmp | ||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | ▶ | my $use_tmpdir = $self->{scratch}{use_tmpdir} // 0; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"scratch"}{"use_tmpdir"} // 0
MC/DC0%0/1
$self->{"scratch"}{"use_tmpdir"} // 0
$self->{"scratch"}{"use_tmpdir"}
Truth table50%1/2
A
A= $self->{"scratch"}{"use_tmpdir"}
| |||||||||||||||||||||||||||||||||||||||||
| 308 | my $scratch_base = defined $args{scratch_dir} ? $args{scratch_dir} | ||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | ▶ | : $use_tmpdir ? '${TMPDIR:-/tmp}' | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 310 | : '/tmp'; | ||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | my $scratch_init = qq{SCRATCH=\$(mktemp -d "$scratch_base/${tool}_XXXXXXXX")}; | |||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||
| 313 | # ── Assemble script ─────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | my $sep = '# ' . '─' x 74; | |||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | my $script = <<"SCRIPT"; | |||||||||||||||||||||||||||||||||||||||
| 317 | set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||
| 319 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 320 | # Generated by nbilaunch v${nbi_l_version} / NBI::Slurm v${nbi_version} | ||||||||||||||||||||||||||||||||||||||||
| 321 | # Tool: $tool v$version | ||||||||||||||||||||||||||||||||||||||||
| 322 | # Launcher: $launcher_class | ||||||||||||||||||||||||||||||||||||||||
| 323 | # Submitted: $submitted_at | ||||||||||||||||||||||||||||||||||||||||
| 324 | # Manifest: $manifest_rel | ||||||||||||||||||||||||||||||||||||||||
| 325 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||
| 327 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 328 | # Runtime variables - defined first so traps and manifest can reference them | ||||||||||||||||||||||||||||||||||||||||
| 329 | SAMPLE="$sample" | ||||||||||||||||||||||||||||||||||||||||
| 330 | OUTDIR="\$(realpath "$outdir" 2>/dev/null || echo "$outdir")" | ||||||||||||||||||||||||||||||||||||||||
| 331 | $scratch_init | ||||||||||||||||||||||||||||||||||||||||
| 332 | MANIFEST="\$OUTDIR/.nbilaunch/$sample.manifest.json" | ||||||||||||||||||||||||||||||||||||||||
| 333 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||
| 335 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 336 | # Manifest update - called by ERR trap (failure) and at end (success). | ||||||||||||||||||||||||||||||||||||||||
| 337 | # Uses a perl one-liner so there is no jq dependency on the HPC. | ||||||||||||||||||||||||||||||||||||||||
| 338 | _nbi_manifest_update() { | ||||||||||||||||||||||||||||||||||||||||
| 339 | local status="\$1" exit_code="\$2" completed_at | ||||||||||||||||||||||||||||||||||||||||
| 340 | completed_at=\$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||||||||||||||||||||||||||||||||||||||||
| 341 | perl -i -0777 -pe " | ||||||||||||||||||||||||||||||||||||||||
| 342 | s{\\\"status\\\":\\\\s*\\\"[^\\\"]+\\\"}{\\\"status\\\": \\\"\$status\\\"}; | ||||||||||||||||||||||||||||||||||||||||
| 343 | s{\\\"exit_code\\\":\\\\s*null}{\\\"exit_code\\\": \$exit_code}; | ||||||||||||||||||||||||||||||||||||||||
| 344 | s{\\\"completed_at\\\":\\\\s*null}{\\\"completed_at\\\": \\\"\$completed_at\\\"}; | ||||||||||||||||||||||||||||||||||||||||
| 345 | " "\$MANIFEST" | ||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||
| 348 | trap '_nbi_manifest_update failure \$?' ERR | ||||||||||||||||||||||||||||||||||||||||
| 349 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||
| 351 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 352 | # Scratch cleanup on exit (runs even on success - scratch is empty after mv) | ||||||||||||||||||||||||||||||||||||||||
| 353 | trap 'rm -rf "\$SCRATCH"' EXIT | ||||||||||||||||||||||||||||||||||||||||
| 354 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||
| 356 | SCRIPT | ||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||
| 358 | # Activation section (empty for singularity) | ||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | ▶ | if ($activation) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | $script .= <<"SCRIPT"; | |||||||||||||||||||||||||||||||||||||||
| 361 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 362 | # Environment activation | ||||||||||||||||||||||||||||||||||||||||
| 363 | $activation$sep | ||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||
| 365 | SCRIPT | ||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||
| 368 | 2 | $script .= <<"SCRIPT"; | |||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||
| 370 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 371 | # Tool command | ||||||||||||||||||||||||||||||||||||||||
| 372 | $tool_command | ||||||||||||||||||||||||||||||||||||||||
| 373 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||
| 375 | SCRIPT | ||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | ▶ | if ($validation) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 378 | 2 | $script .= <<"SCRIPT"; | |||||||||||||||||||||||||||||||||||||||
| 379 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 380 | # Output validation | ||||||||||||||||||||||||||||||||||||||||
| 381 | ${validation}$sep | ||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||
| 383 | SCRIPT | ||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||
| 386 | 2 | $script .= <<"SCRIPT"; | |||||||||||||||||||||||||||||||||||||||
| 387 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 388 | # Promote outputs from scratch to outdir and record success | ||||||||||||||||||||||||||||||||||||||||
| 389 | mkdir -p "\$OUTDIR" "\$OUTDIR/.nbilaunch" | ||||||||||||||||||||||||||||||||||||||||
| 390 | mv "\$SCRATCH"/* "\$OUTDIR"/ | ||||||||||||||||||||||||||||||||||||||||
| 391 | _nbi_manifest_update success 0 | ||||||||||||||||||||||||||||||||||||||||
| 392 | echo "[nbilaunch] Done. Outputs in: \$OUTDIR" | ||||||||||||||||||||||||||||||||||||||||
| 393 | $sep | ||||||||||||||||||||||||||||||||||||||||
| 394 | SCRIPT | ||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | return $script; | |||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||
| 399 | # ── _resolve_args(%args) ────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 400 | # Internal: apply default_env and default fallbacks, inject slurm_sync values, | ||||||||||||||||||||||||||||||||||||||||
| 401 | # and resolve absolute paths. Returns the resolved %args hash. | ||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | ▶ | sub _resolve_args { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_args: called CC=14 SCAR=26.9
| |||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||
| 405 | # Apply param defaults | ||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | for my $p (@{ $self->{params} }) { | |||||||||||||||||||||||||||||||||||||||
| 407 | 3 | my $name = $p->{name}; | |||||||||||||||||||||||||||||||||||||||
| 408 | 3 | ▶ | next if defined $args{$name}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | ▶ | if ($p->{default_env} && defined $ENV{ $p->{default_env} }) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$p->{"default_env"} and defined $ENV{$p->{"default_env"}}
MC/DC50%1/2
$p->{"default_env"} and defined $ENV{$p->{"default_env"}}
$p->{"default_env"}
defined $ENV{$p->{"default_env"}}
Truth table66%2/3
A and B
A= $p->{"default_env"}B= defined $ENV{$p->{"default_env"}}
| |||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | $args{$name} = $ENV{ $p->{default_env} }; | |||||||||||||||||||||||||||||||||||||||
| 411 | } elsif (defined $p->{default}) { | ||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | $args{$name} = $p->{default}; | |||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||
| 416 | # Resolve absolute paths for file/dir inputs and params | ||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | for my $spec (@{ $self->{inputs} }, @{ $self->{params} }) { | |||||||||||||||||||||||||||||||||||||||
| 418 | 5 | my $name = $spec->{name}; | |||||||||||||||||||||||||||||||||||||||
| 419 | 5 | ▶ | next unless defined $args{$name}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 420 | 4 | ▶ | my $type = $spec->{type} // ''; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$spec->{"type"} // ""
MC/DC0%0/1
$spec->{"type"} // ""
$spec->{"type"}
Truth table50%1/2
A
A= $spec->{"type"}
| |||||||||||||||||||||||||||||||||||||||||
| 421 | 4 | ▶ | if ($type eq 'file' || $type eq 'dir') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "file" or $type eq "dir"
MC/DC100%2/2
$type eq "file" or $type eq "dir"
$type eq "file"
$type eq "dir"
Truth table100%3/3
A or B
A= $type eq "file"B= $type eq "dir"
| |||||||||||||||||||||||||||||||||||||||||
| 422 | 2 | ▶ | $args{$name} = realpath($args{$name}) // $args{$name}; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
realpath($args{$name}) // $args{$name}
MC/DC0%0/2
realpath($args{$name}) // $args{$name}
realpath($args{$name})
$args{$name}
Truth table33%1/3
A // B
A= realpath($args{$name})B= $args{$name}
| |||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||
| 426 | # Absolute outdir | ||||||||||||||||||||||||||||||||||||||||
| 427 | 1 | ▶ | if (defined $args{outdir}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 428 | # realpath requires the path to exist; use abs_path fallback | ||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | my $abs = eval { realpath($args{outdir}) }; | |||||||||||||||||||||||||||||||||||||||
| 430 | 1 | ▶ | $args{outdir} = $abs if defined $abs; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||
| 433 | 1 | return %args; | |||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||
| 436 | # ── _runtime_to_hours($str) ─────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 437 | # Convert HH:MM:SS or simple hour strings to decimal hours for NBI::Opts. | ||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | ▶ | sub _runtime_to_hours { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_runtime_to_hours: called CC=10 SCAR=43.7
| |||||||||||||||||||||||||||||||||||||||||
| 439 | 1 | my ($rt) = @_; | |||||||||||||||||||||||||||||||||||||||
| 440 | 1 | ▶ | if ($rt =~ /^(\d+):(\d+):(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 441 | 1 | return $1 + $2 / 60 + $3 / 3600; | |||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ($rt =~ /^(\d+):(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | return $1 + $2 / 60; | |||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ($rt =~ /^(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | return $1; # bare integer = hours | |||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||
| 449 | # Fall back: try NBI::Opts internal parser pattern | ||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | my $hours = 0; | |||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $upper = uc $rt; | |||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | while ($upper =~ /(\d+)([DHMS])/g) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my ($v, $u) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | $hours += $v * 24 if $u eq 'D'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | $hours += $v if $u eq 'H'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | $hours += $v / 60 if $u eq 'M'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | $hours += $v / 3600 if $u eq 'S'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | return $hours || 1; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hours || 1
MC/DC0%0/1
$hours || 1
$hours
Truth table0%0/2
A
A= $hours
| |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||
| 462 | # ── build(%args) ───────────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 463 | # The main entry point called by bin/nbilaunch. | ||||||||||||||||||||||||||||||||||||||||
| 464 | # | ||||||||||||||||||||||||||||||||||||||||
| 465 | # Validates inputs, resolves defaults, builds NBI::Job and NBI::Manifest. | ||||||||||||||||||||||||||||||||||||||||
| 466 | # Returns a two-element list: ($job, $manifest). | ||||||||||||||||||||||||||||||||||||||||
| 467 | # | ||||||||||||||||||||||||||||||||||||||||
| 468 | # %args keys: | ||||||||||||||||||||||||||||||||||||||||
| 469 | # All inputs/params by name (from nbilaunch arg parsing) | ||||||||||||||||||||||||||||||||||||||||
| 470 | # outdir - output directory (required) | ||||||||||||||||||||||||||||||||||||||||
| 471 | # sample_name - optional override for derived sample name | ||||||||||||||||||||||||||||||||||||||||
| 472 | # slurm_queue - override slurm_defaults{queue} | ||||||||||||||||||||||||||||||||||||||||
| 473 | # slurm_threads - override slurm_defaults{threads} | ||||||||||||||||||||||||||||||||||||||||
| 474 | # slurm_memory - override slurm_defaults{memory} (GB) | ||||||||||||||||||||||||||||||||||||||||
| 475 | # slurm_runtime - override slurm_defaults{runtime} (HH:MM:SS or hours) | ||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=15 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | require NBI::Job; | |||||||||||||||||||||||||||||||||||||||
| 480 | 1 | require NBI::Opts; | |||||||||||||||||||||||||||||||||||||||
| 481 | 1 | require NBI::Manifest; | |||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||
| 483 | # ── Resolve Slurm resource values ───────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | ▶ | my $queue = $args{slurm_queue} // $self->{slurm_defaults}{queue}; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"slurm_queue"} // $self->{"slurm_defaults"}{"queue"}
MC/DC0%0/2
$args{"slurm_queue"} // $self->{"slurm_defaults"}{"queue"}
$args{"slurm_queue"}
$self->{"slurm_defaults"}{"queue"}
Truth table33%1/3
A // B
A= $args{"slurm_queue"}B= $self->{"slurm_defaults"}{"queue"}
| |||||||||||||||||||||||||||||||||||||||||
| 485 | 1 | ▶ | my $threads = $args{slurm_threads} // $self->{slurm_defaults}{threads}; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"slurm_threads"} // $self->{"slurm_defaults"}{"threads"}
MC/DC0%0/2
$args{"slurm_threads"} // $self->{"slurm_defaults"}{"threads"}
$args{"slurm_threads"}
$self->{"slurm_defaults"}{"threads"}
Truth table33%1/3
A // B
A= $args{"slurm_threads"}B= $self->{"slurm_defaults"}{"threads"}
| |||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | ▶ | my $mem_gb = $args{slurm_memory} // $self->{slurm_defaults}{memory}; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"slurm_memory"} // $self->{"slurm_defaults"}{"memory"}
MC/DC0%0/2
$args{"slurm_memory"} // $self->{"slurm_defaults"}{"memory"}
$args{"slurm_memory"}
$self->{"slurm_defaults"}{"memory"}
Truth table33%1/3
A // B
A= $args{"slurm_memory"}B= $self->{"slurm_defaults"}{"memory"}
| |||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | ▶ | my $runtime = $args{slurm_runtime} // $self->{slurm_defaults}{runtime}; | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"slurm_runtime"} // $self->{"slurm_defaults"}{"runtime"}
MC/DC0%0/2
$args{"slurm_runtime"} // $self->{"slurm_defaults"}{"runtime"}
$args{"slurm_runtime"}
$self->{"slurm_defaults"}{"runtime"}
Truth table33%1/3
A // B
A= $args{"slurm_runtime"}B= $self->{"slurm_defaults"}{"runtime"}
| |||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||
| 489 | # Inject slurm_sync params (e.g. threads param mirrors Slurm --cpus) | ||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | for my $p (@{ $self->{params} }) { | |||||||||||||||||||||||||||||||||||||||
| 491 | 3 | ▶ | next unless $p->{slurm_sync}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | ▶ | if ($p->{slurm_sync} eq 'threads') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 493 | 1 | $args{ $p->{name} } = $threads; | |||||||||||||||||||||||||||||||||||||||
| 494 | } elsif ($p->{slurm_sync} eq 'memory') { | ||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | $args{ $p->{name} } = $mem_gb; | |||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||
| 499 | # ── Resolve and validate args ───────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | %args = $self->_resolve_args(%args); | |||||||||||||||||||||||||||||||||||||||
| 501 | 1 | $self->validate(%args); | |||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||
| 503 | # ── Derive sample name ──────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | my $sample = $self->sample_name(%args); | |||||||||||||||||||||||||||||||||||||||
| 505 | 1 | $args{sample} = $sample; | |||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||
| 507 | # ── Paths ───────────────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | my $outdir = $args{outdir}; | |||||||||||||||||||||||||||||||||||||||
| 509 | 1 | my $nbi_dir = "$outdir/.nbilaunch"; | |||||||||||||||||||||||||||||||||||||||
| 510 | 1 | my $job_name = "$self->{name}_$sample"; | |||||||||||||||||||||||||||||||||||||||
| 511 | 1 | my $manifest_path = "$nbi_dir/$sample.manifest.json"; | |||||||||||||||||||||||||||||||||||||||
| 512 | 1 | my $script_rel = ".nbilaunch/${job_name}.script.sh"; | |||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | $args{manifest_path} = $manifest_path; | |||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||
| 516 | # ── Generate script body ────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | my $script_body = $self->generate_script(%args); | |||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||
| 519 | # ── Build NBI::Opts ─────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | my $hours = _runtime_to_hours($runtime); | |||||||||||||||||||||||||||||||||||||||
| 521 | 1 | my $mem_mb = $mem_gb * 1024; | |||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||
| 523 | 1 | my $opts = NBI::Opts->new( | |||||||||||||||||||||||||||||||||||||||
| 524 | -queue => $queue, | ||||||||||||||||||||||||||||||||||||||||
| 525 | -threads => $threads, | ||||||||||||||||||||||||||||||||||||||||
| 526 | -memory => $mem_mb, | ||||||||||||||||||||||||||||||||||||||||
| 527 | -time => $hours, | ||||||||||||||||||||||||||||||||||||||||
| 528 | -tmpdir => $nbi_dir, | ||||||||||||||||||||||||||||||||||||||||
| 529 | ); | ||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||
| 531 | # ── Build NBI::Job ──────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 532 | 1 | my $job = NBI::Job->new( | |||||||||||||||||||||||||||||||||||||||
| 533 | -name => $job_name, | ||||||||||||||||||||||||||||||||||||||||
| 534 | -command => $script_body, | ||||||||||||||||||||||||||||||||||||||||
| 535 | -opts => $opts, | ||||||||||||||||||||||||||||||||||||||||
| 536 | ); | ||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||
| 538 | # Log/err go to provenance directory; %j is expanded by Slurm to the job ID | ||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | $job->outputfile = "$nbi_dir/${job_name}.%j.log"; | |||||||||||||||||||||||||||||||||||||||
| 540 | 1 | $job->errorfile = "$nbi_dir/${job_name}.%j.err"; | |||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||
| 542 | # ── Collect resolved inputs/params/outputs for manifest ─────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | my %inp_snapshot; | |||||||||||||||||||||||||||||||||||||||
| 544 | 1 | for my $inp (@{ $self->{inputs} }) { | |||||||||||||||||||||||||||||||||||||||
| 545 | $inp_snapshot{ $inp->{name} } = $args{ $inp->{name} } | ||||||||||||||||||||||||||||||||||||||||
| 546 | 2 | ▶ | if defined $args{ $inp->{name} }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | my %par_snapshot; | |||||||||||||||||||||||||||||||||||||||
| 550 | 1 | for my $p (@{ $self->{params} }) { | |||||||||||||||||||||||||||||||||||||||
| 551 | $par_snapshot{ $p->{name} } = $args{ $p->{name} } | ||||||||||||||||||||||||||||||||||||||||
| 552 | 3 | ▶ | if defined $args{ $p->{name} }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||
| 555 | 1 | my %out_snapshot; | |||||||||||||||||||||||||||||||||||||||
| 556 | 1 | for my $out (@{ $self->{outputs} }) { | |||||||||||||||||||||||||||||||||||||||
| 557 | 2 | ▶ | my $pat = $out->{pattern} // next; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$out->{"pattern"} // (next)
MC/DC0%0/1
$out->{"pattern"} // (next)
$out->{"pattern"}
Truth table50%1/2
A
A= $out->{"pattern"}
| |||||||||||||||||||||||||||||||||||||||||
| 558 | 2 | (my $filename = $pat) =~ s/\{sample\}/$sample/g; | |||||||||||||||||||||||||||||||||||||||
| 559 | 2 | $out_snapshot{ $out->{name} } = $filename; | |||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||
| 562 | # ── Build manifest ──────────────────────────────────────────────────────── | ||||||||||||||||||||||||||||||||||||||||
| 563 | my $manifest = NBI::Manifest->new( | ||||||||||||||||||||||||||||||||||||||||
| 564 | tool => $self->{name}, | ||||||||||||||||||||||||||||||||||||||||
| 565 | tool_version => $self->{version}, | ||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | sample => $sample, | |||||||||||||||||||||||||||||||||||||||
| 567 | outdir => $outdir, | ||||||||||||||||||||||||||||||||||||||||
| 568 | inputs => \%inp_snapshot, | ||||||||||||||||||||||||||||||||||||||||
| 569 | params => \%par_snapshot, | ||||||||||||||||||||||||||||||||||||||||
| 570 | outputs => \%out_snapshot, | ||||||||||||||||||||||||||||||||||||||||
| 571 | slurm_queue => $queue, | ||||||||||||||||||||||||||||||||||||||||
| 572 | slurm_cpus => $threads, | ||||||||||||||||||||||||||||||||||||||||
| 573 | slurm_mem_gb => $mem_gb, | ||||||||||||||||||||||||||||||||||||||||
| 574 | script => $script_rel, | ||||||||||||||||||||||||||||||||||||||||
| 575 | status => 'submitted', | ||||||||||||||||||||||||||||||||||||||||
| 576 | ); | ||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||
| 578 | 1 | return ($job, $manifest); | |||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||
| 581 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||
| 583 | __END__ | ||||||||||||||||||||||||||||||||||||||||