Permalink
Browse files

Merge branch 'devel' of github.com:htgt/LIMS2-WebApp into devel

  • Loading branch information...
2 parents 7c7af5e + 3dc28da commit 80a99455f08c5ecf563a5f6d6dd96a46cdd73b70 Ray Miller committed Aug 1, 2012
View
@@ -6,3 +6,4 @@ ddl/lims2_test2
ddl/lims2_live
ddl/lims2_staging
ddl/lims2_sp12
+cover_db
@@ -14,17 +14,18 @@ requires qw( schema check_params throw retrieve log trace );
sub list_plate_types {
my $self = shift;
- return [ $self->schema->resultset('PlateType')->search( {}, { order_by => { -asc => 'id' } } ) ];
+ return [
+ $self->schema->resultset('PlateType')->search( {}, { order_by => { -asc => 'id' } } ) ];
}
sub pspec_list_plates {
return {
species => { validate => 'existing_species' },
- plate_name => { validate => 'non_empty_string', optional => 1 },
+ plate_name => { validate => 'non_empty_string', optional => 1 },
plate_type => { validate => 'existing_plate_type', optional => 1 },
- page => { validate => 'integer', optional => 1, default => 1 },
- pagesize => { validate => 'integer', optional => 1, default => 15 }
- }
+ page => { validate => 'integer', optional => 1, default => 1 },
+ pagesize => { validate => 'integer', optional => 1, default => 15 }
+ };
}
sub list_plates {
@@ -35,7 +36,8 @@ sub list_plates {
my %search = ( 'me.species_id' => $validated_params->{species} );
if ( $validated_params->{plate_name} ) {
- $search{'me.name'} = { -like => '%' . sanitize_like_expr( $validated_params->{plate_name} ) . '%' };
+ $search{'me.name'}
+ = { -like => '%' . sanitize_like_expr( $validated_params->{plate_name} ) . '%' };
}
if ( $validated_params->{plate_type} ) {
@@ -44,8 +46,7 @@ sub list_plates {
my $resultset = $self->schema->resultset('Plate')->search(
\%search,
- {
- prefetch => [ 'created_by' ],
+ { prefetch => ['created_by'],
order_by => { -desc => 'created_at' },
page => $validated_params->{page},
rows => $validated_params->{pagesize}
@@ -90,37 +91,48 @@ sub create_plate {
my $validated_params = $self->check_params( $params, $self->pspec_create_plate );
my $plate = $self->schema->resultset('Plate')->create(
- { slice_def( $validated_params, qw( name species_id type_id description created_by_id created_at ) ) }
+ { slice_def(
+ $validated_params,
+ qw( name species_id type_id description created_by_id created_at )
+ )
+ }
);
+ # refresh object data from database, sets created_by value
+ # if it was set by database
+ $plate->discard_changes;
+
for my $c ( @{ $validated_params->{comments} || [] } ) {
my $validated_c = $self->check_params( $c, $self->pspec_create_plate_comment );
$plate->create_related( plate_comments =>
{ slice_def( $validated_c, qw( comment_text created_by_id created_at ) ) } );
}
- $self->create_plate_wells( $validated_params->{wells}, $plate )
- if exists $validated_params->{wells} and @{ $validated_params->{wells} };
+ if ( exists $validated_params->{wells} ) {
+ $self->create_plate_well( $_, $plate ) for @{ $validated_params->{wells} };
+ }
return $plate;
}
sub pspec_retrieve_plate {
return {
- name => { validate => 'plate_name', optional => 1, rename => 'me.name' },
- id => { validate => 'integer', optional => 1, rename => 'me.id' },
- type => { validate => 'existing_plate_type', optional => 1, rename => 'me.type_id' },
- species => { validate => 'existing_species', rename => 'me.species_id', optional => 1 },
+ name => { validate => 'plate_name', optional => 1, rename => 'me.name' },
+ id => { validate => 'integer', optional => 1, rename => 'me.id' },
+ type => { validate => 'existing_plate_type', optional => 1, rename => 'me.type_id' },
+ species => { validate => 'existing_species', rename => 'me.species_id', optional => 1 },
REQUIRE_SOME => { name_or_id => [ 1, qw( name id ) ] }
};
}
sub retrieve_plate {
my ( $self, $params ) = @_;
- my $validated_params = $self->check_params( $params, $self->pspec_retrieve_plate, ignore_unknown => 1 );
+ my $validated_params
+ = $self->check_params( $params, $self->pspec_retrieve_plate, ignore_unknown => 1 );
- return $self->retrieve( Plate => { slice_def $validated_params, qw( me.name me.id me.type_id me.species_id ) } );
+ return $self->retrieve(
+ Plate => { slice_def $validated_params, qw( me.name me.id me.type_id me.species_id ) } );
}
sub delete_plate {
@@ -133,30 +145,28 @@ sub delete_plate {
$self->delete_well( { id => $well->id } );
}
- $plate->search_related_rs( 'plate_comments' )->delete;
+ $plate->search_related_rs('plate_comments')->delete;
$plate->delete;
return;
}
sub pspec_set_plate_assay_complete {
- my $self = shift;
- return +{
- %{ $self->pspec_retrieve_plate },
+ return {
completed_at => { validate => 'date_time', optional => 1, post_filter => 'parse_date_time' }
};
}
sub set_plate_assay_complete {
my ( $self, $params ) = @_;
- my $validated_params = $self->check_params( $params, $self->pspec_set_plate_assay_complete );
+ my $validated_params = $self->check_params( $params, $self->pspec_set_plate_assay_complete,
+ ignore_unknown => 1 );
- my $plate = $self->retrieve_plate( $validated_params );
+ my $plate = $self->retrieve_plate($params);
for my $well ( $plate->wells ) {
$self->set_well_assay_complete(
- {
- id => $well->id,
+ { id => $well->id,
completed_at => $validated_params->{completed_at}
}
);
@@ -165,49 +175,81 @@ sub set_plate_assay_complete {
return $plate;
}
-sub create_plate_wells {
- my ( $self, $wells, $plate ) = @_;
+sub pspec_create_plate_well {
+ return {
+ well_name => { validate => 'well_name' },
+ process_type => { validate => 'existing_process_type' },
+ };
+}
- for my $well_data ( @{ $wells } ) {
- my $parent_well_ids = $self->find_parent_well_ids( $well_data );
+# input will be in the format a user trying to create a plate will use
+# we need to convert this into a format expected by create_well
+sub create_plate_well {
+ my ( $self, $params, $plate ) = @_;
- my %well_params = (
- plate_name => $plate->name,
- well_name => delete $well_data->{well_name},
- created_by => $plate->created_by->name,
- created_at => $plate->created_at->iso8601,
- );
- my $process_type = delete $well_data->{process_type};
+ my $validated_params
+ = $self->check_params( $params, $self->pspec_create_plate_well, ignore_unknown => 1 );
- $well_params{process_data} = $well_data;
- $well_params{process_data}{type} = $process_type;
- $well_params{process_data}{input_wells} = [ map{ { id => $_ } } @{ $parent_well_ids } ];
+ my $parent_well_ids = $self->find_parent_well_ids($params);
- $self->create_well( \%well_params, $plate );
- }
+ my %well_params = (
+ plate_name => $plate->name,
+ well_name => $validated_params->{well_name},
+ created_by => $plate->created_by->name,
+ created_at => $plate->created_at->iso8601,
+ );
+
+ # the remaining params are specific to the process
+ delete @{$params}{qw( well_name process_type )};
+
+ $well_params{process_data} = $params;
+ $well_params{process_data}{type} = $validated_params->{process_type};
+ $well_params{process_data}{input_wells} = [ map { { id => $_ } } @{$parent_well_ids} ];
+
+ $self->create_well( \%well_params, $plate );
return;
}
+sub pspec_find_parent_well_ids {
+ return {
+ parent_plate => { validate => 'plate_name', optional => 1 },
+ parent_well => { validate => 'well_name', optional => 1 },
+ allele_plate => { validate => 'plate_name', optional => 1 },
+ allele_well => { validate => 'well_name', optional => 1 },
+ vector_plate => { validate => 'plate_name', optional => 1 },
+ vector_well => { validate => 'well_name', optional => 1 },
+ DEPENDENCY_GROUPS => { parent => [qw( parent_plate parent_well )] },
+ DEPENDENCY_GROUPS => { vector => [qw( vector_plate vector_well )] },
+ DEPENDENCY_GROUPS => { allele => [qw( allele_plate allele_well )] },
+ };
+}
+
sub find_parent_well_ids {
- my ( $self, $well_data, $plate_type ) = @_;
+ my ( $self, $params ) = @_;
+
+ my $validated_params
+ = $self->check_params( $params, $self->pspec_find_parent_well_ids, ignore_unknown => 1 );
+
my @parent_well_ids;
- if ( $well_data->{process_type} eq 'second_electroporation' ) {
+ if ( $params->{process_type} eq 'second_electroporation' ) {
push @parent_well_ids,
- $self->get_well_id( $well_data->{allele_plate}, $well_data->{allele_well} );
+ $self->get_well_id( $validated_params->{allele_plate},
+ $validated_params->{allele_well} );
push @parent_well_ids,
- $self->get_well_id( $well_data->{vector_plate}, $well_data->{vector_well} );
+ $self->get_well_id( $validated_params->{vector_plate},
+ $validated_params->{vector_well} );
- delete @{$well_data}
- {qw( allele_plate vector_plate allele_well vector_well )};
+ delete @{$params}{qw( allele_plate vector_plate allele_well vector_well )};
}
else {
push @parent_well_ids,
- $self->get_well_id( $well_data->{parent_plate}, $well_data->{parent_well} );
+ $self->get_well_id( $validated_params->{parent_plate},
+ $validated_params->{parent_well} );
- delete @{$well_data}{qw( parent_plate parent_well )};
+ delete @{$params}{qw( parent_plate parent_well )};
}
return \@parent_well_ids;
@@ -217,9 +259,8 @@ sub get_well_id {
my ( $self, $plate_name, $well_name ) = @_;
my $well = $self->retrieve_well(
- {
- plate_name => $plate_name,
- well_name => substr( $well_name, -3),
+ { plate_name => $plate_name,
+ well_name => substr( $well_name, -3 ),
}
);
View
@@ -86,13 +86,13 @@ ok my $dfv_profile = model->form_validator->dfv_profile( $pspec ),
lives_ok {
model->check_params( { foo => '' }, \%pspec )
- } 'comma_separeted_list validates empty list';
+ } 'comma_separeted_list validates empty list';
}
{
my %pspec = ( url => { validate => 'absolute_url' } );
- lives_ok {
+ lives_ok {
model->check_params( { url => 'http://example.org/foo/bar' }, \%pspec )
} 'validate absolute_url';
View
@@ -34,7 +34,7 @@ my %bac2_data = (
chr_start => 194454015,
chr_name => '1'
}
- ]
+ ]
);
ok my $bac2 = $model->create_bac_clone( \%bac2_data ),
@@ -12,24 +12,24 @@ use Test::Most;
can_ok $design, 'as_hash';
ok my $h1 = $design->as_hash(), 'as hash, with relations';
isa_ok $h1, ref {};
- ok $h1->{genotyping_primers}, '...has genotyping primers';
+ ok $h1->{genotyping_primers}, '...has genotyping primers';
ok my $h2 = $design->as_hash(1), 'as_hash, suppress relations';
- ok !$h2->{genotyping_primers}, '...no genotyping primers';
+ ok !$h2->{genotyping_primers}, '...no genotyping primers';
}
{
ok my $designs = model->list_assigned_designs_for_gene( { species => 'Mouse', gene_id => 'MGI:94912' } ), 'list assigned designs by MGI accession';
isa_ok $designs, ref [];
ok @{$designs} > 0, '...the list is not empty';
- isa_ok $_, 'LIMS2::Model::Schema::Result::Design' for @{$designs};
+ isa_ok $_, 'LIMS2::Model::Schema::Result::Design' for @{$designs};
}
{
ok my $designs = model->list_assigned_designs_for_gene( { species => 'Mouse', gene_id => 'MGI:106032', type => 'conditional' } ),
'list assigned designs by MGI accession and design type conditional';
isa_ok $designs, ref [];
ok @{$designs} > 0, '...the list is not empty';
- isa_ok $_, 'LIMS2::Model::Schema::Result::Design' for @{$designs};
+ isa_ok $_, 'LIMS2::Model::Schema::Result::Design' for @{$designs};
}
{
View
@@ -29,9 +29,6 @@ note( "Testing plate creation" );
ok my $retrieve_plate = model->retrieve_plate( { id => $plate->id } ),
'retrieve_plate by id should succeed';
is $plate->id, $retrieve_plate->id, 'has correct id';
-
- ok $plate_comments->delete, 'can delete plate comments';
- ok $plate->delete, 'can delete plate';
}
note( "Testing plate retrieve" );
@@ -43,4 +40,62 @@ note( "Testing plate retrieve" );
is $plate->name, 'PCS00075_A', 'retrieved correct plate';
}
+note( "Testing plate create with wells" );
+
+{
+ ok my $plate = model->create_plate( $plate_data->{plate_create_wells} ),
+ 'create_plate should succeed';
+ isa_ok $plate, 'LIMS2::Model::Schema::Result::Plate';
+
+ ok my $wells = $plate->wells, 'can retrieve plate wells';
+ ok my $well = $wells->find( { name => 'A01' } ), '..retrieve well A01';
+ ok my $process = $well->output_processes->first, '..can get output process';
+ is $process->type_id, 'first_electroporation', 'process is correct type';
+ ok my $input_well = $process->process_input_wells->first->well, 'retrieve input well for process';
+ is $input_well->plate->name, 'MOHFAQ0001_A_2', '..correct plate';
+ is $input_well->name, 'A01', '..correct well';
+
+}
+
+note( "Testing SEP type plate create with wells" );
+
+{
+ ok my $plate = model->create_plate( $plate_data->{sep_plate_create_wells} ),
+ 'create_plate should succeed';
+ isa_ok $plate, 'LIMS2::Model::Schema::Result::Plate';
+
+ ok my $wells = $plate->wells, 'can retrieve plate wells';
+ ok my $well = $wells->find( { name => 'A01' } ), '..retrieve well A01';
+ ok my $process = $well->output_processes->first, '..can get output process';
+ is $process->type_id, 'second_electroporation', 'process is correct type';
+ ok my $process_input_wells = $process->process_input_wells, 'retrieve input well for process';
+ is $process_input_wells->count, 2, 'we have 2 input wells for process';
+}
+
+note( "Plate Assay Complete" );
+
+{
+ ok my $plate = model->set_plate_assay_complete( $plate_data->{plate_assay_complete} ),
+ 'create_plate should succeed';
+ isa_ok $plate, 'LIMS2::Model::Schema::Result::Plate';
+
+ ok my $wells = $plate->wells, 'can retrieve plate wells';
+ ok my $well = $wells->find( { name => 'A05' } ), '..retrieve well A05';
+ is $well->assay_complete,'2012-05-21T00:00:00', 'assay complete is correct';
+}
+
+{
+ note( "Testing delete_plate" );
+
+ lives_ok {
+ model->delete_plate( { name => 'PCS101' } )
+ } 'delete plate';
+
+ lives_ok {
+ model->delete_plate( { name => 'EP10001' } )
+ } 'delete plate';
+}
+
+#TODO add tests for set_plate_assay_complete
+
done_testing();
Oops, something went wrong.

0 comments on commit 80a9945

Please sign in to comment.