1 package CXGN
::Genotype
::Search
;
5 CXGN::Genotype::Search - an object to handle searching genotypes for stocks
9 my $genotypes_search = CXGN::Genotype::Search->new({
11 accession_list=>$accession_list,
12 trial_list=>$trial_list,
13 protocol_id=>$protocol_id
15 my $resultset = $genotypes_search->get_genotype_info();
16 my $genotypes = $resultset->{genotypes};
23 Nicolas Morales <nm529@cornell.edu>
24 With code moved from CXGN::BreederSearch
25 Lukas Mueller <lam87@cornell.edu>
26 Aimin Yan <ay247@cornell.edu>
35 use SGN
::Model
::Cvterm
;
38 has
'bcs_schema' => ( isa
=> 'Bio::Chado::Schema',
43 has
'accession_list' => (
44 isa
=> 'ArrayRef[Int]|Undef',
49 isa
=> 'ArrayRef[Int]|Undef',
53 has
'protocol_id' => (
69 =head2 get_genotype_info
71 returns: an array with genotype information
75 sub get_genotype_info
{
77 my $schema = $self->bcs_schema;
78 my $trial_list = $self->trial_list;
79 my $protocol_id = $self->protocol_id;
80 my $accession_list = $self->accession_list;
81 my $limit = $self->limit;
82 my $offset = $self->offset;
86 my $snp_genotyping_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($self->bcs_schema, 'snp genotyping', 'genotype_property')->cvterm_id();
88 my @trials_accessions;
89 foreach (@
$trial_list){
90 my $trial = CXGN
::Trial
->new({bcs_schema
=>$schema, trial_id
=>$_});
91 my $accessions = $trial->get_accessions();
92 foreach (@
$accessions){
93 push @trials_accessions, $_->{stock_id
};
97 #If accessions are explicitly given, then accessions found from trials will not be added to the search.
98 if (!$accession_list || scalar(@
$accession_list)==0) {
99 push @
$accession_list, @trials_accessions;
102 #For projects inserted into database during the addition of genotypes and genotypeprops
103 if (scalar(@trials_accessions)==0){
104 if ($trial_list && scalar(@
$trial_list)>0) {
105 $search_params{'nd_experiment_projects.project_id'} = { -in => $trial_list };
109 $search_params{'genotypeprops.type_id'} = $snp_genotyping_cvterm_id;
110 $search_params{'nd_protocol.nd_protocol_id'} = $protocol_id;
111 if ($accession_list && scalar(@
$accession_list)>0) {
112 $search_params{'stock.stock_id'} = { -in => $accession_list };
115 my @select_list = ('genotypeprops.genotypeprop_id', 'genotypeprops.value', 'nd_protocol.name', 'stock.stock_id', 'stock.uniquename', 'genotype.uniquename');
116 my @select_as_list = ('genotypeprop_id', 'value', 'protocol_name', 'stock_id', 'uniquename', 'genotype_uniquename');
117 #$self->bcs_schema->storage->debug(1);
118 my $rs = $self->bcs_schema->resultset('NaturalDiversity::NdExperiment')->search(
120 {join=> [{'nd_experiment_genotypes' => {'genotype' => 'genotypeprops'} }, {'nd_experiment_protocols' => 'nd_protocol' }, 'nd_experiment_projects', {'nd_experiment_stocks' => 'stock'} ],
121 select=> \
@select_list,
122 as
=> \
@select_as_list,
123 order_by
=>{ -asc
=>'genotypeprops.genotypeprop_id' }
128 if ($limit && defined($offset)){
129 my $rs_slice = $rs->slice($offset, $limit);
132 while (my $row = $rs->next()) {
133 my $genotype_json = $row->get_column('value');
134 my $genotype = JSON
::Any
->decode($genotype_json);
137 markerProfileDbId
=> $row->get_column('genotypeprop_id'),
138 germplasmDbId
=> $row->get_column('stock_id'),
139 germplasmName
=> $row->get_column('uniquename'),
140 genotypeUniquename
=> $row->get_column('genotype_uniquename'),
141 analysisMethod
=> $row->get_column('protocol_name'),
142 genotype_hash
=> $genotype,
143 resultCount
=> scalar(keys(%$genotype))
147 #print STDERR Dumper \@data;
149 my $total_count = $rs->count();
151 return ($total_count, \
@data);