changes to the parameters of map overview constructors
[cview.git] / lib / CXGN / Cview / Map.pm
blobc58b6b7f2534cdeb9a4a99456f3c788044031acb
4 =head1 NAME
6 CXGN::Cview::Map - an abstract class to deal with maps for the SGN comparative viewer.
8 =head1 DESCRIPTION
10 The SGN mapviewer traditionally used a Perl module called CXGN::Cview::Cview_data_adapter to interface to different data sources. However, this approach was not scalable and was replaced with the CXGN::Cview::Map abstract interface approach.
12 Every Map represented in the SGN comparative viewer version 2.0 needs a corresponding Map object. It needs to inherit from CXGN::Cview::Map, and implement its functions. Each map should be identifyable by an identifier, which is used by CXGN::Cview::MapFactory to create the appropriate map object. If a new map type is added, corresponding code has to be added to the MapFactory to create the map object.
14 The inherited classes should be placed in the CXGN::Cview::Map::<DATABASE>:: namespace, where <DATABASE> signifies the website these interfaces are specific to. For SGN, <DATABASE> equals "SGN".
16 See L<CXGN::Cview::MapFactory> for the current list of supported identifiers and which types of maps they will generate.
18 =head1 AUTHOR(S)
20 Lukas A. Mueller <lam87@cornell.edu>
22 =head1 VERSION
24 part of the compatibility layer of version 2.0 of the SGN mapviewer
26 =head1 FUNCTIONS
28 This class implements the following functions:
30 =cut
32 use strict;
34 package CXGN::Cview::Map;
36 use CXGN::DB::Object;
37 use CXGN::Cview::Chromosome;
38 use CXGN::Cview::Chromosome::IL;
39 use CXGN::Cview::Chromosome::PachyteneIdiogram;
40 use CXGN::Cview::Legend;
42 use base qw | CXGN::DB::Object |;
44 =head2 function new()
46 Synopsis: constructor
47 Arguments: should take a database handle and a parameter identifying a map.
48 Returns:
49 Side effects:
50 Description:
52 =cut
54 sub new {
55 my $class = shift;
56 my $dbh = shift;
57 my $self = $class->SUPER::new($dbh);
59 # set some defaults
61 $self->set_preferred_chromosome_width(20);
62 $self->set_type("generic");
63 $self->set_units("cM");
64 $self->set_short_name("unknown map");
65 $self->set_long_name("");
66 $self->set_chromosome_names("");
67 $self->set_chromosome_lengths(1);
68 $self->set_chromosome_count(1);
69 $self->set_organism("Solanum lycopersicum");
70 $self->set_common_name("Tomato");
71 $self->set_marker_link("/maps/physical/clone_info.pl?id=");
72 $self->set_legend(CXGN::Cview::Legend->new()); # an empty legend.
74 return $self;
77 =head2 accessors set_id(), get_id()
79 Property: the primary id of the map object
80 Side Effects:
81 Description:
83 =cut
85 sub get_id {
86 my $self=shift;
87 return $self->{id};
90 sub set_id {
91 my $self=shift;
92 $self->{id}=shift;
97 =head2 function get_chromosome()
99 Synopsis: my $chr = $map -> get_chromosome( $chr_nr);
100 Arguments: a legal linkage group name (usually a number, but could also
101 be alphanumeric for certain linkage groups).
102 Returns: a CXGN::Cview::Chromosome object, or a derived class thereof.
103 Side effects: in most implementations, this function will likely access
104 the databases and generate the chromosome object anew for
105 each call, such that there is considerable overhead calling
106 this function on complex chromosomes.
107 Description:
109 =cut
111 sub get_chromosome {
112 my $self = shift;
113 my $chr_nr = shift;
114 # this function should return a CXGN::Cview::Chromosome object
115 # or subclass thereof
116 my $empty_chr = CXGN::Cview::Chromosome->new($chr_nr, 100, 40, 40);
117 #$emtpy_chr -> set_height(1);
118 #$emtpy_chr -> set_length(1);
119 #$emtpy_chr -> set_color(255, 255, 255);
120 return $empty_chr;
124 =head2 function get_linkage_group()
126 Synopsis: this is a synonym for get_chromosome()
127 Arguments: see get_chromosome()
128 Returns: see get_chromosome()
129 Side effects: etc.
130 Description:
132 =cut
134 sub get_linkage_group {
135 my $self = shift;
136 return $self->get_chromosome(@_);
140 =head2 function get_chromosome_section()
142 Synopsis: my $chr_section = $map->
143 get_chromosome_section($chr_nr, $start, $end, $comparison);
144 Arguments: the chromosome name, the start offset in map units,
145 and the end offset in map units. The $comparison bit
146 tells the function that there is a comparison present
147 in the viewer, which can be used to subtly change the
148 appearance of the zoomed in section.
149 Returns: a chr_section.
150 Side effects:
151 Note: the default implementation just calls get_chromosome, ignoring the
152 start and end parameters. This is probably a useful behaviour if the
153 Map does not support sections.
155 =cut
157 sub get_chromosome_section {
158 my $self = shift;
159 my $chr_nr = shift;
161 return $self->get_chromosome($chr_nr);
165 =head2 function get_chromosomes()
167 Synopsis: my @lg = $map->get_chromosomes()
168 Arguments: none
169 Returns: a list of the linkage groups in the order
170 defined by lg_order (in the case of genetic maps anyway)
171 Side effects: accesses the database, if the map is db-based.
172 Description: calls get_chromosome_names and then get_chromosome on
173 each name
175 Synopsis:
176 Arguments:
177 Returns:
178 Side effects:
179 Description:
181 =cut
183 sub get_chromosomes {
184 my $self = shift;
185 my @linkage_groups = ();
186 foreach my $lg ($self->get_chromosome_names()) {
187 push @linkage_groups, $self->get_chromosome($lg);
189 return @linkage_groups;
195 =head2 function get_linkage_groups()
197 Synopsis: a synonym for get_chromosomes()
198 Arguments: none
199 Returns:
200 Side effects: calls get_chromosomes()
201 Description: see get_chromosomes().
204 =cut
206 sub get_linkage_groups {
207 my $self = shift;
208 return $self->get_chromosomes(@_);
211 =head2 function get_overview_chromosome()
213 Synopsis:
214 Arguments:
215 Returns:
216 Side effects:
217 Description:
219 =cut
221 sub get_overview_chromosome {
222 my $self =shift;
223 my $chr_nr = shift;
224 my $chr = $self->get_chromosome($chr_nr);
225 return $chr;
228 =head2 function get_chromosome_connections()
230 Synopsis: my @chr_links = $map->get_chromosome_connections($chr_name);
231 Arguments: a chromosome name
232 Returns: a list of hashrefs, containing 4 keys
233 map_version_id, lg_name, marker_count, short_name
234 and the corresponding values
235 Side effects: most implementations will query the database
236 Description: the default implementation does nothing and returns
237 an empty list.
239 =cut
241 sub get_chromosome_connections {
242 my $self = shift;
243 my @connections = ();
244 return @connections;
248 =head2 accessors set_chromosome_count(), get_chromosome_count()
250 Synopsis: my $chr_count = $map->get_chromosome_count();
251 Property: the number of chromosomes in the Map (integer).
252 Side Effects:
253 Notes: The constructor should set this property
254 in subclasses.
256 =cut
258 sub get_chromosome_count {
259 my $self=shift;
260 return $self->{chromosome_count};
264 sub set_chromosome_count {
265 my $self=shift;
266 $self->{chromosome_count}=shift;
270 =head2 accessors set_chromosome_names(), get_chromosome_names()
272 Property: an ordered list of chromosome names
273 Side Effects: names will be used on the display to identify the
274 chromosomes.
275 Description: This property should be set in the constructor of the
276 Map object.
278 =cut
280 sub get_chromosome_names {
281 my $self=shift;
282 return @{$self->{chromosome_names}};
285 sub set_chromosome_names {
286 my $self=shift;
287 @{$self->{chromosome_names}}= @_;
291 =head2 accessors set_chromosome_lengths(), get_chromosome_lengths()
293 Synopsis: an ordered list of chromosomes lengths in the Map units.
294 Arguments: none.
295 Returns:
296 Side effects:
297 Description: Note: the first chromosome is in list element 0.
299 =cut
301 sub get_chromosome_lengths {
302 my $self = shift;
303 return @{$self->{chromosome_lengths}};
307 sub set_chromosome_lengths {
308 my $self = shift;
309 @{$self->{chromosome_lengths}} = @_;
313 =head2 get_chr_length_by_name
315 Usage:
316 Desc:
317 Ret:
318 Args:
319 Side Effects:
320 Example:
322 =cut
324 sub get_chr_len_by_name {
325 my $self = shift;
326 my $chr_name = shift;
327 my @names = $self->get_chromosome_names();
328 for (my $i=0; $i<@names; $i++) {
329 if ($names[$i] eq $chr_name) {
330 return ($self->get_chromosome_lengths())[$i];
333 return undef;
338 =head2 function has_linkage_group()
340 Synopsis: if ($map->has_linkage_group("7F")) { ... }
341 Arguments: a chromosome or linkage group name
342 Returns: returns a true value if a linkage group
343 of that name exists, a false value if it does
344 not exist. This default implementation should
345 work for all subclasses that set the chromosome_names
346 in the constructor.
347 Side effects:
348 Description:
350 =cut
352 sub has_linkage_group {
353 my $self = shift;
354 my $linkage_group = shift;
355 foreach my $lg ($self->get_chromosome_names()) {
356 if ($lg eq $linkage_group) {
357 return 1;
360 return 0;
363 =head2 function get_marker_count()
365 Synopsis: $map->get_marker_count($chr_nr)
366 Arguments: a chromosome number
367 Returns: the number of markers on that chr in the map
368 Side effects: depending on implementation, may access db
369 Description: this function needs to be implemented in sub-
370 classes for the map statistics in the SGN
371 mapviewer to work.
373 =cut
375 sub get_marker_count {
376 my $self = shift;
377 return "?";
380 =head2 function get_marker_type_stats()
382 Synopsis:
383 Arguments:
384 Returns:
385 Side effects:
386 Description:
388 =cut
390 sub get_marker_type_stats {
395 =head2 accessors set_short_name(), get_short_name()
397 Property:
398 Setter Args:
399 Getter Args:
400 Getter Ret:
401 Side Effects:
402 Description:
404 =cut
406 sub get_short_name {
407 my $self=shift;
408 return $self->{short_name};
411 sub set_short_name {
412 my $self=shift;
413 $self->{short_name}=shift;
416 =head2 accessors set_long_name(), get_long_name()
418 Property:
419 Setter Args:
420 Getter Args:
421 Getter Ret:
422 Side Effects:
423 Description:
425 =cut
427 sub get_long_name {
428 my $self=shift;
429 return $self->{long_name};
432 sub set_long_name {
433 my $self=shift;
434 $self->{long_name}=shift;
437 =head2 accessors set_abstract(), get_abstract()
439 Property:
440 Setter Args:
441 Getter Args:
442 Getter Ret:
443 Side Effects:
444 Description:
446 =cut
448 sub get_abstract {
449 my $self=shift;
450 return $self->{abstract};
453 sub set_abstract {
454 my $self=shift;
455 $self->{abstract}=shift;
459 =head2 accessors set_centromere(), get_centromere()
461 Synopsis: my ($north, $south, $center) = $map->get_centromere($lg_name)
462 Arguments: a valid linkage group name
463 Returns: this function should return a three member list, the first
464 element corresponds to the north boundary of the centromere in cM
465 the second corresponds to the south boundary of
466 the centromere in cM, the third is the arithmetic mean
467 of the two first values.
468 Side effects: none
469 Description: this property should be set in the constructor. The setter takes
470 the north and the south position as parameters.
471 $map->set_centromere($lg_name, $north, $south)
473 =cut
475 sub get_centromere {
476 my $self=shift;
477 my $chr_name = shift;
478 return ($self->{centromere}->{$chr_name}->{north}, $self->{centromere}->{$chr_name}->{south}, ($self->{centromere}->{$chr_name}->{north}+$self->{centromere}->{$chr_name}->{south})/2);
481 sub set_centromere {
482 my $self = shift;
483 my $chr_name = shift;
484 ($self->{centromere}->{$chr_name}->{north}, $self->{centromere}->{$chr_name}->{south}) = @_;
489 =head2 accessors set_deprecated_by(), get_deprecated_by()
491 Property: some maps will support deprecation information,
492 such as the maps in the SGN database. This
493 property returns the id of the map that supercedes
494 the current map.
495 Side Effects:
496 Description:
498 =cut
500 sub get_deprecated_by {
501 my $self=shift;
502 return $self->{deprecated_by};
505 sub set_deprecated_by {
506 my $self=shift;
507 $self->{deprecated_by}=shift;
512 =head2 accessors set_type(), get_type()
514 Property: the map type, which is defined for
515 the database-based maps. Types include
516 FISH and Genetic
517 Side Effects:
518 Description:
520 =cut
522 sub get_type {
523 my $self=shift;
524 return $self->{type};
527 sub set_type {
528 my $self=shift;
529 $self->{type}=shift;
533 =head2 accessors set_units(), get_units()
535 Property: the unit measure of the map, such
536 as cM or MB
537 Side Effects:
538 Description:
540 =cut
542 sub get_units {
543 my $self=shift;
544 return $self->{units};
547 sub set_units {
548 my $self=shift;
549 $self->{units}=shift;
554 =head2 accessors set_preferred_chromosome_width(), get_preferred_chromosome_width()
556 Synopsis:
557 Arguments:
558 Returns:
559 Side effects:
560 Description:
562 =cut
564 sub set_preferred_chromosome_width {
565 my $self = shift;
566 $self->{preferred_chromosome_width}= shift;
569 sub get_preferred_chromosome_width {
570 my $self = shift;
571 return $self->{preferred_chromosome_width};
574 =head2 function can_zoom()
576 Synopsis: if ($map->can_zoom()) { ...
577 Arguments: none
578 Returns: 1 if the map supports zooming in, 0 if it
579 doesn\'t
580 Side effects: none
581 Description: default is zooming not supported.
583 =cut
585 sub can_zoom {
586 return 0;
589 =head2 show_ruler
591 Usage: should return 0 or 1, depending whether the ruler
592 should be shown on a map overview.
593 Desc: default is 1, show ruler.
594 Ret:
595 Args:
596 Side Effects:o
597 Example:
599 =cut
601 sub show_ruler {
602 return 1;
607 =head2 function show_stats()
609 Synopsis: whether to show the stats on the overview page for
610 this map. Override if default of 1 is not appropriate.
611 Arguments:
612 Returns:
613 Side effects:
614 Description:
616 =cut
618 sub show_stats {
619 return 1;
623 =head2 function get_map_stats()
625 Synopsis: my $marker_type_html = $map->get_map_stats()
626 Returns: a HTML snippet with marker type information on this map.
627 Side effects: this will be displayed on the map overview page.
629 =cut
631 sub get_map_stats {
635 =head2 function collapsed_marker_count()
637 Synopsis:
638 Arguments:
639 Returns:
640 Side effects:
641 Description: the comparative viewer displays the reference chromosome
642 with only a small number of markers shown. This function
643 should give a number for the number of markers shown.
644 The default is 12.
646 =cut
648 sub collapsed_marker_count {
649 my $self = shift;
650 return 12;
653 =head2 function initial_zoom_height()
655 Synopsis: the initial zoom level, in map units.
656 Arguments:
657 Returns:
658 Side effects:
659 Description:
661 =cut
663 sub initial_zoom_height {
664 my $self = shift;
665 if ($self->get_units() eq "MB") {
666 return 4;
668 return 20;
672 =head2 accessors set_marker_link(), get_marker_link()
674 Synopsis: returns the appropriate link for marker $m
675 Arguments: a marker name
676 Returns:
677 Side effects: will be used to link that marker from the map
678 Description:
680 =cut
682 sub get_marker_link {
683 my $self=shift;
684 my $id = shift;
685 if ($id) {
686 return $self->{marker_link}.$id;
688 return "";
691 sub set_marker_link {
692 my $self=shift;
693 $self->{marker_link}=shift;
696 =head2 function has_IL()
698 Synopsis: if the map has an associated IL map.
699 Arguments:
700 Returns:
701 Side effects:
702 Description:
704 =cut
706 sub has_IL {
709 =head2 function has_physical()
711 Synopsis: if the map has an associated physical map.
712 Arguments:
713 Returns:
714 Side effects:
715 Description: soon to be deprecated but still used...
717 =cut
719 sub has_physical {
722 =head2 accessors set_organism(), get_organism()
724 Property: the organism name
726 Getter Args:
727 Getter Ret:
728 Side Effects:
729 Description:
730 to do: this should be expanded the two parents...
732 =cut
734 sub get_organism {
735 my $self=shift;
736 return $self->{organism};
739 sub set_organism {
740 my $self=shift;
741 $self->{organism}=shift;
744 =head2 accessors set_common_name(), get_common_name()
746 Property: the common name
747 Setter Args:
748 Getter Args:
749 Getter Ret:
750 Side Effects:
751 Description:
753 =cut
755 sub get_common_name {
756 my $self=shift;
757 return $self->{common_name};
760 sub set_common_name {
761 my $self=shift;
762 $self->{common_name}=shift;
765 =head2 function append_messages()
767 Synopsis:
768 Arguments:
769 Returns:
770 Side effects:
771 Description: appends a message string that can be displayed by the
772 chromosome viewer to tell the user about unexpected
773 conditions or errors. The messages can be retrieved
774 using get_messages().
776 =cut
778 sub append_messages {
779 my $self = shift;
780 $self->{messages} .= shift;
784 =head2 function get_messages()
786 Synopsis:
787 Arguments:
788 Returns:
789 Side effects:
790 Description: gets the message string that has been constructed using
791 the append_messages() function.
793 =cut
795 sub get_messages {
796 my $self = shift;
797 return $self->{messages};
800 =head2 map_id2map_version_id
802 Usage: $map_version_id = $map->map_id2map_version_id($map_id)
803 Desc: converts the $map_id to its corresponding $map_version_id
804 if the map supports versioning of maps. The default
805 implementation returns the same id that is fed to it
806 (no versioning).
807 Note: Needs to be over-ridden in a subclass for maps that
808 support versioning. The most recent, current version
809 should be returned.
810 Side Effects:
811 Example:
813 =cut
815 sub map_id2map_version_id {
816 my $self = shift;
817 my $map_id = shift;
818 return $map_id;
821 =head2 map_version_id2map_id
823 Usage: $map_id = $map->map_version_id2map_id($map_version_id)
824 Desc: converts the $map_version_id to its corresponding $map_id
825 if the map supports versioning of maps. The default
826 implementation returns the same id that is fed to it
827 (no versioning).
828 Note: Needs to be over-ridden in a subclass for maps that
829 support versioning.
830 Side Effects:
831 Example:
833 =cut
835 sub map_version_id2map_id {
836 my $self = shift;
837 my $map_version_id = shift;
838 return $map_version_id;
841 =head2 accessors get_legend, set_legend
843 Usage: $m->set_legend($legend_object)
844 Desc: the legend object defines the legend that
845 will be displayed in the viewer.
846 Property: a CXGN::Cview::Legend object
847 Side Effects:
848 Example:
850 =cut
852 sub get_legend {
853 my $self = shift;
854 return $self->{legend};
857 sub set_legend {
858 my $self = shift;
859 $self->{legend} = shift;
862 =head2 accessors get_temp_dir, set_temp_dir
864 Usage: $m->get_temp_dir()
865 Desc: Accessors for the temp dir [string]
866 Property
867 Side Effects: temporary files generated by this object will
868 be stored in the specified dir
869 Example:
871 =cut
873 sub get_temp_dir {
874 my $self = shift;
875 return $self->{temp_dir};
878 sub set_temp_dir {
879 my $self = shift;
880 $self->{temp_dir} = shift;
886 return 1;