EEDB/Assembly.pm untested

filter: Statementstmt 0.0% 0 / 91 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 162 CC 15 SCAR 20.4
CC
15
Cov
0%
ncbi_version
12.0
ucsc_name
12.0
release_date
12.0
CRAP 7.7
1 =head1 NAME - EEDB::Assembly
2  
3 =head1 SYNOPSIS
4  
5 =head1 DESCRIPTION
6  
7 =head1 CONTACT
8  
9 Jessica Severin <severin@gsc.riken.jp>
10  
11 =head1 LICENSE
12  
13 * Software License Agreement (BSD License)
14 * EdgeExpressDB [eeDB] system
15 * copyright (c) 2007-2009 Jessica Severin RIKEN OSC
16 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are met:
19 * * Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * * Neither the name of Jessica Severin RIKEN OSC nor the
25 * names of its contributors may be used to endorse or promote products
26 * derived from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
29 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  
39 =head1 APPENDIX
40  
41 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
42  
43 =cut
44  
45 my $__riken_gsc_assembly_global_should_cache = 1;
46 my $__riken_gsc_assembly_global_id_cache = {};
47  
48 $VERSION = 0.953;
49  
50 package EEDB::Assembly;
51  
52 use strict;
53 use Time::HiRes qw(time gettimeofday tv_interval);
54  
55 use MQdb::MappedQuery;
56 our @ISA = qw(MQdb::MappedQuery);
57  
58 #################################################
59 # Class methods
60 #################################################
61  
62 sub class { return "Assembly"; }
63  
64 sub set_cache_behaviour {
65 my $class = shift;
66 my $mode = shift;
67
68 $__riken_gsc_assembly_global_should_cache = $mode;
69
70 if(defined($mode) and ($mode eq '0')) {
71 #if turning off caching, then flush the caches
72 $__riken_gsc_assembly_global_id_cache = {};
73 }
74 }
75  
76 #################################################
77 # Instance methods
78 #################################################
79  
80 sub init {
81 my $self = shift;
82 $self->SUPER::init;
83
84 $self->{'assembly_name'} = undef;
85 $self->{'taxon_id'} = undef;
86 $self->{'ncbi_version'} = undef;
87 $self->{'ucsc_name'} = undef;
88 $self->{'release_date'} = undef;
89 return $self;
90 }
91  
92 ##########################
93 #
94 # getter/setter methods of data which is stored in database
95 #
96 ##########################
97  
98 sub taxon_id {
99 my $self = shift;
100 return $self->{'taxon_id'} = shift if(@_);
101 return $self->{'taxon_id'};
102 }
103  
104 sub ncbi_version {
105 my $self = shift;
106 return $self->{'ncbi_version'} = shift if(@_);
107 $self->{'ncbi_version'}='' unless(defined($self->{'ncbi_version'}));
108 return $self->{'ncbi_version'};
109 }
110  
111 sub ucsc_name {
112 my $self = shift;
113 return $self->{'ucsc_name'} = shift if(@_);
114 $self->{'ucsc_name'}='' unless(defined($self->{'ucsc_name'}));
115 return $self->{'ucsc_name'};
116 }
117  
118 sub release_date {
119 my $self = shift;
120 return $self->{'release_date'} = shift if(@_);
121 $self->{'release_date'}=''unless(defined($self->{'release_date'}));
122 return $self->{'release_date'};
123 }
124  
125 sub display_desc
126 {
127 my $self = shift;
128 return sprintf("Assembly(db %s ) %s : %s : %s",
129 $self->id,
130 $self->ncbi_version,
131 $self->ucsc_name,
132 $self->release_date);
133 }
134  
135 sub xml {
136 my $self = shift;
137 return sprintf("<assembly taxon_id=\"%s\" ncbi=\"%s\" ucsc=\"%s\" />\n",
138 $self->taxon_id,
139 $self->ncbi_version,
140 $self->ucsc_name);
141 }
142  
143 ####################################
144  
145 sub name_equals {
146 my $self = shift;
147 my $other = shift;
148
149 return 1 if(($self->ucsc_name eq $other->ucsc_name) or ($self->ncbi_version eq $other->ncbi_version));
150 return 0;
151 }
152  
153 #################################################
154 #
155 # DBObject override methods
156 #
157 #################################################
158  
159 sub store {
160 my $self = shift;
161 my $db = shift;
162
163 if($db) { $self->database($db); }
164 my $dbh = $self->database->get_connection;
165 my $sql = "INSERT ignore INTO assembly (
166 taxon_id,
167 ncbi_version,
168 ucsc_name,
169 release_date)
170 VALUES(?,?,?,?)";
171 my $sth = $dbh->prepare($sql);
172 $sth->execute($self->taxon_id,
173 $self->ncbi_version,
174 $self->ucsc_name,
175 $self->release_date);
176  
177 my $dbID = $sth->{'mysql_insertid'};
178 $sth->finish;
179 return undef unless($dbID);
180 $self->primary_id($dbID);
181 }
182  
183 ##### DBObject instance override methods #####
184  
185 sub mapRow {
186 my $self = shift;
187 my $rowHash = shift;
188 my $dbh = shift;
189  
190 $self->primary_id($rowHash->{'assembly_id'});
191 $self->taxon_id($rowHash->{'taxon_id'});
192 $self->ncbi_version($rowHash->{'ncbi_version'});
193 $self->ucsc_name($rowHash->{'ucsc_name'});
194 $self->release_date($rowHash->{'release_date'});
195
196 if($__riken_gsc_assembly_global_should_cache != 0) {
197 $__riken_gsc_assembly_global_id_cache->{$self->database() . $self->id} = $self;
198 }
199
200 return $self;
201 }
202  
203  
204 ##### public class methods for fetching by utilizing DBObject framework methods #####
205  
206 sub fetch_by_id {
207 my $class = shift;
208 my $db = shift;
209 my $id = shift;
210  
211 if($__riken_gsc_assembly_global_should_cache != 0) {
212 my $assembly = $__riken_gsc_assembly_global_id_cache->{$db . $id};
213 return $assembly if(defined($assembly));
214 }
215 my $sql = "SELECT * FROM assembly WHERE assembly_id=?";
216 return $class->fetch_single($db, $sql, $id);
217 }
218  
219  
220 sub fetch_by_name {
221 #a 'high level' method where by either the ncbi name or ucsc name is valid
222 my $class = shift;
223 my $db = shift;
224 my $name = shift;
225  
226 my $sql = "SELECT * FROM assembly WHERE ncbi_version=? or ucsc_name=?";
227 return $class->fetch_single($db, $sql, $name, $name);
228 }
229  
230  
231 sub fetch_all {
232 my $class = shift;
233 my $db = shift;
234
235 my $sql = "SELECT * FROM assembly";
236 return $class->fetch_multiple($db, $sql);
237 }
238  
239  
240 1;
241