-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_tredegar.sh
executable file
·102 lines (85 loc) · 3.44 KB
/
auto_tredegar.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
#!/bin/bash
#----#----#----#----#----#----#----#----#----#----
HELP="
This BASH script will run Tredegar as new BS Projects are populated on the DGS BaseSpace account.
USAGE = auto_tredegar.sh <mounted_BS_directory> <output_directory>
Option: list of basespace projects
If you wish to run Tredegar on extant BaseSpace projects, provide the names of these projects as an optional third positional argument in a comma-sepparated list without spaces, e.g. project1,project2,project3
"
#----#----#----#----#----#----#----#----#----#----
# If the user invokes the script with -h or any command line arguments, print some help.
if [ "$#" -eq 0 ] || [ "$1" == "-h" ] ; then
echo "$HELP"
exit 0
fi
# set variables from user input
bs_path=$1
if [ -z "$2" ]; then
echo "Output directory is required.
$HELP"
exit 0
else
output=$2
fi
project_list=$3
#ensure basemount directory is mounted
if [ -n "$(basemount-cmd --path ${bs_path}/Projects refresh | grep Error)" ]
then
echo "Issue with basemount directory; attempting to remount ${bs_path}"
yes | basemount --unmount ${path}
basemount ${path}
fi
#capture list of bs_projects
ls ${bs_path}/Projects > ${output}/bs_projects.log
# check to see if a speific list of projects have been provided
if [ ! -z "$project_list" -a "$project_list" != " " ]; then
for project in $(echo $project_list | sed "s/,/ /g")
do
# if so, remove project from bs_project.log so that tredegar reports will be generated for those projects
echo ${project}
sed -e s/${project}//g -i ${output}/bs_projects.log
done
fi
#run tredegar for newly added BS projects
while [ -d "$bs_path" ]
do
bs_projects="$(ls ${bs_path}/Projects)"
# makew newlines only separator
IFS=$'\n'
for project in ${bs_projects}
do
# if a project in the mounted directory isn't in the bs_projects.log file, run tredegar
if ! grep "${project}" ${output}/bs_projects.log
then
echo "new project found: ${project}"
# check to make sure read files in addition to the positive controls are availalbe before running tredegar
number_of_samples="$(ls ${bs_path}/Projects/${project}/Samples/ | wc -l)"
if (( ${number_of_samples} > 2 ))
then
# allow time for all read data to be transferred to BaseSpace project
sleep 15m
strt="$(date +%s)"
staphb_toolkit_workflows tredegar ${bs_path}/Projects/${project} -o ${output}/${project}
end="$(date +%s)"
runtime=$((${end}-${strt}))
runtime_min=$(echo "scale=2; $runtime / 60" | bc)
mkdir ${bs_path}/Projects/${project}/AppResults/Tredegar_"$(date +%F)"_"$(date +%H:%M)"/
# copy file to a Tredegar AppResults and mark session complete
cp ${output}/${project}/tredegar_output/*report.tsv ${bs_path}/Projects/${project}/AppResults/Tredegar_"$(date +%F)"_"$(date +%H:%M)"/ && cd ${bs_path}/Projects/${project}/AppResults/Tredegar_"$(date +%F)"_"$(date +%H:%M)"/ && basemount-cmd mark-as-complete
cd $HOME
echo "$project added "$(date +%F)"_"$(date +%H:%M)". Runtime: ${runtime_min}M" >> ${output}/bs_projects.log
else
echo "Read files not yet available for ${project}"
fi
fi
done
sleep 30m
# refresh basemounted directory
if [ -n "$(basemount-cmd --path ${bs_path}/Projects refresh | grep Error)" ]
then
echo "Issue with basemount directory; attempting to remount ${bs_path}"
yes | basemount --unmount ${path}
basemount ${path}
fi
done
echo "ERROR: Auto loop has ended "$(date +%F)"" >> ${output}/bs_projects.log