fixed recursive_children cvterm function, and added tests for parents and children
[cxgn-corelibs.git] / lib / CXGN / Chado / FeatureLoc.pm
blob3eec5be08a4997ca4de3be8acbfd55083b320948
2 =head1 NAME
4 CXGN::Chado::FeatureLoc - a database wrapper class for the Chado featureloc table
6 =head1 DESCRIPTION
8 The featureloc table is used to map features onto other features, for example, exons on genomic sequence, or domains on proteins. The meaning of the database fields in the featureloc table has been reverse engineered to mean the following:
10 =over 4
12 =item featureloc_id: primary key
14 =item feature_id: the feature that is being mapped (let's called f1)
16 =item srcfeature_id: the feature we're mapping on (let's call it f2)
18 =item fmin: the start coordinate of f1 on f2
20 =item is_fmin_partial: is f2 truncated?
22 =item fmax: the end coordinate of f1 on f2
24 =item is_fmax_partial: is f2 truncated?
26 =item strand: either -1,-2,-3,1,2,3
28 =item phase: the phase for protein coding exons
30 =item residue_info: this is possibly used for snps (?)
32 =item locgroup:
34 =item rank:
36 =back
38 =head1 AUTHOR
40 Lukas Mueller <lam87@cornell.edu>
42 =head1 METHODS
44 This class implements the following methods:
46 =cut
50 use strict;
52 package CXGN::Chado::FeatureLoc;
54 use CXGN::DB::Object;
56 use base "CXGN::DB::Object";
59 =head2 new
61 Usage:
62 Desc:
63 Ret:
64 Args:
65 Side Effects:
66 Example:
68 =cut
71 sub new {
72 my $class = shift;
73 my $dbh = shift;
74 my $id = shift;
75 my $self = $class->SUPER::new($dbh);
77 if ($id) {
78 $self->set_featureloc_id($id);
79 $self->fetch();
82 return $self;
85 =head2 fetch
87 Usage:
88 Desc:
89 Ret:
90 Args:
91 Side Effects:
92 Example:
94 =cut
98 sub fetch {
99 my $self = shift;
100 my $query = "SELECT featureloc_id, feature_id, srcfeature_id, fmin, is_fmin_partial, famx, is_fmax_partial, strand, phase, residue_info, locgroup, rank FROM
101 featureloc WHERE featureloc_id=?";
102 my $sth = $self->get_dbh()->prepare($query);
103 $sth->execute($self->get_featureloc_id());
104 my ($featureloc_id, $feature_id, $srcfeature_id, $fmin, $is_fmin_partial, $fmax, $is_fmax_partial, $strand, $phase, $residue_info, $locgroup, $rank) = $sth->fetchrow_array();
105 $self->set_featureloc_id($featureloc_id);
106 $self->set_feature_id($feature_id);
107 $self->set_scrfeature_id($srcfeature_id);
108 $self->set_fmin($fmin);
109 $self->set_is_fmin_partial($is_fmin_partial);
110 $self->set_fmax($fmax);
111 $self->set_is_fmax_partial($is_fmax_partial);
112 $self->set_strand($strand);
113 $self->set_phase($phase);
114 $self->set_residue_info($residue_info);
115 $self->set_locgroup($locgroup);
116 $self->set_rank($rank);
119 =head2 store
121 Usage:
122 Desc:
123 Ret:
124 Args:
125 Side Effects:
126 Example:
128 =cut
131 sub store {
132 my $self = shift;
133 if ($self->get_featureloc_id()) {
134 my $query = "UPDATE featureloc SET
135 feature_id=?, srcfeature_id=?, fmin=?, is_fmin_partial=?, fmax=?, is_fmax_partial=?, strand=?, phase=?, residue_info=?, locgroup=?, rank=? WHERE featureloc_id=?";
136 my $sth = $self->get_dbh()->prepare($query);
137 $sth->execute($self->get_feature_id(),
138 $self->get_srcfeature_id(),
139 $self->get_fmin(),
140 $self->get_is_fmin_partial(),
141 $self->get_fmax(),
142 $self->get_is_fmax_partial(),
143 $self->get_strand(),
144 $self->get_phase(),
145 $self->get_residue_info(),
146 $self->get_locgroup(),
147 $self->get_rank(),
148 $self->get_featureloc_id(),
150 return $self->get_featureloc_id();
152 else {
153 my $query = "INSERT INTO featureloc (feature_id, srcfeature_id, fmin, is_fmin_partial, fmax, is_fmax_partial, strand, phase, residue_info, locgroup, rank) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
154 my $sth = $self->get_dbh()->prepare($query);
155 $sth->execute( $self->get_feature_id(),
156 $self->get_srcfeature_id(),
157 $self->get_fmin(),
158 $self->get_is_fmin_partial(),
159 $self->get_fmax(),
160 $self->get_is_fmax_partial(),
161 $self->get_strand(),
162 $self->get_phase(),
163 $self->get_residue_info(),
164 $self->get_locgroup(),
165 $self->get_rank()
167 my $id = $self->get_currval("featureloc_featureloc_id_seq");
168 $self->set_featureloc_id($id);
169 return $id;
173 =head2 accessors get_featureloc_id, set_featureloc_id
175 Usage:
176 Desc:
177 Property
178 Side Effects:
179 Example:
181 =cut
183 sub get_featureloc_id {
184 my $self = shift;
185 return $self->{featureloc_id};
188 sub set_featureloc_id {
189 my $self = shift;
190 $self->{featureloc_id} = shift;
193 =head2 accessors get_feature_id, set_feature_id
195 Usage:
196 Desc:
197 Property
198 Side Effects:
199 Example:
201 =cut
203 sub get_feature_id {
204 my $self = shift;
205 return $self->{feature_id};
208 sub set_feature_id {
209 my $self = shift;
210 $self->{feature_id} = shift;
213 =head2 accessors get_srcfeature_id, set_srcfeature_id
215 Usage:
216 Desc:
217 Property
218 Side Effects:
219 Example:
221 =cut
223 sub get_srcfeature_id {
224 my $self = shift;
225 return $self->{srcfeature_id};
228 sub set_srcfeature_id {
229 my $self = shift;
230 $self->{srcfeature_id} = shift;
233 =head2 accessors get_fmin, set_fmin
235 Usage:
236 Desc:
237 Property
238 Side Effects:
239 Example:
241 =cut
243 sub get_fmin {
244 my $self = shift;
245 return $self->{fmin};
248 sub set_fmin {
249 my $self = shift;
250 $self->{fmin} = shift;
253 =head2 accessors get_is_fmin_partial, set_is_fmin_partial
255 Usage:
256 Desc:
257 Property
258 Side Effects:
259 Example:
261 =cut
263 sub get_is_fmin_partial {
264 my $self = shift;
265 if (!exists($self->{is_fmin_partial}) || !defined($self->{is_fmin_partial})) {
266 $self->{is_fmin_partial}='f';
268 return $self->{is_fmin_partial};
271 sub set_is_fmin_partial {
272 my $self = shift;
273 $self->{is_fmin_partial} = shift;
276 =head2 accessors get_fmax, set_fmax
278 Usage:
279 Desc:
280 Property
281 Side Effects:
282 Example:
284 =cut
286 sub get_fmax {
287 my $self = shift;
288 return $self->{fmax};
291 sub set_fmax {
292 my $self = shift;
293 $self->{fmax} = shift;
296 =head2 accessors get_is_fmax_partial, set_is_fmax_partial
298 Usage:
299 Desc:
300 Property
301 Side Effects:
302 Example:
304 =cut
306 sub get_is_fmax_partial {
307 my $self = shift;
308 if (!exists($self->{is_fmax_partial})||!defined($self->{is_fmax_partial})) {
309 $self->{is_fmax_partial}='f';
311 return $self->{is_fmax_partial};
314 sub set_is_fmax_partial {
315 my $self = shift;
316 $self->{is_fmax_partial} = shift;
319 =head2 accessors get_strand, set_strand
321 Usage:
322 Desc:
323 Property
324 Side Effects:
325 Example:
327 =cut
329 sub get_strand {
330 my $self = shift;
331 return $self->{strand};
334 sub set_strand {
335 my $self = shift;
336 $self->{strand} = shift;
339 =head2 accessors get_phase, set_phase
341 Usage:
342 Desc:
343 Property
344 Side Effects:
345 Example:
347 =cut
349 sub get_phase {
350 my $self = shift;
351 return $self->{phase};
354 sub set_phase {
355 my $self = shift;
356 $self->{phase} = shift;
359 =head2 accessors get_residue_info, set_residue_info
361 Usage:
362 Desc:
363 Property
364 Side Effects:
365 Example:
367 =cut
369 sub get_residue_info {
370 my $self = shift;
371 return $self->{residue_info};
374 sub set_residue_info {
375 my $self = shift;
376 $self->{residue_info} = shift;
379 =head2 accessors get_locgroup, set_locgroup
381 Usage:
382 Desc:
383 Property
384 Side Effects:
385 Example:
387 =cut
389 sub get_locgroup {
390 my $self = shift;
391 if (!exists($self->{locgroup}) || !defined($self->{locgroup})) {
392 $self->{locgroup}=0;
394 return $self->{locgroup};
397 sub set_locgroup {
398 my $self = shift;
399 $self->{locgroup} = shift;
402 =head2 accessors get_rank, set_rank
404 Usage:
405 Desc:
406 Property
407 Side Effects:
408 Example:
410 =cut
412 sub get_rank {
413 my $self = shift;
414 if (!exists($self->{rank}) || !defined($self->{rank})) {
415 $self->{rank} = 0;
417 return $self->{rank};
420 sub set_rank {
421 my $self = shift;
422 $self->{rank} = shift;
427 return 1;