Debian Codegraph @

GO/Model/GeneProduct.pm

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 # $Id: GeneProduct.pm,v 1.11 2007/09/13 12:44:47 girlwithglasses Exp $
2 #
3 # This GO module is maintained by Chris Mungall <[email protected]>
4 #
5 # see also - http://www.geneontology.org
6 # - http://www.godatabase.org/dev
7 #
8 # You may distribute this module under the same terms as perl itself
9
10 package GO::Model::GeneProduct;
11
12 =head1 NAME
13
14 GO::Model::GeneProduct;
15
16 =head1 DESCRIPTION
17
18 represents a gene product in a particular species (this will
19 effectively always be refered to implicitly by the gene symbol even
20 though a gene may have >1 product)
21
22 =cut
23
24
25 use Carp;
26 use Exporter;
27 use GO::Utils qw(rearrange);
28 use GO::Model::Root;
29 use strict;
30 use vars qw(@ISA);
31 use Data::Dumper;
32
33 @ISA = qw(GO::Model::Root Exporter);
34
35 sub _valid_params {
36 return qw(id acc symbol properties full_name type_id type xref speciesdb synonym_list seq_list species);
37 }
38
39 sub _initialize
40 {
41 my $self = shift;
42 my $paramh = shift;
43
44 my $db;
45 if ($paramh->{speciesdb}) {
46 $db = $paramh->{speciesdb};
47 }
48 else {
49 $db = $paramh->{xref_dbname};
50 }
51
52 my $xref =
53 GO::Model::Xref->new({xref_key=>$paramh->{acc},
54 xref_keytype=>"acc",
55 xref_dbname=>$db});
56
57 $self->xref($xref);
58 delete $paramh->{acc};
59 delete $paramh->{speciesdb};
60
61 $self->SUPER::_initialize($paramh);
62 }
63
64 =head2 acc
65
66 Usage -
67 Returns -
68 Args -
69
70 =cut
71
72 sub acc {
73 my $self = shift;
74 my $acc = shift;
75 if ($acc) {
76 $self->xref->xref_key($acc);
77 }
78 return $self->xref->xref_key;
79 }
80
81
82 =head2 symbol
83
84 Usage -
85 Returns -
86 Args -
87
88 =cut
89
90 # AUTOGENERATED
91
92 =head2 type
93
94 Usage -
95 Returns -
96 Args -
97
98 =cut
99
100 # AUTOGENERATED
101
102 =head2 full_name
103
104 Usage -
105 Returns -
106 Args -
107
108 =cut
109
110 # AUTOGENERATED
111
112 =head2 as_str
113
114 Usage -
115 Returns -
116 Args -
117
118 =cut
119
120 sub as_str {
121 my $self = shift;
122 return "GP-".$self->xref->as_str;
123 }
124
125 =head2 add_synonym
126
127 =cut
128
129 sub add_synonym {
130 my $self = shift;
131 if (!$self->{synonym_list}) {
132 $self->{synonym_list} = [];
133 }
134 push(@{$self->{synonym_list}}, (shift));
135 return $self->{synonym_list};
136 }
137
138
139 =head2 synonym_list
140
141 accessor: gets/set list of synonyms [array reference]
142
143 =cut
144
145 # AUTOGENERATED
146
147 =head2 speciesdb
148
149 Usage -
150 Returns -
151 Args -
152
153 =cut
154
155 sub speciesdb {
156 my $self = shift;
157 my $db = shift;
158 if ($db) {
159 $self->xref->xref_dbname ($db);
160 }
161 return $self->xref->xref_dbname;
162 }
163
164
165 =head2 add_seq
166
167 Usage -
168 Returns -
169 Args - GO::Model::Seq
170
171 =cut
172
173 sub add_seq {
174 my $self = shift;
175 my $seq = shift;
176
177 if ($seq->isa("Bio::SeqI")) {
178 my $bpseq = $seq;
179 $seq = GO::Model::Seq->new;
180 $seq->pseq($bpseq);
181 }
182 $seq->isa("GO::Model::Seq") or confess ("Not a seq object");
183 $self->{seq_list} = [] unless $self->{seq_list};
184
185 push(@{$self->{seq_list}}, $seq);
186 $self->{seq_list};
187 }
188
189 #indicate fetching seqs has been done: no need to try even if no seq (see seq_list)
190 sub _seqs_obtained {
191 my $self = shift;
192 $self->{_seqs_obtained} = shift if @_;
193 return $self->{_seqs_obtained};
194 }
195
196 =head2 seq_list
197
198 Usage -
199 Returns - GO::Model::Seq listref
200 Args -
201
202 =cut
203
204 sub seq_list {
205 my $self = shift;
206 if (@_) {
207 $self->{seq_list} = shift;
208 }
209 else {
210 if (!defined($self->{seq_list})) {
211 $self->{seq_list} =
212 $self->apph->get_seqs({product=>$self}) unless ($self->_seqs_obtained);
213 }
214 }
215 return $self->{seq_list};
216 }
217
218
219 =head2 seq
220
221 Usage -
222 Returns - GO::Model::Seq
223 Args -
224
225 returns representative sequence object for this product
226
227 =cut
228
229 sub seq {
230 my $self = shift;
231 my $seqs = $self->seq_list;
232 my $str = "";
233 # longest by default
234 my $longest;
235
236 foreach my $seq (@$seqs) {
237 if (!defined($longest) || $seq->length > $longest->length) {
238 $longest = $seq;
239 }
240 }
241 return $longest;
242 }
243
244 =head2 properties
245
246 Usage -
247 Returns - hashref
248 Args - hashref
249
250 =cut
251
252
253 =head2 set_property
254
255 Usage - $sf->set_property("wibble", "on");
256 Returns -
257 Args - property key, property scalar
258
259 note: the property is assumed to be multivalued, therefore
260 $sf->set_property($k, $scalar) will add to the array, and
261 $sf->set_property($k, $arrayref) will set the array
262
263 =cut
264
265 sub set_property {
266 my $self = shift;
267 my $p = shift;
268 my $v = shift;
269 if (!$self->properties) {
270 $self->properties({});
271 }
272 if (ref($v) eq 'ARRAY') {
273 confess("@$v is not all scalar") if grep {ref($_)} @$v;
274 $self->properties->{$p} = $v;
275 }
276 else {
277 push(@{$self->properties->{$p}}, $v);
278 }
279 # uniqify
280 my @vals = @{$self->properties->{$p}};
281 my %h = ();
282 my @nu_vals = ();
283 foreach (@vals) {
284 next if $h{$_};
285 $h{$_} = 1;
286 push(@nu_vals, $_);
287 }
288 $self->properties->{$p} = \@nu_vals;
289 $v;
290 }
291
292 =head2 get_property
293
294 Usage -
295 Returns - first element of the property
296 Args - property key
297
298 =cut
299
300 sub get_property {
301 my $self = shift;
302 my $p = shift;
303 if (!$self->properties) {
304 $self->properties({});
305 }
306 my $val = $self->properties->{$p};
307 if ($val) {
308 $val = $val->[0];
309 }
310 return $val;
311 }
312
313 =head2 get_property_list
314
315 Usage -
316 Returns - the property arrayref
317 Args - property key
318
319 =cut
320
321 sub get_property_list {
322 my $self = shift;
323 my $p = shift;
324 if (!$self->properties) {
325 $self->properties({});
326 }
327 $self->properties->{$p};
328 }
329
330
331 =head2 to_fasta
332
333 Usage -
334 Returns -
335 Args -
336
337 returns the longest seq by default
338
339 =cut
340
341 sub to_fasta {
342 my $self = shift;
343 my ($fullhdr, $hdrinfo, $gethdr) =
344 rearrange([qw(fullheader headerinfo getheader)], @_);
345 $hdrinfo = " " . ($hdrinfo || "");
346 my $seqs = $self->seq_list;
347 my $str = "";
348 # longest by default
349 my $longest;
350
351 return "" unless @{$seqs || []};
352
353 foreach my $seq (@$seqs) {
354 if (!defined($longest) || $seq->length > $longest->length) {
355 $longest = $seq;
356 }
357 }
358 $seqs = [$longest];
359 if ($gethdr) {
360 my $apph = $self->get_apph;
361 my $terms = $apph->get_terms({product=>$self});
362 my @h_elts = ();
363 foreach my $term (@$terms) {
364 my $al = $term->selected_association_list;
365 my %codes = ();
366 map { $codes{$_->code} = 1 } map { @{$_->evidence_list} } @$al;
367 push(@h_elts,
368 sprintf("%s evidence=%s",
369 $term->public_acc,
370 join(";", keys %codes),
371 )
372 );
373 }
374 $hdrinfo = join(", ", @h_elts);
375 }
376 foreach my $seq (@$seqs) {
377 my $desc;
378 if ($fullhdr) {
379 $desc = $fullhdr;
380 }
381 else {
382 $desc =
383 sprintf("%s|%s symbol:%s %s %s %s",
384 uc($self->xref->xref_dbname),
385 $self->xref->xref_key,
386 $self->symbol,
387 $self->species ? sprintf("species:%s \"%s\"", $self->species->ncbi_taxa_id, $self->species->binomial) : '-',
388 $hdrinfo,
389 join(" ",
390 map {$_->as_str} @{$seq->xref_list || []})
391 );
392 }
393 $seq->description($desc);
394 $str.= $seq->to_fasta;
395 }
396 return $str;
397 }
398
399 sub to_idl_struct {
400 my $self = shift;
401 return
402 {
403 "symbol"=>$self->symbol,
404 "full_name"=>$self->full_name,
405 "acc"=>$self->xref->xref_key,
406 "speciesdb"=>$self->xref->xref_dbname,
407 };
408 }
409
410 sub to_ptuples {
411 my $self = shift;
412 my ($th) =
413 rearrange([qw(tuples)], @_);
414 my @s = ();
415 push(@s,
416 ["product",
417 $self->xref->as_str,
418 $self->symbol,
419 $self->full_name,
420 ]);
421 push(@s, $self->xref->to_ptuples(-tuples=>$th));
422 @s;
423 }
424
425 # **** EXPERIMENTAL CODE ****
426 # the idea is to be homogeneous and use graphs for
427 # everything; eg gene products are nodes in a graph,
428 # associations are arcs
429 # cf rdf, daml+oil etc
430
431 # args - optional graph to add to
432 sub graphify {
433 my $self = shift;
434 my ($ref, $subg, $opts) =
435 rearrange([qw(ref graph opts)], @_);
436
437 $opts = {} unless $opts;
438 $subg = $self->apph->create_graph_obj unless $subg;
439
440 my $t =
441 $self->apph->create_term_obj({name=>$self->as_str,
442 acc=>$self->as_str});
443 $subg->add_node($t);
444 $subg->add_arc($t, $ref, "hasProduct");
445 return $subg;
446 }
447
448 1;