From 5b0932e6ecf8a2be05a16571a07b719318d45701 Mon Sep 17 00:00:00 2001 From: Marina Gourtovaia Date: Wed, 27 Sep 2023 17:44:09 +0100 Subject: [PATCH] Simplified code for insert size and restored is tests. --- lib/st/api/lims.pm | 36 ++++++++++-------------------------- t/40-st-lims.t | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/lib/st/api/lims.pm b/lib/st/api/lims.pm index 4d5e77da..2790c40e 100644 --- a/lib/st/api/lims.pm +++ b/lib/st/api/lims.pm @@ -542,44 +542,28 @@ sub _build_required_insert_size { my $self = shift; my $is_hash = {}; - my $size_element_defined = 0; - if (defined $self->position && !$self->is_control) { + if (defined $self->position) { my @alims = $self->associated_lims; - if (!@alims) { - @alims = ($self); - } + @alims = @alims ? @alims : ($self); foreach my $lims (@alims) { - $self->_entity_required_insert_size($lims, $is_hash, \$size_element_defined); - } - } - return $is_hash; -} -sub _entity_required_insert_size { - my ($self, $lims, $is_hash, $isize_defined) = @_; - - if (!$is_hash) { - croak q[Isize hash ref should be supplied]; - } - if (!$lims) { - croak q[Lims object should be supplied]; - } - - if (!$lims->is_control) { - my $is = $lims->required_insert_size_range; - if ($is && keys %{$is}) { - ${$isize_defined} = 1; + if ($lims->is_control) { + next; + } + my $is = $lims->required_insert_size_range || {}; foreach my $key (qw/to from/) { my $value = $is->{$key}; if ($value) { - my $lib_key = $lims->library_id || $lims->tag_index || $lims->sample_id; + my $lib_key = $lims->library_id || $lims->sample_id; $is_hash->{$lib_key}->{$key} = $value; } } } } - return; + + return $is_hash; } + =head2 seq_qc_state 1 for passes, 0 for failed, undef if the value is not set. diff --git a/t/40-st-lims.t b/t/40-st-lims.t index 80a41911..ff92df01 100644 --- a/t/40-st-lims.t +++ b/t/40-st-lims.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 15; use Test::Exception; use Test::Warn; use File::Temp qw/ tempdir /; @@ -620,4 +620,39 @@ subtest 'Dual index' => sub { is($plex->purpose, 'standard', 'purpose'); }; +subtest 'Insert size' => sub { + plan tests => 14; + + local $ENV{NPG_CACHED_SAMPLESHEET_FILE} = + 't/data/samplesheet/4pool4libs_extended.csv'; + + my $lims = st::api::lims->new(id_run => 9999); + is_deeply($lims->required_insert_size, {}, 'no insert size on run level'); + + $lims = st::api::lims->new(id_run => 9999, position => 1); + my $id = $lims->library_id; + my $insert_size = $lims->required_insert_size; + is (keys %{$insert_size}, 1, 'one entry in the insert size hash'); + is ($insert_size->{$id}->{q[from]}, 400, 'required FROM insert size'); + is ($insert_size->{$id}->{q[to]}, 550, 'required TO insert size'); + + $lims = st::api::lims->new(id_run => 9999, position => 7); + ok ($lims->is_pool, 'lane is a pool'); + $insert_size = $lims->required_insert_size; + is (keys %{$insert_size}, 2, 'two entries in the insert size hash'); + $id = '8324594'; + is ($insert_size->{$id}->{q[from]}, 100, 'required FROM insert size'); + is ($insert_size->{$id}->{q[to]}, 1000, 'required TO insert size'); + $id = '8324595'; + is ($insert_size->{$id}->{q[from]}, 100, 'required FROM insert size'); + is ($insert_size->{$id}->{q[to]}, 1000, 'required TO insert size'); + ok (!exists $insert_size->{q[6946_7_ACAACGCAAT]}, 'no required insert size'); + + $lims = st::api::lims->new(id_run => 9999, position => 7, tag_index => 77); + $insert_size = $lims->required_insert_size; + is (keys %{$insert_size}, 1, 'one entry in the insert size hash'); + is ($insert_size->{$id}->{q[from]}, 100, 'required FROM insert size'); + is ($insert_size->{$id}->{q[to]}, 1000, 'required TO insert size'); +}; + 1;