Skip to content

Commit

Permalink
Samplesheet generation tests - move to mlwh driver.
Browse files Browse the repository at this point in the history
Previously the tests uses XML feeds as a source of LIMS
data. All production code is using mlwh database as a
source of LIMS data. Amend tests to use mlwh data and
the default ml_warehouse lims driver.

Amended how an undefined sample public name is dealt with,
i.e. converted an error to a warning and assigned a sensible
fall-back value.

Some samplesheets are generated without names of study owners,
followers, etc. This is due to the fact that some studies
do not have fixtures for user data.

The database fixtures were generated from the current data,
this explains multiple differences between the old and new
content of the generated samplesheets.

In some tests newer production batches were used insted of
hand-crafted data.
  • Loading branch information
mgcam committed Aug 31, 2023
1 parent 0f18be3 commit d70ecf3
Show file tree
Hide file tree
Showing 11 changed files with 17,419 additions and 175 deletions.
4 changes: 4 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,10 @@ t/data/fixtures_stlims_wh/000-Study.yml
t/data/fixtures_stlims_wh/100-IseqFlowcell.yml
t/data/fixtures_stlims_wh/100-StudyUser.yml
t/data/fixtures_stlims_wh/200-IseqProductMetric.yml
t/data/fixtures_lims_wh_samplesheet/000-Sample.yml
t/data/fixtures_lims_wh_samplesheet/000-Study.yml
t/data/fixtures_lims_wh_samplesheet/100-StudyUser.yml
t/data/fixtures_lims_wh_samplesheet/100-IseqFlowcell.yml
t/data/gaii/staging/IL3/incoming/100622_IL3_01234/this_run_is_not_complete_yet
t/data/gaii/staging/IL5/incoming/not_a_dir
t/data/gaii/staging/IL999/incoming/100622_IL3_01234/Recipe_GA2-PEM_2x76Cycle_v7.7.xml
Expand Down
4 changes: 2 additions & 2 deletions lib/npg/samplesheet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ sub _build__limsreflist {
foreach my $attr (qw/library_id sample_publishable_name/) {
my $value = _csv_compatible_value($tmpl->$attr);
if (!$value) {
croak sprintf '%s is not available for position %i %s',
carp sprintf '%s is not available for position %i %s',
$attr, $tmpl->position,
defined $tmpl->tag_index ? 'tag index ' . $tmpl->tag_index : q[];
}
if ($self->mkfastq) {
if (!$value || $self->mkfastq) {
# when making a samplesheet for mkfastq, replace value by run_position
$value = $self->id_run . q[_] . $tmpl->position;
if($self->_index_read) {
Expand Down
76 changes: 34 additions & 42 deletions t/47-samplesheet.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,22 @@ my $schema = t::dbic_util->new->test_schema();

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

local $ENV{NPG_WEBSERVICE_CACHE_DIR} = q(t/data/samplesheet);

my $dir = tempdir( CLEANUP => 1 );

subtest 'object creation' => sub {
plan tests => 8;

my $result = q();
dies_ok { npg::samplesheet->new( lims_driver_type=>'xml', repository=>$dir, output=>\$result)->process }
'sample sheet process fails when neither run object nor id_run given';

my $ss;
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>7007); } 'sample sheet object - no output provided';
cmp_ok($ss->output, 'eq', '/nfs/sf49/ILorHSorMS_sf49/samplesheets/wibble/MS0001309-300.csv', 'default output location (with zeroes trimmed appropriately)');
is($ss->lims->[0]->driver_type, 'xml', 'xml driver is used');

lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946); } 'sample sheet object - no output provided';
cmp_ok($ss->output, 'eq', '/nfs/sf49/ILorHSorMS_sf49/samplesheets/wibble/000000000-A0616.csv', 'default output location');

lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>7007); } 'sample sheet object - no output provided';
my $orig_flowcell_id = $ss->run->flowcell_id;
$ss->run->flowcell_id(q(MS2000132-500V2));
cmp_ok($ss->output, 'eq', '/nfs/sf49/ILorHSorMS_sf49/samplesheets/wibble/MS2000132-500V2.csv', 'default output location copes with V2 MiSeq cartirdges/reagent kits');
};

