diff --git a/modules/Bio/EnsEMBL/IdMapping/StableIdGenerator/EnsemblGeneric.pm b/modules/Bio/EnsEMBL/IdMapping/StableIdGenerator/EnsemblGeneric.pm index c3c6311fb520fa0196baa82a9b06645b0af9350b..eb7966b62ef373237225fc01e024191621ae0922 100644 --- a/modules/Bio/EnsEMBL/IdMapping/StableIdGenerator/EnsemblGeneric.pm +++ b/modules/Bio/EnsEMBL/IdMapping/StableIdGenerator/EnsemblGeneric.pm @@ -2,20 +2,74 @@ package Bio::EnsEMBL::IdMapping::StableIdGenerator::EnsemblGeneric; =head1 NAME +Bio::EnsEMBL::IdMapping::StableIdGenerator::EnsemblGeneric - default Ensembl +StableIdGenerator implementation =head1 SYNOPSIS +# inject the confiured StableIdGenerator plugin +my $stable_id_generator = $conf->param('plugin_stable_id_generator'); +inject($stable_id_generator); + +# create a new StableIdGenerator object +my $generator_instance = $stable_id_generator->new( + -LOGGER => $self->logger, + -CONF => $self->conf, + -CACHE => $self->cache +); + +# determine starting stable ID for new assignments +my $new_stable_id = $generator_instance->initial_stable_id('gene'); + +# loop over genes +foreach my $target_gene (@all_target_genes) { + + # if the stable Id for this gene was mapped, assign it + if ($mapping_exists{$target_gene->id}) { + my $source_gene = $mappings{$target_gene->id}; + $target_gene->stable_id($source_gene->stable_id); + + # calculate and set version + my $version = $generator_instance->calculate_version($source_gene, + $target_gene); + $target_gene->version($version); + + # no mapping exists, assign a new stable Id + } else { + $target_gene->stable_id($new_stable_id); + $target_gene->version('1'); + + # increment the stable Id (to be assigned to the next unmapped gene) + $new_stable_id = $generator_instance->increment_stable_id($new_stable_id); + } +} =head1 DESCRIPTION +This is the default implementation for a StableIdGenerator, which is used by +Bio::EnsEMBL::IdMapping::StableIdMapper to generate new stable Ids and increment +versions on mapped stable Ids. Refer to the documentation in this module if you +would like to implement your own StableIdGenerator. + +The stable Id mapping application allows you to plugin your own implementation +by specifying it with the --plugin_stable_id_generator configuration parameter. + +Requirements for a StableIdGenerator plugin: + + - inherit from Bio::EnsEMBL::IdMapping::BaseObject + - implement all methods listed in METHODS below (see method POD for + signatures) =head1 METHODS +initial_stable_id +increment_stable_id +calculate_version =head1 LICENCE This code is distributed under an Apache style licence. Please see -http:#www.ensembl.org/info/about/code_licence.html for details. +http://www.ensembl.org/info/about/code_licence.html for details. =head1 AUTHOR @@ -39,6 +93,20 @@ our @ISA = qw(Bio::EnsEMBL::IdMapping::BaseObject); use Bio::EnsEMBL::Utils::Exception qw(throw warning); +=head2 initial_stable_id + + Arg[1] : String $type - an entity type (gene|transcript|translation|exon) + Example : my $new_stable_id = $generator->initial_stable_id('gene'); + Description : Determine the initial stable Id to use for new assignments. This + method is called once at the beginning of stable Id mapping. + Return type : String - a stable Id of appropriate type + Exceptions : none + Caller : Bio::EnsEMBL::IdMapping::StableIdMapper::map_stable_ids() + Status : At Risk + : under development + +=cut + sub initial_stable_id { my $self = shift; my $type = shift; @@ -57,7 +125,13 @@ sub initial_stable_id { $init_stable_id = $self->fetch_value_from_db($s_dbh, $sql); if ($init_stable_id) { + # since $init_stable_id now is the highest existing stable Id for this + # object type, we need to increment it to find the first one we want to use + # for new assignments + $init_stable_id = $self->increment_stable_id($init_stable_id); + $self->logger->debug("Using $init_stable_id as base for new $type stable IDs\n"); + } else { $self->logger->warning("Can't find highest ${type}_stable_id in source db.\n"); } @@ -66,6 +140,22 @@ sub initial_stable_id { } +=head2 increment_stable_id + + Arg[1] : String $stable_id - the stable Id to increment + Example : $next_stable_id = $generator->increment_stable_id( + $current_stable_id); + Description : Increments the stable Id used for new assigments. This method is + called after each new stable Id assigment to generate the next + stable Id to be used. + Return type : String - the next new stable Id + Exceptions : thrown on missing or malformed argument + Caller : Bio::EnsEMBL::IdMapping::StableIdMapper::map_stable_ids() + Status : At Risk + : under development + +=cut + sub increment_stable_id { my $self = shift; my $stable_id = shift; @@ -81,6 +171,27 @@ sub increment_stable_id { } +=head2 calculate_version + + Arg[1] : Bio::EnsEMBL::IdMapping::TinyFeature $s_obj - source object + Arg[2] : Bio::EnsEMBL::IdMapping::TinyFeature $t_obj - target object + Example : my $version = $generator->calculate_version($source_gene, + $target_gene); + $target_gene->version($version); + Description : Determines the version for a mapped stable Id. For Ensembl + genes, the rules for incrementing the version number are: + - exons: if exon sequence changed + - transcript: if spliced exon sequence changed + - translation: if transcript changed + - gene: if any of its transcript changed + Return type : String - the version to be used + Exceptions : thrown on wrong argument + Caller : Bio::EnsEMBL::IdMapping::StableIdMapper::map_stable_ids() + Status : At Risk + : under development + +=cut + sub calculate_version { my $self = shift; my $s_obj = shift; diff --git a/modules/Bio/EnsEMBL/IdMapping/StableIdMapper.pm b/modules/Bio/EnsEMBL/IdMapping/StableIdMapper.pm index 0878345a5b0c6910fc28033320bb7e5e001ee3be..5524df2dbd8dc23931891de57a28856bcd2fc133 100644 --- a/modules/Bio/EnsEMBL/IdMapping/StableIdMapper.pm +++ b/modules/Bio/EnsEMBL/IdMapping/StableIdMapper.pm @@ -260,8 +260,6 @@ sub map_stable_ids { # no mapping was found, assign a new stable ID } else { - $new_stable_id = $self->stable_id_generator->increment_stable_id( - $new_stable_id); $t_obj->stable_id($new_stable_id); $t_obj->version(1); $t_obj->created_date($self->mapping_session_date); @@ -281,6 +279,10 @@ sub map_stable_ids { $self->add_stable_id_event('new', $key); } + # increment the stable Id (to be assigned to the next unmapped gene) + $new_stable_id = $self->stable_id_generator->increment_stable_id( + $new_stable_id); + # stats $stats{'new'}++;