Commit 6caa4d9e authored by Andreas Kusalananda Kähäri's avatar Andreas Kusalananda Kähäri
Browse files

In BaseFeatureAdaptor:

  Add the methods _create_feature() and _create_feature_fast()
  that returns a feature created by calling new() and new_fast()
  respectively, of the given type and with the given argument hashes.

In the various feature adaptors:

  Create features using the two new methods above instead of new() and
  new_fast().  This allows for hijacking feature creation in the feature
  collection "adaptor" later.
parent 288b56c1
......@@ -73,7 +73,6 @@ sub new {
return $self;
}
=head2 fetch_all_by_Slice
Arg [1] : Bio::EnsEMBL::Slice $slice
......@@ -280,6 +279,23 @@ sub fetch_all_by_logic_name {
return $self->generic_fetch($constraint);
}
# Method that creates an object. Called by the _objs_from_sth() method
# in the sub-classes (the various feature adaptors). Overridden by the
# feature collection classes.
sub _create_feature {
my ( $self, $feature_type, $args ) = @_;
return $feature_type->new( %{$args} );
}
# This is the same as the above, but calls the new_fast() constructor of
# the feature type.
sub _create_feature_fast {
my ( $self, $feature_type, $args ) = @_;
return $feature_type->new_fast($args);
}
#
# helper function used by fetch_all_by_Slice_constraint method
#
......
......@@ -252,40 +252,45 @@ sub get_db_adaptor {
=cut
sub get_available_adaptors{
my %pairs = (
# Firstly those that just have an adaptor named after there object in the main DBSQL directory
map( { $_ => "Bio::EnsEMBL::DBSQL::${_}Adaptor" } qw(
AffyFeature AffyArray AffyProbe
Analysis ArchiveStableId Attribute
AssemblyExceptionFeature AssemblyMapper CoordSystem
CompressedSequence DBEntry DnaAlignFeature
DensityFeature DensityType Exon
Gene KaryotypeBand MiscSet
MiscFeature OligoArray OligoFeature
OligoProbe PredictionTranscript PredictionExon
ProteinFeature ProteinAlignFeature RepeatConsensus
RepeatFeature Sequence SimpleFeature
Slice SupportingFeature Transcript
TranscriptSupportingFeature Translation UnmappedObject
UnconventionalTranscriptAssociation
AssemblySlice
) ),
# Those whose adaptors are in Map::DBSQL
sub get_available_adaptors {
my %pairs = (
# Firstly those that just have an adaptor named after there object
# in the main DBSQL directory.
map( { $_ => "Bio::EnsEMBL::DBSQL::${_}Adaptor" } qw(
AffyFeature AffyArray AffyProbe
Analysis ArchiveStableId Attribute
AssemblyExceptionFeature AssemblyMapper CoordSystem
CompressedSequence DBEntry DnaAlignFeature
DensityFeature DensityType Exon
Gene KaryotypeBand MiscSet
MiscFeature OligoArray OligoFeature
OligoProbe PredictionTranscript PredictionExon
ProteinFeature ProteinAlignFeature RepeatConsensus
RepeatFeature Sequence SimpleFeature
Slice SupportingFeature Transcript
TranscriptSupportingFeature Translation UnmappedObject
UnconventionalTranscriptAssociation
AssemblySlice
) ),
# Those whose adaptors are in Map::DBSQL
map( { $_ => "Bio::EnsEMBL::Map::DBSQL::${_}Adaptor" } qw(
Marker MarkerFeature QtlFeature Qtl Ditag DitagFeature
) ),
# Finally the exceptions... those that have non-standard mapping between object / adaptor ....
# 'Blast' => 'Bio::EnsEMBL::External::BlastAdaptor',
'MetaCoordContainer' => 'Bio::EnsEMBL::DBSQL::MetaCoordContainer',
'MetaContainer' => 'Bio::EnsEMBL::DBSQL::MetaContainer',
'SNP' => 'Bio::EnsEMBL::DBSQL::ProxySNPAdaptor'
);
return (\%pairs);
}
Marker MarkerFeature QtlFeature Qtl Ditag DitagFeature
) ),
# Finally the exceptions... those that have non-standard mapping
# between object / adaptor ....
# 'Blast' => 'Bio::EnsEMBL::External::BlastAdaptor',
'MetaCoordContainer' => 'Bio::EnsEMBL::DBSQL::MetaCoordContainer',
'MetaContainer' => 'Bio::EnsEMBL::DBSQL::MetaContainer',
'SNP' => 'Bio::EnsEMBL::DBSQL::ProxySNPAdaptor',
# Feature Collections:
'GeneCollection' => 'Bio::EnsEMBL::Collection::Gene',
'TranscriptCollection' => 'Bio::EnsEMBL::Collection::Transcript',
'ExonCollection' => 'Bio::EnsEMBL::Collection::Exon',
'RepeatFeatureCollection' =>
'Bio::EnsEMBL::Collection::RepeatFeature' );
return ( \%pairs );
} ## end sub get_available_adaptors
###########################################################
#
......
......@@ -448,15 +448,19 @@ sub _objs_from_sth {
$slice = $dest_slice;
}
push @features, Bio::EnsEMBL::DensityFeature->new
(-dbID => $density_feature_id,
-adaptor => $self,
-start => $seq_region_start,
-end => $seq_region_end,
-seq_region => $slice,
-density_value => $density_value,
-density_type => $density_type);
push( @features,
$self->_create_feature( 'Bio::EnsEMBL::DensityFeature', {
-dbID => $density_feature_id,
-adaptor => $self,
-start => $seq_region_start,
-end => $seq_region_end,
-seq_region => $slice,
-density_value => $density_value,
-density_type => $density_type
} ) );
}
return \@features;
}
......
......@@ -344,25 +344,29 @@ sub _objs_from_sth {
$slice = $dest_slice;
}
#finally, create the new dna align feature
push @features, Bio::EnsEMBL::DnaDnaAlignFeature->new_fast
( { 'slice' => $slice,
'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'hseqname' => $hit_name,
'hstart' => $hit_start,
'hend' => $hit_end,
'hstrand' => $hit_strand,
'score' => $score,
'p_value' => $evalue,
'percent_id' => $perc_ident,
'cigar_string' => $cigar_line,
'analysis' => $analysis,
'adaptor' => $self,
'dbID' => $dna_align_feature_id,
'external_db_id'=> $external_db_id,
'hcoverage' => $hcoverage } );
# Finally, create the new DnaAlignFeature.
push( @features,
$self->_create_feature_fast(
'Bio::EnsEMBL::DnaDnaAlignFeature', {
'slice' => $slice,
'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'hseqname' => $hit_name,
'hstart' => $hit_start,
'hend' => $hit_end,
'hstrand' => $hit_strand,
'score' => $score,
'p_value' => $evalue,
'percent_id' => $perc_ident,
'cigar_string' => $cigar_line,
'analysis' => $analysis,
'adaptor' => $self,
'dbID' => $dna_align_feature_id,
'external_db_id' => $external_db_id,
'hcoverage' => $hcoverage
} ) );
}
return \@features;
......
......@@ -616,29 +616,31 @@ sub _objs_from_sth {
$slice = $dest_slice;
}
#finally, create the new repeat feature
push @exons, Bio::EnsEMBL::Exon->new(
'-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-dbID' => $exon_id,
'-stable_id' => $stable_id,
'-version' => $version,
'-created_date' => $created_date || undef,
'-modified_date' => $modified_date || undef,
'-phase' => $phase,
'-end_phase' => $end_phase,
'-is_current' => $is_current
);
# Finally, create the new exon.
push( @exons,
$self->_create_feature( 'Bio::EnsEMBL::Exon', {
'-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-dbID' => $exon_id,
'-stable_id' => $stable_id,
'-version' => $version,
'-created_date' => $created_date
|| undef,
'-modified_date' => $modified_date
|| undef,
'-phase' => $phase,
'-end_phase' => $end_phase,
'-is_current' => $is_current
} ) );
}
return \@exons;
}
=head1 DEPRECATED METHODS
=cut
......
......@@ -1449,29 +1449,33 @@ sub _objs_from_sth {
$display_xref->status( $external_status );
}
#finally, create the new gene
push @genes, Bio::EnsEMBL::Gene->new(
'-analysis' => $analysis,
'-biotype' => $biotype,
'-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-dbID' => $gene_id,
'-stable_id' => $stable_id,
'-version' => $version,
'-created_date' => $created_date || undef,
'-modified_date' => $modified_date || undef,
'-description' => $gene_description,
'-external_name' => $external_name,
'-external_db' => $external_db,
'-external_status' => $external_status,
'-display_xref' => $display_xref,
'-status' => $status,
'-source' => $source,
'-is_current' => $is_current
);
# Finally, create the new Gene.
push( @genes,
$self->_create_feature(
'Bio::EnsEMBL::Gene', {
'-analysis' => $analysis,
'-biotype' => $biotype,
'-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-dbID' => $gene_id,
'-stable_id' => $stable_id,
'-version' => $version,
'-created_date' => $created_date || undef,
'-modified_date' => $modified_date
|| undef,
'-description' => $gene_description,
'-external_name' => $external_name,
'-external_db' => $external_db,
'-external_status' => $external_status,
'-display_xref' => $display_xref,
'-status' => $status,
'-source' => $source,
'-is_current' => $is_current
} ) );
}
return \@genes;
......
......@@ -116,18 +116,21 @@ sub _objs_from_sth {
$sth->bind_columns(\$karyotype_id, \$seq_region_id, \$seq_region_start,
\$seq_region_end, \$band, \$stain);
while($sth->fetch()) {
while ( $sth->fetch() ) {
my $slice = $slice_cache{$seq_region_id} ||=
$slice_adaptor->fetch_by_seq_region_id($seq_region_id);
push @features, Bio::EnsEMBL::KaryotypeBand->new
(-START => $seq_region_start,
-END => $seq_region_end,
-SLICE => $slice,
-ADAPTOR => $self,
-DBID => $karyotype_id,
-NAME => $band,
-STAIN => $stain);
push( @features,
$self->_create_feature( 'Bio::EnsEMBL::KaryotypeBand', {
-START => $seq_region_start,
-END => $seq_region_end,
-SLICE => $slice,
-ADAPTOR => $self,
-DBID => $karyotype_id,
-NAME => $band,
-STAIN => $stain
} ) );
}
return \@features;
......
......@@ -475,14 +475,17 @@ sub _objs_from_sth {
$seen_attribs->{"$attrib_type_code:$attrib_value"} = 1;
}
$feat = Bio::EnsEMBL::MiscFeature->new_fast
({'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'slice' => $slice,
'adaptor' => $self,
'dbID' => $misc_feature_id,
'attributes' => $feat_attribs });
$feat =
$self->_create_feature_fast( 'Bio::EnsEMBL::MiscFeature', {
'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'slice' => $slice,
'adaptor' => $self,
'dbID' => $misc_feature_id,
'attributes' => $feat_attribs
} );
push @features, $feat;
if ($misc_set_id) {
......
......@@ -424,17 +424,20 @@ sub _objs_from_sth {
$slice = $dest_slice;
}
#finally, create the new PredictionExon
push @exons, Bio::EnsEMBL::PredictionExon->new
( '-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);
# Finally, create the new PredictionExon.
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;
......
......@@ -382,16 +382,19 @@ sub _objs_from_sth {
$slice = $dest_slice;
}
#finally, create the new repeat feature
push @ptranscripts, Bio::EnsEMBL::PredictionTranscript->new
( '-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-analysis' => $analysis,
'-dbID' => $prediction_transcript_id,
'-display_label' => $display_label);
# Finally, create the new PredictionTranscript.
push( @ptranscripts,
$self->_create_feature('Bio::EnsEMBL::PredictionTranscript', {
'-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-analysis' => $analysis,
'-dbID' => $prediction_transcript_id,
'-display_label' => $display_label
} ) );
}
return \@ptranscripts;
......
......@@ -294,25 +294,31 @@ sub _objs_from_sth {
$slice = $dest_slice;
}
#finally, create the new dna align feature
push @features, Bio::EnsEMBL::DnaPepAlignFeature->new_fast
( { '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, #dna_pep_align features are always 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 } );
# Finally, create the new ProteinAlignFeature.
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, # dna_pep_align features
# are always 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
} ) );
}
return \@features;
......
......@@ -303,19 +303,21 @@ sub _objs_from_sth {
$slice = $dest_slice;
}
#finally, create the new repeat feature
push @features, Bio::EnsEMBL::RepeatFeature->new_fast
( { '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,
'dbID' => $repeat_feature_id } );
# Finally, create the new RepeatFeature.
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
} ) );
}
......
......@@ -290,16 +290,20 @@ sub _objs_from_sth {
$slice = $dest_slice;
}
push @features, Bio::EnsEMBL::SimpleFeature->new_fast(
{'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'slice' => $slice,
'analysis' => $analysis,
'adaptor' => $self,
'dbID' => $simple_feature_id,
'display_label' => $display_label,
'score' => $score});
push( @features,
$self->_create_feature_fast(
'Bio::EnsEMBL::SimpleFeature', {
'start' => $seq_region_start,
'end' => $seq_region_end,
'strand' => $seq_region_strand,
'slice' => $slice,
'analysis' => $analysis,
'adaptor' => $self,
'dbID' => $simple_feature_id,
'display_label' => $display_label,
'score' => $score
} ) );
}
return \@features;
......
......@@ -1284,29 +1284,32 @@ sub _objs_from_sth {
}
#finally, create the new transcript
push @transcripts, Bio::EnsEMBL::Transcript->new(
'-analysis' => $analysis,
'-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-dbID' => $transcript_id,
'-stable_id' => $stable_id,
'-version' => $version,
'-created_date' => $created_date || undef,
'-modified_date' => $modified_date || undef,
'-external_name' => $xref_display_label,
'-external_db' => $external_db,
'-external_status' => $external_status,
'-external_display_name' => $external_db_name,
'-display_xref' => $display_xref,
'-description' => $description,
'-biotype' => $biotype,
'-status' => $status,
'-is_current' => $is_current
);
# Finally, create the new Transcript.
push( @transcripts,
$self->_create_feature(
'Bio::EnsEMBL::Transcript', {
'-analysis' => $analysis,
'-start' => $seq_region_start,
'-end' => $seq_region_end,
'-strand' => $seq_region_strand,
'-adaptor' => $self,
'-slice' => $slice,
'-dbID' => $transcript_id,
'-stable_id' => $stable_id,
'-version' => $version,
'-created_date' => $created_date || undef,
'-modified_date' => $modified_date || undef,