fix AGP map and upgrade to new, WGS-based AGPs.
[cview.git] / lib / CXGN / Cview / MapFactory / ChlamyBase.pm
blob99f295692385feeeba3774ab2c84ca68979640e4
2 use strict;
4 package CXGN::Cview::MapFactory::ChlamyBase;
6 use base qw | CXGN::DB::Object | ;
8 use CXGN::Cview::Map::SGN::Genetic;
10 sub new {
11 my $class = shift;
12 my $dbh = shift;
13 my $self = $class->SUPER::new($dbh);
15 return $self;
19 sub create {
20 my $self = shift;
21 my $hashref = shift;
23 #print STDERR "Hashref = map_id => $hashref->{map_id}, map_version_id => $hashref->{map_version_id}\n";
25 if (!exists($hashref->{map_id}) && !exists($hashref->{map_version_id})) {
26 die "[CXGN::Cview::MapFactory] Need either a map_id or map_version_id.\n";
28 if ($hashref->{map_id} && $hashref->{map_version_id}) {
29 die "[CXGN::Cview::MapFactory] Need either a map_id or map_version_id - not both.\n";
31 if ($hashref->{map_id}) {
32 $hashref->{map_version_id}=CXGN::Cview::Map::Tools::find_current_version($self->get_dbh(), $hashref->{map_id});
35 # now, we only deal with map_versions...
37 my $id = $hashref->{map_version_id};
39 #print STDERR "MapFactory: dealing with id = $id\n";
41 # if the map_version_id is purely numeric,
42 # check if the map is in the maps table and generate the
43 # appropriate map
45 if ($id=~/^\d+$/) {
46 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=?";
47 my $sth = $self->get_dbh()->prepare($query);
48 $sth->execute($id);
49 my ($id, $map_type) = $sth->fetchrow_array();
50 if ($map_type =~ /genetic/i) {
51 return CXGN::Cview::Map::SGN::Genetic->new($self->get_dbh(), $id);
54 print STDERR "Map NOT FOUND!!!!!!!!!!!!!!!!!!\n\n";
55 return undef;
59 =head2 function get_all_maps()
61 Synopsis:
62 Arguments: none
63 Returns: a list of all maps currently defined, as
64 CXGN::Cview::Map objects (and subclasses)
65 Side effects: Queries the database for certain maps
66 Description:
68 =cut
70 sub get_all_maps {
71 my $self = shift;
73 my @system_maps = $self->get_system_maps();
74 my @user_maps = $self->get_user_maps();
75 my @maps = (@system_maps, @user_maps);
76 return @maps;
81 =head2 get_system_maps
83 Usage: my @system_maps = $map_factory->get_system_maps();
84 Desc: retrieves a list of system maps (from the sgn
85 database) as a list of CXGN::Cview::Map objects
86 Ret:
87 Args:
88 Side Effects:
89 Example:
91 =cut
93 sub get_system_maps {
94 my $self = shift;
96 my @maps = ();
98 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";
99 my $sth = $self->get_dbh()->prepare($query);
100 $sth->execute();
102 while (my ($map_id) = $sth->fetchrow_array()) {
103 my $map = $self->create({ map_id => $map_id });
104 if ($map) { push @maps, $map; }
107 # push il, physical, contig, and agp map
109 foreach my $id ("il6.5", "il6.9", "p9", "c9", "agp") {
110 my $map = $self->create( {map_id=>$id} );
111 if ($map) { push @maps, $map; }
114 return @maps;
119 =head2 get_user_maps
121 Usage:
122 Desc: retrieves the current user maps of the logged in user.
123 Ret: a list of CXGN::Cview::Map objects
124 Args: none
125 Side Effects: none
126 Example:
128 =cut
130 sub get_user_maps {
131 my $self = shift;
132 # push the maps that are specific to that user and not public, if somebody is logged in...
134 my @maps = ();
135 my $login = CXGN::Login->new($self->get_dbh());
136 my $user_id = $login->has_session();
137 if ($user_id) {
138 my $q3 = "SELECT user_map_id FROM sgn_people.user_map WHERE obsolete='f' AND sp_person_id=?";
139 my $h3 = $self->get_dbh()->prepare($q3);
140 $h3->execute($user_id);
141 while (my ($user_map_id) = $h3->fetchrow_array()) {
142 my $map = $self->create( {map_id=>"u".$user_map_id} );
144 if ($map) { push @maps, $map; }
147 return @maps;
152 return 1;