wrapper_transfer.sh 1.27 KB
Newer Older
1 2 3
#! /bin/sh

### ASDP PIPELINE ###
4 5 6 7
## Version: 0.0.1
## Licence: AGPLv3
## Author: anne-sophie.denomme-pichon@u-bourgogne.fr
## Description: a wrapper for qsubing bam transfer for STR pipeline
8
## Usage: qsub -pe smp 1 -v INPUTFILE=<path to the bam file>,TRANSFER_OUTPUTDIR=<output directory>,[LOGFILE=<path to the log file>] wrapper_transfer.sh
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30


# Log file path option
if [ -z "$LOGFILE" ]
then
    LOGFILE=transfer.$(date +"%F_%H-%M-%S").log
fi

# Logging
exec 1>> "$LOGFILE" 2>&1
echo "$(date +"%F_%H-%M-%S"): START"


# Check if input file exists
if [ ! -f "$INPUTFILE" ]
then
    echo "Input file '$INPUTFILE' does not exist"
    echo "$(date +"%F_%H-%M-%S"): END"
    exit 1
fi

# Check if output directory is specified
31
if [ -z "$TRANSFER_OUTPUTDIR" ]
32 33 34 35 36 37 38
then
    echo "Output directory is not specified"
    echo "$(date +"%F_%H-%M-%S"): END"
    exit 1
fi

# Transfer and check exit code
39
echo "command : rsync -aX \
40
    $INPUTFILE $(echo "$INPUTFILE" | sed 's/\.bam$/.bai/') \
41 42
    $TRANSFER_OUTPUTDIR"
rsync -aX \
43
    "$INPUTFILE" "$(echo "$INPUTFILE" | sed 's/\.bam$/.bai/')" \
44
    "$TRANSFER_OUTPUTDIR"
45 46 47 48 49 50 51 52 53 54 55

transfer_exitcode=$? 

echo "transfer exit code : $transfer_exitcode"
if [ $transfer_exitcode != 0 ]
then
    echo "$(date +"%F_%H-%M-%S"): END"
    exit 1
fi

echo "$(date +"%F_%H-%M-%S"): END"