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, %slice_hash, %sr_name_hash, %sr_cs_hash);
my (
$oligo_feature_id, $seq_region_id,
$seq_region_start, $seq_region_end,
$seq_region_strand, $mismatches,
$oligo_probe_id, $analysis_id,
$array_name, $probeset,
$oligo_probe_name,
);
$sth->bind_columns(\$
oligo_feature_id,\$ seq_region_id,\$
seq_region_start,\$ seq_region_end,\$
seq_region_strand,\$ mismatches,\$
oligo_probe_id,\$ analysis_id,\$
array_name,\$ probeset,\$
oligo_probe_name,
);
my $asm_cs;
my $cmp_cs;
my $asm_cs_name;
my $asm_cs_vers;
my $cmp_cs_name;
my $cmp_cs_vers;
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();
}
my $last_feature_id = -1;
FEATURE: while ( $sth->fetch() ) {
next if ($last_feature_id == $oligo_feature_id);
$last_feature_id = $oligo_feature_id;
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) {
unless ($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;
}
}
next FEATURE if $seq_region_end < 1 || $seq_region_start > $dest_slice_length
|| ( $dest_slice_sr_id ne $seq_region_id );
$slice = $dest_slice;
}
push @features, $self->_new_fast( {
'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'slice' => $slice,
'analysis' => $analysis,
'adaptor' => $self,
'dbID' => $oligo_feature_id,
'mismatchcount' => $mismatches,
'_probe_id' => $oligo_probe_id,
'probeset' => $probeset,
'_probe_name' => $oligo_probe_name
} );
}
return\@ features; } |
sub _tables
{ my $self = shift;
return (
[ 'oligo_feature', 'of' ],
[ 'oligo_probe', 'op' ],
[ 'oligo_array', 'oa' ]
); } |
sub fetch_all_by_Slice_arrayname
{ my ($self, $slice, @arraynames) = @_;
throw('Need array name as parameter') if !@arraynames;
my $constraint;
if (scalar @arraynames == 1) {
$constraint = qq( oa.name = '$arraynames[0]' );
} else {
$constraint = join q(','), @arraynames;
$constraint = qq( oa.name IN ('$constraint') );
}
return $self->SUPER::fetch_all_by_Slice_constraint($slice, $constraint); } |
sub fetch_all_by_Slice_type
{ my ($self, $slice, $type, $logic_name) = @_;
throw('Need type as parameter') if !$type;
my $constraint = qq( oa.type = '$type' );
return $self->SUPER::fetch_all_by_Slice_constraint($slice, $constraint, $logic_name); } |
sub store
{ my ($self, @ofs) = @_;
if (scalar(@ofs) == 0) {
throw('Must call store with a list of OligoFeature objects');
}
my $sth = $self->prepare("
INSERT INTO oligo_feature (
seq_region_id, seq_region_start,
seq_region_end, seq_region_strand,
oligo_probe_id, analysis_id,
mismatches
) VALUES (?, ?, ?, ?, ?, ?, ?)
");
my $db = $self->db();
my $analysis_adaptor = $db->get_AnalysisAdaptor();
FEATURE: foreach my $of (@ofs) {
if( !ref $of || !$of->isa('Bio::EnsEMBL::OligoFeature') ) {
throw('Feature must be an OligoFeature object');
}
if ( $of->is_stored($db) ) {
warning('OligoFeature [' . $of->dbID() . '] is already stored in the database');
next FEATURE;
}
if ( !defined $of->analysis() ) {
throw('An analysis must be attached to the OligoFeature objects to be stored.');
}
if ( !$of->analysis->is_stored($db) ) {
$analysis_adaptor->store( $of->analysis() );
}
my $original = $of;
my $seq_region_id;
($of, $seq_region_id) = $self->_pre_store($of);
$sth->bind_param(1, $seq_region_id, SQL_INTEGER);
$sth->bind_param(2, $of->start(), SQL_INTEGER);
$sth->bind_param(3, $of->end(), SQL_INTEGER);
$sth->bind_param(4, $of->strand(), SQL_TINYINT);
$sth->bind_param(5, $of->probe->dbID(), SQL_INTEGER);
$sth->bind_param(6, $of->analysis->dbID(), SQL_INTEGER);
$sth->bind_param(7, $of->mismatchcount(), SQL_TINYINT);
$sth->execute();
$original->dbID( $sth->{'mysql_insertid'} );
$original->adaptor($self);
} } |