Upload tasks/genome-completeness/run_script.sh with huggingface_hub
Browse files
tasks/genome-completeness/run_script.sh
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# =============================================================================
|
| 5 |
+
# Task 29: Genome Completeness and Contamination Assessment
|
| 6 |
+
#
|
| 7 |
+
# DAG (depth 5):
|
| 8 |
+
# L0: assembled genome
|
| 9 |
+
# L1: ├── BUSCO (single-copy orthologs)
|
| 10 |
+
# ├── QUAST (assembly metrics)
|
| 11 |
+
# └── Prokka (gene prediction for stats)
|
| 12 |
+
# L2: ├── seqkit stats (basic stats)
|
| 13 |
+
# └── parse BUSCO/QUAST/Prokka outputs
|
| 14 |
+
# L3: checkv (if viral) OR manual assessment
|
| 15 |
+
# L4: MERGE (comprehensive quality report)
|
| 16 |
+
# =============================================================================
|
| 17 |
+
|
| 18 |
+
THREADS=$(( $(nproc) > 8 ? 8 : $(nproc) ))
|
| 19 |
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
| 20 |
+
DATA="${SCRIPT_DIR}/data"
|
| 21 |
+
REF="${SCRIPT_DIR}/reference"
|
| 22 |
+
OUT="${SCRIPT_DIR}/outputs"
|
| 23 |
+
RES="${SCRIPT_DIR}/results"
|
| 24 |
+
|
| 25 |
+
GENOME="${DATA}/genome.fna"
|
| 26 |
+
REFERENCE="${REF}/reference.fna"
|
| 27 |
+
|
| 28 |
+
log_step() {
|
| 29 |
+
echo "=================================================================="
|
| 30 |
+
echo "STEP: $1"
|
| 31 |
+
echo "$(date)"
|
| 32 |
+
echo "=================================================================="
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
mkdir -p "${OUT}"/{busco_out,quast,prokka,stats} "${RES}"
|
| 36 |
+
|
| 37 |
+
# L1-A: BUSCO
|
| 38 |
+
log_step "L1-A: BUSCO"
|
| 39 |
+
if [ ! -d "${OUT}/busco_out/busco" ]; then
|
| 40 |
+
busco -i "${GENOME}" -o busco --out_path "${OUT}/busco_out" \
|
| 41 |
+
-l bacteria_odb10 -m genome -c ${THREADS} --force
|
| 42 |
+
else echo "Skipping (exists)"; fi
|
| 43 |
+
|
| 44 |
+
# L1-B: QUAST with reference
|
| 45 |
+
log_step "L1-B: QUAST"
|
| 46 |
+
if [ ! -f "${OUT}/quast/report.tsv" ]; then
|
| 47 |
+
quast "${GENOME}" -r "${REFERENCE}" -o "${OUT}/quast" -t ${THREADS}
|
| 48 |
+
else echo "Skipping (exists)"; fi
|
| 49 |
+
|
| 50 |
+
# L1-C: Prokka
|
| 51 |
+
log_step "L1-C: Prokka"
|
| 52 |
+
if [ ! -f "${OUT}/prokka/genome.gff" ]; then
|
| 53 |
+
prokka "${GENOME}" --outdir "${OUT}/prokka" --prefix genome \
|
| 54 |
+
--cpus ${THREADS} --kingdom Bacteria --force
|
| 55 |
+
else echo "Skipping (exists)"; fi
|
| 56 |
+
|
| 57 |
+
# L2: seqkit + parse
|
| 58 |
+
log_step "L2: Parse results"
|
| 59 |
+
|
| 60 |
+
seqkit stats "${GENOME}" -T > "${OUT}/stats/seqkit.tsv"
|
| 61 |
+
|
| 62 |
+
# BUSCO
|
| 63 |
+
BUSCO_SUM=$(grep "C:" "${OUT}/busco_out/busco/short_summary.specific.bacteria_odb10.busco.txt" 2>/dev/null \
|
| 64 |
+
| head -1 | sed 's/^[[:space:]]*//' || echo "N/A")
|
| 65 |
+
BUSCO_COMPLETE=$(echo "$BUSCO_SUM" | grep -oP 'C:[\d.]+' | tr -d 'C:')
|
| 66 |
+
BUSCO_FRAGMENTED=$(echo "$BUSCO_SUM" | grep -oP 'F:[\d.]+' | tr -d 'F:')
|
| 67 |
+
BUSCO_MISSING=$(echo "$BUSCO_SUM" | grep -oP 'M:[\d.]+' | tr -d 'M:')
|
| 68 |
+
|
| 69 |
+
# QUAST
|
| 70 |
+
TOTAL_LEN=$(grep "^Total length" "${OUT}/quast/report.tsv" | head -1 | cut -f2)
|
| 71 |
+
NUM_CONTIGS=$(grep "^# contigs " "${OUT}/quast/report.tsv" | head -1 | cut -f2)
|
| 72 |
+
N50=$(grep "^N50" "${OUT}/quast/report.tsv" | cut -f2)
|
| 73 |
+
GC=$(grep "^GC" "${OUT}/quast/report.tsv" | cut -f2)
|
| 74 |
+
LARGEST=$(grep "^Largest contig" "${OUT}/quast/report.tsv" | cut -f2)
|
| 75 |
+
GF=$(grep "^Genome fraction" "${OUT}/quast/report.tsv" | cut -f2)
|
| 76 |
+
MISASSEMBLIES=$(grep "^# misassemblies" "${OUT}/quast/report.tsv" | cut -f2)
|
| 77 |
+
DUPLICATION=$(grep "^Duplication ratio" "${OUT}/quast/report.tsv" | cut -f2)
|
| 78 |
+
|
| 79 |
+
# Prokka
|
| 80 |
+
CDS=$(grep "^CDS" "${OUT}/prokka/genome.txt" | awk '{print $2}')
|
| 81 |
+
TRNA=$(grep "^tRNA" "${OUT}/prokka/genome.txt" | awk '{print $2}')
|
| 82 |
+
RRNA=$(grep "^rRNA" "${OUT}/prokka/genome.txt" | awk '{print $2}')
|
| 83 |
+
CODING_DENSITY=$(python3 -c "
|
| 84 |
+
cds_len = 0
|
| 85 |
+
for line in open('${OUT}/prokka/genome.gff'):
|
| 86 |
+
if '\tCDS\t' in line:
|
| 87 |
+
parts = line.split('\t')
|
| 88 |
+
cds_len += int(parts[4]) - int(parts[3]) + 1
|
| 89 |
+
print(f'{cds_len/${TOTAL_LEN}*100:.1f}')
|
| 90 |
+
" 2>/dev/null || echo "N/A")
|
| 91 |
+
|
| 92 |
+
# L4: MERGE
|
| 93 |
+
log_step "L4-MERGE"
|
| 94 |
+
|
| 95 |
+
cat > "${RES}/completeness_report.csv" << CSVEOF
|
| 96 |
+
metric,value
|
| 97 |
+
total_length,${TOTAL_LEN}
|
| 98 |
+
num_contigs,${NUM_CONTIGS}
|
| 99 |
+
n50,${N50}
|
| 100 |
+
gc_content,${GC}
|
| 101 |
+
largest_contig,${LARGEST}
|
| 102 |
+
genome_fraction,${GF}
|
| 103 |
+
misassemblies,${MISASSEMBLIES}
|
| 104 |
+
duplication_ratio,${DUPLICATION}
|
| 105 |
+
busco_complete_pct,${BUSCO_COMPLETE}
|
| 106 |
+
busco_fragmented_pct,${BUSCO_FRAGMENTED}
|
| 107 |
+
busco_missing_pct,${BUSCO_MISSING}
|
| 108 |
+
cds_count,${CDS}
|
| 109 |
+
trna_count,${TRNA}
|
| 110 |
+
rrna_count,${RRNA}
|
| 111 |
+
coding_density_pct,${CODING_DENSITY}
|
| 112 |
+
CSVEOF
|
| 113 |
+
|
| 114 |
+
echo ""
|
| 115 |
+
echo "=== Pipeline complete ==="
|
| 116 |
+
cat "${RES}/completeness_report.csv"
|