Skip to content

Commit

Permalink
Merge pull request #796 from mgcam/daemon4novaseqx_samplesheet
Browse files Browse the repository at this point in the history
Daemon4novaseqx samplesheet
  • Loading branch information
jmtcsngr authored Jan 9, 2024
2 parents be4b819 + 9a2c9f0 commit 1c8b653
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 40 deletions.
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ bin/illumina_instruments_uptime
bin/npg_daemon_control
bin/npg_move_runfolder
bin/npg_samplesheet4MiSeq
bin/npg_samplesheet4NovaSeqX
bin/npg_samplesheet_generator_NovaSeqXSeries
bin/npg_status_save
bin/staging_area_monitor
bin/npg_deletable_dr_runs
Expand Down
98 changes: 98 additions & 0 deletions bin/npg_samplesheet4NovaSeqX
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env perl

use strict;
use warnings;
use FindBin qw($Bin);
use lib ( -d "$Bin/../lib/perl5" ? "$Bin/../lib/perl5" : "$Bin/../lib" );
use Log::Log4perl qw(:easy);

use npg::samplesheet::auto;

our $VERSION = '0';

Log::Log4perl->easy_init($INFO);

my $log = Log::Log4perl->get_logger('main');
$log->info('Starting npg samplesheet daemon for NovaSeqX instruments');

npg::samplesheet::auto->new(instrument_format => 'NovaSeqX')->loop();

0;

__END__

=head1 NAME

npg_samplesheet4NovaSeqX

=head1 USAGE

npg_samplesheet4NovaSeqX

=head1 DESCRIPTION

The script, once started, runs in perpetuity, generating Illumina-style
samplesheets for any NovaSeqX run with status 'run pending'.

=head1 REQUIRED ARGUMENTS

None

=head1 OPTIONS

=head1 DIAGNOSTICS

=head1 CONFIGURATION

Access to both npg_tracking and ml warehouse database is required.

=head1 DEPENDENCIES

=over

=item strict

=item warnings

=item FindBin

=item lib

=item Log::Log4perl

=item npg::samplesheet::auto

=back

=head1 EXIT STATUS

Does not exit unless is sent a signal to terminate.

=head1 INCOMPATIBILITIES

=head1 BUGS AND LIMITATIONS

=head1 AUTHOR

Marina Gourtovaia E<lt>[email protected]<gt>

=head1 LICENSE AND COPYRIGHT

Copyright (C) 2023 GRL.

This file is part of NPG.

NPG is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

=cut
4 changes: 2 additions & 2 deletions bin/npg_samplesheet_generator_NovaSeqXSeries
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ npg_samplesheet_generator_NovaSeqXSeries

=head1 DESCRIPTION

Generates a samplesheet for the NovaSeq Series X Illumina instrument and
DRAGEN analysis.
Generates a single samplesheet for the NovaSeq Series X Illumina instrument
and DRAGEN analysis.

=head1 EXIT STATUS

Expand Down
20 changes: 1 addition & 19 deletions lib/npg/samplesheet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,6 @@ Readonly::Scalar my $MIN_COLUMN_NUM => 3;
####################### Public attributes ########################
##################################################################

=head2 id_run
An optional attribute
=cut

has '+id_run' => (
'lazy_build' => 1,
'required' => 0,
);
sub _build_id_run {
my ($self) = @_;
if($self->has_tracking_run()){
return $self->run()->id_run();
}
croak 'id_run or a run is required';
}

=head2 extend
A boolean attribute, false by default.
Expand Down Expand Up @@ -509,7 +491,7 @@ David K. Jackson E<lt>[email protected]<gt>
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2019, 2020, 2023 Genome Research Ltd.
Copyright (C) 2019,2020,2023,2024 Genome Research Ltd.
This file is part of NPG.
Expand Down
47 changes: 41 additions & 6 deletions lib/npg/samplesheet/auto.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ use Readonly;
use File::Copy;
use File::Spec::Functions;
use Carp;
use List::MoreUtils qw(none);

use npg::samplesheet;
use npg_tracking::Schema;
use WTSI::DNAP::Warehouse::Schema;
use st::api::lims::samplesheet;
use npg::samplesheet;
use npg::samplesheet::novaseq_xseries;

with q(MooseX::Log::Log4perl);

our $VERSION = '0';

Readonly::Scalar my $MISEQ_INSTRUMENT_FORMAT => 'MiSeq';
Readonly::Scalar my $DEFAULT_SLEEP => 90;
Readonly::Array my @INSTRUMENT_FORMATS => (
$MISEQ_INSTRUMENT_FORMAT,
$npg::samplesheet::novaseq_xseries::NX_INSTRUMENT_FORMAT
);

##no critic (Subroutines::ProhibitUnusedPrivateSubroutine)

Expand Down Expand Up @@ -97,7 +103,7 @@ Tests that a valid instrument format is used.

