Submitting jobs

  • qsub -cwd -o out.txt -e err.txt script.sh
  • environment and module
  • debugging info in scripts:
    • date
    • uname -a
    • $PATH, env

Shell scripting

hello.sh

#!/usr/bin/bash
#
# hello.sh
#

# this is a comment

echo "Hello, world!"
date
uname -a 
pwd
echo "PATH: $PATH"
env
sleep 5


loops.sh

#!/bin/bash

# loops.sh

# variables and quoting

name="Stuart Noah"
echo "My name is $name"
echo 'My name is $name' # single-quote is "more literal"
echo "My name is (${name/tuart/arah})"

# loop

for a in one two three
do
    echo $a
done

# user input

date
echo "Press <enter> to continue"
read answer

# seq for generating numeric sequences

for i in $(seq -w 1 10)
do
    filename="output${i}.txt"
    echo "Processing $filename"
done


process_dir.sh

#!/bin/bash

# process_dir.sh 

# check that there is exactly one argument

if [ $# -ne 1 ]
then
    echo "Usage: process_dir.sh directory"
    exit 1
fi

# check that the argument is actually a directory

if [ ! -d $1 ]
then
    echo $1 is not a directory
    exit 1
fi

directory=$1
echo "directory: $directory"

files=$(ls $directory)
# echo "Files: $files"

for f in $files
do
    echo "Processing $f"
    outputFile=${f/txt/out}
    echo "Output file: $outputFile"
done



Python and wrapper scripts

count_species.py

#!/usr/bin/env python

# count_species.py

count = 0

for line in open("bacteria.fasta"):
    if line.startswith(">"):
        count += 1

print(count)



run_count_species.sh

#!/bin/bash

# run_count_species.sh

module load python3/3.8.0

./count_species.py