sub _objs_from_sth
{ my ($self, $sth, $mapper, $dest_slice) = @_;
my $rca = $self->db()->get_RepeatConsensusAdaptor();
my $sa = $self->db()->get_SliceAdaptor();
my $aa = $self->db->get_AnalysisAdaptor();
my @features;
my %rc_hash;
my %analysis_hash;
my %slice_hash;
my %sr_name_hash;
my %sr_cs_hash;
my($repeat_feature_id, $seq_region_id, $seq_region_start, $seq_region_end,
$seq_region_strand, $repeat_consensus_id, $repeat_start, $repeat_end,
$analysis_id, $score, $repeat_name, $repeat_class, $repeat_type,
$repeat_consensus);
$sth->bind_columns(\$ repeat_feature_id,\$ seq_region_id,\$ seq_region_start,\$
seq_region_end,\$ seq_region_strand,\$
repeat_consensus_id,\$ repeat_start,\$repeat_end,\$
analysis_id,\$ score,\$ repeat_name,\$ repeat_class,\$
repeat_type,\$ repeat_consensus );
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 $rc = $rc_hash{$repeat_consensus_id} ||=
Bio::EnsEMBL::RepeatConsensus->new_fast
({'dbID' => $repeat_consensus_id,
'adaptor' => $rca,
'name' => $repeat_name,
'repeat_class' => $repeat_class,
'repeat_type' => $repeat_type,
'repeat_consensus' => $repeat_consensus,
'length' => length($repeat_consensus)});
my $analysis = $analysis_hash{$analysis_id} ||=
$aa->fetch_by_dbID($analysis_id);
$seq_region_id = $self->get_seq_region_id_internal($seq_region_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::RepeatFeature', {
'dbID' => $repeat_feature_id,
'analysis' => $analysis,
'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'score' => $score,
'hstart' => $repeat_start,
'hend' => $repeat_end,
'repeat_consensus' => $rc,
'adaptor' => $self,
'slice' => $slice
} ) );
}
return\@ features; } |
sub store
{ my( $self, @repeats ) = @_;
my $db = $self->db();
my $rca = $db->get_RepeatConsensusAdaptor();
my $sa = $db->get_SliceAdaptor();
my ($cons, $db_id);
my $sth = $self->prepare(qq{
INSERT into repeat_feature( repeat_feature_id
, seq_region_id
, seq_region_start
, seq_region_end
, seq_region_strand
, repeat_consensus_id
, repeat_start
, repeat_end
, score
, analysis_id )
VALUES(NULL, ?,?,?,?,?,?,?,?,?)
});
FEATURE: foreach my $rf (@repeats) {
if(!ref($rf) || !$rf->isa('Bio::EnsEMBL::RepeatFeature')) {
throw('Expected RepeatFeature argument not [' . ref($rf) .'].');
}
if($rf->is_stored($db)) {
warning("RepeatFeature [".$rf->dbID."] is already stored in this DB.");
next FEATURE;
}
my $cons = $rf->repeat_consensus();
throw("Must have a RepeatConsensus attached") if(!defined($cons));
if ($cons->repeat_class eq 'trf') {
my @match = @{$rca->fetch_all_by_class_seq('trf', $cons->repeat_consensus)};
if (@match) {
$cons->dbID($match[0]->dbID());
}
else {
$rca->store($cons);
}
} elsif ($cons->repeat_class eq 'Simple_repeat') {
my $rcon = $cons->name;
$rcon =~ s/\((\S+)\)n/$1/; $cons->repeat_consensus($rcon);
my $match = $rca->fetch_by_name_class($cons->name, 'Simple_repeat');
if ($match) {
$cons->dbID($match->dbID());
}
else {
$rca->store($cons);
}
} else {
if(!$cons->dbID) {
my $match = ($rca->fetch_by_name($cons->name));
if($match) {
$cons->dbID($match->dbID());
} else {
warning("Can't find " . $cons->name . "\n");
$cons->repeat_consensus("N");
$rca->store($cons);
}
}
}
my $slice = $rf->slice();
if(!ref($slice) || !$slice->isa("Bio::EnsEMBL::Slice")) {
throw("RepeatFeature cannot be stored without an associated slice.");
}
my $original = $rf;
my $seq_region_id;
($rf, $seq_region_id) = $self->_pre_store($rf);
$sth->bind_param(1,$seq_region_id,SQL_INTEGER);
$sth->bind_param(2,$rf->start,SQL_INTEGER);
$sth->bind_param(3,$rf->end,SQL_INTEGER);
$sth->bind_param(4,$rf->strand,SQL_TINYINT);
$sth->bind_param(5,$rf->repeat_consensus->dbID,SQL_INTEGER);
$sth->bind_param(6,$rf->hstart,SQL_INTEGER);
$sth->bind_param(7,$rf->hend,SQL_INTEGER);
$sth->bind_param(8,$rf->score,SQL_DOUBLE);
$sth->bind_param(9,$rf->analysis->dbID,SQL_INTEGER);
$sth->execute();
my $db_id = $sth->{'mysql_insertid'}
or throw("Didn't get an insertid from the INSERT statement");
$original->dbID($db_id);
$original->adaptor($self);
} } |