Skip to content

Commit

Permalink
arrayref constraint not needed. use well mehtods instead of ProcessGr…
Browse files Browse the repository at this point in the history
…aph methods. more tests
  • Loading branch information
af11-sanger committed Oct 22, 2012
1 parent f1c17a4 commit 6d77656
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 38 deletions.
6 changes: 0 additions & 6 deletions lib/LIMS2/Model/FormValidator/Constraint.pm
Expand Up @@ -381,12 +381,6 @@ sub hashref {
}
}

sub arrayref {
return sub {
ref $_[0] eq ref [];
}
}

sub file_handle {
return sub {
my $val = shift;
Expand Down
16 changes: 2 additions & 14 deletions lib/LIMS2/Model/Plugin/Well.pm
Expand Up @@ -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{

Expand All @@ -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;
Expand Down
31 changes: 15 additions & 16 deletions lib/LIMS2/Model/Util/EngSeqParams.pm
Expand Up @@ -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};

Expand Down Expand Up @@ -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';
Expand Down
17 changes: 15 additions & 2 deletions t/50-model-plugin-well.t
Expand Up @@ -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" );
Expand Down
20 changes: 20 additions & 0 deletions 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
20 changes: 20 additions & 0 deletions 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

0 comments on commit 6d77656

Please sign in to comment.