-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfam_hhblits_lock.sh
executable file
·57 lines (47 loc) · 1.4 KB
/
pfam_hhblits_lock.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
#!/bin/bash
source paths.sh
source ~/.bashrc
set -e
mkdir -p "${LOCAL}/${USER}"
MYLOCAL=$(mktemp -d --tmpdir=${LOCAL}/${USER})
trap "if [ -d \"${MYLOCAL}\" ] && [ \"${MYLOCAL}\" != \"/\" ]; then rm -rf -- \"${MYLOCAL}\"; fi" EXIT
# copy database to local ssd
db=${uniprot}
db_bn=$(basename $db)
#cp ${db}*.ff* ${MYLOCAL}
#DB=${MYLOCAL}/${db_bn}
cp ${db}*.ff* /dev/shm
DB=/dev/shm/${db_bn}
open_sem() {
mkfifo pipe-$$
exec 3<>pipe-$$
rm pipe-$$
local i=$1
for ((;i>0;i--)); do
printf %s 000 >&3
done
}
# run the given command asynchronously and pop/push tokens
run_with_lock() {
local x
# this read waits until there is something to read
read -u 3 -n 3 x && ((0==x)) || exit $x
(
( "$@"; )
# push the return code of the command to the semaphore
printf '%.3d' $? >&3
)&
}
task() {
dd if=${pfam_build_dir}/pfam_a3m_seed.ffdata ibs=1 skip="${OFF}" count="${LEN}" status=none | \
hhblits -i stdin -oa3m ${MYLOCAL}/a3m/${KEY} -o /dev/null -cpu 1 -d "${DB}" -n 3 -v 0
}
mkdir -p "${MYLOCAL}/a3m"
N=128
open_sem $N
while read -r KEY OFF LEN; do
run_with_lock task "${KEY}" "${OFF}" "${LEN}"
done < ${pfam_build_dir}/pfam_a3m_seed.ffindex
wait
rm -rf -- "${pfam_build_dir}/pfam_a3m.ffdata" "${pfam_build_dir}/pfam_a3m.ffindex"
(cd "${MYLOCAL}/a3m" && ffindex_build -s "${pfam_build_dir}/pfam_a3m.ffdata" "${pfam_build_dir}/pfam_a3m.ffindex" .)