Skip to content

Commit

Permalink
Added sample_uuid, sample_lims methods to st::api::lims
Browse files Browse the repository at this point in the history
Patched st::api::lims::samplesheet to allow for scalar attributes
ending with 's'. Previously the values of attributes with names
ending with 's' were automatically converted to lists. In fact,
this was necessary only for comma-separated strings of email addresses.
The part of code that deals with email addresses was changed to
work on attributes with names starting with 'email' rather than
ending with 's'. Prior to applying this patch the value of the
new sample_lims attribute was returned as a list when a samplesheet
was used as a source of LIMS data.

Updated tests and test data.
  • Loading branch information
mgcam committed Oct 11, 2024
1 parent 942a67a commit 6c5fc04
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 183 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ t/data/run_params/runParameters.hiseqx.xml
t/data/run_params/runParameters.miseq.xml
t/data/run_params/RunParameters.novaseq.xp.lite.xml
t/data/run_params/RunParameters.novaseqx.prod.xml
t/data/samplesheet/data4merge.csv
t/data/samplesheet/samplesheet_7753.csv
t/data/samplesheet/samplesheet_27483.csv
t/data/samplesheet/samplesheet_33990.csv
Expand Down
2 changes: 2 additions & 0 deletions lib/st/api/lims.pm
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ Readonly::Hash my %METHODS_PER_CATEGORY => {
/],

