in reply to Re^3: PERL STRING QUESTION
in thread PERL STRING QUESTION
Hi Monk,
This is one of the best script for pattern finding. But how can I print the location/position of the pattern match in my sequence.
Thanks
www.bioinformaticsonline.com
====
#!/usr/bin/perl
use strict;
if ( @ARGV != 2 ) {
die "Usage: $0 pattern file.name\n";
}
my ( $find, $filename ) = @ARGV;
open( my $fh, "<", $filename ) or die "Cannot open $filename: $!\n";
$/ = undef; # set INPUT_RECORD_SEPARATOR to "slurp-mode"
my $seq = <$fh>; # entire file is now in $seq;
$seq =~ tr/\n//d; # remove all newlines (I think you don't want space
+s)
open( my $out, ">", "write.txt" ) or die "Cannot create write.txt: $!\
+n";
while ( $seq =~ /(..)$find(..)/g ) {
print "before = $1 ; after = $2\n";
print $out "$1\n$2\n";
}
=====