Merge pull request #42 from solgenomics/topic/duplicate_image_warning
[cxgn-corelibs.git] / lib / CXGN / Insitu / Probe.pm
blob21b805028348f34a119e3c1de5be699ebb7b1402
2 =head1 NAME
5 =cut
7 ##
9 use strict;
11 package CXGN::Insitu::Probe;
13 use CXGN::Insitu::Experiment;
15 use base qw / CXGN::Insitu::DB /;
17 =head2 new
19 Usage:
20 Desc:
21 Ret:
22 Args:
23 Side Effects:
24 Example:
26 =cut
28 sub new {
29 my $class = shift;
30 my $dbh = shift;
31 my $id = shift;
33 my $self = $class->SUPER::new($dbh);
35 if ($id) {
36 $self->set_probe_id($id);
37 $self->fetch_probe();
40 return $self;
43 =head2 fetch_probe
45 Usage:
46 Desc:
47 Ret:
48 Args:
49 Side Effects:
50 Example:
52 =cut
54 sub fetch_probe {
55 my $self = shift;
56 my $query = "SELECT probe_id,
57 name,
58 sequence,
59 clone,
60 link_desc,
61 link,
62 dbxref_type_id,
63 identifier,
64 primer1,
65 primer1_seq,
66 primer2,
67 primer2_seq,
68 user_id
69 FROM insitu.probe
70 WHERE insitu.probe.probe_id=?";
71 my $sth = $self->get_dbh()->prepare($query);
72 $sth->execute($self->get_probe_id());
73 my ($probe_id, $name, $sequence, $clone, $link_desc, $link, $dbxref_type_id, $identifier, $primer1,
74 $primer1_seq, $primer2, $primer2_seq, $user_id) =
75 $sth->fetchrow_array();
76 $self->set_probe_id($probe_id);
77 $self->set_name($name);
78 $self->set_sequence($sequence);
79 $self->set_clone($clone);
80 $self->set_link_desc($link_desc);
81 $self->set_link($link);
82 $self->set_dbxref_type_id($dbxref_type_id);
83 $self->set_identifier($identifier);
84 $self->set_primer1($primer1);
85 $self->set_primer1_seq($primer1_seq);
86 $self->set_primer2($primer2);
87 $self->set_primer2_seq($primer2_seq);
88 $self->set_user_id($user_id);
91 sub store {
92 my $self = shift;
93 if ($self->get_probe_id()) {
94 my $query = "UPDATE insitu.probe SET
95 name=?,
96 sequence=?,
97 clone=?,
98 link_desc=?,
99 link=?,
100 dbxref_type_id=?,
101 identifier =?,
102 primer1 = ?,
103 primer1_seq = ?,
104 primer2 = ?,
105 primer2_seq = ?,
106 user_id=?
107 WHERE
108 probe_id=?";
109 my $sth = $self->get_dbh()->prepare($query);
110 $sth->execute($self->get_name(),
111 $self->get_sequence(),
112 $self->get_clone(),
113 $self->get_link_desc(),
114 $self->get_link(),
115 $self->get_dbxref_type_id(),
116 $self->get_identifier(),
117 $self->get_primer1(),
118 $self->get_primer1_seq(),
119 $self->get_primer2(),
120 $self->get_primer2_seq(),
121 $self->get_user_id(),
122 $self->get_probe_id()
124 return $self->get_probe_id();
126 else {
127 my $query = "INSERT INTO insitu.probe (
128 name, sequence, clone, link_desc, link, dbxref_type_id, identifier, primer1, primer1_seq, primer2, primer2_seq, user_id
129 ) VALUES (
130 ?, ?, ?, ?, ?, ?, ?,?,?,?,?,?)";
131 my $sth = $self->get_dbh()->prepare($query);
132 $sth->execute($self->get_name(),
133 $self->get_sequence(),
134 $self->get_clone(),
135 $self->get_link_desc(),
136 $self->get_link(),
137 $self->get_dbxref_type_id(),
138 $self->get_identifier(),
139 $self->get_primer1(),
140 $self->get_primer1_seq(),
141 $self->get_primer2(),
142 $self->get_primer2_seq(),
143 $self->get_user_id(),
145 return $self->get_dbh()->last_insert_id("probe");
149 sub delete {
150 my $self = shift;
152 if (!$self->get_probe_id()) { # can't delete if not in db
153 return 1;
155 if ($self->get_experiments()) { # can't delete if has experiments
156 return 2;
158 my $query = "UPDATE insitu.probe SET
159 obsolete='t'
160 WHERE probe.probe_id =?";
161 my $sth = $self->get_dbh()->prepare($query);
162 $sth->execute($self->get_probe_id());
164 return 0;
167 =head2 get_probe_id
169 Usage:
170 Desc:
171 Ret:
172 Args:
173 Side Effects:
174 Example:
176 =cut
178 sub get_probe_id {
179 my $self=shift;
180 return $self->{probe_id};
184 =head2 set_probe_id
186 Usage:
187 Desc:
188 Ret:
189 Args:
190 Side Effects:
191 Example:
193 =cut
195 sub set_probe_id {
196 my $self=shift;
197 $self->{probe_id}=shift;
202 =head2 get_name
204 Usage:
205 Desc:
206 Ret:
207 Args:
208 Side Effects:
209 Example:
211 =cut
213 sub get_name {
214 my $self=shift;
215 return $self->{name};
219 =head2 set_name
221 Usage:
222 Desc:
223 Ret:
224 Args:
225 Side Effects:
226 Example:
228 =cut
230 sub set_name {
231 my $self=shift;
232 $self->{name}=shift;
235 =head2 get_sequence
237 Usage:
238 Desc:
239 Ret:
240 Args:
241 Side Effects:
242 Example:
244 =cut
246 sub get_sequence {
247 my $self=shift;
248 return $self->{sequence};
252 =head2 set_sequence
254 Usage:
255 Desc:
256 Ret:
257 Args:
258 Side Effects:
259 Example:
261 =cut
263 sub set_sequence {
264 my $self=shift;
265 $self->{sequence}=shift;
268 =head2 get_clone
270 Usage:
271 Desc:
272 Ret:
273 Args:
274 Side Effects:
275 Example:
277 =cut
279 sub get_clone {
280 my $self=shift;
281 return $self->{clone};
285 =head2 set_clone
287 Usage:
288 Desc:
289 Ret:
290 Args:
291 Side Effects:
292 Example:
294 =cut
296 sub set_clone {
297 my $self=shift;
298 $self->{clone}=shift;
301 =head2 get_link_desc
303 Usage:
304 Desc:
305 Ret:
306 Args:
307 Side Effects:
308 Example:
310 =cut
312 sub get_link_desc {
313 my $self=shift;
314 return $self->{link_desc};
318 =head2 set_link_desc
320 Usage:
321 Desc:
322 Ret:
323 Args:
324 Side Effects:
325 Example:
327 =cut
329 sub set_link_desc {
330 my $self=shift;
331 $self->{link_desc}=shift;
334 =head2 get_link
336 Usage:
337 Desc:
338 Ret:
339 Args:
340 Side Effects:
341 Example:
343 =cut
345 sub get_link {
346 my $self=shift;
347 return $self->{link};
351 =head2 set_link
353 Usage:
354 Desc:
355 Ret:
356 Args:
357 Side Effects:
358 Example:
360 =cut
362 sub set_link {
363 my $self=shift;
364 $self->{link}=shift;
367 =head2 get_dbxref_type_id
369 Usage:
370 Desc:
371 Ret:
372 Args:
373 Side Effects:
374 Example:
376 =cut
378 sub get_dbxref_type_id {
379 my $self=shift;
380 return $self->{dbxref_type_id};
384 =head2 set_dbxref_type_id
386 Usage:
387 Desc:
388 Ret:
389 Args:
390 Side Effects:
391 Example:
393 =cut
395 sub set_dbxref_type_id {
396 my $self=shift;
397 $self->{dbxref_type_id}=shift;
401 =head2 get_identifier
403 Usage:
404 Desc:
405 Ret:
406 Args:
407 Side Effects:
408 Example:
410 =cut
412 sub get_identifier {
413 my $self=shift;
414 return $self->{identifier};
418 =head2 set_identifier
420 Usage:
421 Desc:
422 Ret:
423 Args:
424 Side Effects:
425 Example:
427 =cut
429 sub set_identifier {
430 my $self=shift;
431 $self->{identifier}=shift;
434 =head2 get_primer1
436 Usage:
437 Desc:
438 Ret:
439 Args:
440 Side Effects:
441 Example:
443 =cut
445 sub get_primer1 {
446 my $self=shift;
447 return $self->{primer1};
451 =head2 set_primer1
453 Usage:
454 Desc:
455 Ret:
456 Args:
457 Side Effects:
458 Example:
460 =cut
462 sub set_primer1 {
463 my $self=shift;
464 $self->{primer1}=shift;
467 =head2 get_primer1_seq
469 Usage:
470 Desc:
471 Ret:
472 Args:
473 Side Effects:
474 Example:
476 =cut
478 sub get_primer1_seq {
479 my $self=shift;
480 return $self->{primer1_seq};
484 =head2 set_primer1_seq
486 Usage:
487 Desc:
488 Ret:
489 Args:
490 Side Effects:
491 Example:
493 =cut
495 sub set_primer1_seq {
496 my $self=shift;
497 $self->{primer1_seq}=shift;
500 =head2 get_primer2
502 Usage:
503 Desc:
504 Ret:
505 Args:
506 Side Effects:
507 Example:
509 =cut
511 sub get_primer2 {
512 my $self=shift;
513 return $self->{primer2};
517 =head2 set_primer2
519 Usage:
520 Desc:
521 Ret:
522 Args:
523 Side Effects:
524 Example:
526 =cut
528 sub set_primer2 {
529 my $self=shift;
530 $self->{primer2}=shift;
533 =head2 get_primer2_seq
535 Usage:
536 Desc:
537 Ret:
538 Args:
539 Side Effects:
540 Example:
542 =cut
544 sub get_primer2_seq {
545 my $self=shift;
546 return $self->{primer2_seq};
550 =head2 set_primer2_seq
552 Usage:
553 Desc:
554 Ret:
555 Args:
556 Side Effects:
557 Example:
559 =cut
561 sub set_primer2_seq {
562 my $self=shift;
563 $self->{primer2_seq}=shift;
568 =head2 get_antibody
570 Usage:
571 Desc:
572 Ret:
573 Args:
574 Side Effects:
575 Example:
577 =cut
579 sub get_antibody {
580 my $self=shift;
581 return $self->{antibody};
585 =head2 set_antibody
587 Usage:
588 Desc:
589 Ret:
590 Args:
591 Side Effects:
592 Example:
594 =cut
596 sub set_antibody {
597 my $self=shift;
598 $self->{antibody}=shift;
601 =head2 get_comments
603 Usage:
604 Desc:
605 Ret:
606 Args:
607 Side Effects:
608 Example:
610 =cut
612 sub get_comments {
613 my $self=shift;
614 return $self->{comments};
618 =head2 set_comments
620 Usage:
621 Desc:
622 Ret:
623 Args:
624 Side Effects:
625 Example:
627 =cut
629 sub set_comments {
630 my $self=shift;
631 $self->{comments}=shift;
637 =head2 get_user_id
639 Usage:
640 Desc:
641 Ret:
642 Args:
643 Side Effects:
644 Example:
646 =cut
648 sub get_user_id {
649 my $self=shift;
650 return $self->{user_id};
654 =head2 set_user_id
656 Usage:
657 Desc:
658 Ret:
659 Args:
660 Side Effects:
661 Example:
663 =cut
665 sub set_user_id {
666 my $self=shift;
667 $self->{user_id}=shift;
670 =head2 get_experiments
672 Usage:
673 Desc:
674 Ret:
675 Args:
676 Side Effects:
677 Example:
679 =cut
681 sub get_experiments {
682 my $self = shift;
683 my $query = "SELECT experiment_id
684 FROM insitu.experiment
685 JOIN insitu.probe
686 USING (probe_id)
687 WHERE probe.probe_id=?";
689 my $sth = $self->get_dbh()->prepare($query);
690 $sth->execute($self->get_probe_id());
691 my @experiments = ();
692 while (my ($experiment_id) = $sth->fetchrow_array()) {
693 print STDERR "Instantiating experiment with id = $experiment_id\n";
694 my $experiment = CXGN::Insitu::Experiment->new($self->get_dbh(),$experiment_id);
695 push @experiments, $experiment;
696 print STDERR "experiment: ".$experiment->get_experiment_id()."\n";
698 return @experiments;
704 # =head2 as_html
706 # Usage:
707 # Desc:
708 # Ret:
709 # Args:
710 # Side Effects:
711 # Example:
713 # =cut
715 # sub as_html {
716 # my $self = shift;
718 # print
719 # "Name: ". $self->get_name() ."<br />".
720 # "Sequence: ".$self->get_sequence()."<br />".
721 # "Link: ".$self->get_link()."<br />\n";
725 =head2 get_all_probes
727 Usage:
728 Desc: static function that retrieves two lists,
729 one with probe names and one with probe ids.
730 Ret: ($names_array_ref, $ids_array_ref)
731 Args:
732 Side Effects: none
733 Example:
735 =cut
737 sub get_all_probes {
738 my $dbh=shift;
739 my $query = "SELECT probe_id, name
740 FROM insitu.probe";
741 my $sth = $dbh->prepare($query);
743 $sth->execute();
744 my @names = ();
745 my @ids = ();
746 while (my ($probe_id, $name) = $sth->fetchrow_array()) {
747 push @names, $name;
748 push @ids, $probe_id;
750 return (\@names, \@ids);
755 return 1;