moving stuff around
[cview.git] / lib / CXGN / Cview / MapFactory.pm
blobe2da5430392758eccb4e627d8e3e919a8c3143a5
4 =head1 NAME
6 CXGN::Cview::MapFactory - a factory object for CXGN::Cview::Map objects
8 =head1 SYNOPSYS
10 my $map_factory = CXGN::Cview::MapFactory->new($dbh);
11 $map = $map_factory->create({map_version_id=>"u1"});
13 =head1 DESCRIPTION
15 The MapFactory object is part of a compatibility layer that defines the data sources of the comparative mapviewer. If there are different types of maps that can be distinguished by their ids, the MapFactory should be implemented to return the right map object for the given id. Of course, the corresponding map object also needs to be implemented, using the interface defined in CXGN::Cview::Map .
17 The MapFactory constructor takes a database handle (preferably constructed using CXGN::DB::Connection object). The map objects can then be constructed using the create function, which takes a hashref as a parameter, containing either map_id or map_version_id as a key (but not both). map_ids will be converted to map_version_ids immediately. Map_version_ids are then analyzed and depending on its format, CXGN::Cview::Map object of the proper type is returned.
19 The function get_all_maps returns all maps as list of appropriate CXGN::Cview::Map::* objects.
21 For the current SGN implementation, the following identifier formats are defined and yield following corresponding map objects
23 \d+ refers to a map id in the database and yields either a
24 CXGN::Cview::Map::SGN::Genetic (type genetic)
25 CXGN::Cview::Map::SGN::FISH (type fish)
26 CXGN::Cview::Map::SGN::Sequence (type sequence)
27 u\d+ refers to a user defined map and returns:
28 CXGN::Cview::Map::SGN::User object
29 filepath refers to a map defined in a file and returns a
30 CXGN::Cview::Map::SGN::File object
31 il\d+ refers to a population id in the phenome.population table
32 (which must be of type IL) and returns a
33 CXGN::Cview::Map::SGN::IL object
34 p\d+ CXGN::Cview::Map::SGN::Physical
35 c\d+ CXGN::Cview::Map::SGN::Contig
36 o CXGN::Cview::Map::SGN::ProjectStats map object
38 The actual map objects returned are defined in the CXGN::Cview::Maps namespace. Because this is really a compatibility layer, an additional namespace of the resource is appended, such that a genetic map at SGN could be defined as CXGN::Cview::Maps::SGN::Genetic . If no corresponding map is found, undef is returned.
40 =head1 AUTHOR(S)
42 Lukas Mueller (lam87@cornell.edu)
44 =head1 VERSION
46 1.0, March 2007
48 =head1 LICENSE
50 Refer to the L<CXGN::LICENSE> file.
52 =head1 FUNCTIONS
54 This class implements the following functions:
56 (See the superclass, CXGN::Cview::Maps, for a definition of the class interface)
58 =cut
60 package CXGN::Cview::MapFactory;
61 use strict;
62 use warnings;
63 use Carp;
65 use base qw| CXGN::DB::Object |;
67 =head2 function new()
69 Synopsis: constructor
70 Arguments: database handle, configuration variable hashref
71 the configuration hashref supports the following
72 hash keys:
73 o cview_db_backend
75 with the following values:
76 o cxgn_and_cmap
77 o cmap
78 o cxgn [DEFAULT]
80 Returns: a CXGN::Cview::MapFactory object
81 Side effects: none
82 Description: none
84 =cut
86 sub new {
87 my $class = shift;
88 my ($dbh, $conf_hash_ref) = @_;
90 # if no config was passed, warn about it and try to load SGN::Config
91 # $config ||= do{
92 # carp "WARNING: no config specified, trying to load SGN::Config";
93 # require SGN::Config;
94 # SGN::Config->load
95 # };
97 my $db_backend = $conf_hash_ref->{cview_db_backend};
99 # figure out what map factory class we need. if cview_db_backend
100 # conf var is set, use that, otherwise try to use the project_name
101 # conf var, and if that's not set then fall back to SGN
103 my $mf_name = $db_backend ? $db_backend eq 'cxgn_and_cmap' ? 'CviewAndCmap'
104 : $db_backend eq 'cmap' ? 'Cmap'
105 : $db_backend eq 'cxgn' ? 'SGN'
106 : croak "invalid cview backend $db_backend"
107 : 'SGN';
110 # try to load the mapfactory class
111 my $mf_class = __PACKAGE__."::$mf_name";
112 eval "require $mf_class";
113 $@ and die "error loading $mf_class:\n$@";
115 # now instantiate it, passing along the same dbh and config we got
116 return $mf_class->new( @_ );
123 return 1;