4 CXGN::Cview::MapFactory - a factory object for CXGN::Cview::Map objects
8 my $map_factory = CXGN::Cview::MapFactory->new($dbh);
9 $map = $map_factory->create({map_version_id=>"u1"});
13 see L<CXGN::Cview::MapFactory>.
15 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.
17 The function get_all_maps returns all maps as list of appropriate CXGN::Cview::Map::* objects.
22 Lukas Mueller (lam87@cornell.edu)
30 Refer to the L<CXGN::LICENSE> file.
34 This class implements the following functions:
40 package CXGN
::Cview
::MapFactory
::Ricebase
;
42 use base qw
| CXGN
::DB
::Object
|;
44 use Scalar
::Util qw
/blessed/;
46 use CXGN
::Cview
::Map
::SGN
::Genetic
;
47 #use CXGN::Cview::Map::SGN::User;
48 #use CXGN::Cview::Map::SGN::Fish;
49 use CXGN
::Cview
::Map
::SGN
::Sequence
;
50 #use CXGN::Cview::Map::SGN::IL;
51 #use CXGN::Cview::Map::SGN::Physical;
52 use CXGN
::Cview
::Map
::SGN
::ProjectStats
;
53 #use CXGN::Cview::Map::SGN::AGP;
54 #use CXGN::Cview::Map::SGN::ITAG;
55 use CXGN
::Cview
::Map
::SGN
::Contig
;
56 use CXGN
::Cview
::Map
::SGN
::Scaffold
;
57 use CXGN
::Cview
::Map
::SGN
::Image
;
58 use CXGN
::Cview
::Map
::SGN
::QTL
;
63 Arguments: a database handle
64 Returns: a CXGN::Cview::MapFactory::SGN object
75 unless( blessed
($context) && $context->isa('SGN::Context') ) {
77 $context = SGN
::Context
->new();
79 my $self = $class->SUPER::new
($dbh);
81 $self->{context
}=$context;
87 =head2 function create()
89 Description: creates a map based on the hashref given, which
90 should either contain the key map_id or map_version_id
91 and an appropriate identifier. The function returns undef
92 if a map of the given id cannot be found/created.
100 #print STDERR "Hashref = map_id => $hashref->{map_id}, map_version_id => $hashref->{map_version_id}\n";
102 my $c = $self->{context
};
103 my $temp_dir = $c->path_to( $c->config->{tempfiles_subdir
} );
105 if (!exists($hashref->{map_id
}) && !exists($hashref->{map_version_id
})) {
106 die "[CXGN::Cview::MapFactory] Need either a map_id or map_version_id.\n";
108 if ($hashref->{map_id
} && $hashref->{map_version_id
}) {
109 die "[CXGN::Cview::MapFactory] Need either a map_id or map_version_id - not both.\n";
111 if ($hashref->{map_id
}) {
112 $hashref->{map_version_id
}=CXGN
::Cview
::Map
::Tools
::find_current_version
($self->get_dbh(), $hashref->{map_id
});
115 # now, we only deal with map_versions...
117 my $id = $hashref->{map_version_id
};
119 #print STDERR "MapFactory: dealing with id = $id\n";
121 # if the map_version_id is purely numeric,
122 # check if the map is in the maps table and generate the
126 my $query = "SELECT map_version_id, map_type, map_id, short_name FROM sgn.map join sgn.map_version using(map_id) WHERE map_version_id=?";
127 my $sth = $self->get_dbh()->prepare($query);
129 my ($id, $map_type) = $sth->fetchrow_array();
131 if ($map_type =~ /genetic/i) {
132 return CXGN
::Cview
::Map
::SGN
::Genetic
->new($self->get_dbh(), $id);
136 elsif ($map_type =~ /seq/) {
137 print STDERR
"Creating a seq map...($map_type, $id)\n";
138 my $map = CXGN
::Cview
::Map
::SGN
::Sequence
->new($self->get_dbh(), $id);
139 #$map->set_marker_link("/gb2/gbrowse/nipponbare/?q=");
140 $map->set_link_by_name(0);
149 =head2 function get_all_maps()
153 Returns: a list of all maps currently defined, as
154 CXGN::Cview::Map objects (and subclasses)
155 Side effects: Queries the database for certain maps
163 my @system_maps = $self->get_system_maps();
164 my @user_maps = $self->get_user_maps();
165 my @maps = (@system_maps, @user_maps);
171 =head2 get_system_maps
173 Usage: my @system_maps = $map_factory->get_system_maps();
174 Desc: retrieves a list of system maps (from the sgn
175 database) as a list of CXGN::Cview::Map objects
183 sub get_system_maps
{
188 my $query = "SELECT map.map_id FROM sgn.map LEFT JOIN sgn.map_version USING(map_id) LEFT JOIN sgn.accession on(parent_1=accession.accession_id) LEFT JOIN sgn.organism USING(organism_id) LEFT JOIN common_name USING(common_name_id) WHERE current_version='t' ORDER by common_name.common_name";
189 my $sth = $self->get_dbh()->prepare($query);
192 while (my ($map_id) = $sth->fetchrow_array()) {
193 my $map = $self->create({ map_id
=> $map_id });
194 if ($map) { push @maps, $map; }
197 # push il, physical, contig, and agp map
199 # foreach my $id ("il6.5", "il6.9", "p9", "c9", "agp", "pachy") {
200 # my $map = $self->create( {map_id=>$id} );
201 # if ($map) { push @maps, $map; }
211 Status: DEPRECATED. Does nothing now, as user maps have been disabled.
213 Desc: retrieves the current user maps of the logged in user.
214 Ret: a list of CXGN::Cview::Map objects
223 # push the maps that are specific to that user and not public, if somebody is logged in...
226 # my $login = CXGN::Login->new($self->get_dbh());
227 # my $user_id = $login->has_session();
229 # my $q3 = "SELECT user_map_id FROM sgn_people.user_map WHERE obsolete='f' AND sp_person_id=?";
230 # my $h3 = $self->get_dbh()->prepare($q3);
231 # $h3->execute($user_id);
232 # while (my ($user_map_id) = $h3->fetchrow_array()) {
233 # my $map = $self->create( {map_id=>"u".$user_map_id} );
235 # if ($map) { push @maps, $map; }
246 my $population_id = 6;
247 my $reference_map_id=5;
249 if ($id=~/il(\d+)\.?(\d*)?/) {
251 $reference_map_id=$2;
253 if (!$reference_map_id) { $reference_map_id=5; }
254 if (!$population_id) { $population_id=6; }
255 #print STDERR "Population ID: $population_id, reference_map_id = $reference_map_id\n";
257 return ($population_id, $reference_map_id);