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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# =============================================================================
|
| 5 |
+
# Task 16: Long-read de novo Assembly and Polishing
|
| 6 |
+
#
|
| 7 |
+
# DAG (depth 7, linear chain with late fan-out):
|
| 8 |
+
#
|
| 9 |
+
# L0: raw nanopore reads
|
| 10 |
+
# L1: NanoPlot (read QC)
|
| 11 |
+
# L2: Filtlong (quality/length filter)
|
| 12 |
+
# L3: Flye (de novo assembly)
|
| 13 |
+
# L4: minimap2+samtools (map reads → sorted BAM for polishing)
|
| 14 |
+
# L5: Medaka (consensus polishing, round 1)
|
| 15 |
+
# ├──────────────────────────────────────┐
|
| 16 |
+
# L6: QUAST (assembly QC vs ref) Prokka (annotation)
|
| 17 |
+
# │ │
|
| 18 |
+
# ├── BUSCO (completeness) abricate (AMR)
|
| 19 |
+
# │ │
|
| 20 |
+
# L7: MERGE ─────────────────────────────────┘
|
| 21 |
+
# =============================================================================
|
| 22 |
+
|
| 23 |
+
THREADS=$(( $(nproc) > 8 ? 8 : $(nproc) ))
|
| 24 |
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
| 25 |
+
DATA="${SCRIPT_DIR}/data"
|
| 26 |
+
REF="${SCRIPT_DIR}/reference"
|
| 27 |
+
OUT="${SCRIPT_DIR}/outputs"
|
| 28 |
+
RES="${SCRIPT_DIR}/results"
|
| 29 |
+
|
| 30 |
+
READS="${DATA}/barcode10.fastq.gz"
|
| 31 |
+
REFERENCE="${REF}/salmonella_ref.fna"
|
| 32 |
+
|
| 33 |
+
log_step() {
|
| 34 |
+
echo "=================================================================="
|
| 35 |
+
echo "STEP: $1"
|
| 36 |
+
echo "$(date)"
|
| 37 |
+
echo "=================================================================="
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
mkdir -p "${OUT}"/{nanoplot,filtered,assembly,mapping,polished,qc,prokka,amr} "${RES}"
|
| 41 |
+
|
| 42 |
+
# ===========================================================================
|
| 43 |
+
# L1: Read QC with NanoPlot
|
| 44 |
+
# ===========================================================================
|
| 45 |
+
log_step "L1: NanoPlot read QC"
|
| 46 |
+
if [ ! -f "${OUT}/nanoplot/NanoStats.txt" ]; then
|
| 47 |
+
NanoPlot --fastq "${READS}" -o "${OUT}/nanoplot" -t ${THREADS} --plots dot
|
| 48 |
+
else echo "Skipping (exists)"; fi
|
| 49 |
+
|
| 50 |
+
# ===========================================================================
|
| 51 |
+
# L2: Quality filtering with Filtlong
|
| 52 |
+
# ===========================================================================
|
| 53 |
+
log_step "L2: Filtlong quality filtering"
|
| 54 |
+
if [ ! -f "${OUT}/filtered/filtered.fastq.gz" ]; then
|
| 55 |
+
filtlong --min_length 200 "${READS}" | gzip > "${OUT}/filtered/filtered.fastq.gz"
|
| 56 |
+
else echo "Skipping (exists)"; fi
|
| 57 |
+
|
| 58 |
+
# ===========================================================================
|
| 59 |
+
# L3: De novo assembly with Flye
|
| 60 |
+
# ===========================================================================
|
| 61 |
+
log_step "L3: Flye assembly"
|
| 62 |
+
if [ ! -f "${OUT}/assembly/assembly.fasta" ]; then
|
| 63 |
+
flye --nano-raw "${OUT}/filtered/filtered.fastq.gz" \
|
| 64 |
+
--out-dir "${OUT}/assembly" \
|
| 65 |
+
--threads ${THREADS} --genome-size 5m
|
| 66 |
+
else echo "Skipping (exists)"; fi
|
| 67 |
+
|
| 68 |
+
# ===========================================================================
|
| 69 |
+
# L4: Map reads back to assembly for polishing
|
| 70 |
+
# ===========================================================================
|
| 71 |
+
log_step "L4: minimap2 read mapping"
|
| 72 |
+
if [ ! -f "${OUT}/mapping/reads2assembly.bam" ]; then
|
| 73 |
+
minimap2 -ax map-ont -t ${THREADS} \
|
| 74 |
+
"${OUT}/assembly/assembly.fasta" "${OUT}/filtered/filtered.fastq.gz" \
|
| 75 |
+
| samtools sort -@ ${THREADS} -o "${OUT}/mapping/reads2assembly.bam"
|
| 76 |
+
samtools index "${OUT}/mapping/reads2assembly.bam"
|
| 77 |
+
else echo "Skipping (exists)"; fi
|
| 78 |
+
|
| 79 |
+
# ===========================================================================
|
| 80 |
+
# L5: Consensus polishing with Medaka
|
| 81 |
+
# ===========================================================================
|
| 82 |
+
log_step "L5: Medaka polishing"
|
| 83 |
+
if [ ! -f "${OUT}/polished/consensus.fasta" ]; then
|
| 84 |
+
medaka_consensus -i "${OUT}/filtered/filtered.fastq.gz" \
|
| 85 |
+
-d "${OUT}/assembly/assembly.fasta" \
|
| 86 |
+
-o "${OUT}/polished" \
|
| 87 |
+
-t ${THREADS} -m r1041_e82_400bps_sup_v5.0.0 2>&1 || {
|
| 88 |
+
echo "WARNING: Medaka failed with specified model, trying default"
|
| 89 |
+
medaka_consensus -i "${OUT}/filtered/filtered.fastq.gz" \
|
| 90 |
+
-d "${OUT}/assembly/assembly.fasta" \
|
| 91 |
+
-o "${OUT}/polished" \
|
| 92 |
+
-t ${THREADS} 2>&1 || {
|
| 93 |
+
echo "WARNING: Medaka failed, using unpolished assembly"
|
| 94 |
+
cp "${OUT}/assembly/assembly.fasta" "${OUT}/polished/consensus.fasta"
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
else echo "Skipping (exists)"; fi
|
| 98 |
+
FINAL="${OUT}/polished/consensus.fasta"
|
| 99 |
+
|
| 100 |
+
# ===========================================================================
|
| 101 |
+
# L6 LEFT: Assembly QC
|
| 102 |
+
# ===========================================================================
|
| 103 |
+
log_step "L6-LEFT: QUAST assembly QC"
|
| 104 |
+
if [ ! -f "${OUT}/qc/quast/report.tsv" ]; then
|
| 105 |
+
quast "${FINAL}" -r "${REFERENCE}" -o "${OUT}/qc/quast" -t ${THREADS}
|
| 106 |
+
else echo "Skipping (exists)"; fi
|
| 107 |
+
|
| 108 |
+
log_step "L6-LEFT: BUSCO completeness"
|
| 109 |
+
if [ ! -d "${OUT}/qc/busco" ]; then
|
| 110 |
+
busco -i "${FINAL}" -o busco --out_path "${OUT}/qc" \
|
| 111 |
+
-l bacteria_odb10 -m genome -c ${THREADS} --force
|
| 112 |
+
else echo "Skipping (exists)"; fi
|
| 113 |
+
|
| 114 |
+
# ===========================================================================
|
| 115 |
+
# L6 RIGHT: Annotation + AMR
|
| 116 |
+
# ===========================================================================
|
| 117 |
+
log_step "L6-RIGHT: Prokka annotation"
|
| 118 |
+
if [ ! -f "${OUT}/prokka/SALM.gff" ]; then
|
| 119 |
+
prokka "${FINAL}" --outdir "${OUT}/prokka" --prefix SALM \
|
| 120 |
+
--cpus ${THREADS} --kingdom Bacteria --genus Salmonella --force
|
| 121 |
+
else echo "Skipping (exists)"; fi
|
| 122 |
+
|
| 123 |
+
log_step "L6-RIGHT: abricate AMR detection"
|
| 124 |
+
if [ ! -f "${OUT}/amr/abricate_card.tsv" ]; then
|
| 125 |
+
abricate "${FINAL}" --db card --minid 80 --mincov 60 > "${OUT}/amr/abricate_card.tsv"
|
| 126 |
+
else echo "Skipping (exists)"; fi
|
| 127 |
+
|
| 128 |
+
# ===========================================================================
|
| 129 |
+
# L7: MERGE
|
| 130 |
+
# ===========================================================================
|
| 131 |
+
log_step "L7-MERGE: Building results"
|
| 132 |
+
|
| 133 |
+
# Read QC stats
|
| 134 |
+
MEAN_LEN=$(grep "Mean read length" "${OUT}/nanoplot/NanoStats.txt" | awk '{print $NF}' | tr -d ',')
|
| 135 |
+
MEAN_QUAL=$(grep "Mean read quality" "${OUT}/nanoplot/NanoStats.txt" | awk '{print $NF}')
|
| 136 |
+
TOTAL_BASES=$(grep "Total bases" "${OUT}/nanoplot/NanoStats.txt" | awk '{print $NF}' | tr -d ',')
|
| 137 |
+
NUM_READS=$(grep "Number of reads" "${OUT}/nanoplot/NanoStats.txt" | head -1 | awk '{print $NF}' | tr -d ',')
|
| 138 |
+
|
| 139 |
+
# Assembly stats from QUAST
|
| 140 |
+
TOTAL_LEN=$(grep "^Total length" "${OUT}/qc/quast/report.tsv" | head -1 | cut -f2)
|
| 141 |
+
NUM_CONTIGS=$(grep "^# contigs " "${OUT}/qc/quast/report.tsv" | head -1 | cut -f2)
|
| 142 |
+
N50=$(grep "^N50" "${OUT}/qc/quast/report.tsv" | cut -f2)
|
| 143 |
+
GC=$(grep "^GC" "${OUT}/qc/quast/report.tsv" | cut -f2)
|
| 144 |
+
LARGEST=$(grep "^Largest contig" "${OUT}/qc/quast/report.tsv" | cut -f2)
|
| 145 |
+
GENOME_FRAC=$(grep "^Genome fraction" "${OUT}/qc/quast/report.tsv" | cut -f2)
|
| 146 |
+
MISASSEMBLIES=$(grep "^# misassemblies" "${OUT}/qc/quast/report.tsv" | cut -f2)
|
| 147 |
+
|
| 148 |
+
# BUSCO
|
| 149 |
+
BUSCO_SUM=$(grep "C:" "${OUT}/qc/busco/short_summary.specific.bacteria_odb10.busco.txt" 2>/dev/null \
|
| 150 |
+
| head -1 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' || echo "N/A")
|
| 151 |
+
|
| 152 |
+
# Prokka
|
| 153 |
+
CDS=$(grep "^CDS" "${OUT}/prokka/SALM.txt" | awk '{print $2}')
|
| 154 |
+
TRNA=$(grep "^tRNA" "${OUT}/prokka/SALM.txt" | awk '{print $2}')
|
| 155 |
+
RRNA=$(grep "^rRNA" "${OUT}/prokka/SALM.txt" | awk '{print $2}')
|
| 156 |
+
|
| 157 |
+
# AMR
|
| 158 |
+
AMR_COUNT=$(tail -n +2 "${OUT}/amr/abricate_card.tsv" 2>/dev/null | wc -l | tr -d ' ')
|
| 159 |
+
|
| 160 |
+
cat > "${RES}/longread_assembly_report.csv" << CSVEOF
|
| 161 |
+
metric,value
|
| 162 |
+
num_reads,${NUM_READS}
|
| 163 |
+
mean_read_length,${MEAN_LEN}
|
| 164 |
+
mean_read_quality,${MEAN_QUAL}
|
| 165 |
+
total_bases,${TOTAL_BASES}
|
| 166 |
+
assembly_length,${TOTAL_LEN}
|
| 167 |
+
num_contigs,${NUM_CONTIGS}
|
| 168 |
+
n50,${N50}
|
| 169 |
+
gc_content,${GC}
|
| 170 |
+
largest_contig,${LARGEST}
|
| 171 |
+
genome_fraction,${GENOME_FRAC}
|
| 172 |
+
misassemblies,${MISASSEMBLIES}
|
| 173 |
+
completeness,${BUSCO_SUM}
|
| 174 |
+
cds_count,${CDS}
|
| 175 |
+
trna_count,${TRNA}
|
| 176 |
+
rrna_count,${RRNA}
|
| 177 |
+
amr_genes,${AMR_COUNT}
|
| 178 |
+
CSVEOF
|
| 179 |
+
|
| 180 |
+
echo ""
|
| 181 |
+
echo "=== Pipeline complete ==="
|
| 182 |
+
cat "${RES}/longread_assembly_report.csv"
|
| 183 |
+
echo ""
|
| 184 |
+
ls -lh "${RES}/"
|