Merge pull request #42 from solgenomics/topic/duplicate_image_warning
[cxgn-corelibs.git] / lib / CXGN / SNP.pm
blob8016871376cbc5b8de4770d049bf630ab294fca4
3 =head1 NAME
5 CXGN::SNP - a class to deal with SNP information.
7 =head1 DESCRIPTION
9 This class deals with a single SNP (Simple Nucleotide Polymorphism) - it can be used to store, modify, or delete information about a SNP. The term SNP is interpreted broadly and includes indels as well as polymorphisms that may include several nucleotides.
11 For SNP querying of aggregate information, use the L<CXGN::SNP::Query> class [not yet implemented].
13 It inherits from L<CXGN::DB::ModifiableI>.
15 SNPs are linked to sequences and accessions, and specify the base change. In addition, SNPs can be linked to markers that exploit that SNP, and to other meta information, such as who submitted the information, if it is experimentally verified, and the method of discovery.
17 =head1 AUTHOR
19 Lukas Mueller <lam87@cornell.edu>
21 =head1 FUNCTIONS
23 This class implements the following methods:
25 =cut
27 use strict;
30 package CXGN::SNP;
32 use base qw | CXGN::DB::ModifiableI |;
34 =head2 new
36 Usage:
37 Desc:
38 Ret:
39 Args:
40 Side Effects:
41 Example:
43 =cut
45 sub new {
46 my $class = shift;
47 my $dbh = shift;
48 my $id = shift;
49 my $self = $class->SUPER::new($dbh);
51 $self->set_snp_id($id);
52 if ($id) {
53 $self->fetch();
56 return $self;
60 =head2 fetch
62 Usage:
63 Desc:
64 Ret:
65 Args:
66 Side Effects:
67 Example:
69 =cut
71 sub fetch {
72 my $self = shift;
73 my $q = "SELECT snp_id,
74 reference_unigene_id,
75 reference_position,
76 primer_left_id,
77 primer_right_id,
78 reference_accession_id,
79 snp_accession_id,
80 reference_nucleotide,
81 snp_nucleotide,
82 sp_person_id,
83 modified_date,
84 create_date,
85 obsolete
86 FROM sgn.snp
87 WHERE snp_id = ?";
88 my $h = $self->get_dbh()->prepare($q);
90 $h->execute($self->get_snp_id());
92 my ($snp_id, $reference_unigene_id, $reference_position, $primer_left_id, $primer_right_id, $reference_accession_id, $snp_accession_id, $reference_nucleotide, $snp_nucleotide, $sp_person_id, $modified_date, $create_date, $obsolete) = $h->fetchrow_array();
94 $self->set_snp_id($snp_id);
95 $self->set_reference_unigene_id($reference_unigene_id);
96 $self->set_reference_position($reference_position);
97 $self->set_primer_left_id($primer_left_id);
98 $self->set_primer_right_id($primer_right_id);
99 $self->set_reference_accession_id($reference_accession_id);
100 $self->set_snp_accession_id($snp_accession_id);
101 $self->set_reference_nucleotide($reference_nucleotide);
102 $self->set_snp_nucleotide($snp_nucleotide);
103 $self->set_sp_person_id($sp_person_id);
104 $self->set_modified_date($modified_date);
105 $self->set_create_date($create_date);
106 $self->set_obsolete($obsolete);
113 =head2 store
115 Usage:
116 Desc:
117 Ret:
118 Args:
119 Side Effects:
120 Example:
122 =cut
124 sub store {
125 my $self = shift;
127 if ($self->get_snp_id()) {
128 my $q = "UPDATE sgn.snp SET
129 reference_unigene_id=?,
130 reference_position=?,
131 primer_left_id=?,
132 primer_right_id=?,
133 reference_accession_id=?,
134 snp_accession_id=?,
135 reference_nucleotide=?,
136 snp_nucleotide=?,
137 sp_person_id=?,
138 modified_date=NOW(),
139 obsolete=?
140 WHERE
141 snp_id=?";
142 my $h = $self->get_dbh()->prepare($q);
143 $h->execute(
144 $self->get_reference_unigene_id(),
145 $self->get_reference_position(),
146 $self->get_primer_left_id(),
147 $self->get_primer_right_id(),
148 $self->get_reference_accession_id(),
149 $self->get_snp_accession_id(),
150 $self->get_snp_nucleotide(),
151 $self->get_sp_person_id(),
152 $self->get_obsolete(),
153 $self->get_snp_id()
156 else {
157 my $q = "INSERT INTO sgn.snp
158 (reference_unigene_id,
159 reference_position,
160 primer_left_id,
161 primer_right_id,
162 reference_accession_id,
163 snp_accession_id,
164 reference_nucleotide,
165 snp_nucleotide,
166 sp_person_id,
167 modified_date,
168 create_date,
169 obsolete)
170 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), ?)";
171 my $h = $self->get_dbh()->prepare($q);
172 $h->execute();
180 =Head2_snp_id, set_snp_id
182 Usage:
183 Desc:
184 Property
185 Side Effects:
186 Example:
188 =cut
190 sub get_snp_id {
191 my $self = shift;
192 return $self->{snp_id};
195 sub set_snp_id {
196 my $self = shift;
197 $self->{snp_id} = shift;
200 =head2 accessors get_position, set_position
202 Usage:
203 Desc:
204 Property
205 Side Effects:
206 Example:
208 =cut
210 sub get_position {
211 my $self = shift;
212 return $self->{position};
215 sub set_position {
216 my $self = shift;
217 $self->{position} = shift;
219 =head2 accessors get_reference_nucleotide, set_reference_nucleotide
221 Usage:
222 Desc:
223 Property
224 Side Effects:
225 Example:
227 =cut
229 sub get_reference_nucleotide {
230 my $self = shift;
231 return $self->{reference_nucleotide};
234 sub set_reference_nucleotide {
235 my $self = shift;
236 $self->{reference_nucleotide} = shift;
238 =head2 accessors get_snp_nucleotide, set_snp_nucleotide
240 Usage:
241 Desc:
242 Property
243 Side Effects:
244 Example:
246 =cut
248 sub get_snp_nucleotide {
249 my $self = shift;
250 return $self->{snp_nucleotide};
253 sub set_snp_nucleotide {
254 my $self = shift;
255 $self->{snp_nucleotide} = shift;
259 =head2 accessors get_reference_accession_id, set_reference_accession_id
261 Usage:
262 Desc:
263 Property
264 Side Effects:
265 Example:
267 =cut
269 sub get_reference_accession_id {
270 my $self = shift;
271 return $self->{reference_accession_id};
274 sub set_reference_accession_id {
275 my $self = shift;
276 $self->{reference_accession_id} = shift;
279 =head2 accessors get_snp_accession_id, set_snp_accession_id
281 Usage:
282 Desc:
283 Property
284 Side Effects:
285 Example:
287 =cut
289 sub get_snp_accession_id {
290 my $self = shift;
291 return $self->{snp_accession_id};
294 sub set_snp_accession_id {
295 my $self = shift;
296 $self->{snp_accession_id} = shift;
300 =head2 accessors get_dbxrefs, set_dbxrefs
302 Usage:
303 Desc:
304 Property
305 Side Effects:
306 Example:
308 =cut
310 sub get_dbxrefs {
311 my $self = shift;
312 return $self->{dbxrefs};
315 sub set_dbxrefs {
316 my $self = shift;
317 $self->{dbxrefs} = shift;
320 =head2 add_marker
322 Usage:
323 Desc:
324 Ret:
325 Args:
326 Side Effects:
327 Example:
329 =cut
331 sub add_marker {
335 =head2 get_markers
337 Usage:
338 Desc:
339 Ret:
340 Args:
341 Side Effects:
342 Example:
344 =cut
346 sub get_markers {
353 =head2 create_schema
355 Usage:
356 Desc:
357 Ret:
358 Args:
359 Side Effects:
360 Example:
362 =cut
364 sub create_schema {
365 my $class = shift;
366 my $dbh = shift;
368 my $q = qq{
369 CREATE TABLE sgn.snp (
370 snp_id serial primary key,
371 reference_unigene_id bigint references sgn.unigene,
372 reference_position bigint,
373 primer_left_id bigint references sgn."sequence",
374 primer_right_id bigint references sgn."sequence",
375 reference_accession_id bigint references sgn.accession,
376 snp_accession_id bigint references sgn.accession,
377 reference_nucleotide varchar(1),
378 snp_nucleotide varchar(1),
379 sp_person_id bigint REFERENCES sgn_people.sp_person,
380 modified_date timestamp with time zone,
381 create_date timestamp with time zone,
382 obsolete boolean default false
387 $dbh->do($q);
389 $dbh->do("GRANT SELECT, UPDATE, INSERT ON sgn.snp TO web_usr");
390 $dbh->do("GRANT SELECT, UPDATE, INSERT ON snp_snp_id_seq TO web_usr");
392 my $p = qq {
393 CREATE TABLE sgn.snp_marker (
394 snp_marker_id serial primary key,
395 snp_id bigint references sgn.snp,
396 marker_id bigint references sgn.marker
400 $dbh->do($p);
402 $dbh->do("GRANT SELECT, UPDATE, INSERT ON sgn.snp_marker TO web_usr");
403 $dbh->do("GRANT SELECT, UPDATE, INSERT ON sgn.snp_marker_snp_marker_id_seq TO web_usr");
406 my $x = " CREATE TABLE sgn.snp_dbxref (
407 snp_dbxref_id serial primary key,
408 snp_id bigint references sgn.snp,
409 dbxref_id bigint references public.dbxref,
410 obsolete boolean,
411 sp_person_id bigint references sgn_people.sp_person,
412 create_date timestamp with time zone,
413 modified_date timestamp with time zone
416 $dbh->do($x);
418 $dbh->do("GRANT SELECT, UPDATE, INSERT ON sgn.snp_dbxref TO web_usr");
419 $dbh->do("GRANT SELECT, UPDATE, INSERT ON sgn.snp_dbxref_snp_dbxref_id_seq TO web_usr");
423 $dbh->commit();
429 return 2; #haha