1 package SGN
::Controller
::solGS
::Download
;
5 use namespace
::autoclean
;
8 BEGIN { extends
'Catalyst::Controller::REST' }
12 default => 'application/json',
14 map => { 'application/json' => 'JSON' },
18 sub download_training_pop_data
:Path
('/solgs/download/training/pop/data') Args
(0) {
21 my $args = $c->req->param('arguments');
22 $c->controller('solGS::Utils')->stash_json_args($c, $args);
24 $c->stash->{rest
}{training_pop_raw_geno_file
} = $self->download_raw_geno_data_file($c);
25 $c->stash->{rest
}{training_pop_raw_pheno_file
} = $self->download_raw_pheno_data_file($c);
26 $c->stash->{rest
}{traits_acronym_file
} = $self->download_traits_acronym_file($c);
31 sub download_selection_pop_data
:Path
('/solgs/download/selection/pop/data') Args
(0) {
34 my $args = $c->req->param('arguments');
35 $c->controller('solGS::Utils')->stash_json_args($c, $args);
37 my $geno_file = $self->download_selection_pop_filtered_geno_data_file($c);
38 my $log_file = $self->download_selection_prediction_report_file($c);
40 $c->stash->{rest
}{selection_pop_filtered_geno_file
} = $geno_file;
41 $c->stash->{rest
}{selection_prediction_report_file
} = $log_file;
44 sub download_model_input_data
:Path
('/solgs/download/model/input/data') Args
(0) {
47 my $args = $c->req->param('arguments');
48 $c->controller('solGS::Utils')->stash_json_args($c, $args);
50 my $geno_file = $self->download_model_geno_data_file($c);
51 my $pheno_file = $self->download_model_pheno_data_file($c);
52 my $log_file = $self->download_model_analysis_report_file($c);
54 $c->stash->{rest
}{model_geno_data_file
} = $geno_file;
55 $c->stash->{rest
}{model_pheno_data_file
} = $pheno_file;
56 $c->stash->{rest
}{model_analysis_report_file
} = $log_file;
61 sub download_gebvs
:Path
('/solgs/download/gebvs/pop') Args
(0) {
64 my $args = $c->req->param('arguments');
65 $c->controller('solGS::Utils')->stash_json_args($c, $args);
69 if ($c->stash->{selection_pop_id
})
72 $gebvs_file = $self->download_selection_gebvs_file($c);
77 $gebvs_file = $self->download_training_gebvs_file($c);
80 my $file_id = $c->controller('solGS::Files')->gebvs_file_id($c, $type);
82 $c->stash->{rest
}{gebvs_file
} = $gebvs_file;
83 $c->stash->{rest
}{gebvs_file_id
} = $file_id;
88 sub download_marker_effects
:Path
('/solgs/download/model/marker/effects') Args
(0) {
91 my $args = $c->req->param('arguments');
92 $c->controller('solGS::Utils')->stash_json_args($c, $args);
94 my $marker_effects_file = $self->download_marker_effects_file($c);
95 $c->stash->{rest
}{marker_effects_file
} = $marker_effects_file;
99 sub download_traits_acronym
:Path
('/solgs/download/traits/acronym') Args
(0) {
102 my $args = $c->req->param('arguments');
103 $c->controller('solGS::Utils')->stash_json_args($c, $args);
105 my $acronyms_file = $self->download_traits_acronym_file($c);
106 $c->stash->{rest
}{traits_acronym_file
} = $acronyms_file;
111 sub selection_prediction_download_urls
{
112 my ($self, $c, $training_pop_id, $selection_pop_id) = @_;
114 my $selected_model_traits = $c->stash->{training_traits_ids
} || [$c->stash->{trait_id
}];
115 my $protocol_id = $c->stash->{genotyping_protocol_id
};
117 no warnings
'uninitialized';
120 'training_pop_id' => $training_pop_id,
121 'selection_pop_id' => $selection_pop_id,
122 'genotyping_protocol_id' => $protocol_id,
125 my $selection_traits_ids;
127 if ($selection_pop_id)
129 $c->controller('solGS::Gebvs')->selection_pop_analyzed_traits($c, $training_pop_id, $selection_pop_id);
130 $selection_traits_ids = $c->stash->{selection_pop_analyzed_traits_ids
};
133 my @selection_traits_ids = sort(@
$selection_traits_ids) if $selection_traits_ids->[0];
134 my @selected_model_traits = sort(@
$selected_model_traits) if $selected_model_traits->[0];
136 my $page = $c->req->referer;
137 my $data_set_type = $page =~ /combined/ ?
'combined_populations' : 'single_population';
138 $url_args->{data_set_type
} = $data_set_type;
143 if (@selected_model_traits ~~ @selection_traits_ids)
145 foreach my $trait_id (@selection_traits_ids)
148 $url_args->{trait_id
} = $trait_id;
150 $c->controller('solGS::Trait')->get_trait_details($c, $trait_id);
151 my $trait_abbr = $c->stash->{trait_abbr
};
153 $sel_pop_page = $c->controller('solGS::Path')->selection_page_url($url_args);
155 if ($page =~ /solgs\/traits\
/all\/|solgs\
/models\/combined\
//)
157 $download_url .= " | " if $download_url;
160 $download_url .= qq |<a href
="$sel_pop_page">$trait_abbr</a
> |;
166 my $trait_id = $selected_model_traits[0];
167 $url_args->{trait_id
} = $trait_id;
169 $sel_pop_page = $c->controller('solGS::Path')->selection_page_url($url_args);
170 $download_url = qq | <a href
="$sel_pop_page" onclick
="solGS.waitPage(this.href); return false;">[ Predict
]</a
>|;
173 $c->stash->{selection_prediction_download
} = $download_url;
177 sub download_raw_pheno_data_file
{
180 my $pop_id = $c->stash->{training_pop_id
};
181 my $data_set_type = $c->stash->{data_set_type
};
184 if ($data_set_type =~ /combined_populations/)
186 my $trials_ids = $c->controller('solGS::combinedTrials')->get_combined_pops_list($c, $pop_id);
187 @trials_ids = @
$trials_ids;
191 push @trials_ids, $pop_id;
196 foreach my $trial_id (@trials_ids)
198 my $file = $c->controller('solGS::Files')->phenotype_file_name($c, $trial_id);
199 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
209 sub download_raw_geno_data_file
{
212 my $pop_id = $c->stash->{training_pop_id
};
213 my $protocol_id = $c->stash->{genotyping_protocol_id
};
214 my $data_set_type = $c->stash->{data_set_type
};
217 if ($data_set_type =~ /combined_populations/)
219 my $trials_ids = $c->controller('solGS::combinedTrials')->get_combined_pops_list($c, $pop_id);
220 @trials_ids = @
$trials_ids;
224 push @trials_ids, $pop_id;
229 foreach my $trial_id (@trials_ids)
231 my $file = $c->controller('solGS::Files')->genotype_file_name($c, $trial_id, $protocol_id);
232 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
241 sub download_selection_pop_filtered_geno_data_file
{
244 $c->controller('solGS::Files')->filtered_selection_genotype_file($c);
245 my $file = $c->stash->{filtered_selection_genotype_file
};
246 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
253 sub download_model_geno_data_file
{
256 $c->controller('solGS::Trait')->get_trait_details($c, $c->stash->{trait_id
});
258 my $file = $c->controller('solGS::Files')->model_genodata_file($c);
259 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
266 sub download_model_pheno_data_file
{
269 $c->controller('solGS::Trait')->get_trait_details($c, $c->stash->{trait_id
});
271 my $file = $c->controller('solGS::Files')->model_phenodata_file($c);
272 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
278 sub download_model_analysis_report_file
{
281 $c->controller('solGS::Trait')->get_trait_details($c, $c->stash->{trait_id
});
283 my $page = $c->controller('solGS::Path')->page_type($c, $c->req->referer);
285 if ($page =~ /training_model/)
287 $c->stash->{analysis_type
} = 'training_model';
290 my $file = $c->controller('solGS::Files')->analysis_report_file($c);
291 #$file = $c->controller('solGS::Files')->convert_txt_pdf($file);
293 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
299 sub download_selection_prediction_report_file
{
302 $c->controller('solGS::Trait')->get_trait_details($c, $c->stash->{trait_id
});
304 my $referer = $c->req->referer;
305 $c->stash->{analysis_type
} = $c->controller('solGS::Path')->page_type($c, $referer);
307 my $file = $c->controller('solGS::Files')->analysis_report_file($c);
308 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
314 sub download_training_gebvs_file
{
317 my $training_pop_id = $c->stash->{training_pop_id
};
318 my $trait_id = $c->stash->{trait_id
};
319 my $protocol_id = $c->stash->{genotyping_protocol_id
};
321 $c->controller('solGS::Files')->rrblup_training_gebvs_file($c, $training_pop_id, $trait_id, $protocol_id);
322 my $gebvs_file = $c->stash->{rrblup_training_gebvs_file
};
324 $gebvs_file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $gebvs_file, 'solgs');
331 sub download_selection_gebvs_file
{
334 my $training_pop_id = $c->stash->{training_pop_id
};
335 my $selection_pop_id = $c->stash->{selection_pop_id
};
336 my $trait_id = $c->stash->{trait_id
};
337 my $protocol_id = $c->stash->{genotyping_protocol_id
};
339 $c->controller('solGS::Files')->rrblup_selection_gebvs_file($c, $training_pop_id, $selection_pop_id, $trait_id, $protocol_id);
340 my $gebvs_file = $c->stash->{rrblup_selection_gebvs_file
};
342 $gebvs_file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $gebvs_file, 'solgs');
349 sub download_marker_effects_file
{
352 $c->controller('solGS::Trait')->get_trait_details($c, $c->stash->{trait_id
});
354 my $file = $c->controller('solGS::Files')->marker_effects_file($c);
355 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
360 sub download_traits_acronym_file
{
364 $c->controller('solGS::Files')->traits_acronym_file($c, $c->stash->{training_pop_id
});
365 my $file = $c->stash->{traits_acronym_file
};
367 $file = $c->controller('solGS::Files')->copy_to_tempfiles_subdir($c, $file, 'solgs');
372 sub begin
: Private
{
375 $c->controller('solGS::Files')->get_solgs_dirs($c);