This workshop compares bacterial genome assemblies generated using two assemblers, Redbean and Flye, at approximately 6× and 20× sequencing coverage. Assembly statistics and graphs describe fragmentation and connectivity, while comparison with a reference helps assess accuracy.
Commands below are recorded for documentation and are not executed when this document is knitted.
Commands are run inside the redbean folder.
cd ~/mb5370-workshops/redbean
pwd
cat /pvol/data/amtp4/*_[012].fastq > amtp4.fastq
cd changes directories and pwd confirms the
current location. cat combines the selected FASTQ files
into one input file. The pattern *_[012].fastq selects
filenames ending in _0.fastq, _1.fastq or
_2.fastq. The > operator writes the output
to a file and replaces that file if it already exists.
wtdbg2 -x ont -g 5m -t 4 -i amtp4.fastq -fo amtp4
wtpoa-cns -t 4 -i amtp4.ctg.lay.gz -fo amtp4.ctg.fa
wtdbg2 performs the initial assembly. The options
specify Oxford Nanopore reads (-x ont), an estimated genome
size of five million bases (-g 5m), four threads
(-t 4) and the input file (-i). The combined
-fo option enables overwriting and sets the output
prefix.
wtpoa-cns generates consensus sequences from the
assembly layout. The resulting contigs are stored in
amtp4.ctg.fa.
assembly-stats amtp4.ctg.fa
assembly-stats reports measures including total sequence
length, sequence count, longest sequence and N50. N50 is the sequence
length at which sequences of that length or longer account for at least
half of the total assembly length.
A larger N50 indicates greater contiguity, but does not independently demonstrate completeness or correctness.
cat /pvol/data/amtp4/*.fastq > amtp4_20x.fastq
wtdbg2 -x ont -g 5m -t 4 -i amtp4_20x.fastq -fo amtp4_20x
wtpoa-cns -t 4 -i amtp4_20x.ctg.lay.gz -fo amtp4_20x.ctg.fa
assembly-stats amtp4_20x.ctg.fa
The wildcard *.fastq selects all FASTQ files in the
source folder. Distinct output names keep the smaller and larger
assemblies separate.
cd ~/mb5370-workshops/flye_genome
pwd
ln -s ../redbean/amtp4.fastq .
ln -s ../redbean/amtp4_20x.fastq .
ln -s creates symbolic links to the existing read files
without copying their contents. .. refers to the parent
directory and . refers to the current directory.
The following script is saved as run_flye_small.sh
inside flye_genome. It is submitted through Slurm rather
than run as a standalone command in the Terminal.
#!/bin/bash
#SBATCH --time=60
#SBATCH --cpus-per-task=4 --mem=10gb
echo "Starting flye in $(pwd) at $(date)"
flye --nano-raw amtp4.fastq --out-dir amtp4 --genome-size 5m --threads 4
echo "Finished flye in $(pwd) at $(date)"
The first line specifies Bash. The #SBATCH directives
request a 60-minute time limit, four CPUs and 10 GB of memory.
flye receives the read file, output directory, estimated
genome size and thread count. echo prints messages, while
$(pwd) and $(date) insert the working
directory and current time.
The final echo message alone does not prove success: the assembly log and final output files should also be checked.
sbatch run_flye_small.sh
squeue -u "$USER"
sbatch submits the script and returns a job number.
Submit each job once to avoid simultaneous runs writing to the same
output directory.
squeue -u "$USER" displays my queued and running jobs.
R indicates running and PD indicates
pending.
Replace XXX below with the job number returned by
Slurm.
tail slurm-XXX.out
tail -f slurm-XXX.out
tail displays the last lines of the log. Adding
-f keeps watching for new output, so it does not
automatically return to the prompt when Flye finishes. Pressing Ctrl+C
exits the log viewer without cancelling the submitted Slurm job.
Save this as run_flye_large.sh inside
flye_genome.
#!/bin/bash
#SBATCH --time=360
#SBATCH --cpus-per-task=4 --mem=10gb
echo "Starting flye in $(pwd) at $(date)"
flye --nano-raw amtp4_20x.fastq --out-dir amtp4_20x --genome-size 5m --threads 4
echo "Finished flye in $(pwd) at $(date)"
This script uses the larger input dataset and requests a longer time limit. Its output directory is separate from the small assembly.
sbatch run_flye_large.sh
squeue -u "$USER"
tail -n 20 amtp4_20x/flye.log
Run these commands after the corresponding assemblies finish.
assembly-stats amtp4/assembly.fasta
assembly-stats amtp4_20x/assembly.fasta
Bandage is a graphical application, so these steps are performed through its menus rather than as Terminal commands.
assembly_graph.gfa from the small Flye output
directory.amtp4_20x.Graph segments represent assembled sequence, and links show their connections. Branching can indicate unresolved repeats, while disconnected components can reflect separate biological sequences or fragmentation.
Large circular components may represent chromosomes and smaller circular components may represent plasmids. These are provisional interpretations that require supporting evidence.
Commands are run inside quast.
cd ~/mb5370-workshops/quast
cat ../flye_genome/amtp4_20x/assembly.fasta |
bioawk -c fastx '{print $name, length($seq)}' |
sort -n -k2
The pipe sends one command’s output into the next command.
bioawk reads sequence records and prints each identifier
and length. sort -n -k2 sorts numerically using the second
column, placing the longest contigs at the bottom.
Replace contig_XX and contig_YY with the
identifiers of the two largest contigs in my own Flye result.
samtools faidx ../flye_genome/amtp4_20x/assembly.fasta contig_XX contig_YY > flye_asm/vibrio.fasta
Inspect the Redbean identifiers and lengths before extracting its corresponding sequences.
cat ../redbean/amtp4_20x.ctg.fa |
bioawk -c fastx '{print $name, length($seq)}' |
sort -n -k2
samtools faidx ../redbean/amtp4_20x.ctg.fa ctg1 ctg2 > redbean_asm/vibrio.fasta
samtools faidx retrieves named sequences from a FASTA
file. The identifiers must match the actual assembly.
This comparison focuses on the two major chromosomes represented in the reference. Excluding other contigs means it does not assess recovery of all plasmids or other organisms.
ln -s ../flye_genome/amtp4_20x.fastq .
ln -s /pvol/data/amtp4/reference/vibrio .
quast -o quast_vibrio \
redbean_asm/vibrio.fasta \
flye_asm/vibrio.fasta \
-L -t 4 \
--circos --glimmer \
-r vibrio/vibrio.fna \
--features vibrio/vibrio.gff \
--nanopore amtp4_20x.fastq
The backslash continues a command onto the next line. -o
names the output directory, -t specifies threads and
-r supplies the reference sequence. Other options provide
reference annotations, Nanopore reads and additional analyses.
This command compares the selected higher-coverage Redbean and Flye assemblies, rather than all four complete assemblies.
Download the complete quast_vibrio folder and
inspect:
report.htmlcircos/circos.pngThe report supports comparison of assembly continuity, reference coverage, misassemblies, mismatches and indels. These measures should be interpreted together rather than using N50 alone.
Select the suspected repeat in Bandage, copy its sequence and save it
as repeat.fasta in the repeat folder. Add a
FASTA header such as >repeat_1.
cd ~/mb5370-workshops/repeat
prokka --outdir prokka --prefix repeat repeat.fasta
cat prokka/repeat.tsv
Prokka predicts and annotates genomic features. Its TSV output lists the reported features and their annotations.
ln -s ../quast/vibrio/vibrio.fna .
minimap2 -x map-ont vibrio.fna repeat.fasta > repeat_vs_genome.paf
head repeat_vs_genome.paf
minimap2 aligns the repeat sequence to the reference.
The -x map-ont option selects an alignment preset, and the
results are written in PAF format.
awk -F '\t' 'BEGIN {OFS="\t"} /^repe/ {print $6,$8,$9}' \
repeat_vs_genome.paf > repeat_locations.bed
This selects alignments whose query names begin with
repe and extracts the reference name, start and end
positions. Setting OFS ensures the output fields are
tab-separated.
The positions help distinguish copies clustered next to each other from copies dispersed across the reference.
Workshop instructions: https://mb5370.bioinformatics.guide/workshop2.html