This class is not instantiated. Please see subclasses for usage examples
(e.g. GeneScoreBuilder).
sub create_shrinked_matrix
{ my $self = shift;
my $matrix = shift;
my $mappings = shift;
my $cache_file = shift;
unless ($matrix and
$matrix->isa('Bio::EnsEMBL::IdMapping::ScoredMappingMatrix')) {
throw('Need a Bio::EnsEMBL::IdMapping::ScoredMappingMatrix.');
}
unless ($mappings and
$mappings->isa('Bio::EnsEMBL::IdMapping::MappingList')) {
throw('Need a gene Bio::EnsEMBL::IdMapping::MappingList.');
}
throw('Need a cache file name.') unless ($cache_file);
my $dump_path = path_append($self->conf->param('basedir'), 'matrix');
$cache_file .= '.ser';
my $shrinked_matrix = Bio::EnsEMBL::IdMapping::ScoredMappingMatrix->new(
-DUMP_PATH => $dump_path,
-CACHE_FILE => $cache_file,
-AUTO_LOAD => 1,
);
if ($shrinked_matrix->loaded) {
$self->logger->info("Read existing scoring matrix from $cache_file.\n");
} else {
my %sources = ();
my %targets = ();
foreach my $entry (@{ $mappings->get_all_Entries }) {
$sources{$entry->source} = 1;
$targets{$entry->target} = 1;
}
foreach my $entry (@{ $matrix->get_all_Entries }) {
unless ($sources{$entry->source} or $targets{$entry->target}) {
$shrinked_matrix->add_Entry($entry);
}
}
}
$self->logger->info('Sources '.$matrix->get_source_count.' --> '.
$shrinked_matrix->get_source_count."\n");
$self->logger->info('Targets '.$matrix->get_target_count.' --> '.
$shrinked_matrix->get_target_count."\n");
$self->logger->info('Entries '.$matrix->get_entry_count.' --> '.
$shrinked_matrix->get_entry_count."\n");
$self->logger->info('New mappings: '.$mappings->get_entry_count."\n\n");
return $shrinked_matrix; } |
sub internal_id_rescore
{ my $self = shift;
my $matrix = shift;
unless ($matrix and
$matrix->isa('Bio::EnsEMBL::IdMapping::ScoredMappingMatrix')) {
throw('Need a Bio::EnsEMBL::IdMapping::ScoredMappingMatrix.');
}
my $i = 0;
foreach my $source (@{ $matrix->get_all_sources }) {
my @entries = sort { $b <=> $a }
@{ $matrix->get_Entries_for_source($source) };
next unless (scalar(@entries) > 1);
next unless ($entries[0]->score == $entries[1]->score);
my $ambiguous = 0;
foreach my $e (@entries) {
if ($e->target == $source and $e->score == $entries[0]) {
$ambiguous = 1;
}
}
next unless ($ambiguous);
foreach my $e (@entries) {
if ($e->target != $source and $e->score == $entries[0]) {
$matrix->set_score($source, $e->target, ($e->score * 0.8));
$i++;
}
}
}
$self->logger->debug("Scored entries with internal ID mismatch: $i\n", 1); } |
sub log_matrix_stats
{ my $self = shift;
my $matrix = shift;
unless ($matrix and
$matrix->isa('Bio::EnsEMBL::IdMapping::ScoredMappingMatrix')) {
throw('You must provide a ScoredMappingMatrix.');
}
my $fmt1 = "%-40s%10.0f\n";
my $fmt2 = "%-40s%10.5f\n";
$self->logger->info(sprintf($fmt1, "Scoring matrix entries:",
$matrix->get_entry_count), 1);
$self->logger->info(sprintf($fmt1, "Scoring matrix sources:",
$matrix->get_source_count), 1);
$self->logger->info(sprintf($fmt1, "Scoring matrix targets:",
$matrix->get_target_count), 1);
$self->logger->info(sprintf($fmt2, "Average score:",
$matrix->get_average_score), 1);
my ($min, $max) = @{ $matrix->get_min_max_scores };
$self->logger->info(sprintf($fmt2, "Min. score:", $min), 1);
$self->logger->info(sprintf($fmt2, "Max. score:", $max), 1);
}
1; } |