diff --git a/lib/LIMS2/Model/FormValidator/Constraint.pm b/lib/LIMS2/Model/FormValidator/Constraint.pm index e4b06edb94..eaabc953f2 100644 --- a/lib/LIMS2/Model/FormValidator/Constraint.pm +++ b/lib/LIMS2/Model/FormValidator/Constraint.pm @@ -381,12 +381,6 @@ sub hashref { } } -sub arrayref { - return sub { - ref $_[0] eq ref []; - } -} - sub file_handle { return sub { my $val = shift; diff --git a/lib/LIMS2/Model/Plugin/Well.pm b/lib/LIMS2/Model/Plugin/Well.pm index 3aef5e002e..e37fa713a9 100644 --- a/lib/LIMS2/Model/Plugin/Well.pm +++ b/lib/LIMS2/Model/Plugin/Well.pm @@ -498,22 +498,10 @@ sub pspec_generate_eng_seq_params { well_id => { validate => 'integer', rename => 'id', optional => 1 }, cassette => { validate => 'existing_final_cassette', optional => 1 }, backbone => { validate => 'existing_backbone', optional => 1 }, - recombinase => { validate => 'arrayref', default => [], optional => 1 }, + recombinase => { validate => 'existing_recombinase', default => [], optional => 1 }, targeted_trap => { validate => 'boolean', default => 0, optional => 1 }, } } -use Data::Dumper; -$Data::Dumper::Maxdepth=3; - -sub retrieve_well_design{ - my ( $self, $well ) = @_; - - my $graph = LIMS2::Model::ProcessGraph->new({ start_with => $well, type => 'ancestors' }); - my $proc_design = $graph->find_process($well, 'process_design') - or die "No process_design identified for well ID ".$well->id; - - return $proc_design->design->as_hash; -} sub generate_well_eng_seq_params{ @@ -525,7 +513,7 @@ sub generate_well_eng_seq_params{ $self->throw( NotFound => { entity_class => 'Well', search_params => $params }) unless $well; - my $design = $self->retrieve_well_design( $well ); + my $design = $well->design->as_hash; # Infer stage from plate type information my $plate_type_descr = $well->plate->type->description; diff --git a/lib/LIMS2/Model/Util/EngSeqParams.pm b/lib/LIMS2/Model/Util/EngSeqParams.pm index 98d50b3b5b..d29347fdd6 100644 --- a/lib/LIMS2/Model/Util/EngSeqParams.pm +++ b/lib/LIMS2/Model/Util/EngSeqParams.pm @@ -86,31 +86,29 @@ sub fetch_well_eng_seq_params{ my ($well_params, $method); - my $graph = LIMS2::Model::ProcessGraph->new({ start_with => $well, type => 'ancestors' }); - # Fetch cassette etc from process graph if not user supplied unless ($params->{cassette}){ - my $process_cassette = $graph->find_process($well, 'process_cassette'); - $params->{cassette} = $process_cassette ? $process_cassette->cassette->name - : undef ; + my $cassette = $well->cassette; + $params->{cassette} = $cassette ? $cassette->name + : undef ; } unless (@{ $params->{recombinase} }){ - my $process_recombinases = $graph->find_process($well, 'process_recombinases'); - # FIXME: should these be sorted by rank? - my @recombinases = $process_recombinases ? map { lc $_->recombinase_id } $process_recombinases->all - : () ; - $params->{recombinase} = \@recombinases; + $params->{recombinase} = $well->recombinases; } unless ($params->{backbone} or $params->{is_allele}){ - my $process_backbone = $graph->find_process($well, 'process_backbone'); - $params->{backbone} = $process_backbone ? $process_backbone->backbone->name - : undef ; + my $backbone = $well->backbone; + $params->{backbone} = $backbone ? $backbone->name + : undef ; } - # Always store recombinase - $well_params->{recombinase} = $params->{recombinase}; + # Always store recombinase (in lower case) + my @recom = map { lc $_ } @{ $params->{recombinase} }; + $well_params->{recombinase} = \@recom; + + # We always need a cassette + die "No cassette found for well ".$well->id unless $params->{cassette}; my $design_type = $params->{design_type}; @@ -143,7 +141,8 @@ sub fetch_well_eng_seq_params{ } else { - $well_params->{backbone}->{name} = $params->{backbone}; + $well_params->{backbone}->{name} = $params->{backbone} + or die "No backbone found for well ".$well->id; if ( $design_type eq 'conditional') { $method = 'conditional_vector_seq'; diff --git a/t/50-model-plugin-well.t b/t/50-model-plugin-well.t index ef41f197c7..7bce791a76 100755 --- a/t/50-model-plugin-well.t +++ b/t/50-model-plugin-well.t @@ -17,8 +17,21 @@ my $well_data= test_data( 'well.yaml' ); note( "Testing well EngSeqParam generation"); { - ok my ($method, $params) = model->generate_well_eng_seq_params({ well_id => 850 }), - 'generate well_eng_seq_params should succeed'; + throws_ok { + model->generate_well_eng_seq_params({ well_id => 850 }); + } qr/No cassette found for well/; + + my %user_params = ( cassette => 'L1L2_GT2_LacZ_BSD', backbone => 'R3R4_pBR_amp', recombinase => ['Cre']); + ok my ($method2, $params2) = model->generate_well_eng_seq_params({ well_id => 850, %user_params }), + 'generate well_eng_seq_params with user specified details should succeed'; + is_deeply ($params2, test_data("well_850_user_params.yaml"), + 'engseq params as expected for well 850 with user specified params'); + is $method2, 'conditional_vector_seq', 'engseq method correct'; + + ok my ($method3, $params3) = model->generate_well_eng_seq_params({ well_id => 848, %user_params }), + 'generate well_eng_seq_params should succeed'; + is_deeply ($params3, test_data('well_848.yaml'), 'engseq params as expected for well 848'); + } note( "Testing well creation" ); diff --git a/t/data/well_848.yaml b/t/data/well_848.yaml new file mode 100644 index 0000000000..8731c1ce1d --- /dev/null +++ b/t/data/well_848.yaml @@ -0,0 +1,20 @@ +--- +assembly: GRCm38 +backbone: + name: R3R4_pBR_amp +chromosome: '9' +d_insertion: + name: LoxP +design_id: 170606 +display_id: 170606#L1L2_GT2_LacZ_BSD#R3R4_pBR_amp#cre +five_arm_end: 20926524 +five_arm_start: 20920679 +recombinase: +- cre +strand: -1 +target_region_end: 20920581 +target_region_start: 20917778 +three_arm_end: 20917744 +three_arm_start: 20914201 +u_insertion: + name: L1L2_GT2_LacZ_BSD diff --git a/t/data/well_850_user_params.yaml b/t/data/well_850_user_params.yaml new file mode 100644 index 0000000000..a043935e4b --- /dev/null +++ b/t/data/well_850_user_params.yaml @@ -0,0 +1,20 @@ +--- +assembly: GRCm38 +backbone: + name: R3R4_pBR_amp +chromosome: '15' +d_insertion: + name: LoxP +design_id: 84231 +display_id: 84231#L1L2_GT2_LacZ_BSD#R3R4_pBR_amp#cre +five_arm_end: 58122003 +five_arm_start: 58116316 +recombinase: +- cre +strand: -1 +target_region_end: 58116243 +target_region_start: 58115459 +three_arm_end: 58115448 +three_arm_start: 58111237 +u_insertion: + name: L1L2_GT2_LacZ_BSD