do not attempt get the person object when no one is logged in...
[sgn.git] / lib / CXGN / Phenotypes / Exact.pm
blob5ed2b2ae06bde867c3ff21f1f3af0bbb23f5e9b1
1 package CXGN::Phenotypes::Exact;
3 =head1 NAME
5 CXGN::Phenotypes::Exact - an object to retrieve the exact phenotypes and plot/plant names for a given trial id
7 =head1 SYNOPSIS
9 my $exact_obj = CXGN::Phenotypes::Exact->new({
10 bcs_schema => $schema,
11 trial_id => 1
12 });
13 my $exact_phenotypes = $exact_obj->search();
15 $exact_phenotypes is a hashref of hashrefs, where each phenotyped_trait is a key whose value is another hash where each plot_name is a key and trait value is the value
17 =head1 AUTHORS
19 bje24
21 =cut
23 use strict;
24 use warnings;
25 use Moose;
26 use Try::Tiny;
27 use Data::Dumper;
28 use SGN::Model::Cvterm;
30 has 'bcs_schema' => ( isa => 'Bio::Chado::Schema',
31 is => 'rw',
32 required => 1,
35 has 'trial_id' => (
36 isa => 'Int',
37 is => 'rw',
38 required => 1,
41 has 'data_level' => (
42 is => 'ro',
43 isa => 'Str',
44 default => 'plot',
47 sub search {
48 my $self = shift;
49 my $schema = $self->bcs_schema;
50 my $trial_id = $self->trial_id;
51 my $data_level = $self->data_level;
53 my $stock_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, $data_level, 'stock_type')->cvterm_id();
55 my $h = $schema->storage->dbh->prepare("SELECT stock.name, (((cvterm.name::text || '|'::text) || db.name::text) || ':'::text) || dbxref.accession::text AS trait, phenotype.value
56 FROM project
57 JOIN nd_experiment_project USING(project_id)
58 JOIN nd_experiment_stock AS all_stocks ON(nd_experiment_project.nd_experiment_id = all_stocks.nd_experiment_id)
59 JOIN stock USING(stock_id)
60 JOIN nd_experiment_stock AS my_stocks ON(stock.stock_id = my_stocks.stock_id)
61 JOIN nd_experiment_phenotype ON(my_stocks.nd_experiment_id = nd_experiment_phenotype.nd_experiment_id)
62 JOIN phenotype USING(phenotype_id)
63 JOIN cvterm ON(phenotype.cvalue_id = cvterm.cvterm_id)
64 JOIN dbxref ON cvterm.dbxref_id = dbxref.dbxref_id JOIN db ON dbxref.db_id = db.db_id
65 WHERE project_id = ? AND stock.type_id = ?
66 GROUP BY 1,2,3;");
68 $h->execute($trial_id, $stock_type_id);
70 my %exact_phenotypes;
71 while (my ($stock, $synonym, $value) = $h->fetchrow_array()) {
72 $exact_phenotypes{$synonym}{$stock} = $value;
75 return \%exact_phenotypes;