Skip to content

Commit

Permalink
Propagated driver details for mlwh driver
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcam committed Jan 2, 2024
1 parent dbf9dd5 commit c98b729
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
41 changes: 32 additions & 9 deletions lib/st/api/lims.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ sub BUILD {
my %dargs=();
my %pargs=();
my %primary_arg_type = map {$_ => 1} @{$METHODS_PER_CATEGORY{'primary'}};

my $driver_class=$self->_driver_package_name;

foreach my$k (grep {defined && $_ !~ /^_/smx} map{ $_->has_init_arg ? $_->init_arg : $_->name}
Expand Down Expand Up @@ -198,6 +197,28 @@ sub BUILD {
return;
}

=head2 copy_init_args
Returns a hash reference that can be used to initialise st::api::lims
objects similar to this object. The driver details, if present in this
object, are returned under the 'driver_type' key and, if relevant,
'mlwh_schema' key.
=cut
sub copy_init_args {
my $self = shift;

my %init = %{$self->_driver_arguments()};
if ($self->driver_type()) {
$init{'driver_type'} = $self->driver_type();
if (!$init{'mlwh_schema'} && $init{'driver_type'} =~ /warehouse/smx) {
$init{'mlwh_schema'} = $self->driver()->mlwh_schema;
}
}

return \%init;
}

# Mapping of LIMS object types to attributes for which methods are to
# be generated. These generated methods are 'plural' methods which
# return an array of that attributes e.g. $lims->library_ids (returns
Expand Down Expand Up @@ -724,7 +745,7 @@ sub _build__cached_children {
my $self = shift;

my @children = ();
my @basic_attrs = qw/id_run position tag_index/;
my @basic_attrs = @{$METHODS_PER_CATEGORY{'primary'}};
my $driver_type = $self->driver_type;

if ($self->driver) {
Expand Down Expand Up @@ -760,7 +781,9 @@ sub _build__cached_children {
my %init = %{$self->_driver_arguments()};
$init{'driver_type'} = $driver_type;
foreach my $attr (@basic_attrs) {
$init{$attr} = $component->$attr;
if ($component->can($attr)) {
$init{$attr} = $component->$attr;
}
}
push @children, __PACKAGE__->new(\%init);
}
Expand Down Expand Up @@ -953,7 +976,7 @@ This method can be used both as instance and as a class method.
=cut

sub aggregate_libraries() {
sub aggregate_libraries {
my ($self, $lane_lims_array) = @_;

# This restriction might be lifted in future.
Expand All @@ -975,9 +998,9 @@ sub aggregate_libraries() {
# to create objects for merged entities.
# Do not use $self for copying the driver arguments in order to retain
# ability to use this method as a class method.
my %init = %{$lane_lims_array->[0]->_driver_arguments()};
delete $init{position};
delete $init{id_run};
my $init = $lane_lims_array->[0]->copy_init_args();
delete $init->{position};
delete $init->{id_run};

my $merges = {};
my $lane_set_delim = q[,];
Expand Down Expand Up @@ -1005,7 +1028,7 @@ sub aggregate_libraries() {
->new(rpt_list => $rpt_list)->create_composition()
->freeze2rpt();
$merges->{$lane_set}->{$tag_index} = __PACKAGE__->new(
%init, rpt_list => $rpt_list
%{$init}, rpt_list => $rpt_list
);
}
}
Expand Down Expand Up @@ -1045,7 +1068,7 @@ sub aggregate_libraries() {
return $all_lims_objects;
}

sub _check_merge_correctness{
sub _check_merge_correctness {
my $lib_lims = shift;
my @lanes = uniq map {$_->position} @{$lib_lims};
if (@lanes != @{$lib_lims}) {
Expand Down
29 changes: 28 additions & 1 deletion t/40-st-lims-merge.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use strict;
use warnings;
use Test::More tests => 9;
use Test::More tests => 10;
use Test::Exception;
use List::MoreUtils qw/all none/;
use File::Slurp;
use File::Temp qw/tempdir/;
use Moose::Meta::Class;

use_ok('npg_tracking::glossary::rpt');
use_ok('st::api::lims');
Expand Down Expand Up @@ -367,6 +368,32 @@ subtest 'Multiple lane sets in aggregation by library' => sub {
'merges list - correct object, correct sort order');
};

subtest 'mlwarehouse driver in aggregation by library' => sub {
plan tests => 5;

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

my $id_run = 47995;
my @lane_lims = st::api::lims->new(
id_run => $id_run,
id_flowcell_lims => 98292,
driver_type => 'ml_warehouse',
mlwh_schema => $schema_wh,
)->children();
my $lims = st::api::lims->aggregate_libraries(\@lane_lims);
# Test that lims objects are viable, ie it is possible to retrieve
# their properties.
is (@{$lims->{'singles'}}, 8, 'list of singles contains 8 objects');
lives_ok { $lims->{'singles'}->[0]->sample_name } 'can retrieve sample name';
is (@{$lims->{'merges'}}, 87, 'list of merges contains 87 objects');
lives_ok { $lims->{'merges'}->[0]->sample_name } 'can retrieve sample name';
lives_ok { $lims->{'merges'}->[86]->sample_name } 'can retrieve sample name';
};


sub _generate_rpt_lists {
my ($id_run, $positions, $tag_indexes) = @_;
my @expected_rpt_lists = ();
Expand Down

0 comments on commit c98b729

Please sign in to comment.