Skip to content

Commit

Permalink
Merge pull request #797 from mgcam/lims_driver_patch
Browse files Browse the repository at this point in the history
Correctly propagate driver details for mlwh driver
  • Loading branch information
dkj authored Jan 5, 2024
2 parents c496c98 + de55a4b commit c2d8a58
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 75 deletions.
74 changes: 47 additions & 27 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 @@ -874,9 +897,8 @@ sub aggregate_xlanes {
return;
}; # End of test function

my %init = %{$self->_driver_arguments()};
$init{'driver_type'} = $self->driver_type;
delete $init{'id_run'};
my $init = $self->copy_init_args();
delete $init->{'id_run'};

my $lims4compisitions = {};
my @test_attrs = qw/sample_id library_id/;
Expand All @@ -885,7 +907,7 @@ sub aggregate_xlanes {

if (!@pools) {
$can_merge->(\@lanes, @test_attrs); # Test consistency
push @aggregated, __PACKAGE__->new(%init, rpt_list => $lanes_rpt_list);
push @aggregated, __PACKAGE__->new(%{$init}, rpt_list => $lanes_rpt_list);
} else {
my @sizes = uniq (map { $_->num_children } @lanes);
if (@sizes != 1) { # Test consistency
Expand All @@ -902,11 +924,11 @@ sub aggregate_xlanes {
my $ea = each_arrayref map { [$_->children()] } @lanes;
while ( my @plexes = $ea->() ) {
$can_merge->(\@plexes, @test_attrs, 'tag_index'); # Test consistency
push @aggregated, __PACKAGE__->new(%init,
push @aggregated, __PACKAGE__->new(%{$init},
rpt_list => npg_tracking::glossary::rpt->deflate_rpts(\@plexes));
}
# Add object for tag zero
push @aggregated, __PACKAGE__->new(%init,
push @aggregated, __PACKAGE__->new(%{$init},
rpt_list => npg_tracking::glossary::rpt->tag_zero_rpt_list($lanes_rpt_list));
}

Expand Down Expand Up @@ -953,7 +975,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 +997,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 +1027,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 +1067,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 All @@ -1069,7 +1091,7 @@ sub _check_value_is_unique {

=head2 create_tag_zero_object
Using id_run and position values of this object, creates and returns
Using run ID and position values of this object, creates and returns
st::api::lims object for tag zero. The new object has the same driver
settings as the original object.
Expand All @@ -1086,10 +1108,9 @@ sub create_tag_zero_object {
if (!defined $self->position) {
croak 'Position should be defined';
}
my %init = %{$self->_driver_arguments()};
$init{'driver_type'} = $self->driver_type;
$init{'tag_index'} = 0;
return __PACKAGE__->new(%init);
my $init = $self->copy_init_args();
$init->{'tag_index'} = 0;
return __PACKAGE__->new(%{$init});
}

=head2 create_lane_object
Expand All @@ -1106,13 +1127,12 @@ attributes. The new object has the same driver settings as the original object.
sub create_lane_object {
my ($self, $id_run, $position) = @_;
($id_run and $position) or croak 'id_run and position are expected as arguments';
my %init = %{$self->_driver_arguments()};
$init{'driver_type'} = $self->driver_type;
delete $init{'tag_index'};
delete $init{'rpt_list'};
$init{'id_run'} = $id_run;
$init{'position'} = $position;
return __PACKAGE__->new(%init);
my $init = $self->copy_init_args();
delete $init->{'tag_index'};
delete $init->{'rpt_list'};
$init->{'id_run'} = $id_run;
$init->{'position'} = $position;
return __PACKAGE__->new(%{$init});
}

=head2 cached_samplesheet_var_name
Expand Down
Loading

0 comments on commit c2d8a58

Please sign in to comment.