Upload tasks/genome-comparison/run_script.sh with huggingface_hub
Browse files
tasks/genome-comparison/run_script.sh
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# =============================================================================
|
| 5 |
+
# Task 22: Pairwise Bacterial Genome Comparison
|
| 6 |
+
#
|
| 7 |
+
# DAG (depth 5):
|
| 8 |
+
#
|
| 9 |
+
# L0: genome_A.fna, genome_B.fna
|
| 10 |
+
# L1: ├── prokka A prokka B
|
| 11 |
+
# └── nucmer (whole-genome alignment A vs B)
|
| 12 |
+
# L2: ├── dnadiff (alignment summary)
|
| 13 |
+
# │ └── show-snps (SNP extraction)
|
| 14 |
+
# └── panaroo (ortholog clustering from prokka GFFs)
|
| 15 |
+
# L3: ├── SNP annotation (bedtools intersect SNPs with genes)
|
| 16 |
+
# └── unique gene extraction per genome
|
| 17 |
+
# L4: MERGE
|
| 18 |
+
# =============================================================================
|
| 19 |
+
|
| 20 |
+
THREADS=$(( $(nproc) > 8 ? 8 : $(nproc) ))
|
| 21 |
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
| 22 |
+
DATA="${SCRIPT_DIR}/data"
|
| 23 |
+
OUT="${SCRIPT_DIR}/outputs"
|
| 24 |
+
RES="${SCRIPT_DIR}/results"
|
| 25 |
+
|
| 26 |
+
GENOME_A="${DATA}/genome_A.fna"
|
| 27 |
+
GENOME_B="${DATA}/genome_B.fna"
|
| 28 |
+
|
| 29 |
+
log_step() {
|
| 30 |
+
echo "=================================================================="
|
| 31 |
+
echo "STEP: $1"
|
| 32 |
+
echo "$(date)"
|
| 33 |
+
echo "=================================================================="
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
mkdir -p "${OUT}"/{prokka_A,prokka_B,nucmer,panaroo,snp_annotation} "${RES}"
|
| 37 |
+
|
| 38 |
+
# ===========================================================================
|
| 39 |
+
# L1-A: Annotate genome A
|
| 40 |
+
# ===========================================================================
|
| 41 |
+
log_step "L1-A: Prokka genome A"
|
| 42 |
+
if [ ! -f "${OUT}/prokka_A/genome_A.gff" ]; then
|
| 43 |
+
prokka "${GENOME_A}" --outdir "${OUT}/prokka_A" --prefix genome_A \
|
| 44 |
+
--cpus ${THREADS} --kingdom Bacteria --force
|
| 45 |
+
else echo "Skipping (exists)"; fi
|
| 46 |
+
|
| 47 |
+
# ===========================================================================
|
| 48 |
+
# L1-B: Annotate genome B
|
| 49 |
+
# ===========================================================================
|
| 50 |
+
log_step "L1-B: Prokka genome B"
|
| 51 |
+
if [ ! -f "${OUT}/prokka_B/genome_B.gff" ]; then
|
| 52 |
+
prokka "${GENOME_B}" --outdir "${OUT}/prokka_B" --prefix genome_B \
|
| 53 |
+
--cpus ${THREADS} --kingdom Bacteria --force
|
| 54 |
+
else echo "Skipping (exists)"; fi
|
| 55 |
+
|
| 56 |
+
# ===========================================================================
|
| 57 |
+
# L1-C: Whole-genome alignment with nucmer
|
| 58 |
+
# ===========================================================================
|
| 59 |
+
log_step "L1-C: nucmer alignment"
|
| 60 |
+
if [ ! -f "${OUT}/nucmer/alignment.delta" ]; then
|
| 61 |
+
nucmer --prefix="${OUT}/nucmer/alignment" "${GENOME_A}" "${GENOME_B}"
|
| 62 |
+
else echo "Skipping (exists)"; fi
|
| 63 |
+
|
| 64 |
+
# ===========================================================================
|
| 65 |
+
# L2-A: dnadiff summary statistics
|
| 66 |
+
# ===========================================================================
|
| 67 |
+
log_step "L2-A: dnadiff"
|
| 68 |
+
if [ ! -f "${OUT}/nucmer/dnadiff.report" ]; then
|
| 69 |
+
dnadiff -d "${OUT}/nucmer/alignment.delta" -p "${OUT}/nucmer/dnadiff"
|
| 70 |
+
else echo "Skipping (exists)"; fi
|
| 71 |
+
|
| 72 |
+
# ===========================================================================
|
| 73 |
+
# L2-B: Extract SNPs
|
| 74 |
+
# ===========================================================================
|
| 75 |
+
log_step "L2-B: show-snps"
|
| 76 |
+
if [ ! -f "${OUT}/nucmer/snps.tsv" ]; then
|
| 77 |
+
show-snps -Clr "${OUT}/nucmer/alignment.delta" > "${OUT}/nucmer/snps.tsv"
|
| 78 |
+
else echo "Skipping (exists)"; fi
|
| 79 |
+
|
| 80 |
+
# ===========================================================================
|
| 81 |
+
# L2-C: Panaroo ortholog comparison
|
| 82 |
+
# ===========================================================================
|
| 83 |
+
log_step "L2-C: Panaroo ortholog comparison"
|
| 84 |
+
if [ ! -f "${OUT}/panaroo/summary_statistics.txt" ]; then
|
| 85 |
+
panaroo -i "${OUT}/prokka_A/genome_A.gff" "${OUT}/prokka_B/genome_B.gff" \
|
| 86 |
+
-o "${OUT}/panaroo" --clean-mode strict -c 0.98 \
|
| 87 |
+
--threads ${THREADS} 2>&1 || true
|
| 88 |
+
else echo "Skipping (exists)"; fi
|
| 89 |
+
|
| 90 |
+
# ===========================================================================
|
| 91 |
+
# L3: Parse results
|
| 92 |
+
# ===========================================================================
|
| 93 |
+
log_step "L3: Parse results"
|
| 94 |
+
|
| 95 |
+
# dnadiff stats
|
| 96 |
+
ALIGNED_BASES=$(grep "AlignedBases" "${OUT}/nucmer/dnadiff.report" | head -1 | awk '{print $2}' | sed 's/(.*//')
|
| 97 |
+
AVG_IDENTITY=$(grep "AvgIdentity" "${OUT}/nucmer/dnadiff.report" | head -1 | awk '{print $2}')
|
| 98 |
+
TOTAL_SNPS=$(grep "TotalSNPs" "${OUT}/nucmer/dnadiff.report" | head -1 | awk '{print $2}')
|
| 99 |
+
TOTAL_INDELS=$(grep "TotalIndels" "${OUT}/nucmer/dnadiff.report" | head -1 | awk '{print $2}')
|
| 100 |
+
BREAKPOINTS=$(grep "Breakpoints" "${OUT}/nucmer/dnadiff.report" | head -1 | awk '{print $2}')
|
| 101 |
+
RELOCATIONS=$(grep "Relocations" "${OUT}/nucmer/dnadiff.report" | head -1 | awk '{print $2}')
|
| 102 |
+
INVERSIONS=$(grep "Inversions" "${OUT}/nucmer/dnadiff.report" | head -1 | awk '{print $2}')
|
| 103 |
+
|
| 104 |
+
# Genome sizes
|
| 105 |
+
LEN_A=$(awk '/^>/{if(l)s+=l; l=0; next}{l+=length}END{s+=l; print s}' "${GENOME_A}")
|
| 106 |
+
LEN_B=$(awk '/^>/{if(l)s+=l; l=0; next}{l+=length}END{s+=l; print s}' "${GENOME_B}")
|
| 107 |
+
|
| 108 |
+
# Gene counts from prokka
|
| 109 |
+
CDS_A=$(grep "^CDS" "${OUT}/prokka_A/genome_A.txt" | awk '{print $2}')
|
| 110 |
+
CDS_B=$(grep "^CDS" "${OUT}/prokka_B/genome_B.txt" | awk '{print $2}')
|
| 111 |
+
|
| 112 |
+
# Panaroo: shared vs unique genes
|
| 113 |
+
CORE=$(grep "Core genes" "${OUT}/panaroo/summary_statistics.txt" 2>/dev/null | awk '{print $NF}' || echo "0")
|
| 114 |
+
TOTAL_PAN=$(grep "Total genes" "${OUT}/panaroo/summary_statistics.txt" 2>/dev/null | awk '{print $NF}' || echo "0")
|
| 115 |
+
UNIQUE=$((TOTAL_PAN - CORE))
|
| 116 |
+
|
| 117 |
+
# ===========================================================================
|
| 118 |
+
# L4: MERGE
|
| 119 |
+
# ===========================================================================
|
| 120 |
+
log_step "L4-MERGE"
|
| 121 |
+
|
| 122 |
+
cat > "${RES}/genome_comparison.csv" << CSVEOF
|
| 123 |
+
metric,value
|
| 124 |
+
genome_a_length,${LEN_A}
|
| 125 |
+
genome_b_length,${LEN_B}
|
| 126 |
+
aligned_bases,${ALIGNED_BASES}
|
| 127 |
+
average_identity,${AVG_IDENTITY}
|
| 128 |
+
total_snps,${TOTAL_SNPS}
|
| 129 |
+
total_indels,${TOTAL_INDELS}
|
| 130 |
+
breakpoints,${BREAKPOINTS}
|
| 131 |
+
relocations,${RELOCATIONS}
|
| 132 |
+
inversions,${INVERSIONS}
|
| 133 |
+
cds_genome_a,${CDS_A}
|
| 134 |
+
cds_genome_b,${CDS_B}
|
| 135 |
+
shared_orthologs,${CORE}
|
| 136 |
+
unique_genes,${UNIQUE}
|
| 137 |
+
total_pangenome,${TOTAL_PAN}
|
| 138 |
+
CSVEOF
|
| 139 |
+
|
| 140 |
+
echo ""
|
| 141 |
+
echo "=== Pipeline complete ==="
|
| 142 |
+
cat "${RES}/genome_comparison.csv"
|
| 143 |
+
echo ""
|
| 144 |
+
ls -lh "${RES}/"
|