diff --git a/R/solGS/gs.r b/R/solGS/gs.r index 85302b58d8..6ace582d74 100644 --- a/R/solGS/gs.r +++ b/R/solGS/gs.r @@ -88,7 +88,7 @@ markerFile <- grep('marker_effects', outputFiles, value = TRUE) modelPhenoFile <- grep('model_phenodata', outputFiles, value = TRUE) message('model input trait pheno file ', modelPhenoFile) modelGenoFile <- grep('model_genodata', outputFiles, value = TRUE) -message('model input trait geno file ', modelPhenoFile) +message('model input trait geno file ', modelGenoFile) traitRawPhenoFile <- grep('trait_raw_phenodata', outputFiles, value = TRUE) varianceComponentsFile <- grep("variance_components", outputFiles, value = TRUE) analysisReportFile <- grep("_report_", outputFiles, value = TRUE) @@ -105,7 +105,7 @@ if (is.null(genoFile)) { } if (file.info(genoFile)$size == 0) { - stop("genotype data file is empty.") + stop(paste0("genotype data file ", genoFile, " is empty.")) } readfilteredTrainingGenoData <- c() @@ -187,7 +187,8 @@ if (length(formattedPhenoFile) != 0 && file.info(formattedPhenoFile)$size != 0) } if (file.info(phenoFile)$size == 0) { - stop("phenotype data file is empty.") + stop(paste0("phenotype data file ", phenoFile, " is empty.")) + } phenoData <- data.frame(fread(phenoFile, diff --git a/js/source/legacy/solGS/cluster.js b/js/source/legacy/solGS/cluster.js index 13b3f1416e..9c2d87e7dd 100644 --- a/js/source/legacy/solGS/cluster.js +++ b/js/source/legacy/solGS/cluster.js @@ -1176,8 +1176,8 @@ jQuery(document).ready(function () { jQuery(jobSubmit).appendTo("body"); jQuery("#cluster_submit").dialog({ - height: 200, - width: 400, + height: "auto", + width: "auto", modal: true, title: "cluster job submission", buttons: { diff --git a/js/source/legacy/solGS/kinship.js b/js/source/legacy/solGS/kinship.js index d95ef1eca6..a25d550c0b 100644 --- a/js/source/legacy/solGS/kinship.js +++ b/js/source/legacy/solGS/kinship.js @@ -239,7 +239,6 @@ solGS.kinship = { }, addDowloandLinks: function (res) { - console.log(`adddownloadlinks res: ${JSON.stringify(res)}`); var popName = res.kinship_pop_name; var kinFileId = res.kinship_file_id; var kinshipFile = res.kinship_table_file; @@ -366,8 +365,8 @@ jQuery(document).ready(function () { jQuery(jobSubmit).appendTo("body"); jQuery("#kinship_submit").dialog({ - height: 200, - width: 400, + height: "auto", + width: "auto", modal: true, title: "Kinship job submission", buttons: { diff --git a/js/source/legacy/solGS/pca.js b/js/source/legacy/solGS/pca.js index ffe2927d01..cbdb5ad037 100644 --- a/js/source/legacy/solGS/pca.js +++ b/js/source/legacy/solGS/pca.js @@ -1008,8 +1008,8 @@ jQuery(document).ready(function () { jQuery(jobSubmit).appendTo("body"); jQuery("#pca_submit").dialog({ - height: 200, - width: 400, + height: "auto", + width: "auto", modal: true, title: "pca job submission", buttons: { diff --git a/js/source/legacy/solGS/solGS.js b/js/source/legacy/solGS/solGS.js index ffd18e6f45..4fca9bfbe4 100644 --- a/js/source/legacy/solGS/solGS.js +++ b/js/source/legacy/solGS/solGS.js @@ -364,6 +364,9 @@ solGS.submitJob = { args["analysis_name"] = analysisName; args["analysis_page"] = page; + var hostname = `${location.protocol}//${location.hostname}`; + args['hostname'] = hostname; + args = JSON.stringify(args); var analysisProfile = { diff --git a/lib/SGN/Controller/solGS/AnalysisQueue.pm b/lib/SGN/Controller/solGS/AnalysisQueue.pm index b0b115e8d0..c93684efe7 100644 --- a/lib/SGN/Controller/solGS/AnalysisQueue.pm +++ b/lib/SGN/Controller/solGS/AnalysisQueue.pm @@ -83,7 +83,7 @@ sub check_analysis_name : Path('/solgs/check/analysis/name') Args() { my ( $self, $c ) = @_; my $new_name = $c->req->param('name'); - my $match = $self->check_analyses_names( $c, $new_name ); + my $match = $self->check_analyses_names( $c, $new_name ); my $ret->{analysis_exists} = $match; $ret = to_json($ret); @@ -261,7 +261,8 @@ sub create_itemized_prediction_log_entries { else { $analysis_page = $c->controller('solGS::Path')->model_page_url($url_args); - $analysis_type = $c->controller('solGS::Path')->page_type($c, $analysis_page); + $analysis_type = + $c->controller('solGS::Path')->page_type( $c, $analysis_page ); } my $analysis_name = @@ -437,7 +438,7 @@ sub parse_arguments { my $analysis_data = $c->stash->{analysis_profile}; my $arguments = $analysis_data->{arguments}; - + if ($arguments) { $c->controller('solGS::Utils')->stash_json_args( $c, $arguments ); } @@ -450,8 +451,13 @@ sub structure_output_details { my $analysis_data = $c->stash->{analysis_profile}; my $analysis_page = $analysis_data->{analysis_page}; - my $referer = $c->req->referer || $analysis_page; - my $base = $c->controller('solGS::Path')->clean_base_name($c); + my $uri_base = $c->req->base; + my $referer = $c->req->referer || $analysis_page; + $referer =~ s/$uri_base//; + + my $base = $c->stash->{hostname}; + $referer = $base . "/" . $referer; + my $output_details = {}; my $match_pages = @@ -526,7 +532,7 @@ sub structure_kinship_analysis_output { $c->controller('solGS::Kinship')->stash_kinship_pop_id($c); my $pop_id = $c->stash->{kinship_pop_id}; - my $base = $c->controller('solGS::Path')->clean_base_name($c); + my $base = $c->stash->{hostname}; my $kinship_page = $base . $analysis_page; $analysis_data->{analysis_page} = $kinship_page; @@ -559,24 +565,27 @@ sub structure_pca_analysis_output { my $analysis_data = $c->stash->{analysis_profile}; my $analysis_page = $analysis_data->{analysis_page}; - my $base = $c->controller('solGS::Path')->clean_base_name($c); + my $base = $c->stash->{hostname}; my $pca_page = $base . $analysis_page; $analysis_data->{analysis_page} = $pca_page; my $pop_id = $c->stash->{pca_pop_id}; - + $c->stash->{file_id} = $c->controller('solGS::Files')->create_file_id($c); my $input_file = $c->controller('solGS::pca')->pca_data_input_files($c); - + $c->controller('solGS::pca')->pca_scores_file($c); my $scores_file = $c->stash->{pca_scores_file}; - my %output_details = ('pca_' . $pop_id => { - 'output_page' => $pca_page, - 'pca_pop_id' => $pop_id, - 'input_file' => $input_file, - 'scores_file' => $scores_file, - }); + my %output_details = ( + 'pca_' + . $pop_id => { + 'output_page' => $pca_page, + 'pca_pop_id' => $pop_id, + 'input_file' => $input_file, + 'scores_file' => $scores_file, + } + ); return \%output_details; @@ -590,13 +599,14 @@ sub structure_cluster_analysis_output { my $pop_id = $c->stash->{cluster_pop_id}; - my $base = $c->controller('solGS::Path')->clean_base_name($c); + my $base = $c->stash->{hostname}; my $cluster_page = $base . $analysis_page; $analysis_data->{analysis_page} = $cluster_page; my $cluster_type = $c->stash->{cluster_type}; - my $input_file =$c->controller('solGS::Cluster')->cluster_data_input_files($c); - + my $input_file = + $c->controller('solGS::Cluster')->cluster_data_input_files($c); + $c->stash->{file_id} = $c->controller('solGS::Files')->create_file_id($c); $c->controller('solGS::Cluster')->cluster_result_file($c); @@ -607,13 +617,16 @@ sub structure_cluster_analysis_output { else { $result_file = $c->stash->{"${cluster_type}_result_newick_file"}; } - - my %output_details = ( 'cluster_' . $pop_id => { - 'output_page' => $cluster_page, - 'cluster_pop_id' => $pop_id, - 'input_file' => $input_file, - 'result_file' => $result_file, - }); + + my %output_details = ( + 'cluster_' + . $pop_id => { + 'output_page' => $cluster_page, + 'cluster_pop_id' => $pop_id, + 'input_file' => $input_file, + 'result_file' => $result_file, + } + ); return \%output_details; @@ -626,119 +639,89 @@ sub structure_training_modeling_output { my $analysis_page = $analysis_data->{analysis_page}; my $training_pop_id = $c->stash->{training_pop_id}; - my $protocol_id = $c->stash->{genotyping_protocol_id}; + my $protocol_id = $c->stash->{genotyping_protocol_id}; my @traits_ids = @{ $c->stash->{training_traits_ids} } if $c->stash->{training_traits_ids}; + my $referer = $c->req->referer; + my $base = $c->stash->{hostname}; - my $base = $c->controller('solGS::Path')->clean_base_name($c); my $url_args = { 'training_pop_id' => $training_pop_id, 'genotyping_protocol_id' => $protocol_id, }; - my %output_details = (); - - foreach my $trait_id (@traits_ids) { - $url_args->{trait_id} = $trait_id; + if ( + $referer =~ /solgs\/population\// + || ( $referer =~ /solgs\/search\/trials\/trait\// + && $analysis_page =~ m/solgs\/trait\// ) + ) + { + $url_args->{data_set_type} = 'single_population'; + } + elsif ($referer =~ /solgs\/populations\/combined\// + || $analysis_page =~ /solgs\/model\/combined\/trials\// ) + { + $url_args->{data_set_type} = 'combined_populations'; - $c->stash->{cache_dir} = $c->stash->{solgs_cache_dir}; + $c->stash->{combo_pops_id} = $training_pop_id; + $c->controller('solGS::combinedTrials')->cache_combined_pops_data($c); + } - $c->controller('solGS::Trait')->get_trait_details( $c, $trait_id ); - $c->controller('solGS::Files')->rrblup_training_gebvs_file($c); + my $multi_models_url; + if ( scalar(@traits_ids) > 1 ) { + my $traits_selection_id = $c->controller('solGS::Gebvs') + ->create_traits_selection_id( \@traits_ids ); - my $trait_abbr = $c->stash->{trait_abbr}; - my $trait_page; + $c->controller('solGS::Gebvs') + ->catalogue_traits_selection( $c, \@traits_ids ); - if ( $referer =~ m/solgs\/population\// ) { - $url_args->{data_set_type} = 'single_population'; + $url_args->{'traits_selection_id'} = $traits_selection_id; - my $model_page = - $c->controller('solGS::Path')->model_page_url($url_args); - $trait_page = $base . $model_page; - - if ( $analysis_page =~ m/solgs\/traits\/all\/population\// ) { - my $traits_selection_id = $c->controller('solGS::Gebvs') - ->create_traits_selection_id( \@traits_ids ); - $analysis_data->{analysis_page} = - $base - . "solgs/traits/all/population/" - . $training_pop_id - . '/traits/' - . $traits_selection_id . '/gp/' - . $protocol_id; - - $c->controller('solGS::Gebvs') - ->catalogue_traits_selection( $c, \@traits_ids ); - } - } + $multi_models_url = + $c->controller("solGS::Path")->multi_models_page_url($url_args); + $multi_models_url = $base . $multi_models_url; + } - if ( $referer =~ m/solgs\/search\/trials\/trait\// - && $analysis_page =~ m/solgs\/trait\// ) - { - $url_args->{data_set_type} = 'single_population'; - my $model_page = - $c->controller('solGS::Path')->model_page_url($url_args); - $trait_page = $base . $model_page; - } - - if ( $referer =~ m/solgs\/populations\/combined\// ) { - $url_args->{data_set_type} = 'combined_populations'; + my %output_details = (); - my $model_page = - $c->controller('solGS::Path')->model_page_url($url_args); - $trait_page = $base . $model_page; - - if ( $analysis_page =~ m/solgs\/models\/combined\/trials\// ) { - my $traits_selection_id = $c->controller('solGS::Gebvs') - ->create_traits_selection_id( \@traits_ids ); - $analysis_data->{analysis_page} = - $base - . "solgs/models/combined/trials/" - . $training_pop_id - . '/traits/' - . $traits_selection_id . '/gp/' - . $protocol_id; - - $c->controller('solGS::Gebvs') - ->catalogue_traits_selection( $c, \@traits_ids ); - } - } + foreach my $trait_id (@traits_ids) { + $url_args->{trait_id} = $trait_id; - if ( $analysis_page =~ m/solgs\/model\/combined\/trials\// ) { - $url_args->{data_set_type} = 'combined_populations'; + $c->stash->{cache_dir} = $c->stash->{solgs_cache_dir}; - my $model_page = - $c->controller('solGS::Path')->model_page_url($url_args); + $c->controller('solGS::Trait')->get_trait_details( $c, $trait_id ); + $c->controller('solGS::Files')->rrblup_training_gebvs_file($c); - $trait_page = $base . $model_page; + my $trait_abbr = $c->stash->{trait_abbr}; + + my $model_page = + $c->controller('solGS::Path')->model_page_url($url_args); + $model_page = $base . $model_page; - $c->stash->{combo_pops_id} = $training_pop_id; - $c->controller('solGS::combinedTrials') - ->cache_combined_pops_data($c); - } - - $c->controller('solGS::Files')->model_phenodata_file($c); - my $model_pheno_file = $c->stash->{model_phenodata_file}; + $c->controller('solGS::Files')->model_phenodata_file($c); + my $model_pheno_file = $c->stash->{model_phenodata_file}; - $c->controller('solGS::Files')->model_genodata_file($c); - my $model_geno_file = $c->stash->{model_genodata_file}; + $c->controller('solGS::Files')->model_genodata_file($c); + my $model_geno_file = $c->stash->{model_genodata_file}; - $output_details{ 'trait_id_' . $trait_abbr } = { 'trait_id' => $trait_id, 'trait_name' => $c->stash->{trait_name}, - 'trait_page' => $trait_page, + 'trait_page' => $model_page, 'gebv_file' => $c->stash->{rrblup_training_gebvs_file}, 'pop_id' => $training_pop_id, 'phenotype_file' => $model_pheno_file, 'genotype_file' => $model_geno_file, 'data_set_type' => $c->stash->{data_set_type}, }; + } + $output_details{'multi_models_url'} = $multi_models_url; + return \%output_details; } @@ -748,7 +731,7 @@ sub structure_training_single_pop_data_output { my $pop_id = $c->stash->{pop_id}; my $protocol_id = $c->stash->{genotyping_protocol_id}; - my $base = $c->controller('solGS::Path')->clean_base_name($c); + my $base = $c->stash->{hostname}; my $args = { 'training_pop_id' => $pop_id, 'genotyping_protocol_id' => $protocol_id, @@ -817,7 +800,7 @@ sub structure_training_combined_pops_data_output { my $combo_pops_id = $c->stash->{combo_pops_id}; my $protocol_id = $c->stash->{genotyping_protocol_id}; - my $base = $c->controller('solGS::Path')->clean_base_name($c); + my $base = $c->stash->{hostname}; my $args = { 'training_pop_id' => $combo_pops_id, 'genotyping_protocol_id' => $protocol_id, @@ -888,8 +871,9 @@ sub structure_selection_prediction_output { if $c->stash->{training_traits_ids}; my $protocol_id = $c->stash->{genotyping_protocol_id}; - my $referer = $c->req->referer; - my $base = $c->controller('solGS::Path')->clean_base_name($c); + my $referer = $c->req->referer; + my $base = $c->stash->{hostname}; + my $data_set_type = $c->stash->{data_set_type}; my %output_details = (); @@ -1008,6 +992,15 @@ sub structure_selection_prediction_output { } + if ( scalar(@traits_ids) > 1 ) { + my $uri_base = $c->req->base; + my $referer = $c->req->referer; + $referer =~ s/$uri_base//; + my $base = $c->stash->{hostname}; + + $output_details{'multi_models_url'} = $base . "/" . $referer; + } + return \%output_details; } @@ -1021,7 +1014,7 @@ sub run_analysis { my $analysis_page = $analysis_profile->{analysis_page}; $c->stash->{analysis_page} = $analysis_page; - my $base = $c->controller('solGS::Path')->clean_base_name($c); + my $base = $c->stash->{hostname}; $analysis_page =~ s/$base//; my $referer = $c->req->referer; @@ -1281,13 +1274,13 @@ sub analysis_log_file { } sub get_confirm_msg { - my ( $self, $c, $job ) = @_; + my ( $self, $c, $job ) = @_; - $job =~ s/[_|-]/ /g; - $job = lc($job); + $job =~ s/[_|-]/ /g; + $job = lc($job); - my $msg = "Your $job job is submitted."; - return $msg; + my $msg = "Your $job job is submitted."; + return $msg; } diff --git a/lib/SGN/Controller/solGS/AsyncJob.pm b/lib/SGN/Controller/solGS/AsyncJob.pm index 09fd5239b5..6b03c93320 100644 --- a/lib/SGN/Controller/solGS/AsyncJob.pm +++ b/lib/SGN/Controller/solGS/AsyncJob.pm @@ -818,6 +818,10 @@ sub modeling_jobs { $c->stash->{trait_id} = $trait_id; $c->controller('solGS::Trait')->get_trait_details($c); + if ( $c->stash->{analysis_type} =~ /multiple_models/ ) { + $c->stash->{analysis_type} = 'training_model'; + } + $c->controller('solGS::solGS')->input_files($c); $c->controller('solGS::solGS')->output_files($c); diff --git a/lib/SGN/Controller/solGS/CachedResult.pm b/lib/SGN/Controller/solGS/CachedResult.pm index f18865d02a..8d9d5f6f27 100644 --- a/lib/SGN/Controller/solGS/CachedResult.pm +++ b/lib/SGN/Controller/solGS/CachedResult.pm @@ -375,13 +375,8 @@ sub check_cached_genotype_data { $c->controller('solGS::Files')->genotype_file_name( $c, $pop_id ); my $file = $c->stash->{genotype_file_name}; - my $cached; - if ( -s $file ) { - my @rows = read_file( $file, { binmode => ':utf8' } ); - $cached = 1 if $rows[1]; - } - - return $cached; + my $count = $c->controller('solGS::Utils')->count_data_rows($file); + return $count; } @@ -391,13 +386,8 @@ sub check_cached_phenotype_data { $c->controller('solGS::Files')->phenotype_file_name( $c, $pop_id ); my $file = $c->stash->{phenotype_file_name}; - my $cached; - if ( -s $file ) { - my @rows = read_file( $file, { binmode => ':utf8' } ); - $cached = 1 if $rows[1]; - } - - return $cached; + my $count = $c->controller('solGS::Utils')->count_data_rows($file); + return $count; } diff --git a/lib/SGN/Controller/solGS/Path.pm b/lib/SGN/Controller/solGS/Path.pm index 0bb277d960..384e6b81ac 100644 --- a/lib/SGN/Controller/solGS/Path.pm +++ b/lib/SGN/Controller/solGS/Path.pm @@ -7,175 +7,196 @@ use JSON; BEGIN { extends 'Catalyst::Controller' } +sub check_page_type : Path('/solgs/check/page/type') Args(0) { + my ( $self, $c ) = @_; -sub check_page_type :Path('/solgs/check/page/type') Args(0) { - my ($self, $c) = @_; + my $page_type = $self->page_type( $c, $c->req->param('page') ); - my $page_type = $self->page_type($c, $c->req->param('page')); + my $ret = { 'page_type' => $page_type }; + $ret = to_json($ret); - my $ret = {'page_type' => $page_type}; - $ret = to_json($ret); - - $c->res->content_type('application/json'); + $c->res->content_type('application/json'); $c->res->body($ret); } - sub model_page_url { - my ($self, $args) = @_; + my ( $self, $args ) = @_; - my $trait_id = $args->{trait_id}; - my $pop_id = $args->{training_pop_id}; - my $protocol_id = $args->{genotyping_protocol_id}; + my $trait_id = $args->{trait_id}; + my $pop_id = $args->{training_pop_id}; + my $protocol_id = $args->{genotyping_protocol_id}; - if ($args->{data_set_type} =~ /combined/) - { - return "/solgs/model/combined/trials/$pop_id/trait/$trait_id/gp/$protocol_id"; - } - else - { - return "/solgs/trait/$trait_id/population/$pop_id/gp/$protocol_id"; - } + my $path; + if ( $args->{data_set_type} =~ /combined/ ) { + $path = +"/solgs/model/combined/trials/$pop_id/trait/$trait_id/gp/$protocol_id"; + } + else { + $path = "/solgs/trait/$trait_id/population/$pop_id/gp/$protocol_id"; + } -} + return $path; +} sub training_page_url { - my ($self, $args) = @_; + my ( $self, $args ) = @_; - my $pop_id = $args->{training_pop_id}; - my $protocol_id = $args->{genotyping_protocol_id}; + my $pop_id = $args->{training_pop_id}; + my $protocol_id = $args->{genotyping_protocol_id}; - if ( $args->{data_set_type} =~ /combined/) - { - return "/solgs/populations/combined/$pop_id/gp/$protocol_id"; - } - else - { - return "/solgs/population/$pop_id/gp/$protocol_id"; - } + my $path; + if ( $args->{data_set_type} =~ /combined/ ) { + $path = "/solgs/populations/combined/$pop_id/gp/$protocol_id"; + } + else { + $path = "/solgs/population/$pop_id/gp/$protocol_id"; + } + return $path; } +sub multi_models_page_url { + my ( $self, $args ) = @_; + + my $training_pop_id = $args->{training_pop_id}; + my $protocol_id = $args->{genotyping_protocol_id}; + my $traits_code = $args->{traits_selection_id}; + + my $path; + if ( $args->{data_set_type} =~ /combined/ ) { + $path = + "/solgs/models/combined/trials/" + . $training_pop_id + . '/traits/' + . $traits_code . '/gp/' + . $protocol_id; + } + else { + $path = + "/solgs/traits/all/population/" + . $training_pop_id + . '/traits/' + . $traits_code . '/gp/' + . $protocol_id; + + } + + return $path; + +} sub trial_page_url { - my ($self, $trial_id) = @_; + my ( $self, $trial_id ) = @_; return "/breeders/trial/$trial_id"; } - sub selection_page_url { - my ($self, $args) = @_; + my ( $self, $args ) = @_; - my $tr_pop_id = $args->{training_pop_id}; - my $sel_pop_id = $args->{selection_pop_id}; - my $trait_id = $args->{trait_id}; - my $protocol_id = $args->{genotyping_protocol_id}; + my $tr_pop_id = $args->{training_pop_id}; + my $sel_pop_id = $args->{selection_pop_id}; + my $trait_id = $args->{trait_id}; + my $protocol_id = $args->{genotyping_protocol_id}; - if ($args->{data_set_type} =~ /combined_populations/) - { - return "/solgs/combined/model/$tr_pop_id/selection/$sel_pop_id/trait/$trait_id/gp/$protocol_id"; - } - else - { - return "/solgs/selection/$sel_pop_id/model/$tr_pop_id/trait/$trait_id/gp/$protocol_id"; - } + my $path; + if ( $args->{data_set_type} =~ /combined_populations/ ) { + $path = +"/solgs/combined/model/$tr_pop_id/selection/$sel_pop_id/trait/$trait_id/gp/$protocol_id"; + } + else { + $path = +"/solgs/selection/$sel_pop_id/model/$tr_pop_id/trait/$trait_id/gp/$protocol_id"; + } -} + return $path; +} sub create_hyperlink { - my ($self, $url, $text) = @_; + my ( $self, $url, $text ) = @_; - my $link = qq | $text |; + my $link = qq | $text |; - return $link; + return $link; } - sub page_type { - my ($self, $c, $url) = @_; + my ( $self, $c, $url ) = @_; - $url = $c->req->path if !$url; + $url = $c->req->path if !$url; - my $model_pages = 'solgs/trait' - . '|solgs/traits/all/' - . '|solgs/model/combined/trials/' - . '|solgs/models/combined/trials/'; + my $model_pages = + 'solgs/trait' + . '|solgs/traits/all/' + . '|solgs/model/combined/trials/' + . '|solgs/models/combined/trials/'; - my $selection_pop_pages = 'solgs/selection' - . '|solgs/combined/model/'; + my $selection_pop_pages = 'solgs/selection' . '|solgs/combined/model/'; - my $training_pop_pages = 'solgs/population/' - . '|solgs/populations/combined/'; + my $training_pop_pages = + 'solgs/population/' . '|solgs/populations/combined/'; - my $type; - if ($url =~ $model_pages) - { - $type = 'training_model'; - } - elsif ($url =~ $selection_pop_pages) - { - $type = 'selection_prediction'; - } - elsif ($url =~ $training_pop_pages) { - $type = 'training_population'; - } + my $type; + if ( $url =~ $model_pages ) { + $type = 'training_model'; + } + elsif ( $url =~ $selection_pop_pages ) { + $type = 'selection_prediction'; + } + elsif ( $url =~ $training_pop_pages ) { + $type = 'training_population'; + } - return $type; + return $type; } - sub parse_ids { - my ($self, $c) = @_; - - my $page_type = $self->page_type($c); - my $path = $c->req->path; - - my $ids = {}; - if ($page_type =~ /selection/) - { - my @parts = split(/\//, $path); - my @num = grep(/\d+/, @parts); - - if ($path =~ /combined/) - { - $ids = { - 'training_pop_id' => $num[0], - 'selection_pop_id' => $num[1], - 'trait_id' => $num[2], - 'genotyping_protocol_id' => $num[3] - }; - } - else - { - $ids = { - 'training_pop_id' => $num[1], - 'selection_pop_id' => $num[0], - 'trait_id' => $num[2], - 'genotyping_protocol_id' => $num[3] - }; - - } - } - - return $ids; + my ( $self, $c ) = @_; + + my $page_type = $self->page_type($c); + my $path = $c->req->path; + + my $ids = {}; + if ( $page_type =~ /selection/ ) { + my @parts = split( /\//, $path ); + my @num = grep( /\d+/, @parts ); + + if ( $path =~ /combined/ ) { + $ids = { + 'training_pop_id' => $num[0], + 'selection_pop_id' => $num[1], + 'trait_id' => $num[2], + 'genotyping_protocol_id' => $num[3] + }; + } + else { + $ids = { + 'training_pop_id' => $num[1], + 'selection_pop_id' => $num[0], + 'trait_id' => $num[2], + 'genotyping_protocol_id' => $num[3] + }; + + } + } + + return $ids; } - sub clean_base_name { - my ($self, $c) = @_; + my ( $self, $c ) = @_; my $base = $c->req->base; $base =~ s/:\d+//; $base =~ s/(\/)$//; - return $base; + return $base; } #### diff --git a/lib/SGN/Controller/solGS/solGS.pm b/lib/SGN/Controller/solGS/solGS.pm index a4e103ec28..a30288ff4c 100755 --- a/lib/SGN/Controller/solGS/solGS.pm +++ b/lib/SGN/Controller/solGS/solGS.pm @@ -590,6 +590,7 @@ sub output_files { $c->controller('solGS::Path')->page_type( $c, $c->req->referer ); my $analysis_type = $c->stash->{analysis_type} || $page_type; $analysis_type =~ s/\s+/_/g; + my $trait_abbr = $c->stash->{trait_abbr}; my $trait_id = $c->stash->{trait_id}; $c->stash->{cache_dir} = $c->stash->{solgs_cache_dir}; @@ -914,11 +915,10 @@ sub selection_population_predicted_traits : Path('/solgs/selection/population/predicted/traits/') Args(0) { my ( $self, $c ) = @_; + my $args = $c->req->param('arguments'); + $c->controller('solGS::Utils')->stash_json_args( $c, $args ); - my $args = $c->req->param('arguments'); - $c->controller('solGS::Utils')->stash_json_args($c, $args); - - my $training_pop_id = $c->stash->{training_pop_id}; + my $training_pop_id = $c->stash->{training_pop_id}; my $selection_pop_id = $c->stash->{selection_pop_id}; my $ret->{selection_traits} = undef; diff --git a/lib/solGS/AnalysisReport.pm b/lib/solGS/AnalysisReport.pm index 057a80d120..8523f3521e 100644 --- a/lib/solGS/AnalysisReport.pm +++ b/lib/solGS/AnalysisReport.pm @@ -705,13 +705,7 @@ sub multi_modeling_message { } if ( $cnt > 1 ) { - my $analysis_page = - $output_details->{analysis_profile}->{analysis_page}; - - $message .= -"You can also view the summary of all the analyses in the page below.\n" - . "Additionally, you may find the analytical features in the page useful.\n" - . $analysis_page . "\n\n"; + $message .= $self->multi_models_extra_message($output_details); } return $message; @@ -733,12 +727,12 @@ sub single_modeling_message { if ( $output_details->{$k}->{success} ) { $message = - "The analysis for $trait_name is done." + "The modeling for $trait_name is done." . "\nYou can view the model output here:" . "\n\n$trait_page\n\n"; } else { - $message = "The analysis for $trait_name failed.\n\n"; + $message = "The modeling for $trait_name failed.\n\n"; $message .= 'Refering page: ' . $trait_page . "\n\n"; $message .= "We will troubleshoot the cause and contact you when we find out more."; @@ -774,9 +768,8 @@ sub selection_prediction_message { $message .= "The prediction of selection population $selection_pop_name is done." . "\nYou can view the prediction output here:\n\n"; - } - - $message .= "$selection_pop_page\n\n"; + } + $message .= uc($trait_name) . ":\n" . $selection_pop_page . "\n\n"; } else { my $failure_reason = @@ -793,15 +786,24 @@ sub selection_prediction_message { } if ( $cnt > 1 ) { - $message .= -"You can also view the summary of all the analyses in the page below.\n" - . "Additionally, you may find the analytical features in the page useful.\n" - . $output_details->{referer} . "\n\n"; + $message .= $self->multi_models_extra_message($output_details); } return $message; } +sub multi_models_extra_message { + my ( $self, $output_details ) = @_; + + my $multi_models_url = $output_details->{multi_models_url}; + my $message .= + "You can also view the summary of all the analyses in the page below.\n" + . "Additionally, you may find the analytical features in the page useful.\n" + . $multi_models_url . "\n\n"; + + return $message; +} + sub population_download_message { my ( $self, $output_details ) = @_; diff --git a/lib/solGS/JobSubmission.pm b/lib/solGS/JobSubmission.pm index f5c045fc60..37d8a633de 100644 --- a/lib/solGS/JobSubmission.pm +++ b/lib/solGS/JobSubmission.pm @@ -1,6 +1,5 @@ package solGS::JobSubmission; - use Moose; use namespace::autoclean; @@ -12,199 +11,178 @@ use solGS::queryJobs; with 'MooseX::Getopt'; with 'MooseX::Runnable'; - has "prerequisite_jobs" => ( - is => 'ro', - isa => 'Str', - ); + is => 'ro', + isa => 'Str', +); has "dependent_jobs" => ( is => 'ro', - isa => 'Str', - required => 1, - ); + isa => 'Str', + required => 1, +); has "analysis_report_job" => ( - is => 'ro', - isa => 'Str', - ); + is => 'ro', + isa => 'Str', +); has "config_file" => ( - is => 'ro', - isa => 'Str', - ); - + is => 'ro', + isa => 'Str', +); sub run { my $self = shift; + my $secs = 60 * 4; - my $pre_jobs = $self->run_prerequisite_jobs; - my $dep_jobs = $self->run_dependent_jobs($pre_jobs); - sleep(60 * 4); - $self->send_analysis_report($dep_jobs); + my $pre_jobs = $self->run_prerequisite_jobs(); + sleep($secs); + print STDERR +"\nCompleted prerequisite jobs. After waiting $secs sec...Now running the set of dependent jobs...\n"; -} + my $dep_jobs = $self->run_dependent_jobs(); + sleep($secs); + print STDERR +"\nCompleted dependent jobs. After waiting $secs sec...Now checking results and emailing the results...\n"; + $self->send_analysis_report(); + print STDERR "\nGot done checking results and emailing the results...\n"; + +} sub run_prerequisite_jobs { my $self = shift; - my @jobs; - my $jobs = $self->prerequisite_jobs; - if ($jobs !~ /none/) - { - $jobs = retrieve($jobs); - my $type = reftype $jobs; - - if (reftype $jobs eq 'HASH') - { - my @priority_jobs; - foreach my $rank (sort keys %$jobs) - { - my $js = $jobs->{$rank}; - foreach my $jb (@$js) - { - my $sj = $self->submit_job($jb); - push @priority_jobs, $sj; - } - } - - foreach my $priority_job (@priority_jobs) - { - while (1) - { - last if !$priority_job->alive(); - sleep 30 if $priority_job->alive(); - } - } - } - else - { - if (reftype $jobs eq 'SCALAR' ) - { - $jobs = [$jobs]; - } - - if ($jobs->[0]) - { - foreach my $job (@$jobs) - { - my $job = $self->submit_job($job); - push @jobs, $job; - } - } - } - } - - return \@jobs; + my $remaining_jobs; + my $pre_jobs = $self->prerequisite_jobs; + if ( $pre_jobs !~ /none/ ) { + $pre_jobs = retrieve($pre_jobs); + my $type = reftype $pre_jobs; -} + if ( reftype $pre_jobs eq 'HASH' ) { + my $submitted_priority_jobs; + foreach my $rank ( sort keys %$pre_jobs ) { + my $js = $pre_jobs->{$rank}; -sub run_dependent_jobs { - my $self = shift; - my $pre_jobs = shift; - - if ($pre_jobs->[0]) { - foreach my $pre_job (@$pre_jobs) - { - while (1) - { - last if !$pre_job->alive(); - sleep 30 if $pre_job->alive(); - } + $submitted_priority_jobs = $self->submit_jobs($js); + } + $remaining_jobs = $self->wait_till_jobs_end($submitted_priority_jobs); } - } + else { + if ( reftype $pre_jobs eq 'SCALAR' ) { + $pre_jobs = [$pre_jobs]; + } - my @jobs; - my $jobs_file = $self->dependent_jobs; - my $jobs = retrieve($jobs_file); + my $submitted_jobs = $self->submit_jobs($pre_jobs); - if (reftype $jobs ne 'ARRAY') - { - $jobs = [$jobs]; - } + $remaining_jobs = $self->wait_till_jobs_end($submitted_jobs); + print STDERR "\nremaining jobs: $remaining_jobs\n"; - foreach my $job (@$jobs) - { - my $job = $self->submit_job($job); - push @jobs, $job; + } } - return \@jobs; + return $remaining_jobs; } +sub wait_till_jobs_end { + my ( $self, $jobs, $sleep_time ) = @_; + $sleep_time = 30 if !$sleep_time; + while (@$jobs) { + for ( my $i = 0 ; $i < scalar(@$jobs) ; $i++ ) { + splice( @$jobs, $i, 1 ) if !$jobs->[$i]->alive(); + } + + sleep $sleep_time; -sub send_analysis_report { - my $self = shift; - my $dep_jobs = shift; - - my @jobs; - foreach my $dep_job (@$dep_jobs) - { - while (1) - { - last if !$dep_job->alive(); - sleep 30 if $dep_job->alive(); - } } - my $report_file = $self->analysis_report_job; - unless ($report_file =~ /none/) - { - my $report_job = retrieve($report_file); - my $job = $self->submit_job($report_job); - return $job; + my $remaining_jobs = $jobs ? $jobs->[0] : 0; + return $remaining_jobs; +} + +sub submit_jobs { + my ( $self, $jobs ) = @_; + + my @submitted_jobs; + + if ( $jobs->[0] ) { + foreach my $job (@$jobs) { + my $submitted_job = $self->submit_job($job); + push @submitted_jobs, $submitted_job; + } } + return \@submitted_jobs; } +sub run_dependent_jobs { + my $self = shift; -sub submit_job { - my ($self, $args) = @_; + my $jobs_file = $self->dependent_jobs; + my $dep_jobs = retrieve($jobs_file); - my $job; - ###my $config = $self->config_file; - ###$config = retrieve($config); + if ( reftype $dep_jobs ne 'ARRAY' ) { + $dep_jobs = [$dep_jobs]; + } - print STDERR "submitting job... $args->{cmd}\n"; + my $submitted_jobs = $self->submit_jobs($dep_jobs); - eval - { - $job = CXGN::Tools::Run->new($args->{config}); - $job->do_not_cleanup(1); + my $remaining_jobs = $self->wait_till_jobs_end($submitted_jobs); + print STDERR "\nremaining jobs: $remaining_jobs\n"; + return $remaining_jobs; - $job->is_cluster(1); - $job->run_cluster($args->{cmd}); +} +sub send_analysis_report { + my $self = shift; - if (!$args->{background_job}) - { - print STDERR "\n WAITING job to finish\n"; - $job->wait(); - print STDERR "\n job COMPLETED\n"; - } - }; + my $report_file = $self->analysis_report_job; + unless ( $report_file =~ /none/ ) { + my $report_job = retrieve($report_file); + my $job = $self->submit_job($report_job); + return $job; + } - if ($@) - { - print STDERR "An error occurred submitting job $args->{cmd} \n$@\n"; - } +} - return $job; +sub submit_job { + my ( $self, $args ) = @_; - } + my $job; + ###my $config = $self->config_file; + ###$config = retrieve($config); + print STDERR "submitting job... $args->{cmd}\n"; + eval { + $job = CXGN::Tools::Run->new( $args->{config} ); + $job->do_not_cleanup(1); -__PACKAGE__->meta->make_immutable; + $job->is_cluster(1); + $job->run_cluster( $args->{cmd} ); + if ( !$args->{background_job} ) { + print STDERR "\n WAITING job to finish\n"; + $job->wait(); + print STDERR "\n job COMPLETED\n"; + } + }; + + if ($@) { + print STDERR "An error occurred submitting job $args->{cmd} \n$@\n"; + } + return $job; +} + +__PACKAGE__->meta->make_immutable; #### -1; # +1; # ####