Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KASP and VCF download from project page #4689

Merged
merged 7 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/source/legacy/CXGN/BreedersToolbox/GenotypingTrial.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ jQuery(document).ready(function ($) {
return;
}
if (response.success) {
var success_string = "<h4>Go to new <a href='/breeders_toolbox/protocol/"+response.nd_protocol_id+"'>protocol detail page</a></h4>";
var success_string = "<h4>Go to your <a href='/breeders/trial/"+response.project_id+"'>genotyping project page</a></h4>";
console.log(success_string);
jQuery('#upload_genotype_submit_complete').html(success_string);
Workflow.complete('#upload_genotype_submit');
Expand Down
9 changes: 8 additions & 1 deletion lib/CXGN/Genotype/Download/KASPdata.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ has 'protocol_id_list' => (
is => 'rw',
);

has 'genotype_data_project_list' => (
isa => 'ArrayRef[Int]|Undef',
is => 'ro',
);

has 'genotypeprop_hash_select' => (
isa => 'ArrayRef[Str]',
is => 'ro',
Expand All @@ -64,13 +69,15 @@ sub download {
my $schema = $self->bcs_schema;
my $people_schema = $self->people_schema;
my $protocol_id_list = $self->protocol_id_list;
my $genotyping_project_list = $self->genotype_data_project_list;
my $genotypeprop_hash_select = ['NT', 'XV', 'YV'];
my $return_only_first_genotypeprop_for_stock = $self->return_only_first_genotypeprop_for_stock;

my $genotypes_search = CXGN::Genotype::Search->new({
bcs_schema=>$schema,
people_schema=>$people_schema,
protocol_id_list=>$protocol_id_list,
genotype_data_project_list=>$genotyping_project_list,
genotypeprop_hash_select=>$genotypeprop_hash_select
});

Expand Down
2 changes: 1 addition & 1 deletion lib/CXGN/Genotype/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ sub init_genotype_iterator {
}

#For genotyping_data_project
if ($genotype_data_project_list && scalar($genotype_data_project_list)>0) {
if ($genotype_data_project_list && scalar(@$genotype_data_project_list)>0) {
my $sql = join ("," , @$genotype_data_project_list);
push @where_clause, "project.project_id in ($sql)";
}
Expand Down
34 changes: 29 additions & 5 deletions lib/SGN/Controller/BreedersToolbox/Download.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ sub download_gbs_action : Path('/breeders/download_gbs_action') {
my $forbid_cache = defined($c->req->param('forbid_cache')) ? $c->req->param('forbid_cache') : 0;
my $dl_token = $c->req->param("gbs_download_token") || "no_token";
my $dl_cookie = "download".$dl_token;

my $genotyping_project_id = $c->req->param("genotyping_project_id");
my (@accession_ids, @accession_list, @accession_genotypes, @unsorted_markers, $accession_data, $id_string, $protocol_id, $trial_id_string, @trial_ids);

$trial_id_string = $c->req->param("trial_ids");
Expand All @@ -1069,11 +1069,12 @@ sub download_gbs_action : Path('/breeders/download_gbs_action') {
$id_string = $c->req->param("ids");
@accession_ids = split(',',$id_string);
$protocol_id = $c->req->param("protocol_id");
if (!$protocol_id){
if ((!defined $protocol_id) && (!defined $genotyping_project_id)){
my $default_genotyping_protocol = $c->config->{default_genotyping_protocol};
$protocol_id = $schema->resultset('NaturalDiversity::NdProtocol')->find({name=>$default_genotyping_protocol})->nd_protocol_id();
}
}

elsif ($format eq 'list_id') { #get accession names from list and tranform them to ids
my $accession_list_id = $c->req->param("genotype_accession_list_list_select");
$protocol_id = $c->req->param("genotyping_protocol_select");
Expand Down Expand Up @@ -1115,6 +1116,16 @@ sub download_gbs_action : Path('/breeders/download_gbs_action') {
}
}

my @protocol_list;
if (defined $protocol_id) {
push @protocol_list, $protocol_id;
}

my @genotyping_project_list;
if (defined $genotyping_project_id) {
push @genotyping_project_list, $genotyping_project_id;
}

my $geno = CXGN::Genotype::DownloadFactory->instantiate(
$download_format, #can be either 'VCF' or 'DosageMatrix'
{
Expand All @@ -1124,7 +1135,7 @@ sub download_gbs_action : Path('/breeders/download_gbs_action') {
accession_list=>\@accession_ids,
#tissue_sample_list=>$tissue_sample_list,
trial_list=>\@trial_ids,
protocol_id_list=>[$protocol_id],
protocol_id_list=>\@protocol_list,
chromosome_list=>$chromosome_numbers,
start_position=>$start_position,
end_position=>$end_position,
Expand All @@ -1133,7 +1144,7 @@ sub download_gbs_action : Path('/breeders/download_gbs_action') {
marker_name_list=>\@marker_name_list,
return_only_first_genotypeprop_for_stock=>$return_only_first_genotypeprop_for_stock,
#markerprofile_id_list=>$markerprofile_id_list,
#genotype_data_project_list=>$genotype_data_project_list,
genotype_data_project_list=>\@genotyping_project_list,
#limit=>$limit,
#offset=>$offset
}
Expand Down Expand Up @@ -1649,6 +1660,18 @@ sub download_kasp_genotyping_data_csv : Path('/breeders/download_kasp_genotyping
my $schema = $c->dbic_schema("Bio::Chado::Schema", "sgn_chado");
my $people_schema = $c->dbic_schema("CXGN::People::Schema");
my $protocol_id = $c->req->param("protocol_id");
my $genotyping_project_id = $c->req->param("genotyping_project_id");

my @protocol_list;
if (defined $protocol_id) {
push @protocol_list, $protocol_id;
}

my @genotyping_project_list;
if (defined $genotyping_project_id) {
push @genotyping_project_list, $genotyping_project_id;
}


my $dir = $c->tempfiles_subdir('download');
my $temp_file_name = $protocol_id . "_" . "KASP_data" . "XXXX";
Expand All @@ -1664,7 +1687,8 @@ sub download_kasp_genotyping_data_csv : Path('/breeders/download_kasp_genotyping
{
bcs_schema=>$schema,
people_schema=>$people_schema,
protocol_id_list=>[$protocol_id],
protocol_id_list=>\@protocol_list,
genotype_data_project_list=>\@genotyping_project_list,
filename => $tempfile,
}
);
Expand Down
75 changes: 63 additions & 12 deletions lib/SGN/Controller/BreedersToolbox/Trial.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sub trial_init : Chained('/') PathPart('breeders/trial') CaptureArgs(1) {
my $trial_id = shift;

$c->stash->{trial_id} = $trial_id;
print STDERR "TRIAL ID = $trial_id\n";
# print STDERR "TRIAL ID = $trial_id\n";

my $schema = $c->dbic_schema("Bio::Chado::Schema");
$c->stash->{schema} = $schema;
Expand Down Expand Up @@ -209,20 +209,71 @@ sub trial_info : Chained('trial_init') PathPart('') Args(0) {
$c->stash->{genotype_data_type} = 'SNP'
}

my $plate_info = CXGN::Genotype::GenotypingProject->new({
my $project_info = CXGN::Genotype::GenotypingProject->new({
bcs_schema => $schema,
project_id => $project_id
});
my ($data, $tc) = $plate_info->get_plate_info();
my ($data, $tc) = $project_info->get_plate_info();
my $has_plate;
if (!$data) {
$has_plate = 'none';
}
$c->stash->{has_plate} = $has_plate;
my @genotyping_project_list = ($project_id);
my $protocol_info = CXGN::Genotype::Protocol::list($schema, undef, undef, undef, undef, undef, \@genotyping_project_list);
if ($protocol_info) {
$c->stash->{marker_names} = $protocol_info->[0]->{marker_names} || [];

my $associated_protocol = $project_info->get_associated_protocol();

if ( defined $associated_protocol && scalar(@$associated_protocol)>0) {
my $protocol_id = $associated_protocol->[0]->[0];
my $protocol_info = CXGN::Genotype::Protocol->new({
bcs_schema => $schema,
nd_protocol_id => $protocol_id
});

my $marker_names = $protocol_info->{marker_names};
my $assay_type = $protocol_info->{assay_type};
$c->stash->{marker_names} = $marker_names;
$c->stash->{assay_type} = $assay_type;

my $marker_info_keys = $protocol_info->marker_info_keys;
my @marker_info_headers = ();
if (defined $marker_info_keys) {
foreach my $info_key (@$marker_info_keys) {
if ($info_key eq 'name') {
push @marker_info_headers, 'Marker Name';
} elsif (($info_key eq 'intertek_name') || ($info_key eq 'facility_name')) {
push @marker_info_headers, 'Facility Marker Name';
} elsif ($info_key eq 'chrom') {
push @marker_info_headers, 'Chromosome';
} elsif ($info_key eq 'pos') {
push @marker_info_headers, 'Position';
} elsif ($info_key eq 'alt') {
if ($assay_type eq 'KASP') {
push @marker_info_headers, 'Y-allele';
} else {
push @marker_info_headers, 'Alternate';
}
} elsif ($info_key eq 'ref') {
if ($assay_type eq 'KASP') {
push @marker_info_headers, 'X-allele';
} else {
push @marker_info_headers, 'Reference';
}
} elsif ($info_key eq 'qual') {
push @marker_info_headers, 'Quality';
} elsif ($info_key eq 'filter') {
push @marker_info_headers, 'Filter';
} elsif ($info_key eq 'info') {
push @marker_info_headers, 'Info';
} elsif ($info_key eq 'format') {
push @marker_info_headers, 'Format';
} elsif ($info_key eq 'sequence') {
push @marker_info_headers, 'Sequence';
}
}
} else {
@marker_info_headers = ('Marker Name','Chromosome','Position','Alternate','Reference','Quality','Filter','Info','Format');
}
$c->stash->{marker_info_headers} = \@marker_info_headers;
}

$c->stash->{template} = '/breeders_toolbox/genotype_data_project.mas';
Expand Down Expand Up @@ -322,8 +373,8 @@ sub trial_download : Chained('trial_init') PathPart('download') Args(1) {
my $self = shift;
my $c = shift;
my $what = shift;
print STDERR "WHAT =".Dumper($what)."\n";
print STDERR Dumper $c->req->params();
# print STDERR "WHAT =".Dumper($what)."\n";
# print STDERR Dumper $c->req->params();
my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
my $user = $c->user();
if (!$user) {
Expand Down Expand Up @@ -435,7 +486,7 @@ sub trial_download : Chained('trial_init') PathPart('download') Args(1) {
$rel_file = $rel_file . ".$format";
my $tempfile = $c->config->{basepath}."/".$rel_file;

print STDERR "TEMPFILE : $tempfile\n";
# print STDERR "TEMPFILE : $tempfile\n";

my $download = CXGN::Trial::Download->new({
bcs_schema => $schema,
Expand Down Expand Up @@ -474,7 +525,7 @@ sub trial_download : Chained('trial_init') PathPart('download') Args(1) {
sub trials_download_layouts : Path('/breeders/trials/download/layout') Args(0) {
my $self = shift;
my $c = shift;
print STDERR Dumper $c->req->params();
# print STDERR Dumper $c->req->params();
my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
my $user = $c->user();
if (!$user) {
Expand Down Expand Up @@ -510,7 +561,7 @@ sub trials_download_layouts : Path('/breeders/trials/download/layout') Args(0) {
$rel_file = $rel_file . ".$format";
my $tempfile = $c->config->{basepath}."/".$rel_file;

print STDERR "TEMPFILE : $tempfile\n";
# print STDERR "TEMPFILE : $tempfile\n";

my $trial_download_args = {
bcs_schema => $schema,
Expand Down
12 changes: 8 additions & 4 deletions mason/breeders_toolbox/genotype_data_project.mas
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ $genotype_data_type => undef
$trial_owner => undef
$has_plate => undef
$marker_names => undef
$marker_info_headers => undef
$assay_type => undef
</%args>

<& /util/import_javascript.mas, classes => [ 'jquery.iframe-post-form', 'CXGN.Trial' , 'jstree/dist/jstree', 'CXGN.BreedersToolbox.HTMLSelect', 'moment_min', 'daterangepicker' ] &>
Expand All @@ -60,10 +62,12 @@ $marker_names => undef

<& /page/detail_page_2_col_section.mas, trial_id => $trial_id, info_section_title => "<h4 style='display:inline'>Genotyping Protocols</h4>", info_section_subtitle => 'View basic information about the genotyping protocols used in this genotyping project.', icon_class => "glyphicon glyphicon-cog", info_section_id => "genotyping_data_project_protocols" &>

% if ($genotype_data_type ne 'SSR') {
<& /page/detail_page_2_col_section.mas, trial_id => $trial_id, info_section_title => "<h4 style='display:inline'>Genotyping Data</h4>", info_section_subtitle => 'View and download genotyping data.', icon_class => "glyphicon glyphicon-map-marker", info_section_id => "genotyping_data_project_data" &>
% } elsif ($genotype_data_type eq 'SSR') {
<& /page/detail_page_2_col_section.mas, trial_id => $trial_id, marker_names => $marker_names, info_section_title => "<h4 style='display:inline'>Genotype Data</h4>", info_section_subtitle => 'View and download genotyping data from this project.',buttons_html => '<button class="btn btn-sm btn-primary" style="margin:3px" id="download_project_ssr_data_link">Download SSR Data</button>', icon_class => "glyphicon glyphicon-save-file", info_section_id => "project_pcr_genotype_data" &>
% if ($genotype_data_type eq 'SSR') {
<& /page/detail_page_2_col_section.mas, trial_id => $trial_id, marker_names => $marker_names, info_section_title => "<h4 style='display:inline'>Genotype Data</h4>", info_section_subtitle => 'View and download genotyping data from this project.',buttons_html => '<button class="btn btn-sm btn-primary" style="margin:3px" id="download_project_ssr_data_link">Download SSR Data</button>', icon_class => "glyphicon glyphicon-save-file", info_section_id => "project_pcr_genotype_data" &>
% } elsif ($assay_type eq 'KASP') {
<& /page/detail_page_2_col_section.mas, trial_id => $trial_id, info_section_title => "<h4 style='display:inline'>Genotyping Data</h4>", info_section_subtitle => 'View and download genotyping data.', icon_class => "glyphicon glyphicon-map-marker", buttons_html => '<button class="btn btn-primary" style="margin:3px" id="project_genotype_data_download_all_vcf">Download All Genotype Data VCF</button><button class="btn btn-primary" style="margin:3px" id="project_genotype_data_download_all_dosagematrix">Download All Genotype Data Dosage Matrix</button><button class="btn btn-default" style="margin:3px" id="kasp_project_genotype_data_download_all_csv">Download All Genotype Data (CSV)</button>', info_section_id => "genotyping_data_project_data" &>
% } else {
<& /page/detail_page_2_col_section.mas, trial_id => $trial_id, info_section_title => "<h4 style='display:inline'>Genotyping Data</h4>", info_section_subtitle => 'View and download genotyping data.', icon_class => "glyphicon glyphicon-map-marker", buttons_html => '<button class="btn btn-primary" style="margin:3px" id="project_genotype_data_download_all_vcf">Download All Genotype Data VCF</button><button class="btn btn-primary" style="margin:3px" id="project_genotype_data_download_all_dosagematrix">Download All Genotype Data Dosage Matrix</button>', info_section_id => "genotyping_data_project_data" &>
% }

% my $data_agreement_link = '<button class="btn btn-sm btn-primary" disabled style="margin:3px">Add/edit data agreement</button>';
Expand Down
22 changes: 22 additions & 0 deletions mason/breeders_toolbox/genotyping_data_project/genotype_data.mas
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ jQuery(document).ready(function () {
'ajax': '/ajax/genotyping_data/search?genotyping_data_project_id_list=<% $trial_id %>',
});

var refresh_results;
jQuery("#project_genotype_data_forbid_cache").change(function(){
if (jQuery(this).is(":checked")) {
refresh_results = '1';
var project_genotypes_data_table = jQuery('#genotyping_data_project_genotype_data').DataTable({
'destroy' : true,
'searching' : false,
Expand All @@ -50,6 +52,26 @@ jQuery(document).ready(function () {
}
});

jQuery('#project_genotype_data_download_all_vcf').click(function(){
if (refresh_results) {
window.location.replace("/breeders/download_gbs_action/?genotyping_project_id=<% $trial_id %>&download_format=VCF&format=accession_ids&forbid_cache=1");
} else {
window.location.replace("/breeders/download_gbs_action/?genotyping_project_id=<% $trial_id %>&download_format=VCF&format=accession_ids");
}
});

jQuery('#project_genotype_data_download_all_dosagematrix').click(function(){
if (refresh_results) {
window.location.replace("/breeders/download_gbs_action/?genotyping_project_id=<% $trial_id %>&download_format=DosageMatrix&format=accession_ids&forbid_cache=1");
} else {
window.location.replace("/breeders/download_gbs_action/?genotyping_project_id=<% $trial_id %>&download_format=DosageMatrix&format=accession_ids");
}
});

jQuery('#kasp_project_genotype_data_download_all_csv').click(function(){
window.location.replace("/breeders/download_kasp_genotyping_data_csv/?genotyping_project_id=<% $trial_id %>");
});


});

Expand Down
35 changes: 35 additions & 0 deletions t/unit_fixture/CXGN/Uploading/KASPGenotypes.t
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,41 @@ my $genotypes_search_1 = CXGN::Genotype::Search->new({
my ($total_count_1, $data_1) = $genotypes_search_1->get_genotype_info();
is($total_count_1, 5);

#test KASP data download from project page

my $kasp_project_response = $ua->get("http://localhost:3010/breeders/download_kasp_genotyping_data_csv/?genotyping_project_id=$genotyping_project_id_1");
my $kasp_project_message = $kasp_project_response->decoded_content;

my $kasp_data = '"MARKER NAME","SAMPLE NAME","SNP CALL (X,Y)","X VALUE","Y VALUE"
"S01_0001","new_accession_1","T,T","1.36",".58"
"S01_0001","new_accession_2","T,T","1.25",".49"
"S01_0001","new_accession_3","T,G","1.57","1.38"
"S01_0001","new_accession_4","T,G","1.24","1.56"
"S01_0001","new_accession_5","./.",".65",".58"
"S01_0002","new_accession_1","A,A","1.43",".59"
"S01_0002","new_accession_2","A,G","1.25","1.43"
"S01_0002","new_accession_3","A,G","1.22","1.41"
"S01_0002","new_accession_4","A,G","1.11","1.27"
"S01_0002","new_accession_5","A,A","1.65",".62"
"S02_0001","new_accession_1","T,T","1.75",".75"
"S02_0001","new_accession_2","T,T","1.21",".61"
"S02_0001","new_accession_3","T,T","1.17",".46"
"S02_0001","new_accession_4","T,C","1.59","1.46"
"S02_0001","new_accession_5","T,C","1.26","1.31"
"S02_0002","new_accession_1","A,A","1.75",".32"
"S02_0002","new_accession_2","A,A","1.38",".59"
"S02_0002","new_accession_3","A,C","1.36","1.47"
"S02_0002","new_accession_4","A,A","1.75",".74"
"S02_0002","new_accession_5","A,C","1.32","1.46"
"S03_0001","new_accession_1","C,C","1.76",".38"
"S03_0001","new_accession_2","C,C","1.47",".24"
"S03_0001","new_accession_3","C,T","1.86","1.48"
"S03_0001","new_accession_4","C,T","1.23","1.49"
"S03_0001","new_accession_5","C,T","1.11","1.23"
';

is($kasp_project_message, $kasp_data);

#test upload kasp data using facility names
#store facility sample Names
my $plate_file = $f->config->{basepath} . "/t/data/genotype_trial_upload/plate_with_identifier_upload.xls";
Expand Down
4 changes: 4 additions & 0 deletions t/unit_fixture/CXGN/Uploading/VCFGenotypes.t
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ $message = $response->decoded_content;
#print STDERR Dumper $message;
is($message, $dosage_matrix_string);

#testing genotype data download from project page
my $project_response = $ua->get("http://localhost:3010/breeders/download_gbs_action/?genotyping_project_id=$project_id&download_format=VCF&format=accession_ids&forbid_cache=1");
my $project_message = $project_response->decoded_content;
is($project_message, $dosage_matrix_string);

#Testing genotype search with marker names filter from marker set list object
my $marker_names_filtered = ["S1_21594", "S1_21597", "S1_75465"];
Expand Down