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.
19 For the current SGN implementation, the following identifier formats are defined and yield following corresponding map objects
21 \d+ refers to a map id in the database and yields either a
22 CXGN::Cview::Map::SGN::Genetic (type genetic)
23 CXGN::Cview::Map::SGN::FISH (type fish)
24 CXGN::Cview::Map::SGN::Sequence (type sequence)
25 u\d+ refers to a user defined map and returns:
26 CXGN::Cview::Map::SGN::User object
27 filepath refers to a map defined in a file and returns a
28 CXGN::Cview::Map::SGN::File object
29 il\d+ refers to a population id in the phenome.population table
30 (which must be of type IL) and returns a
31 CXGN::Cview::Map::SGN::IL object
32 p\d+ CXGN::Cview::Map::SGN::Physical
33 c\d+ CXGN::Cview::Map::SGN::Contig
34 o CXGN::Cview::Map::SGN::ProjectStats map object
36 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 Lukas Mueller (lam87@cornell.edu)
48 Refer to the L<CXGN::LICENSE> file.
52 This class implements the following functions:
58 package CXGN
::Cview
::MapFactory
::SGN
;
60 use base qw
| CXGN
::DB
::Object
|;
62 use CXGN
::Cview
::Map
::SGN
::Genetic
;
63 #use CXGN::Cview::Map::SGN::User;
64 use CXGN
::Cview
::Map
::SGN
::Fish
;
65 use CXGN
::Cview
::Map
::SGN
::Sequence
;
66 use CXGN
::Cview
::Map
::SGN
::IL
;
67 use CXGN
::Cview
::Map
::SGN
::Physical
;
68 use CXGN
::Cview
::Map
::SGN
::ProjectStats
;
69 use CXGN
::Cview
::Map
::SGN
::AGP
;
70 use CXGN
::Cview
::Map
::SGN
::ITAG
;
71 use CXGN
::Cview
::Map
::SGN
::Contig
;
72 use CXGN
::Cview
::Map
::SGN
::Scaffold
;
77 Arguments: a database handle
78 Returns: a CXGN::Cview::MapFactory::SGN object
91 $context = SGN
::Context
->new();
93 my $self = $class->SUPER::new
($dbh);
95 $self->{context
}=$context;
101 =head2 function create()
103 Description: creates a map based on the hashref given, which
104 should either contain the key map_id or map_version_id
105 and an appropriate identifier. The function returns undef
106 if a map of the given id cannot be found/created.
114 #print STDERR "Hashref = map_id => $hashref->{map_id}, map_version_id => $hashref->{map_version_id}\n";
116 my $c = $self->{context
};
117 my $temp_dir = $c->path_to( $c->tempfiles_subdir('cview') );
119 if (!exists($hashref->{map_id
}) && !exists($hashref->{map_version_id
})) {
120 die "[CXGN::Cview::MapFactory] Need either a map_id or map_version_id.\n";
122 if ($hashref->{map_id
} && $hashref->{map_version_id
}) {
123 die "[CXGN::Cview::MapFactory] Need either a map_id or map_version_id - not both.\n";
125 if ($hashref->{map_id
}) {
126 $hashref->{map_version_id
}=CXGN
::Cview
::Map
::Tools
::find_current_version
($self->get_dbh(), $hashref->{map_id
});
129 # now, we only deal with map_versions...
131 my $id = $hashref->{map_version_id
};
133 #print STDERR "MapFactory: dealing with id = $id\n";
135 # if the map_version_id is purely numeric,
136 # check if the map is in the maps table and generate the
140 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=?";
141 my $sth = $self->get_dbh()->prepare($query);
143 my ($id, $map_type) = $sth->fetchrow_array();
144 if ($map_type =~ /genetic/i) {
145 return CXGN
::Cview
::Map
::SGN
::Genetic
->new($self->get_dbh(), $id);
147 elsif ($map_type =~ /fish/) {
148 #print STDERR "Creating a fish map...\n";
149 return CXGN
::Cview
::Map
::SGN
::Fish
->new($self->get_dbh(), $id);
151 elsif ($map_type =~ /seq/) {
152 #print STDERR "Creating a seq map...\n";
153 return CXGN
::Cview
::Map
::SGN
::Sequence
->new($self->get_dbh(), $id);
156 elsif ($id =~ /^u/i) {
157 #return CXGN::Cview::Map::SGN::User->new($self->get_dbh(), $id);
159 elsif ($id =~ /^il/i) {
161 "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. ";
163 my ($population_id, $map_id) = $self->get_db_ids($id);
165 $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>.";
167 elsif ($map_id ==5) {
168 $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>. ";
171 my $ref_map = "ExPEN2000";
172 if ($id==5) { $ref_map = "ExPEN1992";}
173 my $long_name =qq | <i
>Solanum lycopersicum
</i
> Zamir Introgression Lines
(IL
) based on
$ref_map |;
175 return CXGN
::Cview
::Map
::SGN
::IL
->new($self->get_dbh(), $id,
176 { short_name
=> "Tomato IL map",
177 long_name
=> $long_name,
178 abstract
=> $abstract
181 elsif ($id =~ /^\//) {
182 #return CXGN::Cview::Map::SGN::File->new($dbh, $id);
184 elsif ($id =~ /^p\d+/) {
185 return CXGN
::Cview
::Map
::SGN
::Physical
->new($self->get_dbh(), $id);
187 elsif ($id =~ /^o$/i) {
189 return CXGN
::Cview
::Map
::SGN
::ProjectStats
->new($self->get_dbh(), {
190 short_name
=>"Tomato Sequencing Progress",
191 long_name
=>"Tomato Sequencing Statistics by Chromosome",
192 abstract
=> $self->get_abstract(),
197 elsif ($id =~ /^agp$/i) {
198 return CXGN
::Cview
::Map
::SGN
::AGP
->new($self->get_dbh(), $id, {
199 short_name
=> "Tomato AGP map",
200 long_name
=> "Tomato (Solanum lycopersicum) Accessioned Golden Path map",
201 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>" ,
202 temp_dir
=> $temp_dir } );
204 elsif ($id =~ /^itag$/i) {
206 my (@sources) = map $_->data_sources(), $c->enabled_feature('gbrowse2');
207 my ($gbrowse_itag) = grep $_->description()=~/ITAG_devel.+genomic/i, @sources;
210 @dbs = $gbrowse_itag->databases();
211 @dbs > 1 and die "I can handle only one db!";
214 my $gbrowse_view_link = $gbrowse_itag->view_url;
216 my $marker_link = sub { my $id = shift; return "$gbrowse_view_link?name=$id"; };
217 return CXGN
::Cview
::Map
::SGN
::ITAG
->new($self->get_dbh(), $id, {
218 short_name
=> "Tomato ITAG map",
219 long_name
=>"Tomato (Solanum lycopersicum) ITAG map",
220 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.",
221 temp_dir
=> $temp_dir,
222 marker_link
=> $marker_link,
227 elsif ($id =~ /scaffold103/) {
229 return CXGN
::Cview
::Map
::SGN
::Scaffold
->new($self->get_dbh(), $id, {
230 file
=> '/data/prod/public/tomato_genome/wgs/chromosomes/assembly_1.03/chromosome_defs_v1.03_sorted.txt',
231 abstract
=>'test abstract',
233 short_name
=>'Tomato scaffold map V1.03',
234 long_name
=>'Solanum lycopersicum scaffold map V1.03',
235 marker_link
=> sub {},
239 elsif ($id =~ /scaffold100/) {
240 my (@sources) = map $_->data_sources(), $c->enabled_feature('gbrowse2');
241 my ($gbrowse) = grep $_->description()=~/ITAG1.+genomic/i, @sources;
242 if (!$gbrowse) { die "No such map in GBrowse."; }
245 @dbs = $gbrowse->databases();
246 @dbs > 1 and die "I can handle only one db!";
249 my $gbrowse_view_link = $gbrowse->view_url;
251 my $marker_link = sub { my $id = shift; return "$gbrowse_view_link?name=$id"; };
253 return CXGN
::Cview
::Map
::SGN
::Scaffold
->new($self->get_dbh(), $id, {
254 file
=> '/data/prod/public/tomato_genome/wgs/chromosomes/assembly_1.00/chromosome_defs_v1.00_sorted.txt',
255 abstract
=>'test abstract',
257 short_name
=>'Tomato scaffold map V1.00',
258 long_name
=>'Solanum lycopersicum scaffold map V1.00',
259 marker_link
=> $marker_link,
262 elsif ($id =~ /^u\d+$/i) {
263 return CXGN
::Cview
::Map
::SGN
::User
->new($self->get_dbh(), $id);
265 elsif ($id =~ /^c\d+$/i) {
266 my ($gbrowse_fpc) = map $_->fpc_data_sources, $c->enabled_feature('gbrowse2');
269 @dbs = $gbrowse_fpc->databases();
270 @dbs > 1 and die "I can handle only one db!";
273 my $gbrowse_view_link = $gbrowse_fpc->view_url;
274 return CXGN
::Cview
::Map
::SGN
::Contig
->new($self->get_dbh(), $id, {
275 gbrowse_fpc
=> $gbrowse_fpc,
276 short_name
=> $gbrowse_fpc->description,
278 temp_dir
=> $temp_dir,
279 #marker_link => $gbrowse_fpc->xrefs(),
280 abstract
=> $gbrowse_fpc->extended_description."\n". qq{
281 <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
>
282 <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>
295 =head2 function get_all_maps()
299 Returns: a list of all maps currently defined, as
300 CXGN::Cview::Map objects (and subclasses)
301 Side effects: Queries the database for certain maps
309 my @system_maps = $self->get_system_maps();
310 my @user_maps = $self->get_user_maps();
311 my @maps = (@system_maps, @user_maps);
317 =head2 get_system_maps
319 Usage: my @system_maps = $map_factory->get_system_maps();
320 Desc: retrieves a list of system maps (from the sgn
321 database) as a list of CXGN::Cview::Map objects
329 sub get_system_maps
{
334 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";
335 my $sth = $self->get_dbh()->prepare($query);
338 while (my ($map_id) = $sth->fetchrow_array()) {
339 my $map = $self->create({ map_id
=> $map_id });
340 if ($map) { push @maps, $map; }
343 # push il, physical, contig, and agp map
345 foreach my $id ("il6.5", "il6.9", "p9", "c9", "agp", "itag") {
346 my $map = $self->create( {map_id
=>$id} );
347 if ($map) { push @maps, $map; }
357 Status: DEPRECATED. Does nothing now, as user maps have been disabled.
359 Desc: retrieves the current user maps of the logged in user.
360 Ret: a list of CXGN::Cview::Map objects
369 # push the maps that are specific to that user and not public, if somebody is logged in...
372 # my $login = CXGN::Login->new($self->get_dbh());
373 # my $user_id = $login->has_session();
375 # my $q3 = "SELECT user_map_id FROM sgn_people.user_map WHERE obsolete='f' AND sp_person_id=?";
376 # my $h3 = $self->get_dbh()->prepare($q3);
377 # $h3->execute($user_id);
378 # while (my ($user_map_id) = $h3->fetchrow_array()) {
379 # my $map = $self->create( {map_id=>"u".$user_map_id} );
381 # if ($map) { push @maps, $map; }
392 my $population_id = 6;
393 my $reference_map_id=5;
395 if ($id=~/il(\d+)\.?(\d*)?/) {
397 $reference_map_id=$2;
399 if (!$reference_map_id) { $reference_map_id=5; }
400 if (!$population_id) { $population_id=6; }
401 #print STDERR "Population ID: $population_id, reference_map_id = $reference_map_id\n";
403 return ($population_id, $reference_map_id);