#!/usr/bin/perl -w use strict; my $FILE_IN = $ARGV[0]; my $FILE_OUT = "patternmatcher.pl"; open FILE_IN, $FILE_IN; open FILE_OUT, ">$FILE_OUT"; print FILE_OUT "\#!/usr/bin/perl -w\n"; print FILE_OUT "\$seq = \$ARGV[0]\;\n"; print FILE_OUT "if (\n"; my $wild = "\\w\{0,2\}"; my $onN = "X"; my $onN2 = "\[ATGCN\]"; my $name; while () { if ( $_ =~ /^\>(.+)$/ ) { $name = $1; } elsif ( $_ =~ /^(\w+)$/ ) { my $seq = $1; my $len = length $seq; print FILE_OUT "\# $name\n"; for my $i ( 0 .. $len ) { #go through $seq base by base, replacing one character with the wild card my $newseq = $seq; substr( $newseq, $i, 1 ) = $wild; $newseq =~ s/N/$onN/go; # these to lines are to allow Ns to match any character $newseq =~ s/X/$onN2/go; # print FILE_OUT " \$seq =~ \/$newseq\/ or \n"; } print FILE_OUT " \$seq =~ \/ZZZ\/) \{\n"; #impossible match to close the if print FILE_OUT " \$match=\$\&\;\n"; print FILE_OUT " \$name = \"$name\"\;\n"; print FILE_OUT " \$matchlength=length\(\$match\)\;\n"; print FILE_OUT " \$firstpos=index\(\$seq,\$match)\;\n"; print FILE_OUT " print \"\$name, \$match, \$matchlength, \$firstpos \\n\"\;\n"; print FILE_OUT " print \"Got it!\\n\"\;\n"; print FILE_OUT "\} elsif \(\n"; } } print FILE_OUT "\"false\"\)\{\n"; # false value to end the series of elsifs print FILE_OUT "\}\n"; close FILE_IN; close FILE_OUT; system( "chmod", "u+x", $FILE_OUT );