-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtormesbot4
134 lines (127 loc) · 5.48 KB
/
tormesbot4
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
#!/bin/bash
banner()
{
echo "+------------------------------------------------------------+"
printf "| %-58s | \n" " `date`"
echo "| |"
printf "|`tput bold` %-58s `tput sgr0`|\n" "$@ "
echo "+------------------------------------------------------------+"
}
banner \ "Welcome to Tormesbot. Please ensure you have all the" \ "files needed to run tormes inside the folder you ran this" \ "script from. Required files are sample1_R1.fastq.gz," \ "sample1_R2.fastq.gz. If you also have a " \ "reference_genome_file.fasta please include it in this" \ "folder. You can run more than one sample at a time." \ "Tormes works better with multiple samples."
ranbot=torm$((1 + RANDOM % 1000))
mkdir $ranbot
function banner2 ()
{
echo "+------------------------------------------------------------+"
printf "|`tput bold` %-58s `tput sgr0`|\n" "$@ "
echo "+------------------------------------------------------------+"
}
banner2 "Tango Connectivity and HPC Notification Information"
echo
read -p "Please enter your email address: " emailvar
echo
read -p "Please enter your tango username: " uservar
echo
banner2 "Tormes minimum required information "
echo
echo "Tormes will create a folder for your output,"
read -p "what would you like this folder to be called?: " outputfolvar
echo -e "Samples\t""Read1\t""Read2\t""Description" >> samples_metadata.txt
plogpoop=y
while [[ "$plogpoop" =~ ^([yY][eE][sS]|[yY])+$ ]]; do
r1check=(*R1.fastq.gz)
r2check=(*R2.fastq.gz)
if [[ -f "$r1check" && -f "$r2check" ]] ; then
for butts in ${!r1check[*]}; do
echo -e "${r1check[$butts]:0:7}""\t""${r1check[$butts]}""\t""${r2check[$butts]}""\t""${r1check[$butts]:0:7}" >> samples_metadata.txt
plogpoop=n
done
else
read -r -p "Either forward or reverse reads are not present in the folder this script ran from. Please move R1 and R2 files into this folder then select y when finished. Select n to quit script. [y/n]: " diarrhea
if [[ "$diarrhea" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
continue
else
echo
echo "Live long and prosper."
echo
exit 0
fi
fi
done
# for stench in ${!r1check[*]}; do
# cp ${r1check[$stench]} $ranbot
# done
# for splash in ${!r2check[*]}; do
# cp ${r2check[$splash]} $ranbot
# done
mv samples_metadata.txt $ranbot
echo "#!/bin/bash -i" >> slurm.sub
echo "#SBATCH --job-name=$ranbot" >> slurm.sub
echo "#SBATCH --mail-type=ALL" >> slurm.sub
echo "#SBATCH --mail-user=$emailvar" >> slurm.sub
echo "#SBATCH --partition=tango" >> slurm.sub
echo "#SBATCH --ntasks=28" >> slurm.sub
echo "#SBATCH --mem=250G" >> slurm.sub
echo "#SBATCH --time=96:00:00" >> slurm.sub
echo echo Running on host \`hostname\` >> slurm.sub
echo echo Time is \`date\` >> slurm.sub
echo "module load miniconda" >> slurm.sub
echo "source activate tormes-1.0" >> slurm.sub
dogpoop=y
while [[ "$dogpoop" =~ ^([yY][eE][sS]|[yY])+$ ]] ; do
refcheck=$(ls *".fasta")
if [ -f "$refcheck" ]; then
echo "tormes -m /scratch/$uservar/$ranbot/samples_metadata.txt -o $outputfolvar -t 28 -r /scratch/$uservar/$ranbot/$refcheck" >> slurm.sub
cp "$refcheck" $ranbot
dogpoop=n
else
read -r -p "No reference genome detected (filename.fasta) If you would like to include a reference genome,please move the '.fasta' file into the folder that you ran this script from and then choose 'y' [y/n]: " brown
if [[ "$brown" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
continue
else
echo "tormes -m /scratch/$uservar/$ranbot/samples_metadata.txt -o $outputfolvar -t 28" >> slurm.sub
dogpoop=n
fi
fi
done
chmod +x slurm.sub
mv slurm.sub $ranbot
echo
banner2 "Tormesbot has created a folder called $ranbot and moved" \ "all of your files into it. Tormesbot will now transfer" \ "the folder and its contents to your Tango /scratch/$uservar/" \ "After the files have been copied to Tango, Tormesbot will" \ "run Tormes."
read -n 1 -s -r -p "Please press any key to continue..... " lol
home=`pwd`
sftp [email protected] <<EOF
cd /scratch/$uservar
put -r $home/$ranbot
exit
EOF
# ssh -t [email protected] "cd /scratch/$uservar/$ranbot; sbatch slurm.sub; exit"
echo
banner2 " !!!IMPORTANT!!!" \ "Upon completion you will receive an email from the HPC." \ "If you would like Tormesbot to retrieve your files," \ "please execute the script 'tormesretrieve' in the folder " \ "where you ran tormesbot from when you have received" \ "the completion email."
echo
echo "#!/bin/bash" >> tormesretrieve
echo "sftp [email protected] <<EOF" >> tormesretrieve
echo "cd /scratch/$uservar" >> tormesretrieve
echo "rm $ranbot/*.fastq.gz" >> tormesretrieve
echo "get -a -r $ranbot" >> tormesretrieve
echo "exit" >> tormesretrieve
echo "EOF" >> tormesretrieve
echo "ssh [email protected] <<EOF" >> tormesretrieve
echo "rm -r /scratch/$uservar/$ranbot/$outputfolvar" >> tormesretrieve
echo "rm -r /scratch/$ranbot" >> tormesretrieve
echo "exit" >> tormesretrieve
echo "EOF" >> tormesretrieve
echo "rm $ranbot/*.fastq.gz" >> tormesretrieve
echo "mv $ranbot/slurm* $ranbot/$outputfolvar/" >> tormesretrieve
echo "mv $ranbot/*.fasta $ranbot/$outputfolvar/" >> tormesretrieve
echo "mv $ranbot/samples_metadata.txt $ranbot/$outputfolvar/" >> tormesretrieve
echo "mv $ranbot/$outputfolvar ." >> tormesretrieve
echo "rm -r $ranbot" >> tormesretrieve
echo "echo '("Your files have been retrieved, they are located in the folder named $outputfolvar")'" >> tormesretrieve
echo "echo" >> tormesretrieve
chmod +x tormesretrieve
echo
banner2 " It has been tormesbot's pleasure to assist" \ "you with all your whole genome sequencing needs." \ "Have a nice day."
echo
echo
exit