5.1

file_list.pl

#!/usr/bin/perl
# Author        :
# Date          : Sat Jan  6 13:39:59 UTC 2007
# Description   :
 
use strict;
use warnings;
 
my @list_of_files = `ls -l /bin`;
 
foreach my $file_line (@list_of_files) {
 
    #output_file_name is scoped here!
    my $output_file_name = "overwrite.txt";
 
    #notice how we use a file for output
    open my $OUTPUTFILE, ">>", $output_file_name or die "you suck!";
 
    #we can use the filehandle $OUTPUTFILE to print to the outputfile
    #because we used the ">" flag in open!
    print $OUTPUTFILE $file_line;
 
    #DON'T FORGET TO CLOSE THE FILE HANDLE!
    close $OUTPUTFILE;
}
__END__

reverse_file_list.pl
#!/usr/bin/perl
# Author        :
# Date          : Sat Jan  6 13:39:59 UTC 2007
# Description   :
 
use strict;
use warnings;
 
my @list_of_files = `ls -l /bin`;
@list_of_files = reverse @list_of_files;
 
foreach my $file_line (@list_of_files) {
 
    #output_file_name is scoped here!
    my $output_file_name = "reverse.txt";
 
    #notice how we use a file for output
    open my $OUTPUTFILE, ">>", $output_file_name or die "you suck!";
 
    #we can use the filehandle $OUTPUTFILE to print to the outputfile
    #because we used the ">" flag in open!
    print $OUTPUTFILE $file_line;
 
    #DON'T FORGET TO CLOSE THE FILE HANDLE!
    close $OUTPUTFILE;
}
__END__
 
If you don't pass the output to a $calar... pass it to an @rray!

parse_date.pl

#!/usr/bin/perl
# Author        :
# Date          : Sat Jan  6 13:49:07 UTC 2007
# Description   :
 
# I have
# Sat Jan 6 00:04:12 PST 2007
 
# I want
# 000412j2007j12j6
 
use strict;
use warnings;
 
#get the date
my $date = qx/date/;
 
#convert it into an array (using any whitespace delim)
my @date_fields = split /\s+/, $date;
 
#make the weird time_string
my $time_string = $date_fields[3];
$time_string =~ s/://g;
 
#get the year
my $year = $date_fields[5];
 
#get seconds
my @hrs_mins_secs = split /:/, $date_fields[3];
my $seconds = $hrs_mins_secs[2];
 
#get the day of the month
my $day_of_month = $date_fields[2];
 
my $output = join('j',$time_string, $year, $seconds, $day_of_month);
print $output;
 
__END__

checker_file_list.pl

#!/usr/bin/perl
# Author        :
# Date          : Sat Jan  6 13:39:59 UTC 2007
# Description   :
 
use strict;
use warnings;
 
#get a unique identifier
my $date        = qx/date/;
my @date_fields = split /\s+/, $date;
my $unique_id   = $date_fields[3];
$unique_id =~ s/://g;
 
#get the data for the file
my @list_of_files = `ls -l /bin`;
 
#assign an output name
my $output_file_name = "overwrite.txt";
 
#test to see if that file and directory exist already and move it if it does
if ( -e $output_file_name ) {
    if ( -d "backup" ) {
    }
    else {
        mkdir "backup";
    }
    rename "$output_file_name", "backup/$output_file_name.$unique_id";
}
 
#print out the results to our file
foreach my $file_line (@list_of_files) {
 
    open my $OUTPUTFILE, ">>", $output_file_name or die "you suck!";
    print $OUTPUTFILE $file_line;
 
    close $OUTPUTFILE;
}
__END__

blast_parser.pl by Jaime

#!/usr/bin/perl
# Author        :
# Date          : Sat Jan  6 14:35:12 UTC 2007
# Description   :
 
use strict;
use warnings;
 
#call this program in the diectory with the blast files
#give this program a command line argument like "perl blast_parser.pl *.bla"
 
my @results_files = @ARGV;
 
