|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Validation script for FragGeneScanRs |
| 5 | +# Usage: |
| 6 | +# ./scripts/validate.sh --baseline Generate baseline output files |
| 7 | +# ./scripts/validate.sh --check Compare current output against baseline (default) |
| 8 | + |
| 9 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 10 | +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" |
| 11 | +BASELINE_DIR="$PROJECT_ROOT/baseline" |
| 12 | +BINARY="$PROJECT_ROOT/target/release/FragGeneScanRs" |
| 13 | + |
| 14 | +# Example files and their configurations |
| 15 | +# Format: "input_file:training_file:whole_genome_flag:output_name" |
| 16 | +EXAMPLES=( |
| 17 | + "example/NC_000913-454.fna:454_10:0:NC_000913-454" |
| 18 | + "example/NC_000913.fna:complete:1:NC_000913" |
| 19 | + "example/contigs.fna:complete:1:contigs" |
| 20 | +) |
| 21 | + |
| 22 | +usage() { |
| 23 | + echo "Usage: $0 [--baseline|--check]" |
| 24 | + echo " --baseline Generate baseline output files" |
| 25 | + echo " --check Compare current output against baseline (default)" |
| 26 | + exit 1 |
| 27 | +} |
| 28 | + |
| 29 | +build_release() { |
| 30 | + echo "Building release binary..." |
| 31 | + cargo build --release --manifest-path "$PROJECT_ROOT/Cargo.toml" |
| 32 | +} |
| 33 | + |
| 34 | +run_example() { |
| 35 | + local input="$1" |
| 36 | + local train="$2" |
| 37 | + local whole="$3" |
| 38 | + local output_prefix="$4" |
| 39 | + |
| 40 | + "$BINARY" \ |
| 41 | + -s "$PROJECT_ROOT/$input" \ |
| 42 | + -t "$train" \ |
| 43 | + -w "$whole" \ |
| 44 | + -o "$output_prefix" |
| 45 | +} |
| 46 | + |
| 47 | +generate_baseline() { |
| 48 | + echo "Generating baseline outputs..." |
| 49 | + mkdir -p "$BASELINE_DIR" |
| 50 | + |
| 51 | + for example in "${EXAMPLES[@]}"; do |
| 52 | + IFS=':' read -r input train whole name <<< "$example" |
| 53 | + echo " Processing $name..." |
| 54 | + run_example "$input" "$train" "$whole" "$BASELINE_DIR/$name" |
| 55 | + done |
| 56 | + |
| 57 | + echo "Baseline generated in $BASELINE_DIR" |
| 58 | +} |
| 59 | + |
| 60 | +check_against_baseline() { |
| 61 | + if [[ ! -d "$BASELINE_DIR" ]]; then |
| 62 | + echo "Error: Baseline directory not found. Run with --baseline first." |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + local temp_dir |
| 67 | + temp_dir=$(mktemp -d) |
| 68 | + trap 'rm -rf "$temp_dir"' EXIT |
| 69 | + |
| 70 | + echo "Running current version and comparing against baseline..." |
| 71 | + local failed=0 |
| 72 | + |
| 73 | + for example in "${EXAMPLES[@]}"; do |
| 74 | + IFS=':' read -r input train whole name <<< "$example" |
| 75 | + echo " Processing $name..." |
| 76 | + run_example "$input" "$train" "$whole" "$temp_dir/$name" |
| 77 | + |
| 78 | + for ext in out faa ffn; do |
| 79 | + local baseline_file="$BASELINE_DIR/$name.$ext" |
| 80 | + local current_file="$temp_dir/$name.$ext" |
| 81 | + |
| 82 | + if [[ ! -f "$baseline_file" ]]; then |
| 83 | + echo " Warning: Baseline file $baseline_file not found" |
| 84 | + continue |
| 85 | + fi |
| 86 | + |
| 87 | + if diff -q "$baseline_file" "$current_file" > /dev/null 2>&1; then |
| 88 | + echo " ✓ $name.$ext matches" |
| 89 | + else |
| 90 | + echo " ✗ $name.$ext DIFFERS" |
| 91 | + failed=1 |
| 92 | + fi |
| 93 | + done |
| 94 | + done |
| 95 | + |
| 96 | + if [[ $failed -eq 0 ]]; then |
| 97 | + echo "All outputs match baseline!" |
| 98 | + exit 0 |
| 99 | + else |
| 100 | + echo "Some outputs differ from baseline!" |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | +} |
| 104 | + |
| 105 | +# Parse arguments |
| 106 | +MODE="check" |
| 107 | +if [[ $# -gt 0 ]]; then |
| 108 | + case "$1" in |
| 109 | + --baseline) |
| 110 | + MODE="baseline" |
| 111 | + ;; |
| 112 | + --check) |
| 113 | + MODE="check" |
| 114 | + ;; |
| 115 | + *) |
| 116 | + usage |
| 117 | + ;; |
| 118 | + esac |
| 119 | +fi |
| 120 | + |
| 121 | +# Main |
| 122 | +build_release |
| 123 | + |
| 124 | +case "$MODE" in |
| 125 | + baseline) |
| 126 | + generate_baseline |
| 127 | + ;; |
| 128 | + check) |
| 129 | + check_against_baseline |
| 130 | + ;; |
| 131 | +esac |
0 commit comments