-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcgi_scripts.sh
More file actions
340 lines (311 loc) · 10.3 KB
/
cgi_scripts.sh
File metadata and controls
340 lines (311 loc) · 10.3 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/env bash
# Load user settings:
if test -f "$HOME/.cgi_user_settings.sh"
then
. "$HOME/.cgi_user_settings.sh"
else
. "$HOME/CGIBashScripts/.cgi_user_settings.sh"
fi
# Logic:
if [ $hpc_cluster == "uppmax" ]
then
jobtype="core"
elif [ $hpc_cluster == "dardel" ]
then
jobtype="main"
alias vim="vim-nox11" # stops .vimrc bug
fi
# Aliases:
alias unnotate="bash ~/CGIBashScripts/subscripts/unnotate.sh" # access universal notes
alias lonotate="bash ~/CGIBashScripts/subscripts/unnotate.sh notes.txt" # create/access notes file at present location
alias todowork="bash ~/CGIBashScripts/subscripts/unnotate.sh ~/.todo_list.txt" # access work todo list
alias projinfoCompute="projinfo | grep -A 5 'Information for compute project:'" # print only available compute projects
# Functions:
## General:
cgi_help ()
{
echo "# Information about CGIBashScripts functions #"
echo ""
echo "### General ###"
echo "nrmupload : upload file to preset nrmcloud folder"
echo "roller : loop a function"
echo "pmocver : reverse-complement a string"
echo "zdiff : run diff on two zipped files"
echo "zhead : display the first 20 lines of a zipped file"
echo ""
echo "### HPC Specific ###"
echo "slurm_cheat : display helpful slurm-function"
echo "rjb : display running jobs"
echo "outslurm : cat the most recent slurm out in current dir"
echo "interact : start an interactive job"
}
nrmupload () # upload one file
{
bash ~/cloudsend.sh/cloudsend.sh "$1" "$upload_link"
}
roller () # loop a function and redraw the output
{
for i in {0..1200}
do
lines=$($1 | wc -l)
$1 | head -n${lines} # print `$lines` lines
sleep 2
echo -e "\e[$((${lines}+1))A" # go `$lines + 1` up
done
}
pmocver () # reverse complement a sequence
{
if [ $1 == "-" ]
then
stdin=$(cat -)
python3 ~/CGIBashScripts/subscripts/pmocver.py $stdin
else
python3 ~/CGIBashScripts/subscripts/pmocver.py $1
fi
}
zdiff () # check diff between two zipped files
{
diff <(zcat $1) <(zcat $2)
}
zhead () # print first 20 lines of a zipped file
{
zcat $1 | head -n 20
}
fqsttr () # get some stats on any number of fastq files
{
get_stats()
{
echo "- Sequence lengths:,"
zcat $1 | awk 'NR % 4 == 2' | awk '{print length}' | Rscript -e 'summary(scan("stdin", quiet = TRUE))'
count_seq=`zgrep "^@" ./$1 | wc -l`
echo "- Sequence count:,"
echo " "$count_seq
}
counter=0
for arg # for every argument
do
if [ $counter -gt 0 ]
then
echo ""
fi
echo $arg
get_stats $arg | column -s ',' -t
counter=$((counter + 1))
done
}
## HPC:
### Dardel:
dardel_pending () { # helper function to format pending jobs for dardel_rjb
while read pending
do
job_id=`echo $pending | awk '{print $1}'`
position=`sprio -S '-Y' | grep --line-number " $job_id " | cut -d: -f1` # figure out place in queue
position=$(( position - 1 )) # do not count header
time_limit=`echo $pending | awk '{print $7}'`
priority=`sprio -S '-Y' | grep " $job_id " | awk '{print $3}'`
job_name=`echo $pending | awk '{print $3}'`
echo $job_id" "$position" PENDING "$time_limit" "$priority" "$job_name
# id pos status time priority name
done < <(squeue --long --user $hpc_user | grep "PENDING") # for all pending jobs
}
dardel_rjb () {
echo -e "\e[4mRunning:\e[0m\e[32m";
squeue --long --user $hpc_user | grep "RUNNING" | awk '{print} END {if(NR==0) print "No jobs currently running"}';
echo -e "\e[0m";
echo -e "\e[4mPending:\e[0m\e[33m";
dardel_pending # format and figure out pending jobs
echo -e "\e[0m"
}
### Uppmax:
uppmax_rjb ()
{
echo -e "\e[4mRunning:\e[0m\e[32m";
jobinfo -u $hpc_user | grep " R " | awk '{print $1 "\t\t" $6 "\t" $8 "\t" $11 "\t" $3} END {if(NR==0) print "No jobs currently running"}';
echo -e "\e[0m";
echo -e "\e[4mPending:\e[0m\e[33m";
jobinfo -u $hpc_user | grep " PD " | awk '{print $1 "\t" $2 "\t" $7 "\t" $9 "\t\t" $10 "\t" $4} END {if(NR==0) print "No jobs currently pending"}';
echo -e "\e[0m"
}
### Common:
slurm_cheat ()
{
echo "sbatch <filename>"
echo "scancel <jobid>"
echo "squeue -u <username>"
echo "scontrol show job <jobid>"
echo "sstat --jobs=your_job-id --format=JobID,aveCPU,MaxRRS,NTasks"
echo "sacct --user=<username>" --starttime=YYYY-MM-DD
echo "sinfo"
echo "sprio --user=<username>"
}
rjb () # print information about pending and running jobs
{
if [ $hpc_cluster == "uppmax" ]
then
uppmax_rjb
elif [ $hpc_cluster == "dardel" ]
then
dardel_rjb
fi
}
outslurm () # print latest or specified slurm output file in a directory
{
var1=$1
if [ ${#var1} == 0 ]; then var1=1; fi
ls | grep "slurm" | tail -$var1 | head -1 | xargs cat | sed '$q'
}
interact () # start an interactive job
{
interactive -A $hpc_project -t 0:15:00
}
mkblast () # create a job script for blastng a fasta file
{
if test -f "$1"
then
fasta_file=$1
out_file=${1/".fa"/""}".out"
cur_dir=`pwd`
job_name=${1/".fa"/""}"_blast"
slurm_script=${1/".fa"/""}"_blast_script.sh"
slurm_script=${slurm_script/"y_"/""}
echo "#! /bin/bash -l" > $slurm_script
echo "#SBATCH -A $hpc_project" >> $slurm_script
echo "#SBATCH -p $jobtype" >> $slurm_script
echo "#SBATCH -n 20" >> $slurm_script
echo "#SBATCH -t 6:00:00" >> $slurm_script
echo "#SBATCH -J $job_name" >> $slurm_script
echo "" >> $slurm_script
echo "# go to this directory:" >> $slurm_script
echo "cd $cur_dir" >> $slurm_script
echo "" >> $slurm_script
echo "# load software modules:" >> $slurm_script
echo "module load bioinfo-tools blast" >> $slurm_script
echo "" >> $slurm_script
echo "# blast sequences:" >> $slurm_script
echo "blastn -query ./$fasta_file -db nt -out ./$out_file -outfmt \"6 qseqid sseqid pident length mismatch gapopen qstart qend sstart send evalue bitscore staxids sscinames scomnames qcovs\" -max_target_seqs 5 -num_threads 20" >> $slurm_script
else
echo "file $1 does not exist."
fi
}
mkdownload () # create a job script for running dada2
{
# download aws download script:
cp ~/CGIBashScripts/subscripts/awsdownload_script.sh .
touch input.txt # create empty input file
cur_dir=`pwd`
slurm_script="download_job.sh"
echo "#! /bin/bash -l" > $slurm_script
echo "#SBATCH -A $hpc_project" >> $slurm_script
echo "#SBATCH -p $jobtype" >> $slurm_script
echo "#SBATCH -n 1" >> $slurm_script
echo "#SBATCH -t 10:00:00" >> $slurm_script
echo "#SBATCH -J aws_download" >> $slurm_script
echo "" >> $slurm_script
echo "# go to this directory:" >> $slurm_script
echo "cd $cur_dir" >> $slurm_script
echo "" >> $slurm_script
echo "# load software modules:" >> $slurm_script
echo "module load bioinfo-tools" >> $slurm_script
echo "module load awscli" >> $slurm_script
echo "" >> $slurm_script
echo "# start aws download (make sure to edit input.txt first):" >> $slurm_script
echo "bash ./awsdownload_script.sh" >> $slurm_script
}
mkupload () # create a job script for uploading data
{
if [ -d "$1" ]
then
folder_input=$1
folder_output=${1/\//""}".tar"
cur_dir=`pwd`
slurm_script="upload_job.sh"
echo "#! /bin/bash -l" > $slurm_script
echo "#SBATCH -A $hpc_project" >> $slurm_script
echo "#SBATCH -p $jobtype" >> $slurm_script
echo "#SBATCH -n 1" >> $slurm_script
echo "#SBATCH -t 10:00:00" >> $slurm_script
echo "#SBATCH -J nrm_upload" >> $slurm_script
echo "" >> $slurm_script
echo "# go to this directory:" >> $slurm_script
echo "cd $cur_dir" >> $slurm_script
echo "" >> $slurm_script
echo "# tar folder:" >> $slurm_script
echo "echo \"Tar-ing folder.\"" >> $slurm_script
echo "tar -cvf $folder_output ./$folder_input" >> $slurm_script
echo "echo \"- done\"" >> $slurm_script
echo "" >> $slurm_script
echo "# upload tar file:" >> $slurm_script
echo "echo \"Uploading tar-file.\"" >> $slurm_script
echo "bash ~/cloudsend.sh/cloudsend.sh \"$folder_output\" \"$upload_link\"" >> $slurm_script
echo "echo \"- done\"" >> $slurm_script
else
echo "directory $1 does not exist."
fi
}
mkdada2 () # create a job script for running dada2
{
cp ~/CGIBashScripts/subscripts/dada2_script.r . # copy the dada2 script to this location
mkdir -p Filtered_data # create directory to put trimmed fastq data in, if it does not exist
cur_dir=`pwd`
slurm_script="dada2_job.sh"
echo "#! /bin/bash -l" > $slurm_script
echo "#SBATCH -A $hpc_project" >> $slurm_script
echo "#SBATCH -p $jobtype" >> $slurm_script
echo "#SBATCH -n 1" >> $slurm_script
# echo "#SBATCH -C mem256GB " >> $slurm_script # this makes it a fat node, does not work on dardel - fix?
echo "#SBATCH -t 1-00:00:00" >> $slurm_script
echo "#SBATCH -J dada2_hpc" >> $slurm_script
echo "" >> $slurm_script
echo "# go to this directory:" >> $slurm_script
echo "cd $cur_dir" >> $slurm_script
echo "" >> $slurm_script
echo "# load software modules:" >> $slurm_script
echo "module load PDC" >> $slurm_script
echo "module load R" >> $slurm_script
echo "" >> $slurm_script
echo "# run dada2 script:" >> $slurm_script
echo "Rscript ./dada2_script.r" >> $slurm_script
}
mktar () # create a job script for tar-ing a folder
{
if test -d "$1"
then
folder_input=$1
folder_output=${1/\//""}".tar"
cur_dir=`pwd`
slurm_script="tar_script.sh"
echo "#! /bin/bash -l" > $slurm_script
echo "#SBATCH -A $hpc_project" >> $slurm_script
echo "#SBATCH -p $jobtype" >> $slurm_script
echo "#SBATCH -n 1" >> $slurm_script
echo "#SBATCH -t 6:00:00" >> $slurm_script
echo "#SBATCH -J tar_folder" >> $slurm_script
echo "" >> $slurm_script
echo "# go to this directory:" >> $slurm_script
echo "cd $cur_dir" >> $slurm_script
echo "" >> $slurm_script
echo "# load software modules:" >> $slurm_script
echo "#module load bioinfo-tools" >> $slurm_script
echo "" >> $slurm_script
echo "# tar folder:" >> $slurm_script
echo "tar -cvf $folder_output ./$folder_input" >> $slurm_script
else
echo "folder $1 does not exist."
fi
}
lcratch () # list scratch discs of all running projects
{
readarray -t scr_list < <(jobinfo -u $hpc_user | grep " R " | awk '{print $11 " ls -lah /scratch/" $1}')
declare -p scr_list > /dev/null
if [ 1 -gt ${#scr_list} ] ; then echo "You have no running jobs." ; fi
for i in "${scr_list[@]}"
do
echo "${i##* }:"
ssh $i
echo ""
done
}
awsout () # check status of aws downloading job
{
outslurm | grep remaining | tail -1
}