my @queries;
my @subjects;
my @evalues;
 
foreach my $file_name (@results_files) {
    open my $FILEHANDLE, "<", $file_name or die "you suck!";
    while ( my $file_line = <$FILEHANDLE> ) {
        chomp $file_line;
        if ( $file_line =~ m/^>/ ) {
        }
        else {
 
            #parse the line into an array
            my @query_subject_evalue = split /,/, $file_line;
 
            #push the query to the query array
            push( @queries, $query_subject_evalue[0] );
 
            #push the subject to a subject array
            push( @subjects, $query_subject_evalue[1] );
 
            #push the evalue to an evalue array
            push( @evalues, $query_subject_evalue[2] );
        }
    }
 
    #DON'T FORGET TO CLOSE THE FILE HANDLE!
    close $FILEHANDLE;
 
}
 
#print the query array
my $query_file_name = "query.txt";
open my $QUERYFILE, ">", $query_file_name or die "you suck at querying";
my $query_string = join( "\n", @queries );
print $QUERYFILE $query_string;
close $QUERYFILE;
 
#print the subject array
my $subject_file_name = "subject.txt";
open my $SUBJECTFILE, ">", $subject_file_name or die "you suck at querying";
my $subject_string = join( "\t", @subjects );
print $SUBJECTFILE $subject_string;
close $SUBJECTFILE;
 
#print the evalue array
my $evalue_file_name = "evalue.txt";
open my $EVALUEFILE, ">", $evalue_file_name or die "you suck at querying";
my $evalue_string = join( ",", @evalues );
print $EVALUEFILE $evalue_string;
close $EVALUEFILE;
 
__END__

blast_parser.pl by Rose!

#!/usr/bin/perl
# Author        : Rose
# Date          : Sat Jan  6 03:59:36 PST 2007
# Description   : parse blast files from a directory
 
use strict;
use warnings;
 
my $dir = "blast_results/";
mkdir "$dir/results";
my $result_dir = "$dir"."results";
 
my $quer = "$result_dir/query.txt";      #initializes query file name
my $sub  = "$result_dir/subject.txt";    #initializes subject file name
my $eval = "$result_dir/evalue.txt";     #initializes evalue file name
 
opendir( my $DH, $dir ) or die "No such directory, sucker";    #open the directory
while ( my $file = readdir $DH ) {                             #read the files in the directory
    if ( $file =~ m/\.$/ ) {                                   #ignore . and ..
    }
    else {
       # print $file, "\n";
        open( my $FH, "<", "$dir/$file" ) or die "$file You are shit out of luck";    #open a file
 
            while ( my $file_line = <$FH> ) {                                  #open the file line by line
                if ( $file_line =~ m/^>/ ) {                                 #ignoring the headers
                }
                else {
                    chomp $file_line;
                    my @parsed       = split /,/, $file_line;                #turns the file line (that is a string) into an array
                    my $query_text   = $parsed[0];                           #saves the first element in the array as the query text
                    my $subject_text = $parsed[1];                           #saves the second element as the subject text
                    my $evalue_text  = $parsed[2];                           #saves the third element as the evalue text
                    open( my $FHQ, ">>", $quer );                            #open the query file
                    print $FHQ "$query_text \n";                             #save text to the query file
                    close $FHQ;                                              #close the query file
                    open( my $FHS, ">>", $sub );
                    print $FHS "$subject_text \t";
                    close $FHS;
                    open( my $FHE, ">>", $eval );
                    print $FHE "$evalue_text" . ",";
                    close $FHE;
                }
            }
        close $FH;
        $file = '';
    }
}
closedir $DH;
 
__END__

directory_blast_parser.pl

#!/usr/bin/perl
# Author        :
# Date          : Sat Jan  6 15:43:26 UTC 2007
# Description   :
 
use strict;
use warnings;
 
