5 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).
9 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.
11 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:
15 map_id genetic or fish
16 map_version_id genetic or fish
19 individual_id indivdual_map
21 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.
25 John Binns <zombieite@gmail.com>, Lukas Mueller (lam87@cornell.edu) and Isaak Y Tecle (iyt2@cornell.edu)
31 This class defines the following functions to be implemented by the subclasses, and keeps the old functions for compatibility (see deprecated functions below).
40 use CXGN
::DB
::Connection
;
41 use CXGN
::Map
::Version
;
43 use base
"CXGN::DB::Object";
47 Usage: my $map = CXGN::Map->new($dbh, {map_version_id=>30})
48 Desc: creates a new CXGN::Map object
50 Args: - a database handle, if possible using
51 CXGN::DB::Connection object
52 - a hashref, containing either a key map_id or a key
53 map_version_id, but not both!
61 my($dbh,$map_info)=@_;
62 my $self=$class->SUPER::new
($dbh);
63 unless(CXGN
::DB
::Connection
::is_valid_dbh
($dbh)){die"Invalid DBH";}
64 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";
65 $self->{map_version_id
}=$map_info->{map_version_id
};
66 $self->{map_id
}=$map_info->{map_id
};
68 my $map_id_t = $self->{map_id
};
69 #print STDERR "map id: $map_id_t from map object\n";
72 if($self->{map_version_id
})
74 die"You must only send in a map_id or a map_version_id, not both";
76 my $map_version_id_q=$dbh->prepare("SELECT map_version_id
79 AND current_version='t'"
81 $map_version_id_q->execute($self->{map_id
});
82 ($self->{map_version_id
})=$map_version_id_q->fetchrow_array();
84 $self->{map_version_id
} or return undef;
85 my $general_info_q=$dbh->prepare
101 inner join map using (map_id)
105 $general_info_q->execute($self->{map_version_id
});
108 $self->{map_version_id
},
109 $self->{date_loaded
},
110 $self->{current_version
},
115 $self->{population_id
},
117 $self->{has_physical
}
119 )=$general_info_q->fetchrow_array();
120 if(!$self->{map_version_id
}){return undef;}
121 my $linkage_q=$dbh->prepare('SELECT linkage_group.lg_id AS lg_id,linkage_group.map_version_id AS map_version_id,
122 lg_order,lg_name, min(position) AS north_centromere, MAX(position) AS south_centromere
124 LEFT JOIN marker_location ON (north_location_id=location_id
125 OR south_location_id=location_id)
126 WHERE linkage_group.map_version_id=?
127 GROUP BY linkage_group.lg_id, linkage_group.map_version_id,
128 lg_order, lg_name order by lg_order');
129 $linkage_q->execute($self->{map_version_id
});
130 while(my $linkage_group=$linkage_q->fetchrow_hashref())
132 push(@
{$self->{linkage_groups
}},$linkage_group);
140 my $map_id = $self->get_map_id();
141 print STDERR
"map id from store: $map_id\n";
143 my $sth = $self->get_dbh()->prepare("UPDATE sgn.map SET
148 parent1_stock_id = ?,
149 parent2_stock_id = ?,
151 population_stock_id = ?
154 $sth->execute($self->{short_name
},
158 $self->{parent1_stock_id
},
159 $self->{parent2_stock_id
},
161 $self->{population_stock_id
},
165 print STDERR
"Storing map data... \n";
166 print STDERR
"updated map id: $map_id\n";
167 #$dbh->last_insert_id("map", "sgn");
171 print STDERR
"No map id\n";
184 print STDERR
"Short map name: $name\n";
186 $sth = $dbh->prepare("SELECT map_id
188 WHERE short_name ILIKE ?"
190 $sth->execute($name);
191 $map_id = $sth->fetchrow_array();
192 print STDERR
"Map Id: $map_id\n";
195 print STDERR
"Provide map name, please.\n";
196 die "No map name provided!\n";
200 $sth = $dbh->prepare("INSERT INTO sgn.map (short_name, map_type) VALUES (?, 'genetic')");
201 $sth->execute($name);
202 $map_id = $dbh->last_insert_id("map", "sgn");
203 print STDERR
"stored new Map Id: $map_id\n";
206 my ($map, $map_version_id);
208 $map_version_id = CXGN
::Map
::Version
->map_version($dbh, $map_id);
209 #$map_version_id= $self->map_version($dbh, $map_id);
210 print STDERR
"created map version_id: $map_version_id for map_id: $map_id\n";
211 $map = CXGN
::Map
->new($dbh, {map_id
=>$map_id});
212 my $new_map_id = $map->{map_id
};
213 print STDERR
"new_map function with map_id = $new_map_id.\n";
223 =head2 accessors set_short_name, get_short_name
236 return $self->{short_name
};
241 $self->{short_name
}=shift;
244 =head2 accessors set_long_name, get_long_name
257 return $self->{long_name
};
262 $self->{long_name
}=shift;
265 =head2 accessors set_abstract, get_abstract
278 return $self->{abstract
};
283 $self->{abstract
}=shift;
287 =head2 accessors get_parent_1, set_parent_1
300 return $self->{parent_1
};
305 $self->{parent_1
} = shift;
308 =head2 accessors get_parent1_stock_id, set_parent1_stock_id
311 Desc: sets the stock id of parent 1 of this map.
318 sub get_parent1_stock_id
{
320 return $self->{parent1_stock_id
};
323 sub set_parent1_stock_id
{
325 $self->{parent1_stock_id
} = shift;
328 =head2 accessors get_parent2_stock_id, set_parent2_stock_id
331 Desc: sets the stock id of the parent 2 of this map.
338 sub get_parent2_stock_id
{
340 return $self->{parent2_stock_id
};
343 sub set_parent2_stock_id
{
345 $self->{parent2_stock_id
} = shift;
348 =head2 accessors get_population_stock_id, set_population_stock_id
351 Desc: sets the population id of the map, referencing
359 sub get_population_stock_id
{
361 return $self->{population_stock_id
};
364 sub set_population_stock_id
{
366 $self->{population_stock_id
} = shift;
369 =head2 accessors get_population_id, set_population_id
380 sub get_population_id
{
382 return $self->{population_id
};
385 sub set_population_id
{
387 $self->{population_id
} = shift;
404 $self->{map_id
}=shift;
408 return $self->{map_id
};
412 =head2 accessors set_linkage_groups, get_linkage_groups
423 sub get_linkage_groups
{
425 return @
{$self->{linkage_groups
}};
428 sub set_linkage_groups
{
430 @
{$self->{linkage_groups
}}=@_;
433 =head2 function add_linkage_group
443 sub add_linkage_group
{
446 push @
{$self->{linkage_groups
}}, $lg;
450 =head2 accessors set_map_type, get_map_type
463 return $self->{map_type
};
468 $self->{map_type
}=shift;
472 =head2 function get_units
484 if ($self->get_map_type() eq "genetic") {
487 elsif ($self->get_map_type() eq "fish") {
490 elsif ($self->get_map_type() =~ /sequenc/) {
493 elsif ($self->get_map_type() =~ /qtl/i) {
506 =head1 DEPRECATED FUNCTIONS
508 These functions are still working but should not be used in new code.
510 Note that these functions only work as getters and not as setters.
514 =head2 function map_id
527 return $self->{map_id
};
530 =head2 function map_version_id
542 return $self->{map_version_id
};
545 =head2 function short_name
557 return $self->{short_name
};
560 =head2 function long_name
572 return $self->{long_name
};
575 =head2 function abstract
587 return $self->{abstract
};
590 =head2 linkage_groups
594 Ret: a reference to an array of hashrefs with linkage group info.
595 hash keys include lg_name and lg_order
604 if($self->{linkage_groups
})
606 return $self->{linkage_groups
};
618 Ret: the type of the map, either 'fish' for a fish map
619 or 'genetic' for a genetic map.
628 return $self->{map_type
};
644 return $self->{has_IL
};
660 return $self->{has_physical
};
669 Desc: a shortcut function to get at the chromosome names,
671 Ret: a list of chromosome names.
680 my $linkage_groups_ref = $self->linkage_groups();
681 my @names = map $_->{lg_name
}, @
{$linkage_groups_ref};
685 =head2 has_linkage_group
689 Ret: 1 if the string or number represents a linkage group
692 Args: a string or number describing a possible linkage
699 sub has_linkage_group
{
701 my $candidate = shift;
703 $candidate=~ s/\s*(.*)\s*/$1/;
704 foreach my $n (map $_->{lg_name
} , @
{$self->linkage_groups()}) {
705 #print STDERR "comparing $n with $candidate...\n";
706 if ($candidate =~ /^$n$/i) {
707 #print STDERR "Yip!\n";
714 =head2 function get_centromere
716 Synopsis: my ($north, $south, $center) = $map->get_centromere($lg_name)
717 Arguments: a valid linkage group name
718 Returns: a three member list, the first element corresponds
719 to the north boundary of the centromere in cM
720 the second corresponds to the south boundary of
721 the centromere in cM, the third is the arithmetic mean
722 of the two first values.
732 if (! $self->has_linkage_group($lg)) {
733 die "Not a valid linkage group for this map!\n";
736 my $lg_hash = $self->get_linkage_group_hash($lg);
737 # foreach my $k (keys %$lg_hash) {
738 # print " $k, $lg_hash->{$k}\n";
740 my $north = $lg_hash->{north_centromere
} || 0;
741 my $south = $lg_hash->{south_centromere
} || 0;
742 return ($north, $south, int(($north+$south)/2));
745 sub get_linkage_group_hash
{
748 foreach my $lg_hash (@
{$self->linkage_groups()}) {
749 if ($lg_hash->{lg_name
} eq $lg_name) {