XGrid Program pipe.pl

From CSclasswiki
Jump to: navigation, search

--Thiebaut 22:00, 9 November 2008 (UTC)


#! /usr/bin/perl -w
# pipe.pl
# D. Thiebaut
# Nov 9 2008
#
# This program gets a pdb file name from the command line.
# It passes the file name to stripAmino.pl which 
#    1) fetches the file from the server xgridmac.dyndns.org/~thiebaut/pdbfiles
#    2) reads the file and extract only the SEQRES lines
#    3) prints the SEQRES line on the standard output
# It also launches computeAminoFreq.pl as a pipe receiving the outpu of 
# stripAmino.pl.
# ComputeAminoFreq.pl gets the SEQRES line, breaks them down in individual 
# amino acids, and prints a histogram for each one found.
# The output is just the list of the amino acids followed by the number of 
# times they appear in the pdb file.
#
# The Syntax:
#
#             pipe.pl  pdbFilename 
#
#
#                  +--------------+
#  pdbFileName.... | Web server   |
#                  |   pdbFile    |
#                  +------+-------+  
#                         |
#                         V
#                  +---------------+      +---------------------+
#                  |               |      |                     |
#                  | stripAmino.pl +----->| computeAminoFreq.pl +--> stdout
#                  |               |      |                     |
#                  +---------------+      +---------------------+
#                  
#
#------------------------------------------------------------------------------

use Cwd;
#------------------------------------------------------------------------------
# runningOnGrid: returns true if running on an XGrid, false otherwise
#                Finds this information by asking for the current working
#                directory, and if it starts by "/private/var/xgrid", 
#                assumes that we are running on an xgrid, otherwise on 
#                a "regular" mac computer.
#------------------------------------------------------------------------------
sub runningOnGrid {
    my ( $currentDir ) =  &Cwd::cwd();
    #print $currentDir . "\n";
    if ( $currentDir =~ m/^\/private\/var\/xgrid\// ) {
        return 1;
    }
    return 0;
}

#------------------------------------------------------------------------------
# main:  gets the pdbfile to be processed from the command line, and starts
#        the pipeline with the two tasks.  The output of the tasks is passed
#        on to the standard output.
#------------------------------------------------------------------------------
sub main {
    $argc = $#ARGV + 1;

    # check # arguments 
    if ( $argc < 1 ) {
        print "Syntax pipe.pl pdb_filename\n\n";
        exit(1);
    }

    # get pdb file name
    my $pdbFile = $ARGV[0];

    
    # the two stages of the pipeline.  Use the prefix "../working/" if programs are to run on XGrid 
    my $prog1; # Stage 1 of the pipe
    my $prog2; # Stage 2 of the pipe
    if ( runningOnGrid() ) {
        $prog1 = "../working/stripAmino.pl $pdbFile";
        $prog2 = "../working/computeAminoFreq.pl";
    }
    else {
        $prog1 = "./stripAmino.pl $pdbFile";
        $prog2 = "./computeAminoFreq.pl";
    }
    
    # start each program, one after the other 
    my $retValue = system( $prog1 . "|" . $prog2 );

    # return combine return values
    return $retValue;
}

main()