subtest 'error on an unknown driver types' => sub {
subtest 'error on an unknown driver type' => sub {
plan tests => 1;

throws_ok {
npg::samplesheet->new(
lims_driver_type => 'foo',
repository => $dir,
npg_tracking_schema => $schema,
mlwh_schema => $mlwh_schema,
id_run => 7007)->lims()
} qr/Lazy-build for driver type foo is not inplemented/,
'error with the driver type for which LIMS objects cannot be built';
Expand All @@ -63,10 +43,6 @@ subtest 'error on an unknown driver types' => sub {
subtest 'simple tests for the default driver' => sub {
plan tests => 2;

my $run_row = $schema->resultset('Run')->find(7007);
my $current_batch_id = $run_row->batch_id;
$run_row->update({batch_id => 57543});

my $ss = npg::samplesheet->new(
repository => $dir,
npg_tracking_schema => $schema,
Expand All @@ -76,8 +52,26 @@ subtest 'simple tests for the default driver' => sub {
is ($ss->lims_driver_type, 'ml_warehouse', 'correct default driver type');
my $lims = $ss->lims();
is (@{$lims}, 1, 'LIMS data for 1 lane is built');
};

subtest 'object creation' => sub {
plan tests => 7;

my $result = q();
dies_ok { npg::samplesheet->new(mlwh_schema => $mlwh_schema, repository=>$dir, output=>\$result)->process }
'sample sheet process fails when neither run object nor id_run given';

my $ss;
lives_ok { $ss = npg::samplesheet->new(mlwh_schema => $mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>7007); } 'sample sheet object - no output provided';
cmp_ok($ss->output, 'eq', '/nfs/sf49/ILorHSorMS_sf49/samplesheets/wibble/MS0001309-300.csv', 'default output location (with zeroes trimmed appropriately)');

$run_row->update({batch_id => $current_batch_id});
lives_ok { $ss = npg::samplesheet->new(mlwh_schema => $mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946); } 'sample sheet object - no output provided';
cmp_ok($ss->output, 'eq', '/nfs/sf49/ILorHSorMS_sf49/samplesheets/wibble/000000000-A0616.csv', 'default output location');

lives_ok { $ss = npg::samplesheet->new(mlwh_schema => $mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>7007); } 'sample sheet object - no output provided';
my $orig_flowcell_id = $ss->run->flowcell_id;
$ss->run->flowcell_id(q(MS2000132-500V2));
cmp_ok($ss->output, 'eq', '/nfs/sf49/ILorHSorMS_sf49/samplesheets/wibble/MS2000132-500V2.csv', 'default output location copes with V2 MiSeq cartirdges/reagent kits');
};

subtest 'values conversion' => sub {
Expand Down Expand Up @@ -125,19 +119,19 @@ Chemistry,Default,,
,,,
[Data],,,
Sample_ID,Sample_Name,GenomeFolder,
3789277,Strongyloides ratti,,
3789277,ERS092590,,
RESULT_7007
$expected_result_7007 =~ s/\n/\r\n/smg;

my $ss;
my $result = q();
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>7007, output=>\$result); } 'sample sheet object for unplexed paired run';
lives_ok { $ss = npg::samplesheet->new(mlwh_schema => $mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>7007, output=>\$result); } 'sample sheet object for unplexed paired run';
lives_ok { $ss->process(); } ' sample sheet generated';
is_string($result, $expected_result_7007);

my $run = $schema->resultset(q(Run))->find(7007);
$result = q();
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, run=>$run, output=>\$result); } 'sample sheet object from run object - no id_run given';
lives_ok { $ss = npg::samplesheet->new(mlwh_schema => $mlwh_schema, repository=>$dir, run=>$run, output=>\$result); } 'sample sheet object from run object - no id_run given';
lives_ok { $ss->process(); } ' sample sheet generated';
is_string($result, $expected_result_7007);
};
Expand All @@ -147,7 +141,7 @@ subtest 'default samplesheet for a plexed paired run' => sub {

my $ss;
my $result = q();
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946, output=>\$result); } 'samplesheet object for plexed paired run';
lives_ok { $ss = npg::samplesheet->new(mlwh_schema => $mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946, output=>\$result); } 'samplesheet object for plexed paired run';
my $expected_result = << 'RESULT_6946';
[Header],,,,
Investigator Name,mq1,,,
Expand Down Expand Up @@ -190,7 +184,7 @@ subtest 'default samplesheet for a plexed paired run with reference fallback' =>

