[Bio] / Sprout / SimBlocks.pm Repository:
ViewVC logotype

Diff of /Sprout/SimBlocks.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3, Fri Jan 6 20:35:01 2006 UTC revision 1.4, Wed Jan 11 19:39:20 2006 UTC
# Line 11  Line 11 
11      use PageBuilder;      use PageBuilder;
12      use Genome;      use Genome;
13      use BasicLocation;      use BasicLocation;
14        use Overlap;
15      use FIG_Config;      use FIG_Config;
16        use FIG;
17    
18  =head1 Similarity Block Database  =head1 Similarity Block Database
19    
# Line 744  Line 746 
746      while (my $region = $query->Fetch) {      while (my $region = $query->Fetch) {
747          # Determine this region's genome set. We only continue if the region is in          # Determine this region's genome set. We only continue if the region is in
748          # one of the sets.          # one of the sets.
749          my ($location) = $region->Value('Region(from-link)');          my ($location) = $region->Value('Region(id)');
750          my $genomeID = Genome::FromContig($location);          my $genomeID = Genome::FromContig($location);
751          if (exists $setMap{$genomeID}) {          if (exists $setMap{$genomeID}) {
752              my $setIndex = $setMap{$genomeID};              my $setIndex = $setMap{$genomeID};
# Line 1243  Line 1245 
1245      return @retVal;      return @retVal;
1246  }  }
1247    
1248    =head3 GetFeatureBlockPieces
1249    
1250    C<< my @pieces = $simBlocks->GetFeatureBlockPieces($fig, \@featureIDs, $distance); >>
1251    
1252    Return a list of the block pieces within the specified distance of the
1253    specified features. This method essentially computes locations from
1254    the distance and the feature locations, then passes them to L/GetBlockPieces>.
1255    That method will return the sections of various similarity blocks that
1256    occur inside the the locations computed.
1257    
1258    =over 4
1259    
1260    =item fig
1261    
1262    A FIG-like object that can be used to convert features into locations.
1263    
1264    =item featureIDs
1265    
1266    Reference to a list of feature IDs. Blocks in the vicinity of any of the
1267    features are returned.
1268    
1269    =item distance
1270    
1271    Distance to search from the feature's actual location.
1272    
1273    =item RETURN
1274    
1275    Returns a list of block piece location objects. A block piece location object
1276    is a standard B<BasicLocation> object with a block ID instead of a contig ID.
1277    
1278    =back
1279    
1280    =cut
1281    #: Return Type @;
1282    sub GetFeatureBlockPieces {
1283        # Get the parameters.
1284        my ($self, $fig, $featureIDs, $distance) = @_;
1285        # Declare a hash for keeping the return data. This will weed out
1286        # duplicates, of which we expect plenty. We'll need to handle
1287        # overlaps later, however.
1288        my %retHash = ();
1289        # Loop through the features.
1290        for my $featureID (@{$featureIDs}) {
1291            # Get the feature's genome ID.
1292            my $genomeID = FIG::genome_of($featureID);
1293            # Get the feature's locations.
1294            my @locations = $fig->feature_location($featureID);
1295            # Loop through the locations, sticking the resulting pieces in the return
1296            # hash.
1297            for my $loc (@locations) {
1298                my $locObject = BasicLocation->new($loc);
1299                # Get the length of the contig in question.
1300                my $len = $fig->contig_ln($genomeID, $locObject->Contig);
1301                # Expand the location.
1302                $locObject->Widen($distance);
1303                # Get the desired block pieces.
1304                my @pieces = $self->GetBlockPieces($locObject);
1305                # Put them in the hash.
1306                for my $piece (@pieces) {
1307                    $retHash{$piece} = 1;
1308                }
1309            }
1310        }
1311        # Now we have all the block pieces that occur in any one of our regions. The
1312        # next step is to merge adjacent and overlapping regions. First we convert
1313        # the pieces to location objects so we can sort them.
1314        my @retVal = ();
1315        for my $piece (keys %retHash) {
1316            my $loc = BasicLocation->new($piece);
1317            push @retVal, $piece;
1318        }
1319        @retVal = sort { BasicLocation::Cmp($a,$b) } @retVal;
1320        # Now the locations are sorted by block ID, start position, and descending
1321        # length. This means that if there's an overlap, the two overlapping
1322        # pieces will be next to each other.
1323        my $i = 0;
1324        while ($i < $#retVal) {
1325            # Check for overlap between this location and the next.
1326            my ($type, $len) = Overlap::CheckOverlap($retVal[$i], $retVal[$i+1]);
1327            if ($len == 0) {
1328                # Here there is no overlap, so we push ahead.
1329                $i++;
1330            } elsif ($type eq 'embedded') {
1331                # Here the second piece is inside the first, so we delete the
1332                # second.
1333                delete $retVal[$i+1];
1334            } else {
1335                # Here we have a normal overlap. Because all of our pieces
1336                # are forward locations, this means the second piece starts
1337                # before the end of the of the first. We set the end point
1338                # if the first to the end point of the second and delete the
1339                # second.
1340                $retVal[$i]->SetEnd($retVal[$i+1]->EndPoint);
1341                delete $retVal[$i+1];
1342            }
1343        }
1344        # Return the result.
1345        return @retVal;
1346    }
1347    
1348  =head3 WalkDNA  =head3 WalkDNA
1349    
1350  C<< my $blockPos = SimBlocks::WalkDNA($blockPos, $contigPos, $dna, $loc); >>  C<< my $blockPos = SimBlocks::WalkDNA($blockPos, $contigPos, $dna, $loc); >>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3