3 CXGN::Cview::MapFactory - a factory object for CXGN::Cview::Map objects
7 my $map_factory = CXGN::Cview::MapFactory->new($dbh);
8 $map = $map_factory->create({map_version_id=>"u1"});
12 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 .
14 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.
16 The function get_all_maps returns all maps as list of appropriate CXGN::Cview::Map::* objects.
18 For the current SGN implementation, the following identifier formats are defined and yield following corresponding map objects
20 \d+ refers to a map id in the database and yields either a
21 CXGN::Cview::Map::SGN::Genetic (type genetic)
22 CXGN::Cview::Map::SGN::FISH (type fish)
23 CXGN::Cview::Map::SGN::Sequence (type sequence)
24 u\d+ refers to a user defined map and returns:
25 CXGN::Cview::Map::SGN::User object
26 filepath refers to a map defined in a file and returns a
27 CXGN::Cview::Map::SGN::File object
28 il\d+ refers to a population id in the phenome.population table
29 (which must be of type IL) and returns a
30 CXGN::Cview::Map::SGN::IL object
31 p\d+ CXGN::Cview::Map::SGN::Physical
32 c\d+ CXGN::Cview::Map::SGN::Contig
33 o CXGN::Cview::Map::SGN::ProjectStats map object
35 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.
39 Lukas Mueller (lam87@cornell.edu)
47 Refer to the L<CXGN::LICENSE> file.
51 This class implements the following functions:
57 package CXGN
::Cview
::MapFactory
::SGN
;
59 use base qw
| CXGN
::DB
::Object
|;
61 use CXGN
::Cview
::Map
::SGN
::Genetic
;
62 #use CXGN::Cview::Map::SGN::User;
63 use CXGN
::Cview
::Map
::SGN
::Fish
;
64 use CXGN
::Cview
::Map
::SGN
::Sequence
;
65 use CXGN
::Cview
::Map
::SGN
::IL
;
66 use CXGN
::Cview
::Map
::SGN
::Physical
;
67 use CXGN
::Cview
::Map
::SGN
::ProjectStats
;
68 use CXGN
::Cview
::Map
::SGN
::AGP
;
69 use CXGN
::Cview
::Map
::SGN
::ITAG
;
70 use CXGN
::Cview
::Map
::SGN
::Contig
;
71 #use CXGN::Cview::Map::SGN::Scaffold;
76 Arguments: a database handle
77 Returns: a CXGN::Cview::MapFactory::SGN object
90 $context = SGN
::Context
->new();
92 my $self = $class->SUPER::new
($dbh);
94 $self->{context
}=$context;
99 =head2 function create()
101 Description: creates a map based on the hashref given, which
102 should either contain the key map_id or map_version_id
103 and an appropriate identifier. The function returns undef
104 if a map of the given id cannot be found/created.
112 #print STDERR "Hashref = map_id => $hashref->{map_id}, map_version_id => $hashref->{map_version_id}\n";
114 my $c = $self->{context
};
115 my $temp_dir = $c->path_to( $c->tempfiles_subdir('cview') );
117 if (!exists($hashref->{map_id
}) && !exists($hashref->{map_version_id
})) {
118 die "[CXGN::Cview::MapFactory] Need either a map_id or map_version_id.\n";
120 if ($hashref->{map_id
} && $hashref->{map_version_id
}) {
121 die "[CXGN::Cview::MapFactory] Need either a map_id or map_version_id - not both.\n";
123 if ($hashref->{map_id
}) {
124 $hashref->{map_version_id
}=CXGN
::Cview
::Map
::Tools
::find_current_version
($self->get_dbh(), $hashref->{map_id
});
127 # now, we only deal with map_versions...
129 my $id = $hashref->{map_version_id
};
131 #print STDERR "MapFactory: dealing with id = $id\n";
133 # if the map_version_id is purely numeric,
134 # check if the map is in the maps table and generate the
138 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=?";
139 my $sth = $self->get_dbh()->prepare($query);
141 my ($id, $map_type) = $sth->fetchrow_array();
142 if ($map_type =~ /genetic/i) {
143 return CXGN
::Cview
::Map
::SGN
::Genetic
->new($self->get_dbh(), $id);
145 elsif ($map_type =~ /fish/) {
146 #print STDERR "Creating a fish map...\n";
147 return CXGN
::Cview
::Map
::SGN
::Fish
->new($self->get_dbh(), $id);
149 elsif ($map_type =~ /seq/) {
150 #print STDERR "Creating a seq map...\n";
151 return CXGN
::Cview
::Map
::SGN
::Sequence
->new($self->get_dbh(), $id);
154 elsif ($id =~ /^u/i) {
155 #return CXGN::Cview::Map::SGN::User->new($self->get_dbh(), $id);
157 elsif ($id =~ /^il/i) {
159 "The tomato Introgression lines (ILs) are a set of nearly isogenic lines (NILs) developed by Dani Zamir through a succession of backcrosses, where each line carries a single genetically defined chromosome segment from a divergent genome. The ILs, representing whole-genome coverage of S. pennellii in overlapping segments in the genetic background of S. lycopersicum cv. M82, were first phenotyped in 1993, and presently this library consists of 76 genotypes. ";
161 my ($population_id, $map_id) = $self->get_db_ids($id);
163 $abstract .= " This IL map is based on markers of the F2-2000 map. ILs have also been mapped <a href=\"map.pl?map_id=il6.5&show_ruler=1&show_offsets=1\" >with the ExPEN1992 map as a reference</a>.";
165 elsif ($map_id ==5) {
166 $abstract .= " The IL lines on this map have been characterized based on the markers on the 1992 tomato map. ILs have also been mapped <a href=\"map.pl?map_id=il6.9&show_ruler=1&show_offsets=1\" >with the ExPEN2000 map as a reference</a>. ";
169 my $ref_map = "ExPEN2000";
170 if ($id==5) { $ref_map = "ExPEN1992";}
171 my $long_name =qq | <i
>Solanum lycopersicum
</i
> Zamir Introgression Lines
(IL
) based on
$ref_map |;
173 return CXGN
::Cview
::Map
::SGN
::IL
->new($self->get_dbh(), $id,
174 { short_name
=> "Tomato IL map",
175 long_name
=> $long_name,
176 abstract
=> $abstract
179 elsif ($id =~ /^\//) {
180 #return CXGN::Cview::Map::SGN::File->new($dbh, $id);
182 elsif ($id =~ /^p\d+/) {
183 return CXGN
::Cview
::Map
::SGN
::Physical
->new($self->get_dbh(), $id);
185 elsif ($id =~ /^o$/i) {
187 return CXGN
::Cview
::Map
::SGN
::ProjectStats
->new($self->get_dbh(), {
188 short_name
=>"Tomato Sequencing Progress",
189 long_name
=>"Tomato Sequencing Statistics by Chromosome",
190 abstract
=> $self->get_abstract(),
195 elsif ($id =~ /^agp$/i) {
196 return CXGN
::Cview
::Map
::SGN
::AGP
->new($self->get_dbh(), $id, {
197 short_name
=> "Tomato AGP map",
198 long_name
=> "Tomato (Solanum lycopersicum) Accessioned Golden Path map",
199 abstract
=> "<p>The AGP map shows the sequencing progress of the international tomato genome sequencing project by listing all finished clones by estimated physical map position . Each sequencing center generates one or more AGP (Accessioned Golden Path) files and uploads them to SGN. These files contain all the sequenced BACs, their position on the chromosome, the overlaps with other BACs and other information. For a complete specification, please refer to the <a href=\"http://www.sanger.ac.uk/Projects/C_elegans/DOCS/agp_files.shtml\">Sanger AGP specification</a>. The AGP files can also be downloaded from the SGN FTP site, at <a href=\"ftp://ftp.sgn.cornell.edu/tomato_genome/agp/\">ftp://ftp.sgn.cornell.edu/tomato_genome/agp/</a>.</p> <p>Note that this map is in testing (beta), and not all features may be functional.</p>" ,
200 temp_dir
=> $temp_dir } );
202 elsif ($id =~ /^itag$/i) {
204 my ($gbrowse_itag) = map $_->data_sources, $c->enabled_feature('gbrowse2');
207 @dbs = $gbrowse_itag->databases();
208 @dbs > 1 and die "I can handle only one db!";
211 my $gbrowse_view_link = $gbrowse_itag->view_url;
213 my $marker_link = sub { my $id = shift; return "$gbrowse_view_link?name=$id"; };
214 return CXGN
::Cview
::Map
::SGN
::ITAG
->new($self->get_dbh(), $id, {
215 short_name
=> "Tomato ITAG map",
216 long_name
=>"Tomato (Solanum lycopersicum) ITAG map",
217 abstract
=>"<p>The ITAG map shows the contig assembly and the corresponding BACs as used by the most recent annotation from the International Tomato Annotation Group (ITAG, see <a href=\"http://www.ab.wur.nl/TomatoWiki\">ITAG Wiki</a>). Clicking on the contigs will show the ITAG annotation in the genome browser.",
218 temp_dir
=> $temp_dir,
219 marker_link
=> $marker_link,
224 # elsif ($id =~ /scaffold/) {
225 # return CXGN::Cview::Map::SGN::Scaffold->new($self->get_dbh(), {
226 # file=> '/home/mueller/dutch_tomato_assembly/chromosome_defs_v1.03_sorted.txt',
227 # abstract=>'test abstract',
228 # temp_dir=>$temp_dir,
229 # short_name=>'Tomato Scaffold map',
230 # long_name=>'Solanum lycopersicum scaffold map',
234 # elsif ($id =~ /^u\d+$/i) {
235 # return CXGN::Cview::Map::SGN::User->new($self->get_dbh(), $id);
237 elsif ($id =~ /^c\d+$/i) {
238 my ($gbrowse_fpc) = map $_->fpc_data_sources, $c->enabled_feature('gbrowse2');
241 @dbs = $gbrowse_fpc->databases();
242 @dbs > 1 and die "I can handle only one db!";
245 my $gbrowse_view_link = $gbrowse_fpc->view_url;
246 return CXGN
::Cview
::Map
::SGN
::Contig
->new($self->get_dbh(), $id, {
247 gbrowse_fpc
=> $gbrowse_fpc,
248 short_name
=> $gbrowse_fpc->description,
250 temp_dir
=> $temp_dir,
251 #marker_link => $gbrowse_fpc->xrefs(),
252 abstract
=> $gbrowse_fpc->extended_description."\n".<<"",
253 <p
>This overview shows the counts of contigs along the chromosome
. Click on any chromosome to view the individual contigs
. More information on
each contig can be obtained by by clicking on a specific contig
.</p
>
254 <p
>Specific contig IDs
, including contigs that are
not mapped
, can be searched on the
<a href
="$gbrowse_view_link">FPC viewer page
</a>.</p>
262 =head2 function get_all_maps()
266 Returns: a list of all maps currently defined, as
267 CXGN::Cview::Map objects (and subclasses)
268 Side effects: Queries the database for certain maps
276 my @system_maps = $self->get_system_maps();
277 my @user_maps = $self->get_user_maps();
278 my @maps = (@system_maps, @user_maps);
284 =head2 get_system_maps
286 Usage: my @system_maps = $map_factory->get_system_maps();
287 Desc: retrieves a list of system maps (from the sgn
288 database) as a list of CXGN::Cview::Map objects
296 sub get_system_maps
{
301 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";
302 my $sth = $self->get_dbh()->prepare($query);
305 while (my ($map_id) = $sth->fetchrow_array()) {
306 my $map = $self->create({ map_id
=> $map_id });
307 if ($map) { push @maps, $map; }
310 # push il, physical, contig, and agp map
312 foreach my $id ("il6.5", "il6.9", "p9", "c9", "agp", "itag") {
313 my $map = $self->create( {map_id
=>$id} );
314 if ($map) { push @maps, $map; }
324 Status: DEPRECATED. Does nothing now, as user maps have been disabled.
326 Desc: retrieves the current user maps of the logged in user.
327 Ret: a list of CXGN::Cview::Map objects
336 # push the maps that are specific to that user and not public, if somebody is logged in...
339 # my $login = CXGN::Login->new($self->get_dbh());
340 # my $user_id = $login->has_session();
342 # my $q3 = "SELECT user_map_id FROM sgn_people.user_map WHERE obsolete='f' AND sp_person_id=?";
343 # my $h3 = $self->get_dbh()->prepare($q3);
344 # $h3->execute($user_id);
345 # while (my ($user_map_id) = $h3->fetchrow_array()) {
346 # my $map = $self->create( {map_id=>"u".$user_map_id} );
348 # if ($map) { push @maps, $map; }
359 my $population_id = 6;
360 my $reference_map_id=5;
362 if ($id=~/il(\d+)\.?(\d*)?/) {
364 $reference_map_id=$2;
366 if (!$reference_map_id) { $reference_map_id=5; }
367 if (!$population_id) { $population_id=6; }
368 #print STDERR "Population ID: $population_id, reference_map_id = $reference_map_id\n";
370 return ($population_id, $reference_map_id);