Commit 0454b51a authored by Robin Erich Muench's avatar Robin Erich Muench
Browse files

update metaSNP_COV

parent 2ed3631b
#!/bin/bash
################################################
# metaSNP Step I: `Coverage estimation` #
################################################
#
# Helper script for the coverage estimation.
# -- This script will execute the coverage estimation for each sample (default)
#
# Parallele computing mode (-P) :
# -- The script will generate a commandline job for each sample in the list.
# -- each job has to be run in order to compute SNPs for the entire population
#
# This code is part of the metagenomic SNP calling pipeline (metaSNP)
# Copyright (c) 2016 Robin Munch
# Licenced under the GNU General Public License (see LICENSE)
# Abort on any errors
set -e
display_usage() {
echo >&2 ""
echo >&2 " Usage: $(basename $0) project_dir/ all_samples"
......@@ -9,8 +28,15 @@ display_usage() {
echo >&2 " project_dir/ DIR A metaSNP initialized project directory (metaSNP_NEW)"
echo >&2 " all_samples FILE Input list of bam files, one file per line."
echo >&2 ""
echo >&2 " Options:"
echo >&2 " -P Print a commandline job for each sample in all_samples"
echo >&2 ""
}
missing_sample(){
echo >&2 "ERROR: '$1' in '$2' does not exist"
}
missing() {
echo >&2 ""
echo >&2 "ERROR: '$1' no such file or directory"
......@@ -34,21 +60,15 @@ make_dir() {
}
# print error message if no argument is supplied
if [ $# -ne 2 ]
then
display_usage
exit 1
fi
# assign arguments to variables
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR="$( dirname $( readlink -f "${BASH_SOURCE[0]}" ) )"
all_samples="$2"
PROJECT_DIR="$1"
OUT_DIR="$PROJECT_DIR/cov"
PRINT=""
# getopt to use -h flag
ARGS=$(getopt -o h -n "$0" -- "$@")
ARGS=$(getopt -o Ph -n "$0" -- "$@")
# reorganize arguments as returned by getopt
eval set -- "$ARGS"
......@@ -61,6 +81,10 @@ while true; do
display_usage
exit 1
;;
-P)
shift
PRINT="P"
;;
--)
shift
break
......@@ -68,6 +92,7 @@ while true; do
esac
done
## Control
[ -d "$PROJECT_DIR" ] || missing "$PROJECT_DIR"
[ -f "$all_samples" ] || missing "$all_samples"
......@@ -75,13 +100,35 @@ done
# Check required output directories
[ -d "$OUT_DIR" ] || make_dir "$PROJECT_DIR" "$OUT_DIR"
# Check if all files exist
missed=""
while read file
do
if [ ! -f $file ]
then
# >&2 echo ""
# >&2 echo "ERROR: '$file' in $all_samples does not exist."
missing_sample "$file" "$all_samples"
missed="T"
fi
done<$all_samples
[ -z "$missed" ] || { echo ""; echo "Please remove erroneous paths in 'all_samples'"; echo ""; exit ; }
##
## Processing
##
## Generate command lines
while read file
do
# name=$(echo $file | awk -F"/" '{split($NF,a,"."); print a[1]}')
# name=$(echo $file | awk -F"/" '{split($NF,a,"/"); print a[1]}')
name=$(basename $file)
echo $DIR/src/qaTools/qaCompute -c 10 -d -i $file $OUT_DIR/$name.cov
if [ $PRINT ]
then
  • I find it a bit worrisome that the commandline that is printed with -P is not the same as the one that is executed if not -P (almost the same, but the basename call makes it potentially different). I'd much prefer something along the lines of

    cmdline=....
    if [ $print] ; then
        echo $cmdline
    else
       eval $cmdline
    fi
Please register or sign in to reply
name=$(basename $file)
echo $DIR/src/qaTools/qaCompute -c 10 -d -i $file $OUT_DIR/$name.cov
else
$DIR/src/qaTools/qaCompute -c 10 -d -i $file $OUT_DIR/$name.cov
fi
done < $all_samples
exit
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment