CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
help with shell script

 



sooper
New User

Jul 26, 2012, 1:32 AM

Post #1 of 7 (2021 views)
help with shell script Can't Post

Hi everyone, I apologize in advance if this is not the appropriate place to ask for this kind of help.

I am very, very new to perl and scripting in general and I am trying to set up a shell script that will allow me to run a series of commands that each rely on the output of the previous after specifying a directory to put the results into (/mypath/user_input_directory/ below).

The first command takes the input files in the working directory and parses them into specific folders (already created):

perl run_pipeline.pl -fork1 -UQseqToTagCountPlugin w mypath/user_input_directory/ -e ApeKI -endPlugin -runfork1

and the second takes the results in that directory and further processes them:

perl run_pipeline.pl -fork1 -UMergeTaxaTagCountPlugin -w mypath/user_input_directory/ -c 5 -endPlugin -runfork1

it continues this way for several more perl commands:

perl run_pipeline.pl -fork1 -UTagCountToTagPairPlugin -w mypath/user_input_directory/ -e 0.03 -endPlugin -runfork1

etc.

Is there an easy way to automate all of these individual commands with an input for the working directory from the user. I ask because each step takes quite a while and it would be nice just to hit run and go.

Thank you so much in advance for any help that anyone may provide, it is much appreciated!

sooper


BillKSmith
Veteran

Jul 26, 2012, 5:56 AM

Post #2 of 7 (2010 views)
Re: [sooper] help with shell script [In reply to] Can't Post

I assume that you are unwilling to change the script run_pipeline.pl to do the entire job. Although all-perl solutions are possible, I agree that a shell script is your easiest solution. No one can offer much more help without knowing your operating system (and shell).

One other solution is a perl program which would consist of almost nothing but calls to system (refer perldoc -f system). Each call would execute one of your steps. If this is intended as production software, you should add error processing.
Good Luck,
Bill


rovf
Veteran

Jul 27, 2012, 4:12 AM

Post #3 of 7 (2003 views)
Re: [sooper] help with shell script [In reply to] Can't Post

You really should post this in a forum for Shell scripts, but....

I would pass the working directory as parameter to the shell script (instead of asking the user for input), because this will make your script useful in a wider context.

You didn't point out, which Shell you are going to use, but from the way you write your pathes, I assume that you are on a Unix like system. Here is an example for zsh (it would work likewise with bash and, AFIK, with ksh, ash and Bourne Shell):


Code
#!/bin/zsh -f 
# Ensure that the user supplied a directory
: ${1?Parameter missing - must be user directory}
perl run_pipeline.pl -fork1 -UQseqToTagCountPlugin w mypath/$1 -e ApeKI -endPlugin -runfork1
....


Of course you would have to adapt the #! line according to your system.


sooper
New User

Jul 30, 2012, 11:02 PM

Post #4 of 7 (1920 views)
Re: [rovf] help with shell script [In reply to] Can't Post

Thank you for your suggestions. Yes I am using a unix shell (ubuntu).

I will give this a shot.

Thank you again!!!


Laurent_R
Enthusiast / Moderator

Jul 31, 2012, 3:05 AM

Post #5 of 7 (1912 views)
Re: [sooper] help with shell script [In reply to] Can't Post

I think that using the unix shell pipe fonctionnality ("|") is the simple way, it takes the output of the first program and feeds it as input for the second one.

Something like at the unix command line :

perl progr1.pl input_file_progr1.txt | perl progr2.pl

A few points to be noted however:

- progr1.pl must write to standard output, not to a file (i.e. you print without a file handla, as if you wanted to print to the screen)

- progr2.pl must read from standard input (i.e. you read the data with something like "while (my $line = <>), juste as if you were waiting a user to enter data).

- You will not have the intermediate file (the result of progr1.pl)



The alternative if you prefer to have an intermediate file, you can do this at the Unix prompt:

perl progr1.pl input_file_progr1.txt > output_file_progr2.txt ; perl progr2.pl output_file_progr2.txt



The semi-colon (;) in this command will guarantee that progr1.pl is completed before starting progr2.pl.


itsbaskar
Novice

Jul 31, 2012, 8:12 PM

Post #6 of 7 (1895 views)
Re: [Laurent_R] help with shell script [In reply to] Can't Post

I would prefer a the second method.
Having a new main program which is going to call these command one by one.


sooper
New User

Aug 28, 2012, 12:20 AM

Post #7 of 7 (1279 views)
Re: [rovf] help with shell script [In reply to] Can't Post

Thank you again for your help. Your suggestion worked perfectly.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives