interaction on sommer
[sgn.git] / lib / CXGN / Trait.pm
blob9f76085c8dc842ad3d116107415713307313c938
2 package CXGN::Trait;
4 use Moose;
6 ## to do: add concept of trait short name; provide alternate constructors for term, shortname, and synonyms etc.
8 has 'bcs_schema' => ( isa => 'Bio::Chado::Schema',
9 is => 'rw',
10 required => 1,
13 has 'cvterm_id' => (isa => 'Int',
14 is => 'rw',
15 required => 1,
18 has 'cvterm' => ( isa => 'Bio::Chado::Schema::Result::Cv::Cvterm',
19 is => 'rw');
22 has 'name' => ( isa => 'Str',
23 is => 'ro',
24 lazy => 1,
25 default => sub {
26 my $self = shift;
27 return $self->cvterm->name();
32 has 'display_name' => (isa => 'Str',
33 is => 'ro',
34 lazy => 1,
35 default => sub {
36 my $self = shift;
37 my $db = $self->db();
38 my $name = $self->name();
39 my $accession = $self->accession();
40 #print STDERR $db." ".$name." ".$accession."\n";
41 if ($db && $name && $accession ) {
42 return $name ."|".$db.":".$accession;
44 return "";
48 has 'accession' => (isa => 'Str',
49 is => 'ro',
50 lazy => 1,
51 default => sub {
52 my $self = shift;
53 my $rs = $self->bcs_schema()->resultset("Cv::Cvterm")
54 -> search( { cvterm_id => $self->cvterm_id() })
55 -> search_related("dbxref");
56 if ($rs->count() ==1) {
57 my $accession = $rs->first()->get_column("accession");
58 return $accession;
60 return "";
65 has 'term' => (isa => 'Str',
66 is => 'ro',
67 lazy => 1,
68 default => sub {
69 my $self = shift;
70 my $accession = $self->accession();
71 my $db = $self->db();
72 if ($accession && $db) {
73 return "$db:$accession";
75 return "";
79 has 'db' => ( isa => 'Str',
80 is => 'ro',
81 lazy => 1,
82 default => sub {
83 my $self = shift;
84 my $rs = $self->bcs_schema()->resultset("Cv::Cvterm")->search( { cvterm_id => $self->cvterm_id()})->search_related("dbxref")->search_related("db");
85 if ($rs->count() == 1) {
86 my $db_name = $rs->first()->get_column("name");
87 #print STDERR "DBNAME = $db_name\n";
88 return $db_name;
90 return "";
95 has 'db_id' => (
96 isa => 'Int',
97 is => 'ro',
98 lazy => 1,
99 default => sub {
100 my $self = shift;
101 my $rs = $self->cvterm->search_related("dbxref");
102 if ($rs->count() == 1) {
103 my $db_id = $rs->first()->get_column("db_id");
104 #print STDERR "DBID = $db_id\n";
105 return $db_id;
107 return "";
111 has 'definition' => (isa => 'Maybe[Str]',
112 is => 'ro',
113 lazy => 1,
114 default => sub {
115 my $self = shift;
116 return $self->cvterm->definition();
121 has 'format' => (isa => 'Str',
122 is => 'ro',
123 lazy => 1,
124 default => sub {
125 my $self = shift;
127 my $row = $self->bcs_schema()->resultset("Cv::Cvtermprop")->find(
129 cvterm_id => $self->cvterm_id(), 'type.name' => 'trait_format'
131 { join => 'type'}
134 if ($row) {
135 return $row->value();
137 return "";
141 has 'default_value' => (
142 isa => 'Str',
143 is => 'ro',
144 lazy => 1,
145 default => sub {
146 my $self = shift;
147 my $row = $self->bcs_schema()->resultset("Cv::Cvtermprop")->find(
148 { cvterm_id => $self->cvterm_id(), 'type.name' => 'trait_default_value' },
149 { join => 'type'}
152 if ($row) {
153 return $row->value();
155 return "";
159 has 'minimum' => (
160 isa => 'Str',
161 is => 'ro',
162 lazy => 1,
163 default => sub {
164 my $self = shift;
165 my $row = $self->bcs_schema()->resultset("Cv::Cvtermprop")->find(
166 { cvterm_id => $self->cvterm_id(), 'type.name' => 'trait_minimum' },
167 { join => 'type'}
170 if ($row) {
171 return $row->value();
173 return "";
177 has 'maximum' => (
178 isa => 'Str',
179 is => 'ro',
180 lazy => 1,
181 default => sub {
182 my $self = shift;
183 my $row = $self->bcs_schema()->resultset("Cv::Cvtermprop")->find(
184 { cvterm_id => $self->cvterm_id(), 'type.name' => 'trait_maximum' },
185 { join => 'type'}
188 if ($row) {
189 return $row->value();
191 return "";
195 has 'categories' => (
196 isa => 'Str',
197 is => 'ro',
198 lazy => 1,
199 default => sub {
200 my $self = shift;
201 my $row = $self->bcs_schema()->resultset("Cv::Cvtermprop")->find(
202 { cvterm_id => $self->cvterm_id(), 'type.name' => 'trait_categories' },
203 { join => 'type'}
206 if ($row) {
207 return $row->value();
209 return "";
213 has 'associated_plots' => ( isa => 'Str',
214 is => 'ro',
215 lazy => 1,
216 default => sub { "not yet implemented" }
219 has 'associated_accessions' => ( isa => 'Str',
220 is => 'ro',
221 lazy => 1,
222 default => sub { "not yet implemented" }
225 has 'uri' => (isa => 'Str',
226 is => 'ro',
227 lazy => 1,
228 default => sub {
229 my $self = shift;
230 my $row = $self->bcs_schema()->resultset("Cv::Cvtermprop")->find(
231 {cvterm_id => $self->cvterm_id(), 'type.name' => 'uri'},
232 { join => 'type'}
235 if ($row) {
236 return $row->value();
238 return "";
242 sub BUILD {
243 #print STDERR "BUILDING...\n";
244 my $self = shift;
245 my $cvterm = $self->bcs_schema()->resultset("Cv::Cvterm")->find( { cvterm_id => $self->cvterm_id() });
246 if ($cvterm) {
247 #print STDERR "Cvterm with ID ".$self->cvterm_id()." was found!\n";
249 $self->cvterm($cvterm);