Skip to content

Commit

Permalink
Simplified code for insert size and restored is tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcam committed Sep 27, 2023
1 parent bb4843e commit 5b0932e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
36 changes: 10 additions & 26 deletions lib/st/api/lims.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 36 additions & 1 deletion t/40-st-lims.t
Original file line number Diff line number Diff line change
@@ -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 /;
Expand Down Expand Up @@ -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;

0 comments on commit 5b0932e

Please sign in to comment.