-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun_pipeline.sh
executable file
·149 lines (124 loc) · 3.76 KB
/
run_pipeline.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
set -x
# use set -x for extra logging
# Wrapper for juno assembly pipeline
#----------------------------------------------#
# User parameters
input_dir="${1%/}"
output_dir="${2%/}"
PROJECT_NAME="${irods_input_projectID}" # This should be an environment variable
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null 2>&1 && pwd )"
cd ${DIR}
# Sanity checks
if [ ! -z "${1}" ] || [ ! -z "${2}" ] || [ ! -z "${irods_input_projectID}" ]
then
INPUTDIR="${1}"
OUTPUTDIR="${2}"
PROJECT_NAME="${irods_input_projectID}"
else
echo "No inputdir, outputdir or project name (param 1, 2, irods_input_projectID)"
exit 1
fi
#check if there is an exclusion file, if so change the parameter
if [ ! -z "${irods_input_sequencing__run_id}" ] && [ -f "/data/BioGrid/NGSlab/sample_sheets/${irods_input_sequencing__run_id}.exclude" ]
then
EXCLUSION_FILE_COMMAND="-ex /data/BioGrid/NGSlab/sample_sheets/${irods_input_sequencing__run_id}.exclude"
else
EXCLUSION_FILE_COMMAND=""
fi
if [ ! -d "${INPUTDIR}" ] || [ ! -d "${OUTPUTDIR}" ]
then
echo "inputdir $INPUTDIR or output dir $OUTPUTDIR does not exist!"
exit 1
fi
set -euo pipefail
#----------------------------------------------#
## make sure conda works
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/mnt/miniconda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/mnt/miniconda/etc/profile.d/conda.sh" ]; then
. "/mnt/miniconda/etc/profile.d/conda.sh"
else
export PATH="/mnt/miniconda/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<export -f conda
export -f __conda_activate
export -f __conda_reactivate
export -f __conda_hashr
#----------------------------------------------#
# we can use the base installation of mamba to create the environment.
# Swapping to a parent env is not necessary anymore.
mamba env create -f envs/juno_assembly.yaml --name pipeline_env
conda activate pipeline_env
#----------------------------------------------#
# Run the pipeline
case $PROJECT_NAME in
adhoc|rogas|svgasuit|bsr_rvp)
GENUS_COMMAND=""
;;
dsshig|svshig)
GENUS_COMMAND="--genus Shigella"
;;
salm|svsalent|svsaltyp|vdl_salm)
GENUS_COMMAND="--genus Salmonella"
;;
svlismon|vdl_list)
GENUS_COMMAND="--genus Listeria"
;;
svstec|vdl_ecoli|vdl_stec)
GENUS_COMMAND="--genus Escherichia"
;;
campy|vdl_campy)
GENUS_COMMAND="--genus Campylobacter"
;;
refsamp)
GENUS_FILE=`realpath $(find ../ -type f -name genus_sheet_refsamp.csv)`
GENUS_COMMAND="--metadata $GENUS_FILE"
;;
*)
GENUS_COMMAND=""
;;
esac
echo -e "\nRun pipeline..."
if [ ! -z ${irods_runsheet_sys__runsheet__lsf_queue} ]; then
QUEUE="${irods_runsheet_sys__runsheet__lsf_queue}"
else
QUEUE="bio"
fi
set -euo pipefail
set -x
# Setting up the tmpdir for singularity as the current directory (default is /tmp but it gets full easily)
# Containers will use it for storing tmp files when building a container
export SINGULARITY_TMPDIR="$(pwd)"
python juno_assembly.py \
--queue $QUEUE \
-i $input_dir \
-o $output_dir \
$EXCLUSION_FILE_COMMAND \
$GENUS_COMMAND \
--prefix /mnt/db/juno/sing_containers
result=$?
# Propagate metadata
set +euo pipefail
SEQ_KEYS=
SEQ_ENV=`env | grep irods_input_sequencing`
for SEQ_AVU in ${SEQ_ENV}
do
SEQ_KEYS="${SEQ_KEYS} ${SEQ_AVU%%=*}"
done
for key in $SEQ_KEYS irods_input_illumina__Flowcell irods_input_illumina__Instrument \
irods_input_illumina__Date irods_input_illumina__Run_number irods_input_illumina__Run_Id
do
if [ ! -z ${!key} ] ; then
attrname=${key:12}
attrname=${attrname/__/::}
echo "${attrname}: '${!key}'" >> ${OUTPUTDIR}/metadata.yml
fi
done
exit ${result}