1 package SGN
::Controller
::solGS
::combinedTrials
;
4 use namespace
::autoclean
;
6 use Algorithm
::Combinatorics qw
/combinations/;
7 use Array
::Utils
qw(:all);
9 use Carp qw
/ carp confess croak /;
11 use File
::Path qw
/ mkpath /;
12 use File
::Spec
::Functions qw
/ catfile catdir/;
13 use File
::Temp qw
/ tempfile tempdir /;
14 use File
::Slurp qw
/write_file read_file/;
18 use List
::MoreUtils qw
/uniq/;
19 use Scalar
::Util qw
/weaken reftype/;
20 use Storable qw
/ nstore retrieve /;
23 use URI
::FromHash
'uri';
25 BEGIN { extends
'Catalyst::Controller' }
27 sub get_combined_pops_id
: Path
('/solgs/get/combined/populations/id') Args
() {
28 my ( $self, $c ) = @_;
30 my @pops_ids = $c->req->param('trials[]');
32 @pops_ids = uniq
(@pops_ids);
34 my $protocol_id = $c->req->param('genotyping_protocol_id');
36 $c->controller('solGS::genotypingProtocol')
37 ->stash_protocol_id( $c, $protocol_id );
40 my $ret->{status
} = 0;
42 if ( @pops_ids > 1 ) {
43 $c->stash->{pops_ids_list
} = \
@pops_ids;
44 $self->create_combined_pops_id($c);
45 my $combo_pops_id = $c->stash->{combo_pops_id
};
47 $self->catalogue_combined_pops( $c, \
@pops_ids );
48 $ret->{combo_pops_id
} = $combo_pops_id;
50 $ret->{genotyping_protocol_id
} = $c->stash->{genotyping_protocol_id
};
55 $c->res->content_type('application/json');
60 sub prepare_data_for_trials
: Path
('/solgs/retrieve/populations/data') Args
() {
61 my ( $self, $c ) = @_;
63 my @pops_ids = $c->req->param('trials[]');
64 my $protocol_id = $c->req->param('genotyping_protocol_id');
66 $c->controller('solGS::genotypingProtocol')
67 ->stash_protocol_id( $c, $protocol_id );
68 $protocol_id = $c->stash->{genotyping_protocol_id
};
71 my $ret->{status
} = 0;
73 my $not_matching_pops;
76 if ( scalar(@pops_ids) > 1 ) {
77 $c->stash->{pops_ids_list
} = \
@pops_ids;
78 $self->create_combined_pops_id($c);
79 $combo_pops_id = $c->stash->{combo_pops_id
};
80 $c->stash->{training_pop_id
} = $combo_pops_id;
82 $self->catalogue_combined_pops( $c, \
@pops_ids );
84 # $c->controller('solGS::solGS')->submit_cluster_training_pop_data_query($c, \@pops_ids);
86 $self->multi_pops_geno_files( $c, \
@pops_ids );
87 my $geno_files = $c->stash->{multi_pops_geno_files
};
88 @g_files = split( /\t/, $geno_files );
90 $c->controller('solGS::Search')
91 ->compare_genotyping_platforms( $c, \
@g_files );
92 $not_matching_pops = $c->stash->{pops_with_no_genotype_match
};
94 if ( !$not_matching_pops ) {
95 $self->save_common_traits_acronyms($c);
98 $ret->{not_matching_pops
} = $not_matching_pops;
101 $ret->{combined_pops_id
} = $combo_pops_id;
102 $ret->{genotyping_protocol_id
} = $protocol_id;
105 my $pop_id = $pops_ids[0];
106 $c->stash->{training_pop_id
} = $pop_id;
108 # $c->controller('solGS::solGS')->submit_cluster_training_pop_data_query($c, \@pops_ids);
111 'training_pop_id' => $pop_id,
112 'genotyping_protocol_id' => $protocol_id,
113 'data_set_type' => 'single_population'
116 my $training_pop_page =
117 $c->controller('solGS::Path')->training_page_url($args);
119 $ret->{redirect_url
} = $training_pop_page;
120 $ret->{pop_id
} = $pop_id;
121 $ret->{genotyping_protocol_id
} = $protocol_id;
124 $ret = to_json
($ret);
126 $c->res->content_type('application/json');
131 sub combined_trials_page
: Path
('/solgs/populations/combined') Args
() {
132 my ( $self, $c, $combo_pops_id, $gp, $protocol_id ) = @_;
134 $c->stash->{training_pop_id
} = $combo_pops_id;
135 $c->stash->{combo_pops_id
} = $combo_pops_id;
136 $c->stash->{data_set_type
} = 'combined_populations';
137 $c->stash->{analysis_type
} = $c->controller('solGS::Path')->page_type($c);
139 $c->controller('solGS::genotypingProtocol')
140 ->stash_protocol_id( $c, $protocol_id );
141 $self->get_combined_pops_list( $c, $combo_pops_id );
142 my $pops_list = $c->stash->{combined_pops_list
};
147 $cached = $c->controller('solGS::CachedResult')
148 ->check_multi_trials_training_data( $c, $pops_list, $protocol_id );
153 "Cached output for this training population does not exist anymore.\n"
154 . "Please go to <a href=\"/solgs/search/\">the search page</a>"
155 . " and create the training population data.";
157 $c->controller('solGS::Utils')->generic_message( $c, $msg );
160 $self->save_common_traits_acronyms($c);
162 $c->controller('solGS::Trait')->get_all_traits( $c, $combo_pops_id );
163 $c->controller('solGS::Trait')->get_acronym_pairs( $c, $combo_pops_id );
165 $self->combined_pops_summary($c);
166 $c->stash->{template
} = $c->controller('solGS::Files')
167 ->template('/population/training_population.mas');
171 sub models_combined_trials
: Path
('/solgs/models/combined/trials') Args
() {
172 my ( $self, $c, $combo_pops_id, $tr_txt, $traits_selection_id, $gp,
176 my $data_set_type = 'combined_populations';
178 $c->stash->{combo_pops_id
} = $combo_pops_id;
179 $c->stash->{model_id
} = $combo_pops_id;
180 $c->stash->{pop_id
} = $combo_pops_id;
181 $c->stash->{data_set_type
} = $data_set_type;
182 $c->stash->{analysis_type
} = $c->controller('solGS::Path')->page_type($c);
184 $c->controller('solGS::genotypingProtocol')
185 ->stash_protocol_id( $c, $protocol_id );
189 if ( $traits_selection_id =~ /^\d+$/ ) {
190 $c->controller('solGS::Gebvs')
191 ->get_traits_selection_list( $c, $traits_selection_id );
192 @traits_ids = @
{ $c->stash->{traits_selection_list
} }
193 if $c->stash->{traits_selection_list
};
196 $self->combined_pops_summary($c);
197 my $training_pop_name = $c->stash->{training_pop_name
};
198 my $training_pop_desc = $c->stash->{training_pop_desc
};
200 #my $training_pop_page = $c->stash->{training_pop_page};
202 my @select_analysed_traits;
204 'training_pop_id' => $combo_pops_id,
205 'genotyping_protocol_id' => $protocol_id,
206 'data_set_type' => $data_set_type
209 my $training_pop_page =
210 $c->controller('solGS::Path')->training_page_url($args);
212 qq | <a href
="$training_pop_page">$training_pop_name</a
> |;
214 if ( !@traits_ids ) {
215 $c->stash->{message
} =
216 "Cached output for this page does not exist anymore.\n"
217 . " Please go to $training_pop_page and run the analysis.";
219 $c->stash->{template
} = "/generic_message.mas";
223 if ( scalar(@traits_ids) == 1 ) {
224 my $trait_id = $traits_ids[0];
226 'trait_id' => $trait_id,
227 'training_pop_id' => $combo_pops_id,
228 'genotyping_protocol_id' => $protocol_id,
229 'data_set_type' => $data_set_type
233 $c->controller('solGS::Path')->model_page_url($args);
234 $c->res->redirect($model_page);
238 foreach my $trait_id (@traits_ids) {
239 $c->stash->{trait_id
} = $trait_id;
241 $c->controller('solGS::modelAccuracy')
242 ->create_model_summary( $c, $combo_pops_id, $trait_id );
243 my $model_summary = $c->stash->{model_summary
};
245 push @traits_pages, $model_summary;
249 $c->stash->{training_pop_id
} = $combo_pops_id;
250 $c->stash->{training_pop_name
} = $training_pop_name;
251 $c->stash->{training_pop_desc
} = $training_pop_desc;
252 $c->stash->{training_pop_page
} = $training_pop_page;
253 $c->stash->{training_traits_ids
} = \
@traits_ids;
254 $c->stash->{training_traits_code
} = $traits_selection_id;
256 $c->controller('solGS::Gebvs')->training_pop_analyzed_traits($c);
257 my $analyzed_traits = $c->stash->{training_pop_analyzed_traits_ids
};
259 $c->stash->{trait_pages
} = \
@traits_pages;
261 my @training_pop_data =
262 ( [ $training_pop_page, $training_pop_desc, \
@traits_pages ] );
264 $c->stash->{model_data
} = \
@training_pop_data;
266 $c->controller('solGS::Trait')->get_acronym_pairs( $c, $combo_pops_id );
267 $c->stash->{template
} = '/solgs/population/models/detail.mas';
271 sub display_combined_pops_result
: Path
('/solgs/model/combined/trials/') Args
()
273 my ( $self, $c, $combo_pops_id, $trait_key, $trait_id, $gp, $protocol_id )
276 my $data_set_type = 'combined_populations';
278 $c->stash->{data_set_type
} = $data_set_type;
279 $c->stash->{combo_pops_id
} = $combo_pops_id;
280 $c->stash->{training_pop_id
} = $combo_pops_id;
281 $c->stash->{analysis_type
} = $c->controller('solGS::Path')->page_type($c);
283 $c->controller('solGS::genotypingProtocol')
284 ->stash_protocol_id( $c, $protocol_id );
287 $c->controller('solGS::CachedResult')
288 ->check_single_trial_model_output( $c, $combo_pops_id, $trait_id,
294 'training_pop_id' => $combo_pops_id,
295 'genotyping_protocol_id' => $protocol_id,
296 'data_set_type' => $data_set_type
299 my $training_pop_page =
300 $c->controller('solGS::Path')->training_page_url($args);
302 qq | <a href
="$training_pop_page">training population page
</a
>|;
304 my $msg = "Cached output for this model does not exist anymore.\n"
305 . " Please go to the $training_pop_page and run the analysis.";
307 $c->controller('solGS::Utils')->generic_message( $c, $msg );
312 my $pops_cvs = $c->req->param('combined_populations');
315 my @pops = split( ',', $pops_cvs );
316 $c->stash->{trait_combo_pops
} = \
@pops;
319 $self->get_combined_pops_list( $c, $combo_pops_id );
320 $c->stash->{trait_combo_pops
} = $c->stash->{combined_pops_list
};
323 $c->controller('solGS::Trait')->get_trait_details( $c, $trait_id );
325 $self->combined_pops_summary($c);
327 $c->controller('solGS::solGS')->model_phenotype_stat($c);
328 $c->controller('solGS::Files')->validation_file($c);
329 $c->controller('solGS::modelAccuracy')->model_accuracy_report($c);
330 $c->controller('solGS::Files')->rrblup_training_gebvs_file($c);
331 $c->controller('solGS::solGS')
332 ->top_blups( $c, $c->stash->{rrblup_training_gebvs_file
} );
334 # $c->controller('solGS::Download')->training_prediction_download_urls($c);
335 $c->controller('solGS::Files')->marker_effects_file($c);
336 $c->controller('solGS::solGS')
337 ->top_markers( $c, $c->stash->{marker_effects_file
} );
338 $c->controller('solGS::solGS')->variance_components($c);
340 #$c->stash->{template} = $c->controller('solGS::Files')->template('/model/combined/populations/trait.mas');
341 $c->stash->{template
} = $c->controller('solGS::Files')
342 ->template('/population/models/model/detail.mas');
346 sub selection_combined_pops_trait
: Path
('/solgs/combined/model/') Args
() {
348 $self, $c, $model_id,
349 $sel_key, $selection_pop_id, $trait_key,
350 $trait_id, $gp, $protocol_id
353 my $data_set_type = 'combined_populations';
355 $c->stash->{combo_pops_id
} = $model_id;
356 $c->stash->{training_pop_id
} = $model_id;
357 $c->stash->{trait_id
} = $trait_id;
358 $c->stash->{selection_pop_id
} = $selection_pop_id;
359 $c->stash->{data_set_type
} = $data_set_type;
360 $c->stash->{combined_populations
} = 1;
361 $c->stash->{analysis_type
} = $c->controller('solGS::Path')->page_type($c);
363 $c->controller('solGS::genotypingProtocol')
364 ->stash_protocol_id( $c, $protocol_id );
365 $protocol_id = $c->stash->{genotyping_protocol_id
};
367 $c->controller('solGS::Trait')->get_trait_details( $c, $trait_id );
368 my $trait_abbr = $c->stash->{trait_abbr
};
370 if ( $selection_pop_id =~ /list/ ) {
371 $c->stash->{list_id
} = $selection_pop_id =~ s/\w+_//r;
372 $c->controller('solGS::List')
373 ->list_population_summary( $c, $selection_pop_id );
374 $c->stash->{selection_pop_id
} = $c->stash->{project_id
};
375 $c->stash->{selection_pop_name
} = $c->stash->{project_name
};
376 $c->stash->{selection_pop_desc
} = $c->stash->{project_desc
};
377 $c->stash->{selection_pop_owner
} = $c->stash->{owner
};
379 elsif ( $selection_pop_id =~ /dataset/ ) {
380 $c->stash->{dataset_id
} = $selection_pop_id =~ s/\w+_//r;
381 $c->controller('solGS::Dataset')->dataset_population_summary($c);
382 $c->stash->{selection_pop_id
} = $c->stash->{project_id
};
383 $c->stash->{selection_pop_name
} = $c->stash->{project_name
};
384 $c->stash->{selection_pop_desc
} = $c->stash->{project_desc
};
385 $c->stash->{selection_pop_owner
} = $c->stash->{owner
};
388 $c->controller('solGS::Search')
389 ->get_project_details( $c, $selection_pop_id );
390 $c->stash->{selection_pop_id
} = $c->stash->{project_id
};
391 $c->stash->{selection_pop_name
} = $c->stash->{project_name
};
392 $c->stash->{selection_pop_desc
} = $c->stash->{project_desc
};
394 $c->controller('solGS::Search')
395 ->get_project_owners( $c, $selection_pop_id );
396 $c->stash->{selection_pop_owner
} = $c->stash->{project_owners
};
400 { 'selection_pop' => 1, 'selection_pop_id' => $selection_pop_id };
402 $c->controller('solGS::solGS')->get_markers_count( $c, $mr_cnt_args );
403 $c->stash->{selection_markers_cnt
} = $sel_pop_mr_cnt;
405 my $protocol = $c->controller('solGS::genotypingProtocol')
406 ->create_protocol_url( $c, $protocol_id );
407 $c->stash->{protocol_url
} = $protocol;
410 'training_pop_id' => $model_id,
411 'trait_id' => $trait_id,
412 'genotyping_protocol_id' => $protocol_id,
413 'data_set_type' => $data_set_type
416 my $training_pop_page =
417 $c->controller('solGS::Path')->training_page_url($args);
418 my $training_pop = "Training population $model_id";
419 my $pop_link = qq | <a href
="$training_pop_page">$training_pop </a
>|;
421 $c->stash->{pop_link
} = $pop_link;
422 $c->stash->{training_pop_name
} = $training_pop;
424 my $training_model_page =
425 $c->controller('solGS::Path')->model_page_url($args);
427 qq | <a href
="$training_model_page">$training_pop -- $trait_abbr </a
>|;
428 $c->stash->{model_page_url
} = $model_link;
430 $c->controller('solGS::Files')
431 ->rrblup_selection_gebvs_file( $c, $model_id, $selection_pop_id,
433 my $gebvs_file = $c->stash->{rrblup_selection_gebvs_file
};
435 my @stock_rows = read_file
( $gebvs_file, { binmode => ':utf8' } );
436 $c->stash->{selection_stocks_cnt
} = scalar(@stock_rows) - 1;
438 $c->controller('solGS::solGS')->top_blups( $c, $gebvs_file );
440 # my $training_pop_name = $c->stash->{training_pop_name};
441 # my $model_link = "$training_pop_name -- $trait_abbr";
442 # $model_page = $c->controller('solGS::Path')->create_hyperlink($model_page, $model_link);
443 # $c->stash->{model_page_url} = $model_page;
445 $c->stash->{template
} = $c->controller('solGS::Files')
446 ->template('/population/selection_prediction_detail.mas');
450 sub combine_populations
: Path
('/solgs/combine/populations/trait') Args
() {
451 my ( $self, $c, $trait_id, $protocol_id ) = @_;
453 my ( @pop_ids, $ids );
455 if ( $trait_id =~ /\d+/ ) {
456 $ids = $c->req->param($trait_id);
457 @pop_ids = split( /,/, $ids );
459 $c->controller('solGS::Trait')->get_trait_details( $c, $trait_id );
463 my $ret->{status
} = 0;
465 if ( scalar(@pop_ids) > 1 ) {
466 $combo_pops_id = crc
( join( '', @pop_ids ) );
467 $c->stash->{combo_pops_id
} = $combo_pops_id;
468 $c->stash->{trait_combo_pops
} = $ids;
470 $c->stash->{trait_combine_populations
} = \
@pop_ids;
472 $self->multi_pops_phenotype_data( $c, \
@pop_ids );
473 $self->multi_pops_genotype_data( $c, \
@pop_ids );
474 $self->multi_pops_geno_files( $c, \
@pop_ids );
475 $self->multi_pops_pheno_files( $c, \
@pop_ids );
477 my $geno_files = $c->stash->{multi_pops_geno_files
};
478 my @g_files = split( /\t/, $geno_files );
480 $c->controller('solGS::Search')
481 ->compare_genotyping_platforms( $c, \
@g_files );
482 my $not_matching_pops = $c->stash->{pops_with_no_genotype_match
};
484 if ( !$not_matching_pops ) {
485 $self->cache_combined_pops_data($c);
487 my $combined_pops_pheno_file =
488 $c->stash->{trait_combined_pheno_file
};
489 my $combined_pops_geno_file = $c->stash->{trait_combined_geno_file
};
491 unless ( -s
$combined_pops_geno_file
492 && -s
$combined_pops_pheno_file )
494 $self->r_combine_populations($c);
496 $combined_pops_pheno_file =
497 $c->stash->{trait_combined_pheno_file
};
498 $combined_pops_geno_file =
499 $c->stash->{trait_combined_geno_file
};
502 if ( -s
$combined_pops_pheno_file && -s
$combined_pops_geno_file ) {
503 my $tr_abbr = $c->stash->{trait_abbr
};
504 $c->stash->{data_set_type
} = 'combined_populations';
505 $c->controller('solGS::solGS')->get_rrblup_output($c);
506 my $analysis_result = $c->stash->{combo_pops_analysis_result
};
508 $ret->{pop_ids
} = $ids;
509 $ret->{combo_pops_id
} = $combo_pops_id;
510 $ret->{status
} = $analysis_result;
512 $self->catalogue_combined_pops( $c, $ids );
516 $ret->{not_matching_pops
} = $not_matching_pops;
520 my $pop_id = $pop_ids[0];
521 $ret->{pop_id
} = $pop_id;
523 'trait_id' => $trait_id,
524 'training_pop_id' => $pop_id,
525 'genotyping_protocol_id' => $protocol_id,
526 'data_set_type' => 'single_population'
529 my $model_page = $c->controller('solGS::Path')->model_page_url($args);
530 $ret->{redirect_url
} = $model_page;
533 $ret = to_json
($ret);
535 $c->res->content_type('application/json');
540 sub combine_populations_confrim
:
541 Path
('/solgs/combine/populations/trait/confirm') Args
() {
542 my ( $self, $c, $trait_id, $protocol_id ) = @_;
544 my ( @pop_ids, $ids );
546 if ( $trait_id =~ /\d+/ ) {
547 $ids = $c->req->param('confirm_populations');
548 @pop_ids = split( /,/, $ids );
549 if ( !@pop_ids ) { @pop_ids = $ids; }
551 $c->stash->{trait_id
} = $trait_id;
555 my @selected_pops_details;
557 foreach my $pop_id (@pop_ids) {
558 my $markers = $c->controller('solGS::Search')->model($c)
559 ->get_project_genotyping_markers($pop_id);
560 my @markers = split( /\t/, $markers );
561 my $markers_num = scalar(@markers);
563 $c->controller('solGS::Search')
564 ->trial_compatibility_table( $c, $markers_num );
565 my $match_code = $c->stash->{trial_compatibility_code
};
567 my $pop_rs = $c->model('solGS::Search')->project_details($pop_id);
569 $c->controller('solGS::Search')->get_projects_details( $c, $pop_rs );
571 #my $pop_details = $self->get_projects_details($c, $pop_rs);
572 my $pop_details = $c->stash->{projects_details
};
573 my $pop_name = $pop_details->{$pop_id}{project_name
};
574 my $pop_desc = $pop_details->{$pop_id}{project_desc
};
575 my $pop_year = $pop_details->{$pop_id}{project_year
};
576 my $pop_location = $pop_details->{$pop_id}{project_location
};
579 qq |<form
> <input style
="background-color: $match_code;" type
="checkbox" checked
="checked" name
="project" value
="$pop_id" /> </form
> |;
582 'trait_id' => $trait_id,
583 'training_pop_id' => $pop_id,
584 'genotyping_protocol_id' => $protocol_id,
585 'data_set_type' => 'single_population'
588 my $model_page = $c->controller('solGS::Path')->model_page_url($args);
590 qq | <div
class=trial_code style
="color: $match_code; background-color: $match_code; height: 100%; width:100%">code
</div
> |;
592 push @selected_pops_details,
595 qq|<a href
="$model_page" onclick
="solGS.waitPage()">$pop_name</a
>|,
604 $c->stash->{selected_pops_details
} = \
@selected_pops_details;
605 $c->stash->{template
} = $c->controller('solGS::Files')
606 ->template('/search/result/confirm/populations.mas');
610 sub multi_pops_pheno_files
{
611 my ( $self, $c, $pop_ids ) = @_;
613 $pop_ids = $c->stash->{pops_ids_list
} if !$pop_ids;
615 my $trait_id = $c->stash->{trait_id
};
618 if ( defined reftype
($pop_ids) && reftype
($pop_ids) eq 'ARRAY' ) {
620 foreach my $pop_id (@
$pop_ids) {
621 $c->controller('solGS::Files')->phenotype_file_name( $c, $pop_id );
622 push @pheno_files, $c->stash->{phenotype_file_name
};
625 $files = join( "\t", @pheno_files );
626 $c->stash->{multi_pops_pheno_files
} = $files;
629 $c->controller('solGS::Files')->phenotype_file_name( $c, $pop_ids );
630 $files = $c->stash->{phenotype_file_name
};
634 my $name = "trait_${trait_id}_multi_pheno_files";
635 my $temp_dir = $c->stash->{solgs_tempfiles_dir
};
637 $c->controller('solGS::Files')->create_tempfile( $temp_dir, $name );
638 write_file
( $tempfile, { binmode => ':utf8' }, $files );
643 sub multi_pops_geno_files
{
644 my ( $self, $c, $pop_ids ) = @_;
646 $pop_ids = $c->stash->{pops_ids_list
} if !$pop_ids;
648 my $trait_id = $c->stash->{trait_id
};
651 if ( defined reftype
($pop_ids) && reftype
($pop_ids) eq 'ARRAY' ) {
653 foreach my $pop_id (@
$pop_ids) {
654 $c->controller('solGS::Files')->genotype_file_name( $c, $pop_id );
655 push @geno_files, $c->stash->{genotype_file_name
};
658 $files = join( "\t", @geno_files );
659 $c->stash->{multi_pops_geno_files
} = $files;
662 $c->controller('solGS::Files')->genotype_file_name( $c, $pop_ids );
663 $files = $c->stash->{genotype_file_name
};
667 my $name = "trait_${trait_id}_multi_geno_files";
668 my $temp_dir = $c->stash->{solgs_tempfiles_dir
};
670 $c->controller('solGS::Files')->create_tempfile( $temp_dir, $name );
671 write_file
( $tempfile, { binmode => ':utf8' }, $files );
676 sub multi_pops_phenotype_data
{
677 my ( $self, $c, $pop_ids ) = @_;
679 $pop_ids = $c->stash->{pops_ids_list
} if !$pop_ids;
681 no warnings
'uninitialized';
684 foreach my $pop_id (@
$pop_ids) {
685 $c->stash->{pop_id
} = $pop_id;
686 $c->controller('solGS::solGS')->phenotype_file( $c, $pop_id );
687 push @job_ids, $c->stash->{r_job_id
};
691 @job_ids = uniq
(@job_ids);
692 $c->stash->{multi_pops_pheno_jobs_ids
} = \
@job_ids;
698 sub multi_pops_genotype_data
{
699 my ( $self, $c, $pop_ids ) = @_;
701 $pop_ids = $c->stash->{pops_ids_list
} if !$pop_ids;
703 no warnings
'uninitialized';
706 foreach my $pop_id (@
$pop_ids) {
707 $c->stash->{pop_id
} = $pop_id;
708 $c->controller('solGS::solGS')->genotype_file( $c, $pop_id );
709 push @job_ids, $c->stash->{r_job_id
};
713 @job_ids = uniq
(@job_ids);
714 $c->stash->{multi_pops_geno_jobs_ids
} = \
@job_ids;
720 sub combined_pops_catalogue_file
{
721 my ( $self, $c ) = @_;
724 key
=> 'combined_pops_catalogue_file',
725 file
=> 'combined_pops_catalogue_file',
726 stash_key
=> 'combined_pops_catalogue_file',
727 cache_dir
=> $c->stash->{solgs_cache_dir
}
730 $c->controller('solGS::Files')->cache_file( $c, $cache_data );
734 sub catalogue_combined_pops
{
735 my ( $self, $c, $trials_ids ) = @_;
737 my $combo_pops_id = $c->stash->{combo_pops_id
};
739 if ( !$combo_pops_id ) {
740 $c->stash->{pops_ids_list
} = $trials_ids;
741 $self->create_combined_pops_id($c);
742 $combo_pops_id = $c->stash->{combo_pops_id
};
745 my $entry = join( ',', @
$trials_ids );
747 $entry = $combo_pops_id . "\t" . $entry;
748 my @entry = ($entry);
750 $self->combined_pops_catalogue_file($c);
751 my $file = $c->stash->{combined_pops_catalogue_file
};
754 my $header = 'combo_pops_id' . "\t" . 'trials_ids' . "\n";
755 write_file
( $file, { binmode => ':utf8' }, ( $header, $entry ) );
758 my (@entries) = map { $_ =~ s/\n// ?
$_ : undef }
759 read_file
( $file, { binmode => ':utf8' } );
760 my @intersect = intersect
( @entry, @entries );
761 unless (@intersect) {
764 { append
=> 1, binmode => ':utf8' },
772 sub get_combined_pops_list
{
773 my ( $self, $c, $id ) = @_;
775 $id = $c->stash->{combo_pops_id
} if !$id;
777 $self->combined_pops_catalogue_file($c);
778 my $combo_pops_catalogue_file = $c->stash->{combined_pops_catalogue_file
};
781 uniq
( read_file
( $combo_pops_catalogue_file, { binmode => ':utf8' } ) );
784 foreach my $entry (@combos) {
785 if ( $entry =~ m/$id/ ) {
787 my ( $combo_pops_id, $pops ) = split( /\t/, $entry );
789 if ( $id == $combo_pops_id ) {
790 @pops_list = split( ',', $pops );
791 $c->stash->{combined_pops_list
} = \
@pops_list;
792 $c->stash->{trait_combo_pops
} = \
@pops_list;
800 sub combined_pops_summary
{
801 my ( $self, $c ) = @_;
803 my $combo_pops_id = $c->stash->{combo_pops_id
};
804 my $protocol_id = $c->stash->{genotyping_protocol_id
};
806 $self->get_combined_pops_list( $c, $combo_pops_id );
807 my @pops_ids = @
{ $c->stash->{trait_combo_pops
} };
809 my $desc = 'This training population is a combination of ';
812 my $tr_page_args = { 'genotyping_protocol_id' => $protocol_id, };
814 my $training_pop_page;
815 foreach my $pop_id (@pops_ids) {
816 $c->controller('solGS::Search')->get_project_details( $c, $pop_id );
817 my $pr_name = $c->stash->{project_name
};
819 $tr_page_args->{training_pop_id
} = $pop_id;
820 $tr_page_args->{'data_set_type'} = 'single_population';
823 $c->controller('solGS::Path')->training_page_url($tr_page_args);
825 $desc .= '<a href=' . $training_pop_page . '> ' . $pr_name . '</a>';
826 $desc .= $pop_id == $pops_ids[-1] ?
'.' : ' and ';
828 $c->controller('solGS::Search')->get_project_owners( $c, $pop_id );
829 my $project_owner = $c->stash->{project_owners
};
831 if ($project_owner) {
833 $projects_owners ?
', ' . $project_owner : $project_owner;
839 'training_pop_id' => $combo_pops_id,
840 'data_set_type' => 'combined_populations'
844 $c->controller('solGS::solGS')->get_markers_count( $c, $marker_args );
846 my $trait_abbr = $c->stash->{trait_abbr
};
847 my $trait_id = $c->stash->{trait_id
};
851 my $model_page_args = {
852 'training_pop_id' => $combo_pops_id,
853 'trait_id' => $trait_id,
854 'genotyping_protocol_id' => $protocol_id,
855 'data_set_type' => 'combined_populations'
859 $c->controller('solGS::Path')->model_page_url($model_page_args);
863 $self->count_combined_trials_lines( $c, $combo_pops_id, $trait_id );
864 my $training_pop_name = "Training population $combo_pops_id";
866 $tr_page_args->{'training_pop_id'} = $combo_pops_id;
867 $tr_page_args->{'data_set_type'} = 'combined_populations';
870 $c->controller('solGS::Path')->training_page_url($tr_page_args);
872 my $pop_link = qq | <a href
="$training_pop_page">$training_pop_name</a
>|;
873 my $protocol = $c->controller('solGS::genotypingProtocol')
874 ->create_protocol_url( $c, $protocol_id );
876 $c->controller('solGS::Files')->traits_acronym_file( $c, $combo_pops_id );
877 my $traits_list_file = $c->stash->{traits_acronym_file
};
879 my @traits_list = read_file
( $traits_list_file, { binmode => ':utf8' } );
880 my $traits_no = scalar(@traits_list) - 1;
883 markers_no
=> $markers_no,
884 stocks_no
=> $stocks_no,
885 traits_no
=> $traits_no,
886 training_pop_id
=> $combo_pops_id,
887 training_pop_desc
=> $desc,
888 training_pop_name
=> $training_pop_name,
889 training_pop_page
=> $pop_link,
890 owner
=> $projects_owners,
891 protocol_url
=> $protocol,
892 training_pop_url
=> $pop_link,
893 model_page_url
=> $model_link
898 sub cache_combined_pops_data
{
899 my ( $self, $c ) = @_;
901 my $trait_id = $c->stash->{trait_id
};
902 my $trait_abbr = $c->stash->{trait_abbr
};
903 my $combo_pops_id = $c->stash->{combo_pops_id
};
906 $c->stash->{data_set_type
} = 'combined_populations';
907 $c->stash->{training_pop_id
} = $combo_pops_id;
908 $c->controller('solGS::Files')->model_phenodata_file($c);
909 $c->stash->{trait_combined_pheno_file
} =
910 $c->stash->{model_phenodata_file
};
913 $c->controller('solGS::Files')->genotype_file_name( $c, $combo_pops_id );
914 $c->stash->{trait_combined_geno_file
} = $c->stash->{genotype_file_name
};
918 sub build_model_combined_trials_trait
{
919 my ( $self, $c ) = @_;
921 $c->stash->{data_set_type
} = 'combined_populations';
922 $c->stash->{pop_id
} = $c->stash->{combo_pops_id
};
923 $c->controller('solGS::Files')->rrblup_training_gebvs_file($c);
924 my $gebv_file = $c->stash->{rrblup_training_gebvs_file
};
926 unless ( -s
$gebv_file ) {
927 $self->get_combine_populations_args_file($c);
928 my $combine_job_file = $c->stash->{combine_populations_args_file
};
930 $c->stash->{prerequisite_jobs
} =
931 $c->stash->{combine_populations_args_file
};
932 $c->stash->{prerequisite_type
} = 'combine_populations';
934 $c->controller('solGS::AsyncJob')->get_gs_modeling_jobs_args_file($c);
935 $c->stash->{dependent_jobs
} = $c->stash->{gs_modeling_jobs_args_file
};
937 $c->controller('solGS::AsyncJob')->run_async($c);
941 sub combine_data_build_multiple_traits_models
{
942 my ( $self, $c ) = @_;
944 my @selected_traits = @
{ $c->stash->{training_traits_ids
} };
945 my $combo_pops_id = $c->stash->{combo_pops_id
};
947 if ( !@selected_traits ) {
948 croak
"No traits to predict: $!\n";
951 my @unpredicted_traits;
952 foreach my $trait_id (@selected_traits) {
953 $c->controller('solGS::Files')
954 ->rrblup_training_gebvs_file( $c, $combo_pops_id, $trait_id );
955 my $gebv_file = $c->stash->{rrblup_training_gebvs_file
};
957 push @unpredicted_traits, $trait_id if !-s
$gebv_file;
960 if (@unpredicted_traits) {
961 $c->stash->{training_traits_ids
} = \
@unpredicted_traits;
963 $self->get_combine_populations_args_file($c);
964 my $combine_job_file = $c->stash->{combine_populations_args_file
};
966 $c->stash->{prerequisite_jobs
} =
967 $c->stash->{combine_populations_args_file
};
968 $c->stash->{prerequisite_type
} = 'combine_populations';
970 $c->stash->{training_pop_id
} = $combo_pops_id;
971 $c->stash->{data_set_type
} = 'combined_populations';
972 $c->controller('solGS::AsyncJob')->get_gs_modeling_jobs_args_file($c);
973 $c->stash->{dependent_jobs
} = $c->stash->{gs_modeling_jobs_args_file
};
975 $c->controller('solGS::AsyncJob')->run_async($c);
980 sub predict_selection_pop_combined_pops_model
{
981 my ( $self, $c ) = @_;
983 my $data_set_type = $c->stash->{data_set_type
};
984 my $training_pop_id =
985 $c->stash->{training_pop_id
}
986 || $c->stash->{combo_pops_id
}
987 || $c->stash->{model_id
};
988 my $selection_pop_id = $c->stash->{selection_pop_id
};
990 $c->stash->{training_pop_id
} = $training_pop_id;
991 $c->stash->{pop_id
} = $training_pop_id;
993 my @selected_traits = @
{ $c->stash->{training_traits_ids
} }
994 if $c->stash->{training_traits_ids
};
996 $c->controller('solGS::solGS')->traits_with_valid_models($c);
997 my @traits_with_valid_models =
998 @
{ $c->stash->{traits_ids_with_valid_models
} };
999 $c->stash->{training_traits_ids
} = \
@traits_with_valid_models;
1001 my @prediction_traits;
1002 foreach my $trait_id (@selected_traits) {
1003 $c->controller('solGS::Files')
1004 ->rrblup_selection_gebvs_file( $c, $training_pop_id,
1005 $selection_pop_id, $trait_id );
1007 if ( !-s
$c->stash->{rrblup_selection_gebvs_file
} ) {
1008 push @prediction_traits, $trait_id;
1012 if (@prediction_traits) {
1013 $c->stash->{training_traits_ids
} = \
@prediction_traits;
1015 $c->controller('solGS::AsyncJob')
1016 ->get_selection_pop_query_args_file($c);
1017 my $pre_req = $c->stash->{selection_pop_query_args_file
};
1019 $c->controller('solGS::Files')
1020 ->selection_population_file( $c, $selection_pop_id );
1022 $c->controller('solGS::AsyncJob')->get_gs_modeling_jobs_args_file($c);
1023 my $dep_jobs = $c->stash->{gs_modeling_jobs_args_file
};
1025 $c->stash->{prerequisite_jobs
} = $pre_req;
1026 $c->stash->{prerequisite_type
} = 'selection_pop_download_data';
1027 $c->stash->{dependent_jobs
} = $dep_jobs;
1029 $c->controller('solGS::AsyncJob')->run_async($c);
1032 croak
"No traits to predict: $!\n";
1037 sub combine_trait_data
{
1038 my ( $self, $c ) = @_;
1040 my $combo_pops_id = $c->stash->{combo_pops_id
};
1041 my $trait_id = $c->stash->{trait_id
};
1043 my $solgs_controller = $c->controller('solGS::solGS');
1044 $solgs_controller->get_trait_details( $c, $trait_id );
1046 $self->cache_combined_pops_data($c);
1048 my $combined_pops_pheno_file = $c->stash->{trait_combined_pheno_file
};
1049 my $combined_pops_geno_file = $c->stash->{trait_combined_geno_file
};
1051 my $geno_cnt = ( split( /\s+/, qx / wc -l $combined_pops_geno_file / ) )[0];
1053 ( split( /\s+/, qx / wc -l $combined_pops_pheno_file / ) )[0];
1055 unless ( $geno_cnt > 10 && $pheno_cnt > 10 ) {
1056 $self->get_combined_pops_list($c);
1057 my $combined_pops_list = $c->stash->{combined_pops_list
};
1058 $c->stash->{trait_combine_populations
} = $combined_pops_list;
1060 $self->prepare_multi_pops_data($c);
1062 my $background_job = $c->stash->{background_job
};
1063 my $prerequisite_jobs = $c->stash->{multi_pops_data_jobs
};
1065 if ($background_job) {
1066 if ( $prerequisite_jobs =~ /^:+$/ ) {
1067 $prerequisite_jobs = undef;
1070 if ($prerequisite_jobs) {
1072 $c->stash->{prerequisite_jobs
} = $prerequisite_jobs;
1073 $c->stash->{prerequisite_type
} = 'download_data';
1081 sub combine_data_build_model
{
1082 my ( $self, $c ) = @_;
1084 my $trait_id = $c->stash->{trait_id
};
1085 $c->controller('solGS::Trait')->get_trait_details( $c, $trait_id );
1087 $c->stash->{prerequisite_type
} = 'combine_populations';
1089 #$self->r_combine_populations_args($c);
1090 $self->build_model_combined_trials_trait($c);
1094 sub r_combine_populations_args
{
1095 my ( $self, $c ) = @_;
1097 $self->combine_trait_data_input($c);
1098 my $input_files = $c->stash->{combine_input_files
};
1099 my $output_files = $c->stash->{combine_output_files
};
1100 my $temp_file_template = $c->stash->{combine_r_temp_file
};
1101 my $r_script = 'R/solGS/combine_populations.r';
1103 my $temp_dir = $c->stash->{solgs_tempfiles_dir
};
1104 my $background_job = $c->stash->{background_job
};
1106 my $cluster_files = $c->controller('solGS::AsyncJob')
1107 ->create_cluster_accessible_tmp_files( $c, $temp_file_template );
1108 my $out_file = $cluster_files->{out_file_temp
};
1109 my $err_file = $cluster_files->{err_file_temp
};
1110 my $in_file = $cluster_files->{in_file_temp
};
1113 my $r_cmd_file = $c->path_to($r_script);
1114 copy
( $r_cmd_file, $in_file )
1115 or die "could not copy '$r_cmd_file' to '$in_file'";
1119 'temp_dir' => $temp_dir,
1120 'out_file' => $out_file,
1121 'err_file' => $err_file
1124 my $job_config = $c->controller('solGS::AsyncJob')
1125 ->create_cluster_config( $c, $config_args );
1128 "Rscript --slave $in_file $out_file --args $input_files $output_files";
1132 'temp_dir' => $temp_dir,
1133 'config' => $job_config,
1134 'background_job' => $background_job,
1137 $c->stash->{combine_populations_args
} = $args;
1141 sub get_combine_populations_args_file
{
1142 my ( $self, $c ) = @_;
1144 my $traits = $c->stash->{training_traits_ids
} || [ $c->stash->{trait_id
} ];
1145 my $protocol_id = $c->stash->{genotyping_protocol_id
};
1147 my $combine_jobs = [];
1149 $self->get_combined_pops_list($c);
1150 my $trials = $c->stash->{combo_pops_list
};
1152 $c->controller('solGS::AsyncJob')
1153 ->training_pop_data_query_job_args( $c, $trials, $protocol_id );
1154 my $query_jobs = $c->stash->{training_pop_data_query_job_args
};
1158 foreach my $trait_id (@
$traits) {
1159 $c->stash->{trait_id
} = $trait_id;
1160 $c->controller('solGS::Trait')->get_trait_details($c);
1161 $self->r_combine_populations_args($c);
1162 push @
$combine_jobs, $c->stash->{combine_populations_args
};
1165 if ( $query_jobs->[0] ) {
1166 $preq_jobs->{1} = $query_jobs;
1167 $preq_jobs->{2} = $combine_jobs;
1170 $preq_jobs = $combine_jobs;
1173 my $temp_dir = $c->stash->{solgs_tempfiles_dir
};
1174 my $args_file = $c->controller('solGS::Files')
1175 ->create_tempfile( $temp_dir, 'combine_pops_args_file' );
1177 nstore
$preq_jobs, $args_file
1179 "combine pops args file: $! serializing combine pops args to $args_file ";
1181 $c->stash->{combine_populations_args_file
} = $args_file;
1185 sub combined_pops_gs_input_files
{
1186 my ( $self, $c ) = @_;
1188 $self->cache_combined_pops_data($c);
1189 my $combined_pops_pheno_file = $c->stash->{trait_combined_pheno_file
};
1190 my $combined_pops_geno_file = $c->stash->{trait_combined_geno_file
};
1192 #$c->controller('solGS::solGS')->save_model_info_file($c);
1194 $c->controller('solGS::Files')->model_info_file($c);
1195 my $model_info_file = $c->stash->{model_info_file
};
1197 my $trait_abbr = $c->stash->{trait_abbr
};
1198 my $temp_dir = $c->stash->{solgs_tempfiles_dir
};
1199 my $dataset_file = $c->controller('solGS::Files')
1200 ->create_tempfile( $temp_dir, "dataset_info_${trait_abbr}" );
1201 write_file
( $dataset_file, { binmode => ':utf8' }, 'combined_populations' );
1203 my $training_pop_id = $c->stash->{training_pop_id
};
1204 my $selection_pop_id = $c->stash->{selection_pop_id
};
1205 my $selection_population_file;
1207 if ($selection_pop_id) {
1208 $c->controller('solGS::Files')
1209 ->selection_population_file( $c, $selection_pop_id );
1210 $selection_population_file = $c->stash->{selection_population_file
};
1213 my $input_files = join( "\t",
1214 $combined_pops_pheno_file, $combined_pops_geno_file, $model_info_file,
1215 $dataset_file, $selection_population_file, );
1218 $c->controller('solGS::Files')
1219 ->create_tempfile( $temp_dir,
1220 "input_files_${trait_abbr}_${training_pop_id}" );
1221 write_file
( $input_file, { binmode => ':utf8' }, $input_files );
1223 $c->stash->{combined_pops_gs_input_files
} = $input_file;
1227 sub count_combined_trials_lines
{
1228 my ( $self, $c, $combo_pops_id, $trait_id ) = @_;
1230 $combo_pops_id = $c->stash->{combo_pops_id
} if !$combo_pops_id;
1231 $trait_id = $c->stash->{trait_id
} if !$trait_id;
1237 if ( $c->req->path =~ /solgs\/model\
/combined\/populations\
// ) {
1239 $self->cache_combined_pops_data($c);
1240 my $combined_pops_geno_file = $c->stash->{trait_combined_geno_file
};
1242 if ( -s
$combined_pops_geno_file ) {
1244 'training_pop_id' => $combo_pops_id,
1245 'trait_id' => $trait_id
1248 $genos_cnt = $c->controller('solGS::solGS')
1249 ->count_predicted_lines( $c, $args );
1253 $self->get_combined_pops_list($c);
1254 my $pops_ids = $c->stash->{combined_pops_list
};
1256 $self->multi_pops_geno_files( $c, $pops_ids );
1257 my $geno_files = $c->stash->{multi_pops_geno_files
};
1259 my @geno_files = split( /\t/, $geno_files );
1261 foreach my $geno_file (@geno_files) {
1262 my $genos = qx /cut -f 1 $geno_file/;
1263 my @genos = split( " ", $genos );
1264 push @genotypes, @genos;
1267 $genos_cnt = scalar( uniq
(@genotypes) );
1274 sub process_trials_list_details
{
1275 my ( $self, $c ) = @_;
1277 my $data_str = $c->stash->{data_structure
};
1279 if ( $data_str =~ /list/ ) {
1280 $c->controller('solGS::List')->get_list_trials_ids($c);
1282 elsif ( $data_str =~ /dataset/ ) {
1283 $c->controller('solGS::Dataset')->get_dataset_trials_ids($c);
1287 $c->stash->{pops_ids_list
}
1288 || $c->stash->{trials_ids
}
1289 || [ $c->stash->{pop_id
} ];
1291 my %pops_names = ();
1293 if ( $pops_ids->[0] ) {
1294 foreach my $p_id (@
$pops_ids) {
1296 $c->controller('solGS::Search')->get_project_details( $c, $p_id );
1297 $pops_names{$p_id} = $c->stash->{project_name
};
1300 if ( scalar(@
$pops_ids) > 1 ) {
1301 $c->stash->{pops_ids_list
} = $pops_ids;
1302 $c->controller('solGS::combinedTrials')
1303 ->create_combined_pops_id($c);
1307 $c->stash->{trials_names
} = \
%pops_names;
1311 sub find_common_traits
{
1312 my ( $self, $c ) = @_;
1314 my $combo_pops_id = $c->stash->{combo_pops_id
};
1316 $self->get_combined_pops_list($c);
1317 my $combined_pops_list = $c->stash->{combined_pops_list
};
1320 foreach my $trial_id (@
$combined_pops_list) {
1322 # my $trial_traits = $c->controller('solGS::Search')->model($c)->trial_traits($pop_id);
1323 # my $clean_traits = $c->controller('solGS::Utils')->remove_ontology($c, $trial_traits);
1324 my $trait_names = $c->controller('solGS::Utils')
1325 ->get_clean_trial_trait_names( $c, $trial_id );
1327 # foreach my $tr (@$clean_traits)
1329 # push @trait_names, $tr->{trait_name};
1332 if (@common_traits) {
1333 @common_traits = intersect
( @common_traits, @
$trait_names );
1336 @common_traits = @
$trait_names;
1340 $c->stash->{common_traits
} = \
@common_traits;
1343 sub save_common_traits_acronyms
{
1344 my ( $self, $c ) = @_;
1346 my $combo_pops_id = $c->stash->{combo_pops_id
};
1348 $self->find_common_traits($c);
1349 my $common_traits = $c->stash->{common_traits
};
1351 $c->stash->{training_pop_id
} = $combo_pops_id;
1352 $c->controller('solGS::Files')->traits_list_file( $c, $combo_pops_id );
1353 my $traits_file = $c->stash->{traits_list_file
};
1354 $common_traits = join( "\t", @
$common_traits );
1355 write_file
( $traits_file, { binmode => ':utf8' }, $common_traits )
1360 sub prepare_multi_pops_data
{
1361 my ( $self, $c ) = @_;
1363 $self->get_combined_pops_list($c);
1364 my $combined_pops_list = $c->stash->{combined_pops_list
};
1366 $self->multi_pops_phenotype_data( $c, $combined_pops_list );
1367 $self->multi_pops_genotype_data( $c, $combined_pops_list );
1368 $self->multi_pops_geno_files( $c, $combined_pops_list );
1369 $self->multi_pops_pheno_files( $c, $combined_pops_list );
1372 @
{ $c->stash->{multi_pops_pheno_jobs_ids
} },
1373 @
{ $c->stash->{multi_pops_geno_jobs_ids
} }
1376 my $prerequisite_jobs;
1378 if ( @all_jobs && scalar(@all_jobs) > 1 ) {
1379 $prerequisite_jobs = join( ':', @all_jobs );
1383 if ( @all_jobs && scalar(@all_jobs) == 1 ) {
1384 $prerequisite_jobs = $all_jobs[0];
1388 if ( $prerequisite_jobs =~ /^:+$/ ) { $prerequisite_jobs = undef; }
1390 #$c->stash->{prerequisite_jobs} = $prerequisite_jobs;
1391 $c->stash->{multi_pops_data_jobs
} = $prerequisite_jobs;
1394 sub combine_trait_data_input
{
1395 my ( $self, $c ) = @_;
1397 my $combo_pops_id = $c->stash->{combo_pops_id
};
1398 my $trait_id = $c->stash->{trait_id
};
1399 my $trait_abbr = $c->stash->{trait_abbr
};
1401 $self->get_combined_pops_list($c);
1402 my $combo_pops_list = $c->stash->{combined_pops_list
};
1403 $self->multi_pops_geno_files( $c, $combo_pops_list );
1404 $self->multi_pops_pheno_files( $c, $combo_pops_list );
1405 my $pheno_files = $c->stash->{multi_pops_pheno_files
};
1406 my $geno_files = $c->stash->{multi_pops_geno_files
};
1408 $self->cache_combined_pops_data($c);
1409 my $combined_pops_pheno_file = $c->stash->{trait_combined_pheno_file
};
1410 my $combined_pops_geno_file = $c->stash->{trait_combined_geno_file
};
1412 # my $trait_info = $trait_id . "\t" . $trait_abbr;
1413 # my $trait_file = $c->controller('solGS::Files')->create_tempfile($temp_dir, "trait_info_${trait_id}");
1414 # write_file($trait_file, {binmode => ':utf8'}, $trait_info);
1416 $c->controller('solGS::solGS')->save_model_info_file($c);
1418 $c->controller('solGS::Files')->model_info_file($c);
1419 my $model_info_file = $c->stash->{model_info_file
};
1421 $c->stash->{cache_dir
} = $c->stash->{solgs_cache_dir
};
1422 $c->controller('solGS::Files')->analysis_report_file($c);
1423 my $analysis_type = $c->stash->{analysis_type
};
1424 $analysis_type =~ s/\s+/_/g;
1425 my $analysis_report_file = $c->stash->{"${analysis_type}_report_file"};
1427 $c->controller("solGS::Files")->trait_raw_phenodata_file($c);
1428 my $trait_raw_phenodatafile = $c->stash->{trait_raw_phenodata_file
};
1430 join( "\t", $pheno_files, $geno_files, $model_info_file, );
1432 my $output_files = join( "\t",
1433 $combined_pops_pheno_file, $combined_pops_geno_file,
1434 $trait_raw_phenodatafile, $analysis_report_file );
1436 my $temp_dir = $c->stash->{solgs_tempfiles_dir
};
1437 my $tempfile_input =
1438 $c->controller('solGS::Files')
1439 ->create_tempfile( $temp_dir,
1440 "input_files_${trait_abbr}_${combo_pops_id}_combine" );
1441 write_file
( $tempfile_input, { binmode => ':utf8' }, $input_files );
1443 my $tempfile_output =
1444 $c->controller('solGS::Files')
1445 ->create_tempfile( $temp_dir,
1446 "output_files_${trait_abbr}_${combo_pops_id}_combine" );
1447 write_file
( $tempfile_output, { binmode => ':utf8' }, $output_files );
1449 die "\nCan't call combine populations R script without a trait id."
1451 die "\nCan't call combine populations R script without input files."
1453 die "\nCan't call combine populations R script without output files."
1456 $c->stash->{combine_input_files
} = $tempfile_input;
1457 $c->stash->{combine_output_files
} = $tempfile_output;
1458 $c->stash->{combine_r_temp_file
} =
1459 "combine-pops-${combo_pops_id}_${trait_abbr}";
1462 sub r_combine_populations
{
1463 my ( $self, $c ) = @_;
1465 $self->combine_trait_data_input($c);
1466 $c->stash->{r_script
} = 'R/solGS/combine_populations.r';
1468 $c->controller('solGS::AsyncJob')->run_r_script($c);
1472 sub create_combined_pops_id
{
1473 my ( $self, $c ) = @_;
1475 $c->stash->{combo_pops_id
} =
1476 crc
( join( '', @
{ $c->stash->{pops_ids_list
} } ) );
1480 sub begin
: Private
{
1481 my ( $self, $c ) = @_;
1483 $c->controller('solGS::Files')->get_solgs_dirs($c);