4 CXGN::LinkageGroup - a class that deals with the
5 sgn.linkage_group table.
9 This class does basic things such as
10 accessing forlinkage_group_ids and their names
11 and storing linkage_group names
12 and map_version_id to the sgn.linkage_group table.
16 Isaak Y Tecle (iyt2@cornell.edu)
25 use CXGN
::DB
::Connection
;
26 package CXGN
::LinkageGroup
;
30 Usage: my $map = CXGN::LinkageGroup->new($dbh, $map_version_id, $lg)
31 Desc: creates a new CXGN::Map object
33 Args: - a database handle, if possible using
34 CXGN::DB::Connection object
36 -an array ref of linkage groups to store linkage groups.
37 Not needed if the goal is to access the linkage_groups
45 my($dbh, $map_version_id, $linkage_groups) = @_;
46 my $self = bless {}, $class;
48 unless ($map_version_id) {die "You must provide a map_version_id\n";}
50 my $valid_map_version_id;
52 #think of better check, here.
53 my $sth = $dbh->prepare("SELECT map_version_id
55 WHERE map_version_id = ?");
56 $sth->execute($map_version_id);
57 $valid_map_version_id = $sth->fetchrow_array();
60 unless ($valid_map_version_id) { die "No such map version id: $map_version_id exists\n"};
62 my (@linkage_groups, @lg_ids, $lg_ids);
63 if ($linkage_groups) {
64 if (@
{$linkage_groups}) {
65 for my $lg_name(@
{$linkage_groups}) {
66 # one digit, optionally followed by another, optionally followed
67 # by a lowercase letter--modify this regex if needed
69 print STDERR
"Linkage group: $lg_name\n";
70 unless ($lg_name=~/^\d\d?[a-z]?$/) {
71 die "'$lg_name' is not a valid linkage group name";
77 my $sth = $dbh->prepare("SELECT lg_id, lg_name
78 FROM sgn.linkage_groups
79 WHERE sgn.map_version_id = ?
80 AND current_version = 't'"
82 $sth->execute($valid_map_version_id);
84 while (my ($lg_id, $lg_name) = $sth->fetchrow_array()) {
86 push @linkage_groups, $lg_name;
89 $linkage_groups = \
@linkage_groups;
92 unless (@lg_ids) { die "(1) You have not provided the linkage_group names
93 for the new map version or \n
94 (2) for the map_version_id you provided there
95 are no existing linkage groups associated with it\n";
100 $self->set_linkage_group_ids($lg_ids);
101 $self->set_linkage_groups($linkage_groups);
102 $self->set_map_version_id($valid_map_version_id);
103 $self->set_dbh($dbh);
114 my $map_version_id = $self->get_map_version_id();
116 die "Valid map_version_id is required!\n" unless ($map_version_id);
119 foreach my $lg (@
{$self->get_linkage_groups()}) {
121 my $sth = $self->get_dbh()->prepare("INSERT INTO sgn.linkage_group
122 (map_version_id, lg_order, lg_name)
131 print STDERR
"INSERTING LINKAGE_GROUP $lg
132 of MAP_VERSION_ID: $map_version_id\n";
140 print STDERR
"Failed storing linkage groups\n";
148 =head2 accessors set_dbh, get_dbh
169 =head2 accessors set_map_version_id, get_map_version_id
180 sub get_map_version_id
{
182 return $self->{map_version_id
};
185 sub set_map_version_id
{
187 $self->{map_version_id
}=shift;
195 =head2 accessors set_linkage_groups, get_linkage_groups
206 sub get_linkage_groups
{
208 return $self->{linkage_groups
};
211 sub set_linkage_groups
{
213 $self->{linkage_groups
}=shift;
216 =head2 accessors set_linkage_group_ids, get_linkage_group_ids
227 sub get_linkage_group_ids
{
229 return $self->{linkage_group_ids
};
232 sub set_linkage_group_ids
{
234 $self->{linkage_group_ids
}=shift;
251 # my $map_version_id = shift;
252 my $sth = $self->get_dbh()->prepare("SELECT lg_id
253 FROM sgn.linkage_group
255 AND map_version_id = ?"
258 $sth->execute($lg, $self->get_map_version_id());
259 my $lg_id = $sth->fetchrow_array();