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

Daemon4novaseqx samplesheet #796

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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
44 changes: 39 additions & 5 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);
jmtcsngr marked this conversation as resolved.
Show resolved Hide resolved

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,21 @@ 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(
id_run => $id_run,
jmtcsngr marked this conversation as resolved.
Show resolved Hide resolved
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 +259,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
4 changes: 3 additions & 1 deletion lib/npg/samplesheet/novaseq_xseries.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ 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 @@ -325,7 +327,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
43 changes: 38 additions & 5 deletions t/47-npg_samplesheet_auto.t
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
use strict;
use warnings;
use Test::More tests => 12;
use Test::More tests => 15;
use Test::Exception;
use File::Temp qw/ tempdir /;
use Moose::Meta::Class;
use Log::Log4perl qw(:easy);
use File::chdir;
use Perl6::Slurp;

use_ok('npg::samplesheet::auto');

my $util = Moose::Meta::Class->create_anon_class(
roles => [qw/npg_testing::db/])->new_object({});
my $schema_wh = $util->create_test_db(q[WTSI::DNAP::Warehouse::Schema]);
my $schema = $util->create_test_db(q[npg_tracking::Schema]);
my $schema_wh = $util->create_test_db(q[WTSI::DNAP::Warehouse::Schema],
q[t/data/fixtures_lims_wh]);
my $schema = $util->create_test_db(q[npg_tracking::Schema],
q[t/data/dbic_fixtures]);

{
my $sm;
Expand All @@ -27,15 +31,15 @@ my $schema = $util->create_test_db(q[npg_tracking::Schema]);
instrument_format => 'NovaSeq'
)}
qr/Samplesheet auto-generator is not implemented for NovaSeq instrument format/,
'MiSeq error for an invalid instrument format';
'Error for an invalid instrument format';
}

{
is(npg::samplesheet::auto::_id_run_from_samplesheet(
't/data/samplesheet/miseq_default.csv'), 10262,
'id run retrieved from a samplesheet');
lives_and { is npg::samplesheet::auto::_id_run_from_samplesheet('some_file'), undef}
'undef reftuned for a non-exisitng samplesheet';
'undef returned for a non-exisitng samplesheet';
}

{
Expand Down Expand Up @@ -66,4 +70,33 @@ my $schema = $util->create_test_db(q[npg_tracking::Schema]);
ok(-e $new_file, 'moved file is in samplesheet_old directory');
}

{
my $dir = tempdir(UNLINK => 1);
mkdir "$dir/samplesheets";

my $id_run = 47995;
my $run_row = $schema->resultset('Run')->find($id_run);
$run_row->update_run_status('run pending');
is ($run_row->current_run_status_description(), 'run pending',
"run $id_run should be picked up by the daemon");
{
local $CWD = $dir;
diag `ls -l`;
npg::samplesheet::auto->new(
npg_tracking_schema => $schema,
mlwh_schema => $schema_wh,
instrument_format => 'NovaSeqX'
)->process();
}
my $glob = q[*_47995_NVX1_A_ssbatch98292.csv];
my @files = glob "$dir/samplesheets/$glob";
is (@files, 1, 'one NovaSeqX samplesheet file is generated');
my $compare_file = 't/data/samplesheet/dragen/' .
'231206_47995_NVX1_A_ssbatch98292_align.csv';
my $expected = slurp($compare_file);
$expected =~ s/KeepFastq,TRUE,,,/KeepFastq,FALSE,,,/;
is (slurp($files[0]), $expected,
'the NovaSeqX samplesheet is generated correctly');
}

1;