Skip to content

Commit

Permalink
plate creation from QC - tidied up and added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
af11-sanger committed Nov 8, 2012
1 parent 7289a95 commit 0c6608e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
50 changes: 36 additions & 14 deletions lib/LIMS2/Model/Plugin/QC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,14 @@ sub pspec_create_plates_from_qc{
qc_run_id => { validate => 'uuid' },
process_type => { validate => 'existing_process_type' },
plate_type => { validate => 'existing_plate_type' },
created_by => { validate => 'existing_user'},
created_by => { validate => 'existing_user' },
rename_plate => { validate => 'hashref', optional => 1 },
view_uri => { validate => 'absolute_url' },
};
}

sub create_plates_from_qc{
my ($self, $params, $c) = @_;
my ($self, $params) = @_;

my $validated_params = $self->check_params( $params, $self->pspec_create_plates_from_qc);

Expand Down Expand Up @@ -720,8 +721,9 @@ sub create_plates_from_qc{
process_type => $validated_params->{process_type},
qc_template_id => $qc_run->qc_template->id,
created_by => $validated_params->{created_by},
view_uri => $validated_params->{view_uri},
qc_run_id => $validated_params->{qc_run_id},
},
$c,
);

push @created_plates, $plate;
Expand All @@ -738,11 +740,13 @@ sub pspec_create_plate_from_qc{
results_by_well => { validate => 'hashref' },
qc_template_id => { validate => 'integer' },
created_by => { validate => 'existing_user'},
view_uri => { validate => 'absolute_url'},
qc_run_id => { validate => 'uuid'},
};
}

sub create_plate_from_qc{
my ($self, $params, $c) = @_;
my ($self, $params) = @_;

DEBUG "Creating plate ".$params->{plate_name};

Expand Down Expand Up @@ -803,9 +807,6 @@ sub create_plate_from_qc{
}
}

use Data::Dumper;
DEBUG Dumper(@new_wells);

my $plate = $self->create_plate({
name => $validated_params->{plate_name},
species => $template->species->id,
Expand All @@ -814,32 +815,53 @@ sub create_plate_from_qc{
created_by => $validated_params->{created_by},
});

$self->_add_well_qc_sequencing_results($plate, $validated_params->{orig_name}, $results_by_well, $c);
$self->_add_well_qc_sequencing_results({
plate => $plate,
orig_name => $validated_params->{orig_name},
results_by_well => $results_by_well,
view_uri => $validated_params->{view_uri},
qc_run_id => $validated_params->{qc_run_id},
});

return $plate;
}

sub pspec_add_well_qc_sequencing_results{
return{
plate => { },
orig_name => { validate => 'non_empty_string' },
results_by_well => { validate => 'hashref' },
view_uri => { validate => 'absolute_url' },
qc_run_id => { validate => 'uuid' },
};
}

sub _add_well_qc_sequencing_results{
my ($self, $plate, $orig_name, $results_by_well, $c) = @_;
my ($self, $params) = @_;

my $v_params = $self->check_params($params, $self->pspec_add_well_qc_sequencing_results);

my $plate = $v_params->{plate};

foreach my $well ($plate->wells->all){
my $results = $results_by_well->{$well->name};
my $results = $v_params->{results_by_well}->{$well->name};
my $best = $results->[0];

my $view_params = {
well_name => lc($well->name),
plate_name => $orig_name,
qc_run_id => $c->req->param('qc_run_id'),
plate_name => $v_params->{orig_name},
qc_run_id => $v_params->{qc_run_id},
};

my $url = $c->uri_for("/user/view_qc_result", $view_params);
my $url = URI->new($v_params->{view_uri});
$url->query_form($view_params);

my $qc_result = {
well_id => $well->id,
valid_primers => join( q{,}, @{ $best->{valid_primers} } ),
mixed_reads => @{ $results } > 1 ? 1 : 0,
pass => $best->{pass} ? 1 : 0,
test_result_url => $url,
test_result_url => $url->as_string,
created_by => $plate->created_by->name,
};
$self->create_well_qc_sequencing_result($qc_result);
Expand Down
7 changes: 4 additions & 3 deletions lib/LIMS2/WebApp/Controller/User/QC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -500,15 +500,16 @@ sub create_plates :Path('/user/create_plates') :Args(0){
$c->model('Golgi')->txn_do(
sub{
try{
# The view_uri is needed to create path to results view
# which is entered in the well_qc_sequencing_result
@new_plates = $c->model('Golgi')->create_plates_from_qc({
qc_run_id => $run_id,
process_type => $c->req->param('process_type'),
plate_type => $c->req->param('plate_type'),
rename_plate => $rename_plate,
created_by => $c->user->name,
},
$c,
);
view_uri => $c->uri_for("/user/view_qc_result"),
});
}
catch{
$c->stash->{error_msg} = "Plate creation failed with error: $_";
Expand Down
29 changes: 29 additions & 0 deletions t/50-model-plugin-qc.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@ use Test::Most;
use Try::Tiny;
use DateTime;

note "Testing creation of plate from QC results";

{
my $params = {
qc_run_id => '534EE22E-3DBF-22E4-5EF2-1234F5CB64C7',
process_type => '3w_gateway',
plate_type => 'FINAL',
created_by => 'test_user@example.org',
view_uri => 'http://test/view',
};

ok my ($new_plate) = model->create_plates_from_qc($params), 'new plates created from QC';
isa_ok $new_plate, 'LIMS2::Model::Schema::Result::Plate';
is $new_plate->name, 'PCS05036_A_1', 'plate name correct';
is $new_plate->type->id, 'FINAL', 'plate type is correct';
my @wells = $new_plate->wells->all;
is scalar @wells, 2, 'plate has 2 wells';
my ($b02) = grep { $_->name eq 'B02'} @wells;
my ($g12) = grep { $_->name eq 'G12'} @wells;
ok $b02, 'well B02 created';
ok $g12, 'well G12 created';
ok my $result = $g12->well_qc_sequencing_result, 'well G12 has sequencing result';
is $result->valid_primers, 'LR','well valid primers correct';
is $result->mixed_reads, '0','well mixed reads correct';
is $result->pass, '1','well pass correct';
my $view_uri = 'http://test/view?well_name=g12&plate_name=PCS05036_A_1&qc_run_id=534EE22E-3DBF-22E4-5EF2-1234F5CB64C7';
is $result->test_result_url, $view_uri, 'well test result url correct';
}

note( "Testing QC template storage and retrieval" );

my $template_data = test_data( 'qc_template.yaml' );
Expand Down

0 comments on commit 0c6608e

Please sign in to comment.