Skip to content

Commit

Permalink
Merge pull request #861 from marcomoscasgr/feature/sample-metadata-in…
Browse files Browse the repository at this point in the history
…-lims

Feature: sample metadata in lims
  • Loading branch information
mgcam authored Dec 4, 2024
2 parents a2f1631 + eb68a5e commit 1e91cdc
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 16 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ t/data/samplesheet/samplesheet_33990.csv
t/data/samplesheet/samplesheet_47995.csv
t/data/samplesheet/samplesheet_singlecell_48460.csv
t/data/samplesheet/4pool4libs_extended.csv
t/data/samplesheet/4pool4libs_extended2.csv
t/data/samplesheet/6946_extended.csv
t/data/samplesheet/7007_extended.csv
t/data/samplesheet/8pools_extended.csv
Expand Down
5 changes: 5 additions & 0 deletions lib/st/api/lims.pm
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ Readonly::Hash my %ATTRIBUTE_LIST_METHODS => {
public_name
reference_genome
supplier_name
uuid
/],
'study' => [qw/ accession_number
id
Expand Down Expand Up @@ -333,6 +334,10 @@ Similar to sample_names, but for public_names.
Similar to sample_names, but for supplier_names.
=head2 sample_uuids
Similar to sample_names, but for LIMS-specific UUIDs
=head2 study_names
A list of study names. if $self->is_pool is true, returns unique study
Expand Down
5 changes: 4 additions & 1 deletion t/40-st-lims-merge.t
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ subtest 'Create lane object from plex object' => sub {
};

subtest 'Create tag zero object' => sub {
plan tests => 10;
plan tests => 14;

local $ENV{NPG_CACHED_SAMPLESHEET_FILE} =
't/data/test40_lims/samplesheet_novaseq4lanes.csv';
Expand Down Expand Up @@ -124,8 +124,11 @@ subtest 'Create tag zero object' => sub {
is ($t0->driver->mlwh_schema, $schema_wh,
'the original db connection is retained');
my @names = $t0->sample_names();
my @uuids = $t0->sample_uuids();
is (@names, 18, '18 sample names are retrieved');
is (@uuids, 18, '18 sample uuids are retrieved');
is ($names[0], '6751STDY13219539', 'first sample name is correct');
is ($uuids[0], '5832d018-56a6-11ed-a8fb-fa163eea3084', 'first sample uuid is correct');
}
};

Expand Down
70 changes: 63 additions & 7 deletions t/40-st-lims.t
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ subtest 'Samplesheet driver for a one-component composition' => sub {
};

subtest 'Samplesheet driver for arbitrary compositions' => sub {
plan tests => 95;
plan tests => 108;

my $path = 't/data/samplesheet/novaseq_multirun.csv';
local $ENV{NPG_CACHED_SAMPLESHEET_FILE} = $path;
Expand All @@ -333,6 +333,7 @@ subtest 'Samplesheet driver for arbitrary compositions' => sub {
is ($ss->tag_index, undef, 'tag_index undefined');
ok (!$ss->is_pool, 'not a pool');
is ($ss->is_composition, 1, 'this is a composition');
is ($ss->sample_uuid, undef, 'sample uuid');
my @children = $ss->children();
is (scalar @children, 5, 'five children');

Expand All @@ -341,8 +342,7 @@ 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->sample_lims, 'SQSCP', '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 All @@ -360,26 +360,54 @@ subtest 'Samplesheet driver for arbitrary compositions' => sub {
is ($ss->tag_index, 9, 'correct tag_index');
ok (!$ss->is_pool, 'plex is not a pool');
is ($ss->is_composition, 0, 'not a composition');
is ($ss->sample_uuid, 'a12b3456-a1bb-12a3-1234-12a34567b890', 'child sample uuid');

$ss = $children[1];
is ($ss->id_run, 26480, 'correct run id');
is ($ss->position, 2, 'correct position');
is ($ss->tag_index, 9, 'correct tag_index');
is ($ss->sample_uuid, 'a12b3456-a1bb-12a3-1234-12a34567b890', 'child sample uuid');

$ss = $children[2];
is ($ss->id_run, 26480, 'correct run id');
is ($ss->position, 3, 'correct position');
is ($ss->tag_index, 9, 'correct tag_index');
is ($ss->sample_uuid, 'a12b3456-a1bb-12a3-1234-12a34567b890', 'child sample uuid');

$ss = $children[3];
is ($ss->id_run, 26480, 'correct run id');
is ($ss->position, 4, 'correct position');
is ($ss->tag_index, 9, 'correct tag_index');
is ($ss->sample_uuid, 'a12b3456-a1bb-12a3-1234-12a34567b890', 'child sample uuid');

$ss = $children[4];
is ($ss->id_run, 28780, 'correct run id');
is ($ss->position, 2, 'correct position');
is ($ss->tag_index, 4, 'correct tag_index');
is ($ss->sample_uuid, 'a12b3456-a1bb-12a3-1234-12a34567b892', 'child sample uuid');

$rpt_list = '28780:1:4;28780:3:4;28780:4:4';
$ss=st::api::lims->new(rpt_list => $rpt_list);
is ($ss->sample_uuid, undef, 'sample uuid');

@children = $ss->children();
$ss = $children[0];
is ($ss->id_run, 28780, 'correct run id');
is ($ss->position, 1, 'correct position');
is ($ss->tag_index, 4, 'correct tag_index');
is ($ss->sample_uuid, 'a12b3456-a1bb-12a3-1234-12a34567b891', 'child sample uuid');

$ss = $children[1];
is ($ss->id_run, 28780, 'correct run id');
is ($ss->position, 3, 'correct position');
is ($ss->tag_index, 4, 'correct tag_index');
is ($ss->sample_uuid, 'a12b3456-a1bb-12a3-1234-12a34567b893', 'child sample uuid');

$ss = $children[2];
is ($ss->id_run, 28780, 'correct run id');
is ($ss->position, 4, 'correct position');
is ($ss->tag_index, 4, 'correct tag_index');
is ($ss->sample_uuid, 'a12b3456-a1bb-12a3-1234-12a34567b894', 'child sample uuid');

$path = 't/data/samplesheet/data4merge.csv';
local $ENV{NPG_CACHED_SAMPLESHEET_FILE} = $path;
Expand Down Expand Up @@ -491,10 +519,10 @@ subtest 'Insert size' => sub {
};

subtest 'Study and sample properties' => sub {
plan tests => 83;
plan tests => 97;

local $ENV{NPG_CACHED_SAMPLESHEET_FILE} =
't/data/samplesheet/4pool4libs_extended.csv';
't/data/samplesheet/4pool4libs_extended2.csv';

# A simple non-indexed lane.
my $lims = st::api::lims->new(id_run => 9999, position => 1);
Expand All @@ -513,6 +541,9 @@ subtest 'Study and sample properties' => sub {
'reference genome');
is( $lims->species_from_reference_genome, 'Haemonchus_contortus',
'species from reference genome');
my $sample_uuid = $lims->sample_uuid;
is_deeply([$lims->sample_uuids], [$sample_uuid],
'sample uuids for non-indexed lane');

# Individual plex.
$lims = st::api::lims->new(id_run => 9999, position => 7, tag_index=> 76);
Expand All @@ -534,8 +565,15 @@ subtest 'Study and sample properties' => sub {
is( $lims->reference_genome, 'Mus_musculus (GRCm38)', 'reference genome');
is( $lims->species_from_reference_genome, 'Mus_musculus',
'species from reference genome');
$sample_uuid = $lims->sample_uuid;
is_deeply([$lims->sample_uuids], [$sample_uuid], 'sample uuids for a plex');
is( $lims->sample_lims, 'SQSCP', 'sample lims');

# Indexed lane and tag zero for the same lane.
my $sample_uuid_77 = st::api::lims->new(
id_run => 9999, position => 7, tag_index=> 77)->sample_uuid;

# Indexed lane and tag zero for the same lane, sample_lims and
# sample_uuid are undefined for tag 168 (control), one-sample pool.
for my $l (
st::api::lims->new(id_run => 9999, position => 7),
st::api::lims->new(id_run => 9999, position => 7, tag_index => 0)
Expand All @@ -548,10 +586,28 @@ subtest 'Study and sample properties' => sub {
is( $l->study_reference_genome, 'Mus_musculus (GRCm38)',
'study reference genome');
is( $l->reference_genome, 'Mus_musculus (GRCm38)', 'reference genome');
is( $lims->species_from_reference_genome, 'Mus_musculus',
is( $l->species_from_reference_genome, 'Mus_musculus',
'species from reference genome');
is_deeply( [$l->sample_uuids(1)], [$sample_uuid, $sample_uuid_77],
'sample uuids for a lane or tag0, counting controls');
is_deeply( [$l->sample_uuids(0)], [$sample_uuid, $sample_uuid_77],
'sample uuids for a lane or tag0, not counting the control');
is( $l->sample_lims, 'SQSCP', 'sample lims');
}

# Tag zero, multiple plexes.
$lims = st::api::lims->new(id_run => 6946, position => 4, tag_index => 0);
is( $lims->sample_uuid, undef, 'sample uuid is undefined for tag0');
is( $lims->sample_lims, undef,
'sample lims is undefined for tag0 where samples come from different LIMS');
my $num_plexes = scalar $lims->children();
is( scalar $lims->sample_uuids(1), $num_plexes,
'multiple uuids, counting controls');
is( scalar $lims->sample_uuids(), $num_plexes,
'multiple uuids, defalt invocation - counting controls');
is( scalar $lims->sample_uuids(0), $num_plexes-1,
'multiple uuids, not counting controls');

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

Expand Down
Loading

0 comments on commit 1e91cdc

Please sign in to comment.