sub BUILD {
my $self = shift;
if ($self->instrument_format ne $MISEQ_INSTRUMENT_FORMAT) {
if (none {$self->instrument_format eq $_ } @INSTRUMENT_FORMATS) {
my $m = sprintf
'Samplesheet auto-generator is not implemented for %s instrument format',
$self->instrument_format;
Expand Down Expand Up @@ -141,9 +147,20 @@ sub process {
my $id_run = $r->id_run;
$self->log->info('Considering ' . join q[,],$id_run,$r->instrument->name);

my $ss = npg::samplesheet->new(
run => $r, mlwh_schema => $self->mlwh_schema
);
my $ss;
if ($self->instrument_format eq $MISEQ_INSTRUMENT_FORMAT) {
$ss = npg::samplesheet->new(
run => $r,
mlwh_schema => $self->mlwh_schema
);
} else {
$ss = npg::samplesheet::novaseq_xseries->new(
run => $r,
mlwh_schema => $self->mlwh_schema,
align => 1
);
}

my $method_name =
'_valid_samplesheet_file_exists_for_' . $self->instrument_format;
my $generate_new = !$self->$method_name($ss, $id_run);
Expand Down Expand Up @@ -241,6 +258,22 @@ sub _valid_samplesheet_file_exists_for_MiSeq {##no critic (NamingConventions::Ca
return;
}

sub _valid_samplesheet_file_exists_for_NovaSeqX {##no critic (NamingConventions::Capitalization)
my ($self, $ss_object, $id_run) = @_;

# The default samplesheet name starts with the date string. A new
# samplesheet will be generated each day. Not a problem since the run
# should either progress or be cancelled.

my $o = $ss_object->output;
if (-e $o) {
$self->log->info(qq($o already exists for $id_run));
return 1;
};

return;
}

__PACKAGE__->meta->make_immutable;

1;
Expand Down Expand Up @@ -273,6 +306,8 @@ __END__
=item Carp
=item List::MoreUtils
=item npg_tracking::Schema
=item npg::samplesheet
Expand All @@ -293,7 +328,7 @@ David K. Jackson E<lt>[email protected]<gt>
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2012,2013,2014,2019,2021,2023 GRL.
Copyright (C) 2012,2013,2014,2019,2021,2023,2024 GRL.
This file is part of NPG.
Expand Down
10 changes: 9 additions & 1 deletion lib/npg/samplesheet/base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ Run ID, an optional attribute.
=cut

has '+id_run' => (
'lazy_build' => 1,
'required' => 0,
);
sub _build_id_run {
my $self = shift;
if ($self->has_tracking_run()) {
return $self->run()->id_run();
}
croak 'id_run or a run is required';
}


=head2 batch_id
Expand Down Expand Up @@ -228,7 +236,7 @@ Marina Gourtovaia E<lt>[email protected]<gt>
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2019, 2020, 2023 Genome Research Ltd.
Copyright (C) 2019,2020,2023,2024 Genome Research Ltd.
This file is part of NPG.
Expand Down
30 changes: 26 additions & 4 deletions lib/npg/samplesheet/novaseq_xseries.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ use List::MoreUtils qw(any none uniq);
use List::Util qw(first max);
use DateTime;
use Data::UUID;
use Try::Tiny;

use npg_tracking::util::types;
use st::api::lims::samplesheet;

extends 'npg::samplesheet::base';
with 'MooseX::Getopt';

our $VERSION = '0';

Readonly::Scalar our $NX_INSTRUMENT_FORMAT => 'NovaSeqX';

Readonly::Scalar my $READ1_LENGTH => 151;
Readonly::Scalar my $READ2_LENGTH => 151;
Readonly::Scalar my $LIST_INDEX_TAG1 => 2;
Expand Down Expand Up @@ -98,7 +102,7 @@ has 'dragen_software_version' => (
sub _build_dragen_software_version {
my $self = shift;

if (!$self->has_id_run) {
if (!$self->id_run) {
croak 'DRAGEN software version cannot be retrieved. ' .
'Either supply it as an argument or supply existing id_run';
}
Expand Down Expand Up @@ -135,7 +139,7 @@ sub _build_file_name {
my $self = shift;

my $file_name;
if ($self->has_id_run) {
if ($self->id_run) {
$file_name = join q[_],
$self->run_name,
q[ssbatch] . $self->batch_id;
Expand Down Expand Up @@ -185,10 +189,24 @@ sub _build_output {


has '+id_run' => (
'isa' => 'Maybe[NpgTrackingRunId]',
'documentation' => 'NPG run ID, optional; if supplied, the record for this '.
'run should exists in the run tracking database',
);
around '_build_id_run' => sub {
my $orig = shift;
my $self = shift;

# Parent's builder method errors if id_run cannot be inferred from
# the database record. Here we allow for this attribute to be undefined.
# Depending on how other atributes are defined, it might be possible to
# generate the samplesheet.
my $id_run;
try {
$id_run = $self->$orig(@_);
};
return $id_run;
};

has '+batch_id' => (
'documentation' => 'LIMS batch identifier, optional. If not set, will be ' .
Expand Down Expand Up @@ -325,7 +343,7 @@ sub _build_run_name {

my $run_name;
if ($self->id_run()) {
if ($self->run->instrument_format()->model() !~ /NovaSeqX/smx) {
if ($self->run->instrument_format()->model() !~ /$NX_INSTRUMENT_FORMAT/smx) {
croak 'Instrument is not registered as NovaSeq X Series ' .
'in the tracking database';
}
Expand Down Expand Up @@ -865,6 +883,10 @@ __END__
=item Data::UUID
=item Try::Tiny
=item npg_tracking::util::types
=back
=head1 BUGS AND LIMITATIONS
Expand All @@ -877,7 +899,7 @@ Marina Gourtovaia E<lt>[email protected]<gt>
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2023 Genome Research Ltd.
Copyright (C) 2023,2024 Genome Research Ltd.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
Loading

0 comments on commit 1c8b653

Please sign in to comment.