Permalink
Browse files

Implement code to retrieve vector wells satisfying cassette/recombina…

…se requirement
  • Loading branch information...
1 parent f9b1fbf commit 84abce08b5fe0073d0133731b1f03b7127384185 Ray Miller committed Jul 30, 2012
Showing with 94 additions and 20 deletions.
  1. +70 −1 lib/LIMS2/AlleleRequest.pm
  2. +10 −5 lib/LIMS2/AlleleRequest/DoubleTargeted.pm
  3. +14 −14 t/60-allele-request.t
View
@@ -48,7 +48,7 @@ sub _build_designs {
sub design_types_for {
my ( $self, $mutation_type ) = @_;
- if ( $mutation_type eq 'ko first' ) {
+ if ( $mutation_type eq 'ko_first' ) {
return [ 'conditional', 'artificial-intron', 'intron-replacement' ];
}
@@ -61,7 +61,76 @@ sub design_wells {
return map { $_->output_wells } $design->process_designs_rs->search_related( process => { type_id => 'create_di' } );
}
+sub final_vector_wells {
+ my ( $self, $design_wells, $cassette_function ) = @_;
+
+ my @final_vector_wells;
+ for my $design_well ( @{$design_wells} ) {
+ for my $node ( $self->find_wells_of_type( 'FINAL', $design_well->descendants, $design_well, {}, {} ) ) {
+ my ( $well, $properties ) = @{$node};
+ if ( $self->satisfies_cassette_function( $cassette_function, $properties->{cassette}, $properties->{recombinases} ) ) {
+ push @final_vector_wells, $well;
+ }
+ }
+ }
+
+ return @final_vector_wells;
+}
+
+## no critic(RequireFinalReturn)
+sub satisfies_cassette_function {
+ my ( $self, $function, $cassette, $recombinases ) = @_;
+
+ if ( $function eq 'ko_first' ) {
+ return $cassette->conditional && ! @{$recombinases};
+ }
+ elsif ( $function eq 'reporter_only' ) {
+ return $cassette->conditional && any { $_ eq 'Cre' } @{$recombinases};
+ }
+
+ LIMS2::Exception::Implementation->throw( "Unrecognized cassette function: $function" );
+}
+## use critic
+
+sub find_wells_of_type {
+ my ( $self, $type, $graph, $node, $node_data, $visited ) = @_;
+
+ return if $visited->{$node->id}++;
+
+ my %node_data = %{$node_data};
+ $node_data{recombinases} = [ @{$node_data{recombinases} || [] } ];
+
+ for my $p ( $graph->input_processes( $node ) ) {
+ if ( $p->process_backbone ) {
+ $node_data{backbone} = $p->process_backbone->backbone;
+ }
+ if ( $p->process_cassette ) {
+ $node_data{cassette} = $p->process_cassette->cassette;
+ }
+ if ( $p->process_cell_line ) {
+ $node_data{cell_line} = $p->process_cell_line->cell_line;
+ }
+ if ( $p->process_design ) {
+ $node_data{design} = $p->process_design->design->id;
+ }
+ if ( my @recombinases = $p->process_recombinases ) {
+ push @{ $node_data{recombinases} }, map { $_->recombinase_id } @recombinases;
+ }
+ }
+
+ my @accumulator;
+
+ if ( $node->plate->type_id eq $type ) {
+ push @accumulator, [ $node, \%node_data ];
+ }
+
+ for my $child_well ( $graph->output_wells( $node ) ) {
+ push @accumulator, $self->find_wells_of_type( $type, $graph, $child_well, \%node_data, $visited );
+ }
+
+ return @accumulator;
+}
# Input:
#
@@ -38,7 +38,7 @@ sub _build_second_allele_designs {
has [
qw( first_allele_design_wells second_allele_design_wells
- first_allele_final_vector_wells second_allele_final_vector_wells
+ first_allele_vector_wells second_allele_vector_wells
)
] => (
is => 'ro',
@@ -49,17 +49,22 @@ has [
sub _build_first_allele_design_wells {
my $self = shift;
- [ map { $self->design_wells($_) } @{$self->first_allele_designs} ];
+ return [ map { $self->design_wells($_) } @{$self->first_allele_designs} ];
}
sub _build_second_allele_design_wells {
my $self = shift;
- [ map { $self->design_wells($_) } @{$self->second_allele_designs} ];
+ return [ map { $self->design_wells($_) } @{$self->second_allele_designs} ];
}
-sub _build_first_allele_final_vector_wells {
+sub _build_first_allele_vector_wells {
my $self = shift;
-
+ return [ $self->final_vector_wells( $self->first_allele_design_wells, $self->first_allele_cassette_function ) ];
+}
+
+sub _build_second_allele_vector_wells {
+ my $self = shift;
+ return [ $self->final_vector_wells( $self->second_allele_design_wells, $self->second_allele_cassette_function ) ];
}
__PACKAGE__->meta->make_immutable;
View
@@ -13,19 +13,19 @@ const my @TEST_DATA => (
allele_request => {
gene_id => 'MGI:1914632',
targeting_type => 'double_targeted',
- first_allele_mutation_type => 'ko first',
- first_allele_cassette_function => 'ko first',
- second_allele_mutation_type => 'ko first',
- second_allele_cassette_function => 'reporter only'
+ first_allele_mutation_type => 'ko_first',
+ first_allele_cassette_function => 'ko_first',
+ second_allele_mutation_type => 'ko_first',
+ second_allele_cassette_function => 'reporter_only'
},
- first_allele_designs => [ 34188 ],
- first_allele_design_wells => [ '56_G04' ],
- second_allele_designs => [ 34188 ],
- second_allele_design_wells => [ '56_G04' ],
- first_allele_vectors => [ 'MOHFAS0001_A_H02' ],
- second_allele_vectors => [ 'MOHSAS0001_A_H02' ],
- first_electorporations => [ 'FEP0006_A01' ],
- second_electroporations => [ 'SEP0006_C01' ]
+ first_allele_designs => [ 34188 ],
+ first_allele_design_wells => [ '56_G04' ],
+ second_allele_designs => [ 34188 ],
+ second_allele_design_wells => [ '56_G04' ],
+ first_allele_vector_wells => [ 'MOHFAS0001_A_H02' ],
+ second_allele_vector_wells => [ 'MOHSAS0001_A_H02' ],
+ first_electroporation_wells => [ 'FEP0006_A01' ],
+ second_electroporation_wells => [ 'SEP0006_C01' ]
}
);
@@ -52,8 +52,8 @@ sub run_allele_request_test {
for my $method (
qw( first_allele_designs second_allele_designs
first_allele_design_wells second_allele_design_wells
- first_allele_vectors second_allele_vectors
- first_electroporations second_electroporations
+ first_allele_vector_wells second_allele_vector_wells
+ first_electroporation_wells second_electroporation_wells
) ) {
check_lives_and_cmp_bag( $ar, $test_data, $method );
}

0 comments on commit 84abce0

Please sign in to comment.