sub _objs_from_sth
{ my ($self, $sth, $mapper, $dest_slice) = @_;
my $sa = $self->db()->get_SliceAdaptor();
my @exons;
my %slice_hash;
my %sr_name_hash;
my %sr_cs_hash;
my($prediction_exon_id,$seq_region_id,
$seq_region_start, $seq_region_end, $seq_region_strand,
$start_phase, $score, $p_value);
$sth->bind_columns(\$prediction_exon_id,\$seq_region_id,\$
seq_region_start,\$ seq_region_end,\$ seq_region_strand,\$
start_phase,\$ score,\$ p_value);
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;
my $dest_slice_cs;
my $asma;
my $dest_slice_sr_name;
my $dest_slice_sr_id;
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();
$dest_slice_cs = $dest_slice->coord_system;
$dest_slice_sr_name = $dest_slice->seq_region_name();
$dest_slice_sr_id = $dest_slice->get_seq_region_id();
$asma = $self->db->get_AssemblyMapperAdaptor();
}
FEATURE: while($sth->fetch()) {
$seq_region_id = $self->get_seq_region_id_internal($seq_region_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
my $dest_mapper = $mapper;
if(!$slice) {
$slice = $sa->fetch_by_seq_region_id($seq_region_id);
$slice_hash{"ID:".$seq_region_id} = $slice;
$sr_name_hash{$seq_region_id} = $slice->seq_region_name();
$sr_cs_hash{$seq_region_id} = $slice->coord_system();
}
if(!$dest_mapper && $dest_slice &&
!$dest_slice_cs->equals($slice->coord_system)) {
$dest_mapper = $asma->fetch_by_CoordSystems($dest_slice_cs,
$slice->coord_system);
$asm_cs = $dest_mapper->assembled_CoordSystem();
$cmp_cs = $dest_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 $sr_name = $sr_name_hash{$seq_region_id};
my $sr_cs = $sr_cs_hash{$seq_region_id};
if($dest_mapper) {
($seq_region_id,$seq_region_start,$seq_region_end,$seq_region_strand) =
$dest_mapper->fastmap($sr_name, $seq_region_start, $seq_region_end,
$seq_region_strand, $sr_cs);
next FEATURE if(!defined($seq_region_id));
$slice = $slice_hash{"ID:".$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;
$seq_region_strand *= -1;
}
}
if($seq_region_end < 1 || $seq_region_start > $dest_slice_length ||
( $dest_slice_sr_id ne $seq_region_id )) {
next FEATURE;
}
$slice = $dest_slice;
}
push( @exons,
$self->_create_feature( 'Bio::EnsEMBL::PredictionExon', {
'-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-dbID' => $prediction_exon_id,
'-phase' => $start_phase,
'-score' => $score,
'-p_value' => $p_value
} ) );
}
return\@ exons;
}
1; } |
sub fetch_all_by_PredictionTranscript
{ my ( $self, $transcript ) = @_;
my $constraint = "pe.prediction_transcript_id = ".$transcript->dbID();
my $tslice = $transcript->slice();
my $slice;
if(!$tslice) {
throw("Transcript must have attached slice to retrieve exons.");
}
$slice = $self->db->get_SliceAdaptor->fetch_by_Feature($transcript);
my $exons = $self->fetch_all_by_Slice_constraint($slice, $constraint);
if($slice->name() ne $tslice->name()) {
my @out;
foreach my $ex (@$exons) {
push @out, $ex->transfer($tslice);
}
$exons =\@ out;
}
return $exons; } |
sub remove
{ my $self = shift;
my $pexon = shift;
my $db = $self->db();
if(!$pexon->is_stored($db)) {
warning('PredictionExon is not in this DB - not removing');
return undef;
}
my $sth = $self->prepare(
"DELETE FROM prediction_exon WHERE prediction_exon_id = ?");
$sth->bind_param( 1, $pexon->dbID, SQL_INTEGER );
$sth->execute();
$pexon->dbID(undef);
$pexon->adaptor(undef); } |
sub store
{ my ( $self, $pexon, $pt_id, $rank ) = @_;
if(!ref($pexon) || !$pexon->isa('Bio::EnsEMBL::PredictionExon') ) {
throw("Expected PredictionExon argument");
}
throw("Expected PredictionTranscript id argument.") if(!$pt_id);
throw("Expected rank argument.") if(!$rank);
my $db = $self->db();
if($pexon->is_stored($db)) {
warning('PredictionExon is already stored in this DB.');
return $pexon->dbID();
}
if( ! $pexon->start || ! $pexon->end ||
! $pexon->strand || ! defined $pexon->phase ) {
throw("PredictionExon does not have all attributes to store.\n" .
"start, end, strand and phase attributes must be set.");
}
my $original = $pexon;
my $seq_region_id;
($pexon, $seq_region_id) = $self->_pre_store($pexon);
my $sth = $db->dbc->prepare
("INSERT into prediction_exon (prediction_transcript_id, exon_rank, " .
"seq_region_id, seq_region_start, seq_region_end, " .
"seq_region_strand, start_phase, score, p_value) " .
"VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? )");
$sth->bind_param(1,$pt_id,SQL_INTEGER);
$sth->bind_param(2,$rank,SQL_SMALLINT);
$sth->bind_param(3,$seq_region_id,SQL_INTEGER);
$sth->bind_param(4,$pexon->start,SQL_INTEGER);
$sth->bind_param(5,$pexon->end,SQL_INTEGER);
$sth->bind_param(6,$pexon->strand,SQL_TINYINT);
$sth->bind_param(7,$pexon->phase,SQL_TINYINT);
$sth->bind_param(8,$pexon->score,SQL_DOUBLE);
$sth->bind_param(9,$pexon->p_value,SQL_DOUBLE);
$sth->execute();
my $dbID = $sth->{'mysql_insertid'};
$original->dbID($dbID);
$original->adaptor($self);
return $dbID; } |