Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'devel' into crispr_qc_variant_type
  • Loading branch information
sajp committed Dec 2, 2014
2 parents 2e4777c + 775265c commit a3e2d44
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 34 deletions.
127 changes: 99 additions & 28 deletions lib/LIMS2/Model/Util/LegacyCreKnockInProjectReport.pm
Expand Up @@ -16,7 +16,7 @@ Cre KnockIn projects.
use Moose;
use Try::Tiny;
use LIMS2::Util::Tarmits;
use List::MoreUtils qw( any part );
use List::MoreUtils qw( any part uniq );
use namespace::autoclean;

with qw( MooseX::Log::Log4perl );
Expand Down Expand Up @@ -44,7 +44,7 @@ has projects => (
);

has project_id => (
is => 'ro',
is => 'ro',
isa => 'Int',
);

Expand Down Expand Up @@ -76,7 +76,7 @@ has project_well_summary_data => (
lazy_build => 1,
handles => {
have_project_data => 'exists',
get_project_data => 'get',
get_project_data => 'get',
}
);

Expand Down Expand Up @@ -119,18 +119,35 @@ sub generate_report_data {
};
$marker_symbol = $gene ? $gene->{gene_symbol} : undef;
}
my $htgt_project_id = $project->htgt_project_id ? $project->htgt_project_id : '';

my $project_status
= $project_data ? $self->find_project_status( $project, $project_data ) : '';
my $project_status = '';
my $allele_details = {};
if ( $project_data ) {
my @es_cell_names = map { $_->{clone_plate_name} . '_' . $_->{clone_well_name} }
grep { $_->{clone_well_id} } @{ $project_data->{ws} };
my @emi_attempts = @{ $self->emi_attempts( \@es_cell_names ) };

$project_status = $self->find_project_status( $project, $project_data, \@emi_attempts );

# Can only get allele details for projects with the following statuses
# Mice - genotype confirmed
# Mice - Microinjection in progress
# ES Cells - Targeting Confirmed
if ( $project_status =~ /^Mice|Targeting Confirmed/ ) {
$allele_details = $self->find_allele_names( \@es_cell_names, \@emi_attempts );
}
}
$self->log->info( "Status: $project_status" );

