Archive Ensembl HomeArchive Ensembl Home
BestHit.pm
Go to the documentation of this file.
00001 package Bio::EnsEMBL::Compara::Filter::BestHit;
00002 
00003 use vars qw(@ISA);
00004 use strict;
00005 
00006 
00007 =head2 filter
00008 
00009     Title   :   filter
00010     Usage   :   filter(\@)
00011     Function:   Clean the Array of Bio::EnsEMBL::DnaDnaAlignFeature in 2 steps, 
00012                 First, sort FeaturePairs by score descending, identity % descending
00013                 Second, hits are kept if they do not exactly overlap the subject sequence of previous strored, 
00014                 higher scored hits.
00015     Returns :   Array reference of Bio::EnsEMBL::DnaDnaAlignFeature
00016     Args    :   Array reference of Bio::EnsEMBL::DnaDnaAlignFeature
00017 
00018 =cut
00019 
00020 sub filter {
00021   my ($self,$DnaDnaAlignFeatures) = @_;
00022 
00023   @{$DnaDnaAlignFeatures} = sort {$b->score <=> $a->score ||
00024                     $b->percent_id <=> $a->percent_id} @{$DnaDnaAlignFeatures};
00025   
00026   my @DnaDnaAlignFeatures_filtered;
00027 
00028   foreach my $fp (@{$DnaDnaAlignFeatures}) {
00029     if ($fp->strand < 0) {
00030       $fp->reverse_complement;
00031     }
00032 
00033     my $add_fp = 1;
00034     
00035     foreach my $feature_filtered (@DnaDnaAlignFeatures_filtered) {
00036 
00037       my ($start,$end) = ($feature_filtered->start,$feature_filtered->end);
00038 
00039       if ($fp->start == $start && $fp->end == $end) {
00040     $add_fp = 0;
00041     last;
00042       }
00043     }
00044     push @DnaDnaAlignFeatures_filtered, $fp if ($add_fp);
00045   }
00046   return \@DnaDnaAlignFeatures_filtered;
00047 }
00048 
00049 1;