Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrego committed Apr 29, 2015
2 parents e5cd200 + bdc31ec commit e7f6365
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 76 deletions.
173 changes: 108 additions & 65 deletions lib/LIMS2/WebApp/Controller/PublicReports.pm
Expand Up @@ -565,92 +565,134 @@ Public gene report, only show targeted clone details:
## no critic (Subroutines::ProhibitExcessComplexity)
sub public_gene_report :Path( '/public_reports/gene_report' ) :Args(1) {
my ( $self, $c, $gene_id ) = @_;
$c->log->info( "Generate public gene report page for gene: $gene_id" );

# by default type is Targeted, Distributable as an option
my $type = 'Targeted';
if ($c->request->param('type') eq 'distributable') {
$type = 'Distributable';
}

$c->log->info( "Generate public $type clone report page for gene: $gene_id" );
my $model = $c->model('Golgi');
my $species = $c->session->{selected_species} || 'Human';

my $designs = $model->c_list_assigned_designs_for_gene(
{ gene_id => $gene_id, species => $species } );
my @design_ids = map { $_->id } @{ $designs };
# get the gene name/symbol
my $gene = $model->find_gene({
species => $species,
search_term => $gene_id
});

my $gene_symbol = $gene->{'gene_symbol'};
$gene_id = $gene->{'gene_id'};

# grab all summary rows for the designs which have ep_pick wells
# get the summary rows
my $design_summaries_rs = $model->schema->resultset('Summary')->search(
{
'me.design_id' => { 'IN' => \@design_ids },
'me.ep_pick_well_id' => { '!=' => undef },
design_gene_id => $gene_id,
ep_pick_plate_name => { '!=', undef },
to_report => 't',
},
{ distinct => 1 }
);

my $gene_symbol;
my %targeted_clones;
# start colecting the clones data, starting by the targeted clones
my %clones;
while ( my $sr = $design_summaries_rs->next ) {
$gene_symbol = $model->find_gene({
species => $species,
search_term => $gene_id
})->{'gene_symbol'};
next if exists $targeted_clones{ $sr->ep_pick_well_id };

my %data;
$data{id} = $sr->ep_pick_well_id;
$data{name} = $sr->ep_pick_plate_name . '_' . $sr->ep_pick_well_name;
$data{plate_name} = $sr->ep_pick_plate_name;
$data{well_name} = $sr->ep_pick_well_name;
$data{accepted} = $sr->ep_pick_well_accepted ? 'yes' : 'no';
$data{created_at} = $sr->ep_pick_well_created_ts->ymd;
next if (!defined $sr->ep_pick_well_id || exists $clones{ $sr->ep_pick_well_id } );
my %ep_pick_data;
$ep_pick_data{id} = $sr->ep_pick_well_id;
$ep_pick_data{name} = $sr->ep_pick_plate_name . '_' . $sr->ep_pick_well_name;
$ep_pick_data{plate_name} = $sr->ep_pick_plate_name;
$ep_pick_data{well_name} = $sr->ep_pick_well_name;
$ep_pick_data{accepted} = $sr->ep_pick_well_accepted ? 'yes' : 'no';
$ep_pick_data{created_at} = $sr->ep_pick_well_created_ts->ymd;

# get crispr es qc data if available
if ( $sr->ep_pick_well_accepted && $sr->crispr_ep_well_name ) {
my $well = $model->schema->resultset('Well')->find( { id => $sr->ep_pick_well_id } );
my $gene_finder = sub { $model->find_genes( @_ ) };
# grab data for alignment popup
try { $data{crispr_qc_data} = $well->genotyping_info( $gene_finder, 1 ) };

# grab data for crispr damage type
# only on validated runs...
my @crispr_es_qc_wells = $model->schema->resultset('CrisprEsQcWell')->search(
{
well_id => $sr->ep_pick_well_id,
'crispr_es_qc_run.validated' => 1,
},
{
join => 'crispr_es_qc_run'

}
);

my @crispr_damage_types = uniq grep { $_ } map{ $_->crispr_damage_type_id } @crispr_es_qc_wells;
my $well = $model->schema->resultset('Well')->find( { id => $sr->ep_pick_well_id } );
my $gene_finder = sub { $model->find_genes( @_ ) };
# grab data for alignment popup
try { $ep_pick_data{crispr_qc_data} = $well->genotyping_info( $gene_finder, 1 ) };

# grab data for crispr damage type
# only on validated runs...
my @crispr_es_qc_wells = $model->schema->resultset('CrisprEsQcWell')->search(
{
well_id => $sr->ep_pick_well_id,
'crispr_es_qc_run.validated' => 1,
},
{
join => 'crispr_es_qc_run'

if ( scalar( @crispr_damage_types ) == 1 ) {
$data{crispr_damage} = $crispr_damage_types[0];
}
elsif ( scalar( @crispr_damage_types ) > 1 ) {
# remove any non accepted results
@crispr_damage_types = uniq grep {$_}
map { $_->crispr_damage_type_id } grep { $_->accepted } @crispr_es_qc_wells;

if ( scalar( @crispr_damage_types ) > 1 ) {
$c->log->warn( $data{name}
. ' ep_pick well has multiple crispr damage types associated with it: '
. join( ', ', @crispr_damage_types ) );
$data{crispr_damage} = '-';
}
else {
$data{crispr_damage} = $crispr_damage_types[0];
}
);

my @crispr_damage_types = uniq grep { $_ } map{ $_->crispr_damage_type_id } @crispr_es_qc_wells;

if ( scalar( @crispr_damage_types ) == 1 ) {
$ep_pick_data{crispr_damage} = $crispr_damage_types[0];
}
elsif ( scalar( @crispr_damage_types ) > 1 ) {
# remove any non accepted results
@crispr_damage_types = uniq grep {$_}
map { $_->crispr_damage_type_id } grep { $_->accepted } @crispr_es_qc_wells;

if ( scalar( @crispr_damage_types ) > 1 ) {
$c->log->warn( $ep_pick_data{name}
. ' ep_pick well has multiple crispr damage types associated with it: '
. join( ', ', @crispr_damage_types ) );
$ep_pick_data{crispr_damage} = '-';
}
else {
$c->log->warn( $data{name}
. ' ep_pick well has no crispr damage type associated with it' );
$data{crispr_damage} = '-';
$ep_pick_data{crispr_damage} = $crispr_damage_types[0];
}
}
$targeted_clones{ $sr->ep_pick_well_id } = \%data;
else {
$c->log->warn( $ep_pick_data{name}
. ' ep_pick well has no crispr damage type associated with it' );
$ep_pick_data{crispr_damage} = '-';
}

# save the clone if targeted clones, keep qc data for distributable clones
$clones{ $sr->ep_pick_well_id } = \%ep_pick_data unless ( $type eq 'Distributable' );

# no need to the distributable clones unless we want them
next unless ( $type eq 'Distributable' );

# get the PIQ clones
if ( defined $sr->piq_well_id && !exists $clones{ $sr->piq_well_id } ) {
my %data;
$data{id} = $sr->piq_well_id;
$data{name} = $sr->piq_plate_name . '_' . $sr->piq_well_name;
$data{plate_name} = $sr->piq_plate_name;
$data{well_name} = $sr->piq_well_name;
$data{accepted} = $sr->piq_well_accepted ? 'yes' : 'no';
$data{created_at} = $sr->piq_well_created_ts->ymd;
$data{crispr_damage} = $ep_pick_data{crispr_damage};
$data{crispr_qc_data} = $ep_pick_data{crispr_qc_data};

$clones{ $sr->piq_well_id } = \%data;
}

# get the ancestor PIQ clones
if ( defined $sr->ancestor_piq_well_id && !exists $clones{ $sr->ancestor_piq_well_id } ) {
my %data;
$data{id} = $sr->ancestor_piq_well_id;
$data{name} = $sr->ancestor_piq_plate_name . '_' . $sr->ancestor_piq_well_name;
$data{plate_name} = $sr->ancestor_piq_plate_name;
$data{well_name} = $sr->ancestor_piq_well_name;
$data{accepted} = $sr->ancestor_piq_well_accepted ? 'yes' : 'no';
$data{created_at} = $sr->ancestor_piq_well_created_ts->ymd;
$data{crispr_damage} = $ep_pick_data{crispr_damage};
$data{crispr_qc_data} = $ep_pick_data{crispr_qc_data};

$clones{ $sr->ancestor_piq_well_id } = \%data;
}
}

my @targeted_clones = sort _sort_by_damage_type values %targeted_clones;
my @clones = sort _sort_by_damage_type values %clones;

my %summaries;
for my $tc ( @targeted_clones ) {
for my $tc ( @clones ) {
$summaries{genotyped}++ if ($tc->{crispr_damage} && ($tc->{crispr_damage} eq 'frameshift' ||
$tc->{crispr_damage} eq 'in-frame' || $tc->{crispr_damage} eq 'wild_type' || $tc->{crispr_damage} eq 'mosaic') );
$summaries{ $tc->{crispr_damage} }++ if ($tc->{crispr_damage} && $tc->{crispr_damage} ne 'unclassified');
Expand All @@ -660,7 +702,8 @@ sub public_gene_report :Path( '/public_reports/gene_report' ) :Args(1) {
'gene_id' => $gene_id,
'gene_symbol' => $gene_symbol,
'summary' => \%summaries,
'targeted_clones' => \@targeted_clones,
'clones' => \@clones,
'type' => $type,
);
return;
}
Expand Down
14 changes: 9 additions & 5 deletions root/site/publicreports/public_gene_report.tt
Expand Up @@ -79,7 +79,7 @@ function toggle_btn(btn, show_or_hide) {
<div class="row">
<div class="span6 offset3">
<div class="well">
<h4 align="center">Targeted Clones Summary</h4>
<h4 align="center">[% type %] Clones Summary</h4>
<dl class="dl-horizontal">
<dt>Genotyped</dt>
<dd>[% summary.genotyped %]</dd>
Expand All @@ -103,7 +103,7 @@ function toggle_btn(btn, show_or_hide) {
</div>
</div>

<h3>Targeted Clones</h3>
<h3>[% type %] Clones</h3>

<button type="button" class="btn btn-info" data-toggle="button" id="epd_accepted_show_toggle" data="show">Show Non Accepted Wells</button>

Expand All @@ -120,7 +120,7 @@ function toggle_btn(btn, show_or_hide) {
<th>Detailed Description</th>
</thead>
<tbody>
[% FOREACH well IN targeted_clones %]
[% FOREACH well IN clones %]
<tr>
<td>[% well.name %]</td>
<td>[% well.plate_name %]</td>
Expand All @@ -129,7 +129,7 @@ function toggle_btn(btn, show_or_hide) {
<td class="accepted"> [% well.accepted %] </td>
<td><a href="[% c.uri_for( '/public_reports/well_eng_seq', well.id ) %]"><i class="icon-file"></i></a></td>
<td>
[% IF well.crispr_qc_data && well.accepted %]
[% IF well.crispr_qc_data %]
<a href="#" class="crispr_qc_accepted">
<!-- insert alignments but hidden -->
<div style="display:none">
Expand All @@ -142,7 +142,11 @@ function toggle_btn(btn, show_or_hide) {
[% IF well.crispr_qc_data %]</a>[% END %]
</td>
<td>[% well.crispr_qc_data.variant_size %]</td>
<td><a href="[% c.uri_for( '/public_reports/well_genotyping_info', well.plate_name, well.well_name ) %]" target="_blank" ><i class="icon-info-sign"></i></a></td>
<td>
[% IF well.crispr_qc_data %]
<a href="[% c.uri_for( '/public_reports/well_genotyping_info', well.plate_name, well.well_name ) %]" target="_blank" ><i class="icon-info-sign"></i></a>
[% END %]
</td>
</tr>
[%- END %]
</tbody>
Expand Down
11 changes: 6 additions & 5 deletions root/site/publicreports/sponsor_sub_report.tt
Expand Up @@ -185,11 +185,11 @@ document.title = "[%- sponsor_id %]";

[%- ELSIF col == 'targeted_clones' %]
[%- IF row.item('targeted_clones') && row.item('chromosome') == "X" %]
<td style="background:#FFA500">[%- colval %]</td>
<td style="background:#FFA500"><a class="brand" href="[% c.uri_for('/public_reports/gene_report', row.item('gene_id') ) %]">[%- colval %]</a></td>
[% ELSIF row.item('targeted_clones') && row.item('fs_count') %]
<td style="background:#8AD95A">[%- colval %]</td>
<td style="background:#8AD95A"><a class="brand" href="[% c.uri_for('/public_reports/gene_report', row.item('gene_id') ) %]">[%- colval %]</a></td>
[% ELSIF row.item('targeted_clones') %]
<td style="background:#FF4646">[%- colval %]</td>
<td style="background:#FF4646"><a class="brand" href="[% c.uri_for('/public_reports/gene_report', row.item('gene_id') ) %]">[%- colval %]</a></td>
[% ELSE %]
<td></td>
[% END %]
Expand All @@ -199,17 +199,18 @@ document.title = "[%- sponsor_id %]";
|| col == 'ms_count' %]

[% IF row.item('targeted_clones') %]
<td style="background:#E5E4E2" ><a class="brand" href="[% c.uri_for('/public_reports/gene_report', row.item('gene_id') ) %]">[% colval %]</a></td>
<td style="background:#E5E4E2" >[% colval %]</td>
[% ELSE %]
<td></td>
[% END %]
[%- ELSIF !colval %]
<td></td>
[%- ELSIF col == 'passing_vector_wells'
|| col == 'accepted_crispr_vector'
|| col == 'distrib_clones'
%]
<td style="background:#8AD95A">[%- colval %]</td>
[%- ELSIF col == 'distrib_clones' %]
<td style="background:#8AD95A"><a class="brand" href="[% c.uri_for('/public_reports/gene_report', row.item('gene_id'), { 'type' => 'distributable' } ) %]">[%- colval %]</a></td>
[%- ELSIF col == 'crispr_pairs'
|| col == 'vector_designs'
|| col == 'vector_wells'
Expand Down
96 changes: 95 additions & 1 deletion root/site/user/report/generic_report_grid.tt
Expand Up @@ -305,7 +305,101 @@
simpleSelect: true,
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', { clicksToEdit: 2 })
]
],
tools:[

{
id : 'download_csv_file_btn',
type : 'save',
minHeight : '20',
minWidth : '20',
handler : function(event, toolEl, panel){
DownloadCsvFile(grid);
}
},

],
});

var tooltips = [{
target : 'download_csv_file_btn',
html : 'Click to download the grid data as a CSV spreadsheet file'
}];

Ext.each(tooltips, function(config) {
Ext.create('Ext.tip.ToolTip', config);
});


function DownloadCsvFile(grid) {
var cols = grid.columns;
var store = grid.store;
var data = '';

var that = this;
Ext.Array.each(cols, function(col, index) {
if (col.hidden != true) {

var text1;

if (col.text == null || col.text == undefined) {
text1 = '';
} else {
text1 = col.text;
}
if (text1.match(/,/)) {
if (!text1.match(/"/)) {
text1 = '"' + text1 + '"';
} else {
text1 = text1.replace(/,/g, ''); // comma's and quotes-- sorry, just loose the commas
}
}
data += text1 + ',';
}
});
data += "\n";

store.each(function(record) {
var entry = record.getData();
Ext.Array.each(cols, function(col, index) {
if (col.hidden != true) {
var fieldName = col.dataIndex;
var text = entry[fieldName];

var text2;

if (text == null || text == undefined) {
text2 = '';
} else if (!text.match) { // a checkcolumn object
text2 = text;
} else {
text2 = text;
if (text2.match(/,/)) {
if (!text2.match(/"/)) {
text2 = '"' + text2 + '"';
} else {
text2 = text2.replace(/,/g, ''); // comma's and quotes-- sorry, just loose the commas
}
}
}

data += text2 + ',';
}
});
data += "\n";
});

// window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(data);

var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(data);
var downloadLink = document.createElement("a");
downloadLink.href = uri;
downloadLink.download = "grid.csv";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);

};

});
</script>

0 comments on commit e7f6365

Please sign in to comment.