# Write a program to go through all the results files to look for significant or not significant
# hits (let's say we consider an evalue of less than 0.1 to be significant). Store the results
# so that there is a different directory for significant and not significant hits.
# In each directory, you should output a file for each original results file that has a header
# and the results separated by semicolons.
# Modify your program so that it checks to make sure that your evalue contains only numbers or
# a single decimal. Output any results that don't match to a new directory and new file for
# errors. Where did your errors get sorted before?
 
#call this program in the diectory with the blast files
#give this program a command line argument like "perl directory_blast_parser.pl *.bla"
 
my @results_files = @ARGV;
 
#create a significant directory
my $sig_dir = "significant/";
if ( -d $sig_dir ) {
}
else {
    mkdir "$sig_dir";
}
 
#create a not_significant directory
my $not_sig_dir = "not_significant/";
if ( -d $not_sig_dir ) {
}
else {
    mkdir "$not_sig_dir";
}
 
#go through each of the results files
foreach my $file_name (@results_files) {
    my $sig_results_file     = "$sig_dir$file_name.out";
    my $not_sig_results_file = "$not_sig_dir$file_name.out";
    open my $FILEHANDLE, "<", $file_name or die "you suck!";
    while ( my $file_line = <$FILEHANDLE> ) {
        chomp $file_line;
        if ( $file_line =~ m/^>/ ) {
        }
        else {
 
            #parse the line into an array
            my @query_subject_evalue = split /,/, $file_line;
            if ( $query_subject_evalue[2] < 0.1 ) {
                if ( -e $sig_results_file ) {
                    open my $SIGOUTHANDLE, ">>", $sig_results_file or die "you suck!";
                    print $SIGOUTHANDLE $file_line,"\n";
                    close $SIGOUTHANDLE;
                }
                else {
                    open my $SIGOUTHANDLE, ">>", $sig_results_file or die "you suck!";
                    print $SIGOUTHANDLE ">query,subject,evalue\n";
                    print $SIGOUTHANDLE $file_line,"\n";
                    close $SIGOUTHANDLE;
                }
            }
            else {
                if ( -e $not_sig_results_file ) {
                    open my $NOTSIGOUTHANDLE, ">>", $not_sig_results_file or die "you suck!";
                    print $NOTSIGOUTHANDLE $file_line,"\n";
                    close $NOTSIGOUTHANDLE;
                }
                else {
                    open my $NOTSIGOUTHANDLE, ">>", $not_sig_results_file or die "you suck!";
                    print $NOTSIGOUTHANDLE ">query,subject,evalue\n";
                    print $NOTSIGOUTHANDLE $file_line,"\n";
                    close $NOTSIGOUTHANDLE;
                }
 
            }
        }
 
    }
}
__END__
 

#!/usr/bin/perl
# Author        :
# Date          : Fri Aug 10 14:57:05 UTC 2007
# Description   :
 
use strict;
use warnings;
 
# (launch_hydro_fox.pl) - Write a program that checks all the fasta files (.fa) in the
# directory created by this tar file  trans.tar for transmembrane passes. Don't use the
# @ARGV array to get the file names! If it finds a transmembrane pass, print "I found a
# pass, let's checkout the structure" and launch pymol. After searching all of the
# files, print out a list of filenames for all of the proteins that did NOT contain a
# transmembrane pass.
 
my @non_hydro;
my $dir = "/home/student/Desktop/transmem";
opendir( my $DH, $dir ) or die "sukas";
 
while ( my $filename = readdir $DH ) {
    if ( $filename =~ m/\.fa$/ ) {
        print $filename;
        open( my $FH, "<", "$dir/$filename" ) or die "problem with fasta file";
        while ( my $file_line = <$FH> ) {
            if ( $file_line =~ m/^>/ ) {
 
                #header
            }
            else {
                if ( $file_line =~ m/[AWYFILV]{7,}/ ) {
                    print "i found a pass in $filename\n, let's check out the structure\n\n\n";
                    system "pymol";
                }
                else {
                    push @non_hydro, $filename;
                }
            }
 
        }
 
    }
}
 
print "these guys have no sticky regions @non_hydro\n\n";
__END__