File: test_fout.sh

package info (click to toggle)
libslow5lib 0.7.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 25,084 kB
  • sloc: ansic: 11,825; python: 1,179; sh: 547; makefile: 90; cpp: 40
file content (145 lines) | stat: -rwxr-xr-x 3,747 bytes parent folder | download | duplicates (2)
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
#!/bin/bash
# Usage $0
# Tests that f2s matches the expected output.

# Note:
#
# - Don't move this file from "slow5/tests/".
#   Requires subdirectory "data/" with testing dataset(s),
#   and "slow5tools" executable in parent directory.
#
# - Expects testing datasets with the following structure:
#     - dataset/
#         |- expected.slow5
#         |- expected.slow5.s5i
#         |- expected.blow5
#         |- expected.blow5.b5i
#         |- fast5_files/
#             |- expected_1.fast5
#             |- ...



# Relative path to "slow5/tests/"
REL_PATH="$(dirname $0)/"

# Change directory to tests folder
# since filenames are output relative this directory
# and will influence test results
# TODO necessary?
cd $REL_PATH

# Folder containing testing datasets
DATA_DIR="data"
# Ensure data directory exists
if [ ! -d $DATA_DIR ]; then
    echo "ERROR: Missing data directory \""$REL_PATH"/"$DATA_DIR"\""

    # Change back to original directory
    cd - >/dev/null

    echo "Exiting"
    exit 1
fi

# Path to slow5tools
SLOW5TOOLS_PATH="../slow5tools"
# Ensure slow5tools exists
if [ ! -f $SLOW5TOOLS_PATH ]; then
    echo "ERROR: Missing slow5tools \""$REL_PATH"/"$SLOW5TOOLS_PATH"\""

    # Change back to original directory
    cd - >/dev/null

    echo "Exiting"
    exit 1
fi

CMD_FAST5_TO_SLOW5="f2s"
CMD_FAST5_TO_BLOW5="f2s -b"
CMD_SLOW5_IDX="index"
CMD_BLOW5_IDX="index"


# Folder name in datasets containing FAST5 files
FAST5_FOLDER="fast5_files/"

# File name of expected SLOW5 output
SLOW5_EXPECTED="expected.slow5"
# File name of actual SLOW5 output
SLOW5_ACTUAL="actual.slow5"

# File name of expected BLOW5 output
BLOW5_EXPECTED="expected.blow5"
# File name of actual BLOW5 output
BLOW5_ACTUAL="actual.blow5"

# File name of expected SLOW5 index output
SLOW5_IDX_EXPECTED="expected.slow5.s5i"
# File name of actual SLOW5 index output
SLOW5_IDX_ACTUAL="actual.slow5.s5i"

# File name of expected SLOW5 index output
BLOW5_IDX_EXPECTED="expected.blow5.b5i"
# File name of actual SLOW5 index output
BLOW5_IDX_ACTUAL="actual.blow5.b5i"

declare -i ret=0

# Iterate through each testset
for testset in $DATA_DIR/*; do
    echo "$testset"

    rm "$testset/$SLOW5_ACTUAL"
    rm "$testset/$SLOW5_IDX_ACTUAL"

    # Sort the reads but not the header
    "$SLOW5TOOLS_PATH" "$CMD_FAST5_TO_SLOW5" "$testset/$FAST5_FOLDER" 2>/dev/null | awk '{if (substr($0,1,1) == "#") print $0 > "/dev/stderr"; else print $0}' 2> "$testset/$SLOW5_ACTUAL" | sort -r >> "$testset/$SLOW5_ACTUAL"
    "$SLOW5TOOLS_PATH" $CMD_SLOW5_IDX "$testset/$SLOW5_ACTUAL" 2>/dev/null

    if diff "$testset/$SLOW5_EXPECTED" "$testset/$SLOW5_ACTUAL" 2>&1 >/dev/null; then
        echo "SUCCESS fast5 -> slow5"
    else
        echo "FAILED fast5 -> slow5"
        ret=1
    fi

    if diff "$testset/$SLOW5_IDX_EXPECTED" "$testset/$SLOW5_IDX_ACTUAL" 2>&1 >/dev/null; then
        echo "SUCCESS slow5 index"
    else
        echo "FAILED slow5 index"
        ret=1
    fi

    rm "$testset/$BLOW5_ACTUAL"
    rm "$testset/$BLOW5_IDX_ACTUAL"

    "$SLOW5TOOLS_PATH" $CMD_FAST5_TO_BLOW5 "$testset/$FAST5_FOLDER" -o "$testset/$BLOW5_ACTUAL" 2>/dev/null
    "$SLOW5TOOLS_PATH" "$CMD_BLOW5_IDX" "$testset/$BLOW5_ACTUAL" 2>/dev/null

    if diff "$testset/$BLOW5_EXPECTED" "$testset/$BLOW5_ACTUAL" 2>&1 >/dev/null; then
        echo "SUCCESS fast5 -> blow5"
    else
        echo "FAILED fast5 -> blow5"
        ret=1
    fi

    if diff "$testset/$BLOW5_IDX_EXPECTED" "$testset/$BLOW5_IDX_ACTUAL" 2>&1 >/dev/null; then
        echo "SUCCESS blow5 index"
    else
        echo "FAILED blow5 index"
        ret=1
    fi

    echo ""
done

# Change back to original directory
cd - >/dev/null

if [ $ret -eq 0 ]; then
    echo "PASSED"
else
    echo "FAILED"
fi
exit $ret