peptide_checker.pl

#!/usr/bin/perl
 
use strict;
use warnings;
 
my $header = '';
 
chomp( my $file_name = <STDIN> );
 
open( $fh, $file_name ) or die "couldn't open the file\n";
 
while ( my $file_line = <$fh> ) {
 
    chomp $file_line;
 
    if ( $file_line =~ m/^>/ ) {
        $header = $file_line;
    }
    else {
 
        #not a header, so let's check the line
 
        #the /x allows me to comment my regular expression, not caring about whitespace.
        while ($file_line =~ m/(.{1,3}[^ACDEFGHIKLMNPQRSTVWY]+.{1,3})/ig) {
 
            my $bad_with_flank  = lc($1); #change the whole match to lower case
 
            $bad_with_flank =~ s/([^ACDEFGHIKLMNPQRSTVWY]+)/ \U$1 /i;
 
            print "$header: ", $bad_with_flank , "\n";
 
        }
    }
}
 
__END__

ecoRI_checker.pl
#!/usr/bin/perl
# Author        : 
# Date          : Thu Aug  9 17:30:09 UTC 2007
# Description   : 
 
use strict;
use warnings;
 
my $header;
my $counter = 0;
 
open( FH, "test.orf");
 
while ( my $file_line = <FH> ) {
    if ( $file_line =~ m/^>/){
        if ($counter > 0){ #check to see if the previous sequence had sites
            print "$header has $counter sites\n"
        }
        $header = $file_line;
        $counter = 0;    
    }
    else {
        while ($file_line=~m/GAATTC/ig){
           $counter++;
        }
    }
}
 
#and print out the last line, after all other sequences have been checked
if ($counter > 0){
    print "$header has $counter sites\n"
}
__END__

string or number

#!/usr/bin/perl
use strict;
use warnings;
 
print "Please enter something:\n";
while(my $user_input=<STDIN>){
    chomp($user_input);
 
    #Why is it [0-9]* versus [0-9]+?  What would I miss with [0-9]* in both?
     if ($user_input=~m/^[0-9]*\.{0,1}[0-9]+$/){
         print "$user_input is a number\n";
     }
     else{
        print "$user_input is a string\n";
    }
    print "Please enter something:\n";
}
 
 
 
__END__
Another, perhaps more readable way:
 
    if ($user_input=~ m/^[0-9]+$/ or #it's an integer
        $user_input=~ m/^[0-9]*\.[0-9]+$/) { #has a decimal point
        print "$user_input is a number\n";
    }

reformat
 
use strict;
use warnings;
 
my $header = '';
my $dna_sequence='';
 
print "Please Enter a fasta file to reformat: \n";
 
my $file = <STDIN>;
chomp $file;
open( FH, $file );
 
while ( my $file_line = <FH> ) {
    chomp $file_line;
    if ( $file_line =~ m/^>/ ) {
        if ($dna_sequence){
            $dna_sequence =~ s/(...)/$1 /g;
            print "$header\n$dna_sequence\n";
 
        }
        $header=$file_line;
        $dna_sequence='';
 
    }
    else{
        $dna_sequence .= $file_line;
    }
}
#let's not forget the very last sequence
$dna_sequence =~ s/(...)/$1 /g;
print "$header\n$dna_sequence\n";
 
 
 
 
 
 
__END__