push @report_data, [
$htgt_project_id,
$project->id,
$marker_symbol,
$project->gene_id,
$project_status,
join( ' | ', keys %{ $allele_details } ),
join( ' | ', values %{ $allele_details } ),
scalar( keys %{ $allele_details } ),
$project_data->{cassette},
$project_data->{design_id},
]
};
Log::Log4perl::NDC->remove;
Expand All @@ -146,29 +163,27 @@ work out status of project
=cut
sub find_project_status {
my ( $self, $project, $project_data ) = @_;
my ( $self, $project, $project_data, $emi_attempts ) = @_;

my $ws_rows = $project_data->{ws};

$self->log->debug( 'Project has ' . scalar(@{ $ws_rows }) . ' summary row(s)' );

my @dist_es_cells = @{ $self->distributable_es_cells( $ws_rows ) };

my @emi_attempts = @{ $self->emi_attempts( $ws_rows ) };
my @dist_es_cells = @{ $self->distributable_es_cells( $ws_rows ) };

$self->log->debug('Considering status: Mice - genotype confirmed');

# Status is 'Mice - genotype confirmed' if there are any EMI attempts
# with status 'Genotype confirmed'
if ( any { $_->{status_name} eq 'Genotype confirmed' } @emi_attempts ) {
if ( any { $_->{status_name} eq 'Genotype confirmed' } @{ $emi_attempts } ) {
return 'Mice - genotype confirmed';
}

$self->log->debug('Considering status: Mice - Microinjection in progress');

# Status is 'Mice - Microinjection in progress' if there ane any
# EMI attempts
if (@emi_attempts) {
if (@{ $emi_attempts }) {
return 'Mice - Microinjection in progress';
}

Expand Down Expand Up @@ -264,13 +279,9 @@ Retrieve any EMI attempts for the ES cells from Tarmits.
=cut
sub emi_attempts {
my ( $self, $ws_rows ) = @_;
my $status = 'foo';

my @es_cell_names = map { $_->{clone_plate_name} . '_' . $_->{clone_well_name} }
grep { $_->{clone_well_id} } @{$ws_rows};
my ( $self, $es_cell_names ) = @_;

my @es_cell_name_arrays = $self->chunk_array( \@es_cell_names );
my @es_cell_name_arrays = $self->chunk_array( $es_cell_names );

my @emi_attempts;
for my $name_array ( @es_cell_name_arrays ) {
Expand All @@ -289,9 +300,65 @@ sub emi_attempts {
push @emi_attempts, @{ $emi_attempts };
}

# Ignore attempts where MI has been aborted
@emi_attempts = grep { $_->{status_name} ne 'Micro-injection aborted' } @emi_attempts;

return \@emi_attempts;
}

=head2 find_allele_names
Retrieve allele names for the ES cells from Tarmits.
=cut
sub find_allele_names {
my ( $self, $es_cell_names, $emi_attempts ) = @_;

my @es_cell_name_arrays = $self->chunk_array( $es_cell_names );

my @es_cells;
for my $name_array ( @es_cell_name_arrays ) {
my @query;
for my $es_cell_name ( @{ $name_array } ) {
push @query, ( 'name_in[]' => $es_cell_name );
}

my $es_cells = try{
$self->tarmits_client->find_es_cell( \@query );
}
catch {
$self->log->error( "Error querying tarmits: $_" );
return [];
};
push @es_cells, @{ $es_cells };
}
# Grab allele information from Tarmits
my @allele_names = uniq grep{ $_ } map { $_->{mgi_allele_symbol_superscript} } @es_cells;
my $allele_products = $self->allele_products( $emi_attempts );

return { map { $_ => exists $allele_products->{$_} ? 'Mice' : 'ES Cells' } @allele_names };
}

=head2 allele_products
Work out if allele has Mice or ES Cell products.
Mice will be available if a MI attempt status is set to Genotyping Confirmed
=cut
sub allele_products {
my ( $self, $emi_attempts ) = @_;

my @mice = grep{ $_->{status_name} eq 'Genotype confirmed' } @{ $emi_attempts };

my %allele_mice;
for my $e ( @mice ) {
$e->{allele_symbol} =~ /<sup>(.*)<\/sup>/;
$allele_mice{$1} = $e->{status_name};
}

return \%allele_mice;
}

=head2 chunk_array
Split up a array into seperate arrays of specific max size
Expand Down Expand Up @@ -353,7 +420,6 @@ my $sql_query = <<"SQL";
WITH project_requests AS (
SELECT
p.id AS project_id,
p.htgt_project_id,
p.gene_id,
p.targeting_type,
pa.mutation_type,
Expand All @@ -371,13 +437,14 @@ AND p.species_id = 'Mouse'
)
SELECT
pr.project_id,
pr.htgt_project_id,
s.design_id AS design_id,
s.design_gene_id AS gene_id,
s.design_gene_symbol AS gene_symbol,
s.final_pick_plate_name AS tv_plate_name,
s.final_pick_well_name AS tv_well_name,
s.final_pick_well_id AS tv_well_id,
s.final_pick_well_accepted AS tv_accepted,
s.final_pick_cassette_name AS cassette,
s.ep_plate_name AS ep_plate_name,
s.ep_well_name AS ep_well_name,
s.ep_well_id AS ep_well_id,
Expand Down Expand Up @@ -426,13 +493,14 @@ AND (
AND s.final_pick_well_id > 0
GROUP BY
pr.project_id,
pr.htgt_project_id,
s.design_id,
s.design_gene_id,
s.design_gene_symbol,
s.final_pick_plate_name,
s.final_pick_well_name,
s.final_pick_well_id,
s.final_pick_well_accepted,
s.final_pick_cassette_name,
s.ep_plate_name,
s.ep_well_name,
s.ep_well_id,
Expand Down Expand Up @@ -471,17 +539,20 @@ sub parse_project_well_summary_results {
my %project_well_data;

for my $datum ( @{ $query_results } ) {
my $project_id = $datum->{project_id };
my $project_id = $datum->{project_id};
push @{ $project_well_data{$project_id}{ws} }, $datum;

if ( $datum->{htgt_project_id} && !exists $project_well_data{$project_id}{htgt_project_id} ) {
$project_well_data{$project_id}{htgt_project_id} = $datum->{htgt_project_id};
}

if ( $datum->{gene_symbol} && !exists $project_well_data{$project_id}{gene} ) {
$project_well_data{$project_id}{gene} = $datum->{gene_symbol};
}

if ( $datum->{cassette} && !exists $project_well_data{$project_id}{cassette} ) {
$project_well_data{$project_id}{cassette} = $datum->{cassette};
}

if ( $datum->{design_id} && !exists $project_well_data{$project_id}{design_id} ) {
$project_well_data{$project_id}{design_id} = $datum->{design_id};
}
}

return \%project_well_data;
Expand Down
7 changes: 5 additions & 2 deletions lib/LIMS2/Report/LegacyCreKnockInProjects.pm
Expand Up @@ -16,11 +16,14 @@ override _build_name => sub {
override _build_columns => sub {
return [
qw(
htgt_project_id
lims2_project_id
marker_symbol
mgi_gene_id
status
allele_names
allele_products
num_alleles
cassette
design_id
)
];
};
Expand Down
6 changes: 3 additions & 3 deletions lib/LIMS2/WebApp/Controller/User/CreateDesign.pm
Expand Up @@ -471,7 +471,7 @@ sub wge_design_importer :Path( '/user/wge_design_importer' ) : Args(0) {
);
my $design_id = $c->request->param('design_id');

$c->log->info('Importing WGE design: $design_id');
$c->log->info("wge_design_importer: Importing WGE design: $design_id");

my $design_data = $client->GET( 'design', { id => $design_id, supress_relations => 0 } );

Expand Down Expand Up @@ -533,11 +533,11 @@ sub wge_design_importer :Path( '/user/wge_design_importer' ) : Args(0) {
assembly_id => $species_default_assembly_id,
} );
}
$c->log->debug( "Successfull design creation with id $design_id" );
$c->log->info( "wge_design_importer: Successfull design creation with id $design_id" );
$c->stash( success_msg => "Successfully imported from WGE design with id $design_id" );
}
catch ($err) {
$c->log->warn("Unable to create design: $err");
$c->log->info("wge_design_importer: Unable to create design: $err");
$c->stash( error_msg => "Error importing WGE design: $err" );
$c->model('Golgi')->txn_rollback;
return;
Expand Down
30 changes: 29 additions & 1 deletion lib/LIMS2/WebApp/Controller/User/Graph.pm
Expand Up @@ -84,6 +84,16 @@ sub index :Path :Args(0) {
return;
}

my $plate;
try{
$plate = $c->model('Golgi')->retrieve_plate({ name => $pr_plate_name });
};

unless($plate){
$c->stash( error_msg => "Plate $pr_plate_name not found" );
return;
}

try{
my $uuid = $self->_write_plate_graph($pr_plate_name, $pr_graph_type);
$c->stash( graph_uri => $c->uri_for( "/user/graph/render/$uuid" ) );
Expand All @@ -106,7 +116,25 @@ sub index :Path :Args(0) {
return;
}

my $well = $c->model('Golgi')->retrieve_well( { plate_name => $plate_name, well_name => $well_name } );
my $plate;
try{
$plate = $c->model('Golgi')->retrieve_plate({ name => $plate_name });
};

unless($plate){
$c->stash( error_msg => "Plate $plate_name not found" );
return;
}

my $well;
try{
$well = $c->model('Golgi')->retrieve_well( { plate_name => $plate_name, well_name => $well_name } );
};

unless($well){
$c->stash( error_msg => "Well $well_name not found on plate $plate_name");
return;
}

# If the well has no design, it means its a crispr already, so no need to include crisprs
my $has_design;
Expand Down

0 comments on commit a3e2d44

Please sign in to comment.