Find the answer to your Linux question:
Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By ramin.honary
Hey guys, I'm using a program this summer which take a DNA sequence and splits it up, looks at the sequence and inherent patterns then outputs a probability of a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2013
    Posts
    7

    Running Multiple Lines of Code in Succession


    Hey guys,

    I'm using a program this summer which take a DNA sequence and splits it up, looks at the sequence and inherent patterns then outputs a probability of a certain entity existing within the sequence.

    I have a few sequence files, and this program can compute predictions based on 20 different models, which are increasingly more stringent.

    It is useful to predict with all 20 models and see where certain cutoffs occur, but it is a pain to manually enter a line of code, then wait the 5-6 minutes for the predictions to run, then go back, edit the line of code, and increase the model number by 1.

    Is there a way where I can enter in all of the lines of code I want to run, and each line of code will run once the one before it has finished?

    For example

    Command 1 + Command 2 + Command 3 + Command 4 .... Command 20

    >>> RUN <<<

    Command 1 Finished
    ...
    Starting Command 2
    ...
    Command 2 Finished
    ...
    Starting command 3
    ...

    etc

    >>>FINISHED ALL<<<

    Excuse my lack of technicality -- I'm brand new to linux and just getting these programs to install was a big hassle for me.

    Thanks a bunch for any help!

    Regards,
    Nick

  2. #2
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    3,190
    Write a script with the commands you want sequentially. If you are not familiar with programming, the first thing you would need to do is post the programming language you need/want to use so that someone familiar with it can assist you.

  3. #3
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    155
    Code:
    for i in $(seq 1 20); do
       command $i
    done
    Stuff happens. Then stays happened.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    260
    This is a nice easy problem.
    The Linux command line is also a programming language called "Bash." So you can write your commands into an ordinary text file, and tell the command line to execute every command in the file. Say your command file is "script.sh". To tell the command line to execute each line in the file, write a dot, then the full path to the file like this:
    Code:
    . ./script.sh
    
    # or equivalently:
    
    . $PWD/script.sh
    Or you could also use the built-in command "source"
    Code:
    source script.sh
    I highly recommend you learn everything you can about the Bash language, Google for introductions, tutorials, tricks.
    Here is an example with conditional execution:
    Code:
    printf 'What is your name? ';
    read Name;
    if [ "${Name}" == 'Dan' -o "${Name}" == 'Bob' ];
    then
        echo "Hey, ${Name}, you're my hero."
    else
        printf "Hello ${Name}, nice to meet you.\n";
    fi;
    printf "Today's date is $(date)\n";
    The file extension for Bash source code is ".sh". Since making scripts is such a common task in Linux, most editors will automatically enable syntax coloring and automatic indentation when you start editing any file with the extension ".sh". I recommend learning Emacs or Vim. In my own experience, Vim is easier to learn once you get the basics, but the basics aren't intuitive and take some getting-used-to.
    Last edited by ramin.honary; 07-03-2013 at 05:26 AM.
    SteelyDan likes this.

  6. #5
    Just Joined!
    Join Date
    Jun 2013
    Posts
    7
    Awesome, thanks you guys for all of your help -- I'll be switching over to my Linux OS soon to test this, and I'll let you know how it goes.

    Thanks again!
    Nick

  7. #6
    Just Joined!
    Join Date
    Jun 2013
    Posts
    7
    Success!

    Writing the script with the command on each line worked beautifully.

    Here's what I ended up with

    Code:
    #03/07/2013 -- miRPara Predictions Script
    #--- Nick Ostan ---
    #Generate Parameter File from Fasta Sequences
    perl miRPara.pl -p 60 -f 100 -o 99 "/home/nick/Downloads/miRPara6.2/sequences/FILE_1.fa"
    perl miRPara.pl -p 60 -f 100 -o 99 "/home/nick/Downloads/miRPara6.2/sequences/FILE_2.fa"
    perl miRPara.pl -p 60 -f 100 -o 99 "/home/nick/Downloads/miRPara6.2/sequences/FILE_3.fa"
    perl miRPara.pl -p 60 -f 100 -o 99 "/home/nick/Downloads/miRPara6.2/sequences/FILE_4.fa"
    perl miRPara.pl -p 60 -f 100 -o 99 "/home/nick/Downloads/miRPara6.2/sequences/FILE_5.fa"
    #Generate SVM Probability and Mature Sequence Predictions from .pmt File
    
    ...
    
    The code goes on here for a long time but its just repeats of random stuff
    Then I put the script in the same folder as my perl .pl file, and executed

    Code:
    . ./script.sh
    Works beautifully. Takes a bit of a altering small things cause for some reason I got a bunch of error messages at the beginning but I couldn't be more pleased.

    If I work with Linux more often I'll be sure to learn this BASH programming language!

    Cheers
    Nick

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •