$Bio::EnsEMBL::IdMapping::InternalIdMapper::EnsemblExonGeneric::VERSION
=
'112.0.0'
;
no
warnings
'uninitialized'
;
our
@ISA
=
qw(Bio::EnsEMBL::IdMapping::InternalIdMapper::BaseMapper)
;
sub
init_basic {
my
$self
=
shift
;
my
$num
=
shift
;
my
$esb
=
shift
;
my
$mappings
=
shift
;
my
$exon_scores
=
shift
;
$self
->logger->info(
"Basic exon mapping...\n"
, 0,
'stamped'
);
$mappings
=
$self
->basic_mapping(
$exon_scores
,
"exon_mappings$num"
);
$num
++;
my
$new_scores
=
$esb
->create_shrinked_matrix(
$exon_scores
,
$mappings
,
"exon_matrix$num"
);
return
(
$new_scores
,
$mappings
);
}
sub
mapped_transcript {
my
$self
=
shift
;
my
$num
=
shift
;
my
$esb
=
shift
;
my
$mappings
=
shift
;
my
$exon_scores
=
shift
;
my
$transcript_mappings
=
shift
;
$self
->logger->info(
"Exons in mapped transcript...\n"
, 0,
'stamped'
);
unless
(
$exon_scores
->loaded) {
$esb
->non_mapped_transcript_rescore(
$exon_scores
,
$transcript_mappings
);
$exon_scores
->write_to_file;
}
$mappings
=
$self
->basic_mapping(
$exon_scores
,
"exon_mappings$num"
);
$num
++;
my
$new_scores
=
$esb
->create_shrinked_matrix(
$exon_scores
,
$mappings
,
"exon_matrix$num"
);
return
(
$new_scores
,
$mappings
);
}
sub
single_transcript {
my
$self
=
shift
;
my
$num
=
shift
;
my
$esb
=
shift
;
my
$mappings
=
shift
;
my
$exon_scores
=
shift
;
$self
->logger->info(
"Exons in single transcript...\n"
, 0,
'stamped'
);
unless
(
$exon_scores
->loaded) {
$exon_scores
->write_to_file;
}
$mappings
=
$self
->same_transcript_exon_mapping(
$exon_scores
,
"exon_mappings$num"
);
$num
++;
my
$new_scores
=
$esb
->create_shrinked_matrix(
$exon_scores
,
$mappings
,
"exon_matrix$num"
);
return
(
$new_scores
,
$mappings
);
}
sub
same_transcript_exon_mapping {
my
$self
=
shift
;
my
$matrix
=
shift
;
my
$mapping_name
=
shift
;
unless
(
$matrix
and
$matrix
->isa(
'Bio::EnsEMBL::IdMapping::ScoredMappingMatrix'
)) {
throw(
'Need a Bio::EnsEMBL::IdMapping::ScoredMappingMatrix.'
);
}
throw(
'Need a name for serialising the mapping.'
)
unless
(
$mapping_name
);
my
$dump_path
= path_append(
$self
->conf->param(
'basedir'
),
'mapping'
);
my
$mappings
= Bio::EnsEMBL::IdMapping::MappingList->new(
-DUMP_PATH
=>
$dump_path
,
-CACHE_FILE
=>
"${mapping_name}.ser"
,
-AUTO_LOAD
=> 1,
);
if
(
$mappings
->loaded) {
$self
->logger->info(
"Read existing mappings from ${mapping_name}.ser.\n"
);
return
$mappings
;
}
my
$sources_done
= {};
my
$targets_done
= {};
my
@sorted_entries
=
sort
{
$b
->score <=>
$a
->score ||
$a
->source <=>
$b
->source ||
$a
->target <=>
$b
->target }
@{
$matrix
->get_all_Entries };
while
(
my
$entry
=
shift
(
@sorted_entries
)) {
next
if
(
$sources_done
->{
$entry
->source} or
$targets_done
->{
$entry
->target});
my
$other_sources
= [];
my
$other_targets
= [];
my
%source_transcripts
= ();
my
%target_transcripts
= ();
if
(
$self
->ambiguous_mapping(
$entry
,
$matrix
,
$other_sources
,
$other_targets
)) {
$other_sources
=
$self
->filter_sources(
$other_sources
,
$sources_done
);
$other_targets
=
$self
->filter_targets(
$other_targets
,
$targets_done
);
$source_transcripts
{
$self
->cache->get_by_key(
'transcripts_by_exon_id'
,
'source'
,
$entry
->source)} = 1;
$target_transcripts
{
$self
->cache->get_by_key(
'transcripts_by_exon_id'
,
'target'
,
$entry
->target)} = 1;
foreach
my
$other_source
(@{
$other_sources
}) {
$source_transcripts
{
$self
->cache->get_by_key(
'transcripts_by_exon_id'
,
'source'
,
$other_source
)} = 1;
}
foreach
my
$other_target
(@{
$other_targets
}) {
$target_transcripts
{
$self
->cache->get_by_key(
'transcripts_by_exon_id'
,
'target'
,
$other_target
)} = 1;
}
if
(
scalar
(
keys
%source_transcripts
) == 1 and
scalar
(
keys
%target_transcripts
) == 1) {
$mappings
->add_Entry(
$entry
);
}
}
else
{
$mappings
->add_Entry(
$entry
);
}
$sources_done
->{
$entry
->source} = 1;
$targets_done
->{
$entry
->target} = 1;
}
$mappings
->write_to_file;
return
$mappings
;
}
sub
internal_id {
my
$self
=
shift
;
my
$num
=
shift
;
my
$esb
=
shift
;
my
$mappings
=
shift
;
my
$exon_scores
=
shift
;
$self
->logger->info(
"Retry with internalID disambiguation...\n"
,
0,
'stamped'
);
if
( !
$exon_scores
->loaded() ) {
$esb
->internal_id_rescore(
$exon_scores
);
$exon_scores
->write_to_file();
}
$mappings
=
$self
->basic_mapping(
$exon_scores
,
"exon_mappings$num"
);
$num
++;
my
$new_scores
=
$esb
->create_shrinked_matrix(
$exon_scores
,
$mappings
,
"exon_matrix$num"
);
return
(
$new_scores
,
$mappings
);
}
1;