my $ss;
my $result = q();
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>7825, output=>\$result); } 'sample sheet object for plexed paired run';
lives_ok { $ss = npg::samplesheet->new(mlwh_schema => $mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>7825, output=>\$result); } 'sample sheet object for plexed paired run';
my $expected_result = << 'RESULT_7825';
[Header],,,,
Investigator Name,nh4,,,
Expand Down Expand Up @@ -300,15 +294,15 @@ subtest 'extended samplesheets' => sub {

my $ss;
my $result = q();
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, extend => 1, id_run=>7007, output=>\$result); } 'extended sample sheet object for unplexed paired run';
lives_ok { $ss = npg::samplesheet->new(mlwh_schema=>$mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, extend => 1, id_run=>7007, output=>\$result); } 'extended sample sheet object for unplexed paired run';
ok(!$ss->_dual_index, 'no dual index');
lives_ok { $ss->process(); } ' sample sheet generated';
lives_ok { $ss->process(); } 'sample sheet generated';
is_string($result, read_file('t/data/samplesheet/7007_extended.csv'));

$result = q();
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946, extend => 1, output=>\$result); } 'extended sample sheet object for plexed paired run';
lives_ok { $ss = npg::samplesheet->new(mlwh_schema=>$mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946, extend => 1, output=>\$result); } 'extended sample sheet object for plexed paired run';
ok(!$ss->_dual_index, 'no dual index');
lives_ok { $ss->process(); } ' sample sheet generated';
lives_ok { $ss->process(); } 'sample sheet generated';
is_string($result, read_file('t/data/samplesheet/6946_extended.csv'));

local $ENV{NPG_WEBSERVICE_CACHE_DIR} = q[t/data/test45];
Expand Down Expand Up @@ -337,17 +331,15 @@ subtest 'extended samplesheets' => sub {
$schema->resultset('Run')->find(6946)->update({batch_id => 23798});

$result = q();
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946, extend => 1, output=>\$result); }
lives_ok { $ss = npg::samplesheet->new(mlwh_schema=>$mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946, extend => 1, output=>\$result); }
'extended sample sheet object for plexed paired run with both pool and library lanes';
ok($ss->_dual_index, 'dual index from a 16 char first index');
lives_ok { $ss->process(); } 'sample sheet generated';
is_string($result, read_file('t/data/samplesheet/4pool4libs_extended.csv'));

local $ENV{NPG_WEBSERVICE_CACHE_DIR} = q[t/data/samplesheet];
$schema->resultset('Run')->find(6946)->update({batch_id => 1,});

$schema->resultset('Run')->find(6946)->update({batch_id => 76873});
$result = q();
lives_ok { $ss = npg::samplesheet->new(lims_driver_type=>'xml', repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946, extend => 1, output=>\$result); }
lives_ok { $ss = npg::samplesheet->new(mlwh_schema=>$mlwh_schema, repository=>$dir, npg_tracking_schema=>$schema, id_run=>6946, extend => 1, output=>\$result); }
'extended sample sheet object for plexed paired run with both pool and library lanes';
ok($ss->_dual_index, 'dual index from two indexes in LIMs');
lives_ok { $ss->process(); } 'sample sheet generated';
Expand Down
Loading

0 comments on commit d70ecf3

Please sign in to comment.