sub _columns
{ my $self = shift;
return ('mf.marker_feature_id', 'mf.marker_id',
'mf.seq_region_id', 'mf.seq_region_start', 'mf.seq_region_end',
'mf.analysis_id', 'mf.map_weight',
'm.left_primer', 'm.right_primer', 'm.min_primer_dist',
'm.max_primer_dist', 'm.priority', 'm.type', 'ms.marker_synonym_id',
'ms.name', 'ms.source'); } |
sub _objs_from_sth
{ my ($self, $sth, $mapper, $dest_slice) = @_;
my ($marker_feature_id, $marker_id,
$seq_region_id, $seq_region_start, $seq_region_end,
$analysis_id, $map_weight,
$left_primer, $right_primer, $min_primer_dist, $max_primer_dist,
$priority, $type, $ms_id, $ms_name, $ms_source);
$sth->bind_columns(\$marker_feature_id,\$ marker_id,\$
seq_region_id,\$ seq_region_start,\$ seq_region_end,\$
analysis_id,\$ map_weight,\$
left_primer,\$ right_primer,\$ min_primer_dist,\$ max_primer_dist,\$
priority,\$ type,\$ ms_id,\$ ms_name,\$ ms_source);
my @out = ();
my %marker_cache;
my %slice_hash;
my %sr_cs_hash;
my %analysis_cache;
my $marker_adp = $self->db->get_MarkerAdaptor;
my $sa = $self->db->get_SliceAdaptor;
my $analysis_adp = $self->db->get_AnalysisAdaptor;
my $asm_cs;
my $cmp_cs;
my $asm_cs_vers;
my $asm_cs_name;
my $cmp_cs_vers;
my $cmp_cs_name;
if($mapper) {
$asm_cs = $mapper->assembled_CoordSystem();
$cmp_cs = $mapper->component_CoordSystem();
$asm_cs_name = $asm_cs->name();
$asm_cs_vers = $asm_cs->version();
$cmp_cs_name = $cmp_cs->name();
$cmp_cs_vers = $cmp_cs->version();
}
my $dest_slice_start;
my $dest_slice_end;
my $dest_slice_strand;
my $dest_slice_length;
if($dest_slice) {
$dest_slice_start = $dest_slice->start();
$dest_slice_end = $dest_slice->end();
$dest_slice_strand = $dest_slice->strand();
$dest_slice_length = $dest_slice->length();
}
FEATURE: while($sth->fetch) {
my $marker;
if(!($marker = $marker_cache{$marker_id})) {
my $ms;
if($ms_id) {
$ms = Bio::EnsEMBL::Map::MarkerSynonym->new
($ms_id, $ms_source, $ms_name);
}
$marker = Bio::EnsEMBL::Map::Marker->new
($marker_id, $marker_adp,
$left_primer, $right_primer, $min_primer_dist, $max_primer_dist,
$priority, $type, $ms);
$marker_cache{$marker_id} = $marker;
}
my $slice = $slice_hash{$seq_region_id};
if(!$slice) {
$slice = $sa->fetch_by_seq_region_id($seq_region_id);
$slice_hash{$seq_region_id} = $slice;
$sr_cs_hash{$seq_region_id} = $slice->coord_system();
}
my $analysis;
unless($analysis = $analysis_cache{$analysis_id}) {
$analysis = $analysis_adp->fetch_by_dbID($analysis_id);
$analysis_cache{$analysis_id} = $analysis;
}
if($mapper) {
my $sr_cs = $sr_cs_hash{$seq_region_id};
($seq_region_id,$seq_region_start,$seq_region_end) =
$mapper->fastmap($slice->seq_region_name(), $seq_region_start, $seq_region_end, 0, $sr_cs);
next FEATURE if(!defined($seq_region_id));
$slice = $slice_hash{"$seq_region_id"} ||=
$sa->fetch_by_seq_region_id($seq_region_id);
}
if($dest_slice) {
if($dest_slice_start != 1 || $dest_slice_strand != 1) {
if($dest_slice_strand == 1) {
$seq_region_start = $seq_region_start - $dest_slice_start + 1;
$seq_region_end = $seq_region_end - $dest_slice_start + 1;
} else {
my $tmp_seq_region_start = $seq_region_start;
$seq_region_start = $dest_slice_end - $seq_region_end + 1;
$seq_region_end = $dest_slice_end - $tmp_seq_region_start + 1;
}
if($seq_region_end < 1 || $seq_region_start > $dest_slice_length) {
next FEATURE;
}
}
$slice = $dest_slice;
}
push @out, Bio::EnsEMBL::Map::MarkerFeature->new
($marker_feature_id, $self,
$seq_region_start, $seq_region_end, $slice,
$analysis, $marker_id, $map_weight, $marker);
}
return\@ out; } |
sub fetch_all_by_Slice_and_priority
{ my ($self, $slice, $priority, $map_weight, @args) = @_;
my $constraint = '';
if(defined $priority) {
$constraint = "m.priority > $priority";
}
if(defined $map_weight) {
if($constraint) {
$constraint .= " AND mf.map_weight < $map_weight";
} else {
$constraint = "mf.map_weight < $map_weight";
}
}
return $self->fetch_all_by_Slice_constraint($slice, $constraint, @args); } |
sub store
{ my ($self, @mfs) = @_;
foreach my $mf (@mfs) {
if(!ref($mf) || !$mf->isa('Bio::EnsEMBL::Map::MarkerFeature')) {
$self->throw("Incorrect argument [$mf] to store. Expected " .
'Bio::EnsEMBL::Map::MarkerFeature');
}
if($mf->is_stored($self->db())) {
warning('MarkerFeature ['.$mf->dbID.'] is already stored in this DB.');
next;
}
my $marker = $mf->marker;
if(!$marker || !ref($marker) ||
!$marker->isa('Bio::EnsEMBL::Map::Marker')) {
throw('Cannot store MarkerFeature without an associated Marker');
}
if(!$marker->is_stored($self->db())) {
my $marker_adaptor = $self->db->get_adaptor('Marker');
$marker_adaptor->store($marker);
}
my $marker_id = $marker->dbID ||
throw('Associated Marker must have dbID to store MarkerFeature');
my $analysis = $mf->analysis;
if(!$analysis || !ref($analysis) ||
!$analysis->isa('Bio::EnsEMBL::Analysis')) {
throw('Cannot store MarkerFeature without an associated Analysis');
}
if(!$analysis->is_stored($self->db())) {
my $analysis_adaptor = $self->db->get_adaptor('Analysis');
$analysis_adaptor->store($mf->analysis());
}
my $analysis_id = $analysis->dbID ||
throw('Associated Analysis must have dbID to store MarkerFeature');
my $original = $mf;
my $seq_region_id;
($mf, $seq_region_id) = $self->_pre_store($mf);
my $sth =
$self->prepare("INSERT INTO marker_feature (marker_id,
seq_region_id, seq_region_start, seq_region_end,
analysis_id, map_weight)
VALUES (?, ?, ?, ?, ?, ?)");
$sth->execute($marker_id,
$seq_region_id, $mf->start, $mf->end,
$analysis_id, $mf->map_weight || 0);
my $dbID = $sth->{'mysql_insertid'};
$original->dbID($dbID);
$original->adaptor($self);
}
}
1; } |