flatten_roda.sh 1.45 KB
Newer Older
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/env sh
#
# Flattens a downloaded RODA database into the format expected by OpenFold
# Args:
#     roda_dir: 
#           The path to the database you want to flatten. E.g. "roda/pdb" 
#           or "roda/uniclust30". Note that, to save space, this script
#           will empty this directory.
#     output_dir:
#           The directory in which to construct the reformatted data

etowahadams's avatar
etowahadams committed
12
13
if [ "$#" -ne 2 ]; then
    echo "Usage: ./flatten_roda.sh <roda_dir> <output_dir>"
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
14
15
16
17
18
19
20
21
22
23
24
25
    exit 1
fi

RODA_DIR=$1
OUTPUT_DIR=$2

DATA_DIR="${OUTPUT_DIR}/data"
ALIGNMENT_DIR="${OUTPUT_DIR}/alignments"

mkdir -p "${DATA_DIR}"
mkdir -p "${ALIGNMENT_DIR}"

etowahadams's avatar
etowahadams committed
26
27
28
29
30
31
32
33
34
35
for chain_dir in "${RODA_DIR}"/*; do
    if [ ! -d "$chain_dir" ]; then
        continue
    fi

    chain_name=$(basename "$chain_dir")

    for subdir in "$chain_dir"/*; do
        if [ ! -d "$subdir" ]; then
            echo "$subdir is not a directory"
36
            continue
etowahadams's avatar
etowahadams committed
37
38
39
        fi

        if [ -z "$(ls -A "$subdir")" ]; then
40
            continue
etowahadams's avatar
etowahadams committed
41
42
43
44
45
46
        fi

        subdir_name=$(basename "$subdir")

        if [ "$subdir_name" = "pdb" ] || [ "$subdir_name" = "cif" ]; then
            mv "$subdir"/* "${DATA_DIR}/"
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
47
        else
etowahadams's avatar
etowahadams committed
48
            CHAIN_ALIGNMENT_DIR="${ALIGNMENT_DIR}/${chain_name}"
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
49
            mkdir -p "${CHAIN_ALIGNMENT_DIR}"
etowahadams's avatar
etowahadams committed
50
            mv "$subdir"/* "${CHAIN_ALIGNMENT_DIR}/"
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
51
52
53
54
55
        fi
    done
done

NO_DATA_FILES=$(find "${DATA_DIR}" -type f | wc -l)
etowahadams's avatar
etowahadams committed
56
57
58
if [ "$NO_DATA_FILES" -eq 0 ]; then
    rm -rf "${DATA_DIR}"
fi