4 CXGN::Map - classes to get information on SGN mapping information and to add new map and map version data (new_map, store, & map_version functions).
8 This class was originally written to retrieve data on genetic maps in the SGN database. However, map types multiplied and this class was re-written as a factory object producing a map object of the appropriate type - genetic, fish, individual, user, etc. These map objects are defined in the CXGN::Map:: namespace. Previous documentation mentioned the existence of a CXGN::Map::Storable class, however, this never seemed to exist and the new map interface and subclasses have been written as read/write objects.
10 The "new" function has been re-cast to act as a factory object and will produce the right type of Map object given the appropriate parameters, which are defined as follows:
14 map_id genetic or fish
15 map_version_id genetic or fish
18 individual_id indivdual_map
20 Note that much of the functionality of this class has been factored out into a CXGN::LinkageGroup object, which also exists in different incarnations for the different map types.
24 John Binns <zombieite@gmail.com>, Lukas Mueller (lam87@cornell.edu) and Isaak Y Tecle (iyt2@cornell.edu)
30 This class defines the following functions to be implemented by the subclasses, and keeps the old functions for compatibility (see deprecated functions below).
35 use CXGN
::DB
::Connection
;
36 use CXGN
::Map
::Version
;
41 Usage: my $map = CXGN::Map->new($dbh, {map_version_id=>30})
42 Desc: creates a new CXGN::Map object
44 Args: - a database handle, if possible using
45 CXGN::DB::Connection object
46 - a hashref, containing either a key map_id or a key
47 map_version_id, but not both!
55 my($dbh,$map_info)=@_;
56 my $self=bless({},$class);
57 unless(CXGN
::DB
::Connection
::is_valid_dbh
($dbh)){die"Invalid DBH";}
58 ref($map_info) eq 'HASH' or die"Must send in a dbh and hash ref with a map_id key or a map_version_id key";
59 $self->{map_version_id
}=$map_info->{map_version_id
};
60 $self->{map_id
}=$map_info->{map_id
};
62 my $map_id_t = $self->{map_id
};
63 #print STDERR "map id: $map_id_t from map object\n";
66 if($self->{map_version_id
})
68 die"You must only send in a map_id or a map_version_id, not both";
70 my $map_version_id_q=$dbh->prepare("SELECT map_version_id
73 AND current_version='t'"
75 $map_version_id_q->execute($self->{map_id
});
76 ($self->{map_version_id
})=$map_version_id_q->fetchrow_array();
78 $self->{map_version_id
} or return undef;
79 my $general_info_q=$dbh->prepare
95 inner join map using (map_id)
99 $general_info_q->execute($self->{map_version_id
});
102 $self->{map_version_id
},
103 $self->{date_loaded
},
104 $self->{current_version
},
109 $self->{population_id
},
111 $self->{has_physical
}
113 )=$general_info_q->fetchrow_array();
114 if(!$self->{map_version_id
}){return undef;}
115 my $linkage_q=$dbh->prepare('SELECT linkage_group.lg_id AS lg_id,linkage_group.map_version_id AS map_version_id,
116 lg_order,lg_name, min(position) AS north_centromere, MAX(position) AS south_centromere
118 LEFT JOIN marker_location ON (north_location_id=location_id
119 OR south_location_id=location_id)
120 WHERE linkage_group.map_version_id=?
121 GROUP BY linkage_group.lg_id, linkage_group.map_version_id,
122 lg_order, lg_name order by lg_order');
123 $linkage_q->execute($self->{map_version_id
});
124 while(my $linkage_group=$linkage_q->fetchrow_hashref())
126 push(@
{$self->{linkage_groups
}},$linkage_group);
133 my $dbh = CXGN
::DB
::Connection
->new();
134 my $map_id = $self->get_map_id();
135 print STDERR
"map id from store: $map_id\n";
137 my $sth = $dbh->prepare("UPDATE sgn.map SET
148 $sth->execute($self->{short_name
},
155 $self->{population_id
},
159 print STDERR
"Storing map data... \n";
160 print STDERR
"updated map id: $map_id\n";
161 #$dbh->last_insert_id("map", "sgn");
165 print STDERR
"No map id\n";
178 print STDERR
"Short map name: $name\n";
180 $sth = $dbh->prepare("SELECT map_id
182 WHERE short_name ILIKE ?"
184 $sth->execute($name);
185 $map_id = $sth->fetchrow_array();
186 print STDERR
"Map Id: $map_id\n";
189 print STDERR
"Provide map name, please.\n";
190 die "No map name provided!\n";
194 $sth = $dbh->prepare("INSERT INTO sgn.map (short_name) VALUES (?)");
195 $sth->execute($name);
196 $map_id = $dbh->last_insert_id("map", "sgn");
197 print STDERR
"stored new Map Id: $map_id\n";
200 my ($map, $map_version_id);
202 $map_version_id = CXGN
::Map
::Version
->map_version($dbh, $map_id);
203 #$map_version_id= $self->map_version($dbh, $map_id);
204 print STDERR
"created map version_id: $map_version_id for map_id: $map_id\n";
205 $map = CXGN
::Map
->new($dbh, {map_id
=>$map_id});
206 my $new_map_id = $map->{map_id
};
207 print STDERR
"new_map function with map_id = $new_map_id.\n";
217 =head2 accessors set_short_name, get_short_name
230 return $self->{short_name
};
235 $self->{short_name
}=shift;
238 =head2 accessors set_long_name, get_long_name
251 return $self->{long_name
};
256 $self->{long_name
}=shift;
259 =head2 accessors set_abstract, get_abstract
272 return $self->{abstract
};
277 $self->{abstract
}=shift;
281 =head2 accessors get_parent_1, set_parent_1
293 return $self->{parent_1
};
298 $self->{parent_1
} = shift;
300 =head2 accessors get_population_id, set_population_id
310 sub get_population_id
{
312 return $self->{population_id
};
315 sub set_population_id
{
317 $self->{population_id
} = shift;
334 $self->{map_id
}=shift;
338 return $self->{map_id
};
344 =head2 accessors set_linkage_groups, get_linkage_groups
355 sub get_linkage_groups
{
357 return @
{$self->{linkage_groups
}};
360 sub set_linkage_groups
{
362 @
{$self->{linkage_groups
}}=@_;
365 =head2 function add_linkage_group
375 sub add_linkage_group
{
378 push @
{$self->{linkage_groups
}}, $lg;
382 =head2 accessors set_map_type, get_map_type
395 return $self->{map_type
};
400 $self->{map_type
}=shift;
404 =head2 function get_units
416 if ($self->get_map_type() eq "genetic") {
419 elsif ($self->get_map_type() eq "fish") {
422 elsif ($self->get_map_type() =~ /sequenc/) {
435 =head1 DEPRECATED FUNCTIONS
437 These functions are still working but should not be used in new code.
439 Note that these functions only work as getters and not as setters.
443 =head2 function map_id
456 return $self->{map_id
};
459 =head2 function map_version_id
471 return $self->{map_version_id
};
474 =head2 function short_name
486 return $self->{short_name
};
489 =head2 function long_name
501 return $self->{long_name
};
504 =head2 function abstract
516 return $self->{abstract
};
519 =head2 linkage_groups
523 Ret: a reference to an array of hashrefs with linkage group info.
524 hash keys include lg_name and lg_order
533 if($self->{linkage_groups
})
535 return $self->{linkage_groups
};
547 Ret: the type of the map, either 'fish' for a fish map
548 or 'genetic' for a genetic map.
557 return $self->{map_type
};
573 return $self->{has_IL
};
589 return $self->{has_physical
};
598 Desc: a shortcut function to get at the chromosome names,
600 Ret: a list of chromosome names.
609 my $linkage_groups_ref = $self->linkage_groups();
610 my @names = map $_->{lg_name
}, @
{$linkage_groups_ref};
614 =head2 has_linkage_group
618 Ret: 1 if the string or number represents a linkage group
621 Args: a string or number describing a possible linkage
628 sub has_linkage_group
{
630 my $candidate = shift;
632 $candidate=~ s/\s*(.*)\s*/$1/;
633 foreach my $n (map $_->{lg_name
} , @
{$self->linkage_groups()}) {
634 #print STDERR "comparing $n with $candidate...\n";
635 if ($candidate =~ /^$n$/i) {
636 #print STDERR "Yip!\n";
643 =head2 function get_centromere
645 Synopsis: my ($north, $south, $center) = $map->get_centromere($lg_name)
646 Arguments: a valid linkage group name
647 Returns: a three member list, the first element corresponds
648 to the north boundary of the centromere in cM
649 the second corresponds to the south boundary of
650 the centromere in cM, the third is the arithmetic mean
651 of the two first values.
661 if (! $self->has_linkage_group($lg)) {
662 die "Not a valid linkage group for this map!\n";
665 my $lg_hash = $self->get_linkage_group_hash($lg);
666 # foreach my $k (keys %$lg_hash) {
667 # print " $k, $lg_hash->{$k}\n";
669 my $north = $lg_hash->{north_centromere
};
670 my $south = $lg_hash->{south_centromere
};
671 return ($north, $south, int(($north+$south)/2));
674 sub get_linkage_group_hash
{
677 foreach my $lg_hash (@
{$self->linkage_groups()}) {
678 if ($lg_hash->{lg_name
} eq $lg_name) {