#!/usr/local/bin/perl
# find_enzymes.pl
# create a lookup table
# of restriction enzyme sequences
# keyed by restriction enzyme name
%re_lookup = (
'Eco47III'=> 'AGCGCT',
'EcoNI' => 'CCT.....AGG',
'EcoRI' => 'GAATTC',
'EcoRII' => 'CC[AT]GG',
'HincII' => 'GT[TC][AG]AC',
'HindII' => 'GT[TC][AG]AC',
'HindIII' => 'AAGCTT',
'HinfI' => 'GA.TC'
);
# get sequence from user
print "Enter sequence:\n";
$userseq = <STDIN>;
chomp $userseq;
# get a list of restriction enzyme names
my @re_names = keys ( %re_lookup );
print "I will check the sequence for all these enzymes: @re_names\n";
# loop through all the restriction enzymes
foreach $re_name ( @re_names ) {
# get the sequence of the enzyme
$re_seq = $re_lookup{$re_name};
# check for the presence of the
# enzyme using the subroutine defined below
sequence_match( $userseq, $re_name, $re_seq );
}
print "Done!\n";
#----
# define a subroutine for checking dna sequences for
# the presence of a specific sequence
sub sequence_match {
# this subroutine takes 3 arguments:
my ( $dnaseq, $re_name, $re_seq ) = @_;
# report which sequence we are checking
print "checking $dnaseq for $re_seq\n";
# do test using regular expression match
if ( $dnaseq =~ /$re_seq/ ) {
print "found $re_name in sequence\n";
}
}