#!/usr/local/bin/perl #use strict; #use warnings; ## dotmatrix1.pl takes a query string and a search string and uses the ## dot-matrix method to find regions of alignment between the two. my $window = 4; my $query = "AAGCGCGTCGCGATTGACATTATAGAAGGCGC"; my $search = "ATGTTCGCGATTGACATTCAAAAGCGAGTCAG"; #$query = "AAGCGCGTCGCGATTGACATTATAGAAGGCGC"; #$search = "AAGTGCGACGCCATTCACAATATGGAACGCGA"; #$query = "GGTAATA"; #$search = "GGTAATA"; my $querylen = length($query); my $searchlen = length($search); my $queryword; my $searchword; my $i; my $j; my @table; ## Define a two-dimensional array consisting of an array of references ## to a series of anonymous arrays of scalars in the second dimension ## and initialize the two-dimensional array with zeros for ($i = 0; $i < $querylen; $i++) { for ($j = 0; $j < $searchlen; $j++) { $table[$i][$j] = 0; # perl "autovivifies" the anonymous arrays # indexed my $j!! } } #$table[0][1] = "\\"; ## Now step through the matrix using "sliding window" substrings of the query ## and search sequences and check off those positions where the substrings are ## identical. for ($i = 0; $i < $querylen; $i++) { for ($j = 0; $j < $searchlen; $j++) { $queryword = substr($query, $i, $window); $searchword = substr($search,$j, $window); if ($queryword eq $searchword) { $table[$i][$j] = "\\"; } } } ## Now that we have "scored" the matrix, let's print it out and see how we did foreach (@table) { print @{$_}, " \n" #{$table}[$i]; }