in reply to Matrix plot help
#!/usr/bin/perl use strict; use warnings; my $seq1 = readfile("./CAM3UCA.txt"); my $seq2 = readfile("./TCH3A.txt"); my @s1 = split '', $seq1; my @s2 = split '', $seq2; my @matrix = (); for my $i (0..$#s2) { for my $j (0..$#s1) { $matrix[$i][$j] = $s2[$i] eq $s1[$j] ? '.' : " "; } } # Printing matrix of dot plot my $outfile = 'dotplot.txt'; open my $oh, '>', $outfile or die "Can't open file, $outfile: $!"; print $oh join('', @s1) . "\n"; print $oh join('', @s2) . "\n"; foreach my $row (@matrix) { print $oh join('', @$row) . "\n"; } close $oh; sub readfile { my $file = shift; open my $fh, $file or die "Can't open file, $file: $!"; local $/; <$fh>; }
|
|---|