oops, this directory was missed...
[cview.git] / lib / CXGN / Map.pm
blobea59e66f60d1c45a77ea80c6161fff654cd1a8e7
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 return $self->get_chromosome();
163 =head2 function get_chromosomes()
165 Synopsis: my @lg = $map->get_chromosomes()
166 Arguments: none
167 Returns: a list of the linkage groups in the order
168 defined by lg_order (in the case of genetic maps anyway)
169 Side effects: accesses the database, if the map is db-based.
170 Description: calls get_chromosome_names and then get_chromosome on
171 each name
173 Synopsis:
174 Arguments:
175 Returns:
176 Side effects:
177 Description:
179 =cut
181 sub get_chromosomes {
182 my $self = shift;
183 my @linkage_groups = ();
184 foreach my $lg ($self->get_chromosome_names()) {
185 push @linkage_groups, $self->get_chromosome($lg);
187 return @linkage_groups;
193 =head2 function get_linkage_groups()
195 Synopsis: a synonym for get_chromosomes()
196 Arguments: none
197 Returns:
198 Side effects: calls get_chromosomes()
199 Description: see get_chromosomes().
202 =cut
204 sub get_linkage_groups {
205 my $self = shift;
206 return $self->get_chromosomes(@_);
209 =head2 function get_overview_chromosome()
211 Synopsis:
212 Arguments:
213 Returns:
214 Side effects:
215 Description:
217 =cut
219 sub get_overview_chromosome {
220 my $self =shift;
221 my $chr_nr = shift;
222 my $chr = $self->get_chromosome($chr_nr);
223 return $chr;
226 =head2 function get_chromosome_connections()
228 Synopsis: my @chr_links = $map->get_chromosome_connections($chr_name);
229 Arguments: a chromosome name
230 Returns: a list of hashrefs, containing 4 keys
231 map_version_id, lg_name, marker_count, short_name
232 and the corresponding values
233 Side effects: most implementations will query the database
234 Description: the default implementation does nothing and returns
235 an empty list.
237 =cut
239 sub get_chromosome_connections {
240 my $self = shift;
241 my @connections = ();
242 return @connections;
246 =head2 accessors set_chromosome_count(), get_chromosome_count()
248 Synopsis: my $chr_count = $map->get_chromosome_count();
249 Property: the number of chromosomes in the Map (integer).
250 Side Effects:
251 Notes: The constructor should set this property
252 in subclasses.
254 =cut
256 sub get_chromosome_count {
257 my $self=shift;
258 return $self->{chromosome_count};
262 sub set_chromosome_count {
263 my $self=shift;
264 $self->{chromosome_count}=shift;
268 =head2 accessors set_chromosome_names(), get_chromosome_names()
270 Property: an ordered list of chromosome names
271 Side Effects: names will be used on the display to identify the
272 chromosomes.
273 Description: This property should be set in the constructor of the
274 Map object.
276 =cut
278 sub get_chromosome_names {
279 my $self=shift;
280 return @{$self->{chromosome_names}};
283 sub set_chromosome_names {
284 my $self=shift;
285 @{$self->{chromosome_names}}= @_;
289 =head2 accessors set_chromosome_lengths(), get_chromosome_lengths()
291 Synopsis: an ordered list of chromosomes lengths in the Map units.
292 Arguments: none.
293 Returns:
294 Side effects:
295 Description:
297 =cut
299 sub get_chromosome_lengths {
300 my $self = shift;
301 return @{$self->{chromosome_lengths}};
305 sub set_chromosome_lengths {
306 my $self = shift;
307 @{$self->{chromosome_lengths}} = @_;
311 =head2 get_chr_length_by_name
313 Usage:
314 Desc:
315 Ret:
316 Args:
317 Side Effects:
318 Example:
320 =cut
322 sub get_chr_len_by_name {
323 my $self = shift;
324 my $chr_name = shift;
325 my @names = $self->get_chromosome_names();
326 for (my $i=0; $i<@names; $i++) {
327 if ($names[$i] eq $chr_name) {
328 return ($self->get_chromosome_lengths())[$i];
331 return undef;
336 =head2 function has_linkage_group()
338 Synopsis: if ($map->has_linkage_group("7F")) { ... }
339 Arguments: a chromosome or linkage group name
340 Returns: returns a true value if a linkage group
341 of that name exists, a false value if it does
342 not exist. This default implementation should
343 work for all subclasses that set the chromosome_names
344 in the constructor.
345 Side effects:
346 Description:
348 =cut
350 sub has_linkage_group {
351 my $self = shift;
352 my $linkage_group = shift;
353 foreach my $lg ($self->get_chromosome_names()) {
354 if ($lg eq $linkage_group) {
355 return 1;
358 return 0;
361 =head2 function get_marker_count()
363 Synopsis: $map->get_marker_count($chr_nr)
364 Arguments: a chromosome number
365 Returns: the number of markers on that chr in the map
366 Side effects: depending on implementation, may access db
367 Description: this function needs to be implemented in sub-
368 classes for the map statistics in the SGN
369 mapviewer to work.
371 =cut
373 sub get_marker_count {
374 my $self = shift;
378 =head2 function get_marker_type_stats()
380 Synopsis:
381 Arguments:
382 Returns:
383 Side effects:
384 Description:
386 =cut
388 sub get_marker_type_stats {
393 =head2 accessors set_short_name(), get_short_name()
395 Property:
396 Setter Args:
397 Getter Args:
398 Getter Ret:
399 Side Effects:
400 Description:
402 =cut
404 sub get_short_name {
405 my $self=shift;
406 return $self->{short_name};
409 sub set_short_name {
410 my $self=shift;
411 $self->{short_name}=shift;
414 =head2 accessors set_long_name(), get_long_name()
416 Property:
417 Setter Args:
418 Getter Args:
419 Getter Ret:
420 Side Effects:
421 Description:
423 =cut
425 sub get_long_name {
426 my $self=shift;
427 return $self->{long_name};
430 sub set_long_name {
431 my $self=shift;
432 $self->{long_name}=shift;
435 =head2 accessors set_abstract(), get_abstract()
437 Property:
438 Setter Args:
439 Getter Args:
440 Getter Ret:
441 Side Effects:
442 Description:
444 =cut
446 sub get_abstract {
447 my $self=shift;
448 return $self->{abstract};
451 sub set_abstract {
452 my $self=shift;
453 $self->{abstract}=shift;
457 =head2 accessors set_centromere(), get_centromere()
459 Synopsis: my ($north, $south, $center) = $map->get_centromere($lg_name)
460 Arguments: a valid linkage group name
461 Returns: this function should return a three member list, the first
462 element corresponds to the north boundary of the centromere in cM
463 the second corresponds to the south boundary of
464 the centromere in cM, the third is the arithmetic mean
465 of the two first values.
466 Side effects: none
467 Description: this property should be set in the constructor. The setter takes
468 the north and the south position as parameters.
469 $map->set_centromere($lg_name, $north, $south)
471 =cut
473 sub get_centromere {
474 my $self=shift;
475 my $chr_name = shift;
476 return ($self->{centromere}->{$chr_name}->{north}, $self->{centromere}->{$chr_name}->{south}, ($self->{centromere}->{$chr_name}->{north}+$self->{centromere}->{$chr_name}->{south})/2);
479 sub set_centromere {
480 my $self = shift;
481 my $chr_name = shift;
482 ($self->{centromere}->{$chr_name}->{north}, $self->{centromere}->{$chr_name}->{south}) = @_;
487 =head2 accessors set_deprecated_by(), get_deprecated_by()
489 Property: some maps will support deprecation information,
490 such as the maps in the SGN database. This
491 property returns the id of the map that supercedes
492 the current map.
493 Side Effects:
494 Description:
496 =cut
498 sub get_deprecated_by {
499 my $self=shift;
500 return $self->{deprecated_by};
503 sub set_deprecated_by {
504 my $self=shift;
505 $self->{deprecated_by}=shift;
510 =head2 accessors set_type(), get_type()
512 Property: the map type, which is defined for
513 the database-based maps. Types include
514 FISH and Genetic
515 Side Effects:
516 Description:
518 =cut
520 sub get_type {
521 my $self=shift;
522 return $self->{type};
525 sub set_type {
526 my $self=shift;
527 $self->{type}=shift;
531 =head2 accessors set_units(), get_units()
533 Property: the unit measure of the map, such
534 as cM or MB
535 Side Effects:
536 Description:
538 =cut
540 sub get_units {
541 my $self=shift;
542 return $self->{units};
545 sub set_units {
546 my $self=shift;
547 $self->{units}=shift;
552 =head2 accessors set_preferred_chromosome_width(), get_preferred_chromosome_width()
554 Synopsis:
555 Arguments:
556 Returns:
557 Side effects:
558 Description:
560 =cut
562 sub set_preferred_chromosome_width {
563 my $self = shift;
564 $self->{preferred_chromosome_width}= shift;
567 sub get_preferred_chromosome_width {
568 my $self = shift;
569 return $self->{preferred_chromosome_width};
572 =head2 function can_zoom()
574 Synopsis: if ($map->can_zoom()) { ...
575 Arguments: none
576 Returns: 1 if the map supports zooming in, 0 if it
577 doesn\'t
578 Side effects: none
579 Description: default is zooming not supported.
581 =cut
583 sub can_zoom {
584 return 0;
587 =head2 function show_stats()
589 Synopsis: whether to show the stats on the overview page for
590 this map. Override if default of 1 is not appropriate.
591 Arguments:
592 Returns:
593 Side effects:
594 Description:
596 =cut
598 sub show_stats {
599 return 1;
603 =head2 function get_map_stats()
605 Synopsis: my $marker_type_html = $map->get_map_stats()
606 Returns: a HTML snippet with marker type information on this map.
607 Side effects: this will be displayed on the map overview page.
609 =cut
611 sub get_map_stats {
615 =head2 function collapsed_marker_count()
617 Synopsis:
618 Arguments:
619 Returns:
620 Side effects:
621 Description: the comparative viewer displays the reference chromosome
622 with only a small number of markers shown. This function
623 should give a number for the number of markers shown.
624 The default is 12.
626 =cut
628 sub collapsed_marker_count {
629 my $self = shift;
630 return 12;
633 =head2 function initial_zoom_height()
635 Synopsis: the initial zoom level, in map units.
636 Arguments:
637 Returns:
638 Side effects:
639 Description:
641 =cut
643 sub initial_zoom_height {
644 my $self = shift;
645 if ($self->get_units() eq "MB") {
646 return 4;
648 return 20;
652 =head2 accessors set_marker_link(), get_marker_link()
654 Synopsis: returns the appropriate link for marker $m
655 Arguments: a marker name
656 Returns:
657 Side effects: will be used to link that marker from the map
658 Description:
660 =cut
662 sub get_marker_link {
663 my $self=shift;
664 my $id = shift;
665 if ($id) {
666 return $self->{marker_link}.$id;
668 return "";
671 sub set_marker_link {
672 my $self=shift;
673 $self->{marker_link}=shift;
676 =head2 function has_IL()
678 Synopsis: if the map has an associated IL map.
679 Arguments:
680 Returns:
681 Side effects:
682 Description:
684 =cut
686 sub has_IL {
689 =head2 function has_physical()
691 Synopsis: if the map has an associated physical map.
692 Arguments:
693 Returns:
694 Side effects:
695 Description: soon to be deprecated but still used...
697 =cut
699 sub has_physical {
702 =head2 accessors set_organism(), get_organism()
704 Property: the organism name
706 Getter Args:
707 Getter Ret:
708 Side Effects:
709 Description:
710 to do: this should be expanded the two parents...
712 =cut
714 sub get_organism {
715 my $self=shift;
716 return $self->{organism};
719 sub set_organism {
720 my $self=shift;
721 $self->{organism}=shift;
724 =head2 accessors set_common_name(), get_common_name()
726 Property: the common name
727 Setter Args:
728 Getter Args:
729 Getter Ret:
730 Side Effects:
731 Description:
733 =cut
735 sub get_common_name {
736 my $self=shift;
737 return $self->{common_name};
740 sub set_common_name {
741 my $self=shift;
742 $self->{common_name}=shift;
745 =head2 function append_messages()
747 Synopsis:
748 Arguments:
749 Returns:
750 Side effects:
751 Description: appends a message string that can be displayed by the
752 chromosome viewer to tell the user about unexpected
753 conditions or errors. The messages can be retrieved
754 using get_messages().
756 =cut
758 sub append_messages {
759 my $self = shift;
760 $self->{messages} .= shift;
764 =head2 function get_messages()
766 Synopsis:
767 Arguments:
768 Returns:
769 Side effects:
770 Description: gets the message string that has been constructed using
771 the append_messages() function.
773 =cut
775 sub get_messages {
776 my $self = shift;
777 return $self->{messages};
780 =head2 map_id2map_version_id
782 Usage: $map_version_id = $map->map_id2map_version_id($map_id)
783 Desc: converts the $map_id to its corresponding $map_version_id
784 if the map supports versioning of maps. The default
785 implementation returns the same id that is fed to it
786 (no versioning).
787 Note: Needs to be over-ridden in a subclass for maps that
788 support versioning. The most recent, current version
789 should be returned.
790 Side Effects:
791 Example:
793 =cut
795 sub map_id2map_version_id {
796 my $self = shift;
797 my $map_id = shift;
798 return $map_id;
801 =head2 map_version_id2map_id
803 Usage: $map_id = $map->map_version_id2map_id($map_version_id)
804 Desc: converts the $map_version_id to its corresponding $map_id
805 if the map supports versioning of maps. The default
806 implementation returns the same id that is fed to it
807 (no versioning).
808 Note: Needs to be over-ridden in a subclass for maps that
809 support versioning.
810 Side Effects:
811 Example:
813 =cut
815 sub map_version_id2map_id {
816 my $self = shift;
817 my $map_version_id = shift;
818 return $map_version_id;
821 =head2 accessors get_legend, set_legend
823 Usage: $m->set_legend($legend_object)
824 Desc: the legend object defines the legend that
825 will be displayed in the viewer.
826 Property: a CXGN::Cview::Legend object
827 Side Effects:
828 Example:
830 =cut
832 sub get_legend {
833 my $self = shift;
834 return $self->{legend};
837 sub set_legend {
838 my $self = shift;
839 $self->{legend} = shift;
842 =head2 accessors get_temp_dir, set_temp_dir
844 Usage: $m->get_temp_dir()
845 Desc: Accessors for the temp dir [string]
846 Property
847 Side Effects: temporary files generated by this object will
848 be stored in the specified dir
849 Example:
851 =cut
853 sub get_temp_dir {
854 my $self = shift;
855 return $self->{temp_dir};
858 sub set_temp_dir {
859 my $self = shift;
860 $self->{temp_dir} = shift;
866 return 1;