sub _objs_from_sth
{ my ($self, $sth, $mapper, $dest_slice) = @_;
my $sa = $self->db()->get_SliceAdaptor();
my $aa = $self->db->get_AnalysisAdaptor();
my @features;
my %analysis_hash;
my %slice_hash;
my %sr_name_hash;
my %sr_cs_hash;
my ($protein_align_feature_id, $seq_region_id, $seq_region_start,
$seq_region_end, $analysis_id, $seq_region_strand, $hit_start,
$hit_end, $hit_name, $cigar_line, $evalue, $perc_ident, $score,
$external_db_id, $hcoverage, $external_db_name, $external_display_db_name );
$sth->bind_columns(\$protein_align_feature_id,\$ seq_region_id,\$
seq_region_start,\$seq_region_end,\$ analysis_id,\$
seq_region_strand,\$ hit_start,\$hit_end,\$ hit_name,\$
cigar_line,\$ evalue,\$ perc_ident,\$ score,\$
external_db_id,\$ hcoverage,\$ external_db_name,\$ external_display_db_name );
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_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_sr_name = $dest_slice->seq_region_name();
$dest_slice_sr_id = $dest_slice->get_seq_region_id();
}
FEATURE: while($sth->fetch()) {
my $analysis = $analysis_hash{$analysis_id} ||=
$aa->fetch_by_dbID($analysis_id);
my $slice = $slice_hash{"ID:".$seq_region_id};
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();
}
my $sr_name = $sr_name_hash{$seq_region_id};
my $sr_cs = $sr_cs_hash{$seq_region_id};
if($mapper) {
($seq_region_id,$seq_region_start,$seq_region_end,$seq_region_strand) =
$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(
@features,
$self->_create_feature_fast(
'Bio::EnsEMBL::DnaPepAlignFeature', {
'slice' => $slice,
'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'hseqname' => $hit_name,
'hstart' => $hit_start,
'hend' => $hit_end,
'hstrand' => 1, 'score' => $score,
'p_value' => $evalue,
'percent_id' => $perc_ident,
'cigar_string' => $cigar_line,
'analysis' => $analysis,
'adaptor' => $self,
'dbID' => $protein_align_feature_id,
'external_db_id' => $external_db_id,
'hcoverage' => $hcoverage,
'dbname' => $external_db_name,
'db_display_name' => $external_display_db_name
} ) );
}
return\@ features; } |
sub store
{ my ($self, @feats) = @_;
throw("Must call store with features") if( scalar(@feats) == 0 );
my @tabs = $self->_tables;
my ($tablename) = @{$tabs[0]};
my $db = $self->db();
my $slice_adaptor = $db->get_SliceAdaptor();
my $analysis_adaptor = $db->get_AnalysisAdaptor();
my $sth = $self->prepare(
"INSERT INTO $tablename (seq_region_id, seq_region_start, seq_region_end,
seq_region_strand, hit_start, hit_end,
hit_name, cigar_line,
analysis_id, score, evalue, perc_ident, external_db_id, hcoverage)
VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?, ?)");
FEATURE: foreach my $feat ( @feats ) {
if( !ref $feat || !$feat->isa("Bio::EnsEMBL::DnaPepAlignFeature") ) {
throw("feature must be a Bio::EnsEMBL::DnaPepAlignFeature,"
. " not a [".ref($feat)."].");
}
if($feat->is_stored($db)) {
warning("PepDnaAlignFeature [".$feat->dbID."] is already stored" .
" in this database.");
next FEATURE;
}
my $hstart = $feat->hstart();
my $hend = $feat->hend();
$self->_check_start_end_strand($hstart,$hend,1);
my $cigar_string = $feat->cigar_string();
if(!$cigar_string) {
$cigar_string = $feat->length() . 'M';
warning("DnaPepAlignFeature does not define a cigar_string.\n" .
"Assuming ungapped block with cigar_string=$cigar_string\n");
}
my $hseqname = $feat->hseqname();
if(!$hseqname) {
throw("DnaPepAlignFeature must define an hseqname.");
}
if(!defined($feat->analysis)) {
throw("An analysis must be attached to the features to be stored.");
}
if(!$feat->analysis->is_stored($db)) {
$analysis_adaptor->store($feat->analysis());
}
my $slice = $feat->slice();
if(!defined($slice) || !$slice->isa("Bio::EnsEMBL::Slice")) {
throw("A slice must be attached to the features to be stored.");
}
my $original = $feat;
my $seq_region_id;
($feat, $seq_region_id) = $self->_pre_store($feat);
$sth->bind_param(1,$seq_region_id,SQL_INTEGER);
$sth->bind_param(2,$feat->start,SQL_INTEGER);
$sth->bind_param(3,$feat->end,SQL_INTEGER);
$sth->bind_param(4,$feat->strand,SQL_TINYINT);
$sth->bind_param(5,$feat->hstart,SQL_INTEGER);
$sth->bind_param(6,$feat->hend,SQL_INTEGER);
$sth->bind_param(7,$feat->hseqname,SQL_VARCHAR);
$sth->bind_param(8,$feat->cigar_string,SQL_LONGVARCHAR);
$sth->bind_param(9,$feat->analysis->dbID,SQL_INTEGER);
$sth->bind_param(10,$feat->score,SQL_DOUBLE);
$sth->bind_param(11,$feat->p_value,SQL_DOUBLE);
$sth->bind_param(12,$feat->percent_id,SQL_REAL);
$sth->bind_param(13,$feat->external_db_id,SQL_INTEGER);
$sth->bind_param(14,$feat->hcoverage,SQL_DOUBLE);
$sth->execute();
$original->dbID($sth->{'mysql_insertid'});
$original->adaptor($self);
}
$sth->finish(); } |