Skip to content
Browse files

Don't re-implement the graph traversal, use depth_first_traversal() a…

…nd take the performance hit of querying ancestors rather than tracking state as the graph is traversed
  • Loading branch information...
1 parent 84abce0 commit 960ad79075a805a16f1d7ddcd2202e023861adef Ray Miller committed Jul 30, 2012
Showing with 7 additions and 47 deletions.
  1. +7 −47 lib/LIMS2/AlleleRequest.pm
View
54 lib/LIMS2/AlleleRequest.pm
@@ -67,11 +67,10 @@ sub final_vector_wells {
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;
- }
+ my $it = $design_well->descendants->depth_first_traversal($design_well, 'out');
+ while ( my $well = $it->next ) {
+ push @final_vector_wells, $well
+ if $well->plate->type_id eq 'FINAL' && $self->satisfies_cassette_function( $cassette_function, $well );
}
}
@@ -80,58 +79,19 @@ sub final_vector_wells {
## no critic(RequireFinalReturn)
sub satisfies_cassette_function {
- my ( $self, $function, $cassette, $recombinases ) = @_;
+ my ( $self, $function, $well ) = @_;
if ( $function eq 'ko_first' ) {
- return $cassette->conditional && ! @{$recombinases};
+ return $well->cassette->conditional && ! @{$well->recombinases};
}
elsif ( $function eq 'reporter_only' ) {
- return $cassette->conditional && any { $_ eq 'Cre' } @{$recombinases};
+ return $well->cassette->conditional && any { $_ eq 'Cre' } @{$well->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:
#
# gene_id: Snf8 ( MGI:1343161 )

0 comments on commit 960ad79

Please sign in to comment.
Something went wrong with that request. Please try again.