#!perl -w use strict; # Searching for motifs, Counting ACGT and errors # documentation written in pod, perldoc perlpod =head1 NAME motif.pl =head1 DESCRIPTION Check for a motif in any number of files. =head1 AUTHOR motif( ) from Beginning Perl for Bioinformatics by James Tisdall, extended by David Scott to tease out a super simple library. =cut my $motif = shift @ARGV; $motif =~ s/["']$//; $motif =~ s/^["']//; while ( my $filename = shift @ARGV ) { my $sequence = slurp($filename); $$sequence =~ s/\s//g; # Remove whitespace print motif($motif, $sequence, $filename); } # my $text = motif($re, $sequence, $filename); sub motif { my ($motif, $sequence, $filename ) = @_; if ( $$sequence =~ /$motif/i ) { return "$motif found: $filename\n"; } else { return "$motif missing: $filename\n" } } # \$data = slurp($filename); # slurp in all data into a single variable # return a reference to avoid copying data # Recommend: File::Slurp library for this # This function was benchmarked with reading an array and reading lines # On a slow PC, it quickly out paced arrays, and did better than lines. sub slurp { my ($filename) = @_; my $inf; my $fileTerminator = $/; undef $/; open($inf, "< $filename") or die("Unable to open $filename: $!"); my $buf = <$inf>; close $inf; $/ = $fileTerminator; return \$buf }