1 package solGS
::queryJobs
;
5 use namespace
::autoclean
;
8 use File
::Spec
::Functions qw
/ catfile catdir/;
9 use File
::Temp qw
/ tempfile tempdir /;
10 use File
::Slurp qw
/write_file read_file/;
12 use Storable qw
/ nstore retrieve /;
13 use solGS
::AnalysisReport
;
14 use Carp qw
/ carp confess croak /;
16 use SGN
::Model
::solGS
::solGS
;
17 use SGN
::Controller
::solGS
::solGS
;
18 use SGN
::Controller
::solGS
::List
;
20 use Bio
::Chado
::Schema
;
21 use CXGN
::People
::Schema
;
23 with
'MooseX::Getopt';
24 with
'MooseX::Runnable';
33 has
'dbname' => (isa
=> 'Str',
39 has
'dbhost' => (isa
=> 'Str',
45 has
'dbport' => (isa
=> 'Int',
51 has
'dbpass' => (isa
=> 'Str',
57 has
'dbuser' => (isa
=> 'Str',
63 has
'population_type' => (
76 has
'check_data_exists' => (
86 if ($self->population_type =~ /trial/) {
87 if ($self->data_type =~ /phenotype/) {
88 $self->trial_phenotype_data();
89 } elsif ($self->data_type =~ /genotype/) {
90 $self->trial_genotype_data();
92 } elsif ($self->population_type =~ /list/) {
94 if ($self->data_type =~ /phenotype/) {
95 $self->plots_list_phenotype_data();
96 } elsif ($self->data_type =~ /genotype/) {
97 $self->genotypes_list_genotype_data();
99 } elsif ($self->population_type =~ /dataset/) {
101 if ($self->data_type =~ /phenotype/) {
102 $self->plots_list_phenotype_data();
103 } elsif ($self->data_type =~ /genotype/) {
104 $self->dataset_genotype_data();
112 return retrieve
($self->args_file);
116 sub trial_genotype_data
{
119 my $args = $self->get_args();
120 my $geno_file = $args->{genotype_file
};
122 my $model = $self->get_model();
124 my $search_obj = $model->genotype_data($args);
125 $self->write_geno_data($search_obj, $geno_file);
130 sub write_geno_data
{
131 my ($self, $search_obj, $file) = @_;
133 my $exists = $self->check_data_exists;
137 my $model = $self->get_model();
139 while (my $geno = $search_obj->get_next_genotype_info())
145 my $geno_hash = $geno->{selected_genotype_hash
};
146 $marker_headers = $model->get_dataset_markers($geno_hash);
151 $geno_data = $model->structure_genotype_data($geno, $marker_headers, $add_headers);
152 write_file
($file, {append
=> 1, binmode => ':utf8'}, $$geno_data);
155 if ($self->check_data_exists)
164 sub trial_phenotype_data
{
167 my $args = $self->get_args();
169 my $pheno_file = $args->{phenotype_file
};
170 my $pop_id = $args->{population_id
};
171 my $traits_file = $args->{traits_list_file
};
172 my $metadata_file = $args->{metadata_file
};
174 my $model = $self->get_model();
175 my $pheno_data = $model->phenotype_data($pop_id);
176 my $metadata = $model->trial_metadata();
180 my $pheno_data = SGN
::Controller
::solGS
::solGS
->format_phenotype_dataset($pheno_data, $metadata, $traits_file);
181 write_file
($pheno_file, {binmode => ':utf8'}, $pheno_data);
184 write_file
($metadata_file, {binmode => ':utf8'}, join("\t", @
$metadata));
188 sub genotypes_list_genotype_data
{
190 my $genotypes_ids = shift;
192 my $args = $self->get_args();
193 $genotypes_ids = $args->{genotypes_ids
} if !$genotypes_ids->[0];
195 my $data_dir = $args->{data_dir
};
196 my $geno_file = $args->{genotype_file
};
197 my $protocol_id = $args->{genotyping_protocol_id
};
199 my $model = $self->get_model();
200 my $search_obj = $model->genotypes_list_genotype_data($genotypes_ids, $protocol_id);
202 ###empty cached geno file first
203 write_file
($geno_file);
204 $self->write_geno_data($search_obj, $geno_file);
209 sub plots_list_phenotype_data
{
212 my $args = $self->get_args();
214 my $list_id = $args->{list_id
};
215 my $plots_ids = $args->{plots_ids
};
216 my $traits_file = $args->{traits_file
};
217 #my $data_dir = $args->{data_dir};
218 my $pheno_file = $args->{phenotype_file
};
219 my $metadata_file = $args->{metadata_file
};
221 my $model = $self->get_model();
222 my $pheno_data = $model->plots_list_phenotype_data($plots_ids);
223 my $metadata = $model->trial_metadata();
225 $pheno_data = SGN
::Controller
::solGS
::solGS
->format_phenotype_dataset($pheno_data, $metadata, $traits_file);
227 write_file
($pheno_file, {binmode => ':utf8'}, $pheno_data);
228 write_file
($metadata_file, {binmode => ':utf8'}, join("\t", @
$metadata));
233 sub dataset_genotype_data
{
236 my $args = $self->get_args();
237 my $dataset_id = $args->{dataset_id
};
238 my $model = $self->get_model();
240 my $genotypes_ids = $model->get_genotypes_from_dataset ($dataset_id);
241 # my $cnt = @$genotypes_ids;
242 if (@
{$genotypes_ids})
244 $self->genotypes_list_genotype_data($genotypes_ids);
248 my $model = $self->get_model();
249 my $protocol_id = $args->{genotyping_protocol_id
};
250 my $search_obj = $model->get_dataset_genotype_data($dataset_id);
251 my $geno_file = $args->{genotype_file
};
252 ###empty cached dataset geno file first
253 write_file
($geno_file);
254 $self->write_geno_data($model, $search_obj, $geno_file);
263 my $dbname = $self->dbname;
264 my $dbhost = $self->dbhost;
266 my $dbuser = $self->dbuser;
267 my $dbpass = $self->dbpass;
269 my $dsn = "dbi:Pg:database=$dbname;host=$dbhost";
271 my $bcs_schema = Bio
::Chado
::Schema
->connect($dsn, $dbuser, $dbpass);
272 my $people_schema = CXGN
::People
::Schema
->connect($dsn, $dbuser, $dbpass, { on_connect_do
=> [ 'SET search_path TO sgn_people, public, sgn' ]});
275 my $model = SGN
::Model
::solGS
::solGS
->new({
276 schema
=> $bcs_schema,
277 people_schema
=>$people_schema });
286 __PACKAGE__
->meta->make_immutable;