'sample' => [qw/ sample_id
sample_uuid
sample_lims
sample_name
organism_taxon_id
organism
Expand Down
2 changes: 1 addition & 1 deletion lib/st/api/lims/samplesheet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ for my $m ( st::api::lims->driver_method_list_short(__PACKAGE__->meta->get_attri
if (defined $value && $value eq q[]) {
$value = undef;
}
if ($m =~ /s$/smx) {
if ($m =~ /^email_addresses/smx) {
my @temp = $value ? split $SAMPLESHEET_ARRAY_SEPARATOR, $value : ();
$value = \@temp;
} elsif ($m eq 'required_insert_size_range') {
Expand Down
12 changes: 10 additions & 2 deletions t/40-st-lims-ml_warehouse-drivers.t
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ qr/No record retrieved for st::api::lims::ml_warehouse\w* id_flowcell_lims 22043
};

subtest 'lane-level driver from run-level driver' => sub {
plan tests => 108;
plan tests => 124;

my $count = 0;
for my $p ($mlwh_d, $mlwh_auto_d, $mlwh_auto_d, $mlwh_alt_d) {
Expand Down Expand Up @@ -169,6 +169,8 @@ subtest 'lane-level driver from run-level driver' => sub {
ok (!$d->study_name, 'no study name');
ok (!$d->sample_id, 'no sample_id');
ok (!$d->sample_supplier_name, 'no supplier name');
ok (!$d->sample_uuid, 'no sample uuid');
ok (!$d->sample_lims, 'no sample lims');
ok (!$d->sample_cohort, 'no cohort');
ok (!$d->sample_donor_id, 'no donor id');
is ($d->default_tag_sequence, undef, 'first index sequence undefined');
Expand All @@ -184,6 +186,8 @@ subtest 'lane-level driver from run-level driver' => sub {
ok(!$lims1->sample_consent_withdrawn(), 'sample consent not withdrawn');
is ($lims1->sample_id, 7283, 'sample id');
is ($lims1->sample_supplier_name, 'sample_33', 'supplier name');
is ($lims1->sample_uuid, 'fdb13110-6a55-11e4-8e19-68b59977951c', 'sample uuid');
is ($lims1->sample_lims, 'CLARITY', 'sample lims');
is ($lims1->sample_cohort, 'plan2', 'cohort');
is ($lims1->sample_donor_id, 'd5678', 'donor id');
is ($lims1->purpose, 'qc', 'purpose');
Expand Down Expand Up @@ -276,7 +280,7 @@ sub _add2query {
}

subtest 'lane and tag level drivers' => sub {
plan tests => 136;
plan tests => 152;

my $lims_id = 16249;
my $id_run = 45678;
Expand Down Expand Up @@ -323,6 +327,8 @@ subtest 'lane and tag level drivers' => sub {
is (scalar $lims->children, 9, 'tag zero - nine-long children list');
is ($lims->spiked_phix_tag_index, 168, 'spike index');
ok (!$lims->sample_supplier_name, 'no supplier name');
ok (!$lims->sample_uuid, 'no sample uuid');
ok (!$lims->sample_lims, 'no sample lims');
ok (!$lims->sample_cohort, 'no cohort');
ok (!$lims->sample_donor_id, 'no donor id');
is ($lims->default_tag_sequence, undef, 'first index sequence undefined');
Expand All @@ -340,6 +346,8 @@ subtest 'lane and tag level drivers' => sub {
ok (!$lims->is_control, 'tag 2 is not control');
is ($lims->sample_id, 1092803, 'sample id');
is ($lims->sample_supplier_name, 'sample_33', 'supplier name');
is ($lims->sample_uuid, 'f44b2ec0-6f67-11e4-a268-68b59977951c', 'sample uuid');
is ($lims->sample_lims, 'SQSCP', 'sample lims');
is ($lims->sample_cohort, 'plan1', 'cohort');
is ($lims->sample_donor_id, '5678', 'donor id');
is ($lims->default_tag_sequence, 'CGATGT', 'first index sequence');
Expand Down
24 changes: 23 additions & 1 deletion t/40-st-lims-samplesheet.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 11;
use Test::More tests => 12;
use Test::Exception;
use Test::Warn;
use File::Slurp;
Expand Down Expand Up @@ -397,4 +397,26 @@ subtest 'dual index default' => sub {
is($p->default_tagtwo_sequence, undef, 'no second index');
};

subtest 'sample uuid and LIMS id' => sub {
plan tests => 10;

my $path = 't/data/samplesheet/4pool4libs_extended.csv';
my $ss = st::api::lims::samplesheet->new(id_run => 6946, position => 1, path => $path);
ok (!$ss->is_pool, 'lane 1 is not a pool');
is ($ss->sample_uuid, 'c46e1810-e8aa-11e2-aafd-68b59976a382', 'sample uuid');
is ($ss->sample_lims, 'SQSCP', 'sample lims');
$ss = st::api::lims::samplesheet->new(id_run => 6946, position => 6, path => $path);
ok ($ss->is_pool, 'lane 6 is a pool');
is ($ss->sample_uuid, undef, 'sample uuid is not defined');
is ($ss->sample_lims, undef, 'sample lims is not defined');
my @plexes = $ss->children();
is ($plexes[0]->sample_uuid, '62a06c60-2139-11e3-b2c2-68b59976a382',
'sample uuid for a plex');
is ($plexes[0]->sample_lims, 'SQSCP', 'sample lims for a plex');
$ss = st::api::lims::samplesheet->new(
id_run => 6946, position => 6, tag_index => 0, path => $path);
is ($ss->sample_uuid, undef, 'sample uuid is not defined');
is ($ss->sample_lims, undef, 'sample lims is not defined');
};

1;
42 changes: 37 additions & 5 deletions t/40-st-lims.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Test::Exception;
use Test::Warn;
use Moose::Meta::Class;

my $num_delegated_methods = 45;
my $num_delegated_methods = 47;

use_ok('st::api::lims');

Expand Down Expand Up @@ -133,7 +133,7 @@ subtest 'Setting return value for primary attributes' => sub {
};

subtest 'Run-level object via samplesheet driver' => sub {
plan tests => 36;
plan tests => 40;

my $path = 't/data/samplesheet/miseq_default.csv';

Expand Down Expand Up @@ -176,6 +176,8 @@ subtest 'Run-level object via samplesheet driver' => sub {
is ($plexes[0]->id_run, 10262, 'id_run of the first plexe set correctly from Experiment Name');
is ($plexes[0]->library_id, 7583411, 'library_id of the first plex');
is ($plexes[0]->sample_name, 'LIA_1', 'sample_name of the first plex');
is ($plexes[0]->sample_uuid, undef, 'sample_uuid of the first plex');
is ($plexes[0]->sample_lims, undef, 'sample_lims of the first plex');
is ($plexes[0]->sample_id, undef, 'sample_id of the first plex in undefined');
is ($plexes[0]->is_pool, 0, 'is_pool false on plex level');
is ($plexes[0]->is_control, undef, 'is_control false on for a plex');
Expand All @@ -187,10 +189,12 @@ subtest 'Run-level object via samplesheet driver' => sub {
is ($plexes[95]->tag_sequence, 'GTCTTGGC', 'tag sequence of the last plex');
is ($plexes[95]->library_id, 7583506, 'library_id of the last plex');
is ($plexes[95]->sample_name, 'LIA_96', 'sample_name of the last plex');
is ($plexes[95]->sample_uuid, undef, 'sample_uuid of the last plex');
is ($plexes[95]->sample_lims, undef, 'sample_lims of the last plex');
};

subtest 'Lane-level and tag zero objects via samplesheet driver' => sub {
plan tests => 20;
plan tests => 24;

my $path = 't/data/samplesheet/miseq_default.csv';

Expand All @@ -217,13 +221,15 @@ subtest 'Lane-level and tag zero objects via samplesheet driver' => sub {
is (scalar $ss->children, 96, '96 plexes returned');
is ($ss->library_id, undef, 'library_id undefined');
is ($ss->sample_name, undef, 'sample name is undefined');
is ($ss->sample_uuid, undef, 'sample uuid is undefined');
is ($ss->sample_lims, undef, 'sample lims is undefined');
is ($ss->default_tag_sequence, undef, 'default tag sequence undefined');
is ($ss->tag_sequence, undef, 'tag sequence undefined');
}
};

subtest 'Plex-level objects via samplesheet driver' => sub {
plan tests => 10;
plan tests => 12;

my $path = 't/data/samplesheet/miseq_default.csv';
my $l;
Expand All @@ -244,6 +250,8 @@ subtest 'Plex-level objects via samplesheet driver' => sub {
'tag sequence is the same as default tag sequence');
is ($l->library_id, 7583413, 'library id is correct');
is ($l->sample_name, 'LIA_3', 'sample name is correct');
is ($l->sample_uuid, undef, 'sample uuid is undefined');
is ($l->sample_lims, undef, 'sample lims is undefined');
is (scalar $l->children, 0, 'zero children returned');
};

Expand Down Expand Up @@ -284,7 +292,7 @@ subtest 'Samplesheet driver for a one-component composition' => sub {
};

subtest 'Samplesheet driver for arbitrary compositions' => sub {
plan tests => 75;
plan tests => 93;

my $path = 't/data/samplesheet/novaseq_multirun.csv';
local $ENV{NPG_CACHED_SAMPLESHEET_FILE} = $path;
Expand All @@ -305,6 +313,8 @@ subtest 'Samplesheet driver for arbitrary compositions' => sub {
is($o->default_tagtwo_sequence, 'CCAACAGA', 'tag2 sequence');
is($o->default_library_type, 'HiSeqX PCR free', 'library type');
is($o->sample_name, '7592352', 'sample name');
is($o->sample_uuid, undef, 'sample uuid');
is($o->sample_lims, undef, 'sample lims');
is($o->study_name, 'UK Study', 'study name');
is($o->library_name, '22802061', 'library name');
is($o->reference_genome, 'Homo_sapiens (GRCh38_15_plus_hs38d1) [minimap2]',
Expand Down Expand Up @@ -342,6 +352,28 @@ subtest 'Samplesheet driver for arbitrary compositions' => sub {
is ($ss->id_run, 28780, 'correct run id');
is ($ss->position, 2, 'correct position');
is ($ss->tag_index, 4, 'correct tag_index');

$path = 't/data/samplesheet/data4merge.csv';
local $ENV{NPG_CACHED_SAMPLESHEET_FILE} = $path;

$rpt_list = '26480:1:9;26480:2:9';
$ss=st::api::lims->new(rpt_list => $rpt_list);
is ($ss->sample_uuid, '673165ec-f8c6-11e0-8838-68b59976a382',
'sample uuid for a composition');
is ($ss->sample_lims, 'CLARITY', 'sample lims for a composition');

$rpt_list = '26480:3:9;26480:4:9';
$ss=st::api::lims->new(rpt_list => $rpt_list);
is ($ss->sample_uuid, 'b6ea25f0-f8cc-11e0-8838-68b59976a382',
'sample uuid for a composition');
is ($ss->sample_lims, 'Traction', 'sample lims for a composition');

$rpt_list = '26480:1:9;26480:2:9;26480:3:9;26480:4:9';
$ss=st::api::lims->new(rpt_list => $rpt_list);
is ($ss->sample_uuid, undef, 'sample uuid for a composition is undefined ' .
'since the values for individual components differ');
is ($ss->sample_lims, undef, 'sample lims for a composition is undefined ' .
'since the values for individual components differ');
};

subtest 'Dual index' => sub {
Expand Down
2 changes: 1 addition & 1 deletion t/data/fixtures_stlims_wh/000-Sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
created: 2009-07-01 16:23:00
deleted_at: ~
description: ~
id_lims: SQSCP
id_lims: CLARITY
id_sample_lims: 7283
cohort: plan2
donor_id: d5678
Expand Down
Loading

0 comments on commit 6c5fc04

Please sign in to comment.