Skip to content

Pipeline Tutorial

minaminii edited this page Oct 14, 2026 · 18 revisions

Applies to: NosoGraph v0.3.x (current: 0.3.0-rc.1). See the Changelog for what changed in each version. Older versions used a different --pipeline name for the Kraken2 pipeline; the Changelog lists it.

This page walks through a complete first-time setup on a fresh Linux machine, from installing prerequisites through running the NosoGraph bacterial-assembly pipeline on a real long-read sample and producing the per-sample kg/ knowledge-graph CSVs.

Tested on: Ubuntu 22.04


1. Install Java (OpenJDK)

Nextflow requires Java 17 or later. Install via sdkman is recommended.

Ubuntu / Debian

curl -s "https://get.sdkman.io" | bash

source "$USER/.sdkman/bin/sdkman-init.sh"

sdk install java

Verify

java -version

2. Install Nextflow

Nextflow is a single self-contained launcher script. No root required.

curl -s https://get.nextflow.io | bash
mv nextflow $HOME/.local/bin/
nextflow -version
# Expected: nextflow version 26.x.x ...

Minimum version: NosoGraph requires Nextflow ≥ 26.04.4 (enforced by manifest.nextflowVersion). If nextflow -version shows an older release, run nextflow self-update.


3. Choose an execution engine

Each tool runs either from a container image or from a conda environment. You pick with -profile:

-profile Engine Needs
(none) or singularity Singularity/Apptainer images (default) Singularity or Apptainer
micromamba Conda envs resolved with micromamba micromamba

Containers (default). Reproducible: every run uses the same frozen images, pulled on first use. Install Apptainer (or SingularityCE) and check it with apptainer --version. The KG exporters are not containerised and run on the host Python, so also install their dependency into the environment you launch Nextflow from:

pip install -r requirements.txt     # from the repo root, after Step 4

Micromamba (conda). Use this when no container runtime is available, or when bandwidth or disk is tight (the envs are much smaller than the images). Environments are solved against current channels on first run, so they can drift over time. Plain conda and mamba also work.

"${SHELL}" <(curl -L micro.mamba.pm/install.sh)
source ~/.bashrc      # or ~/.zshrc
micromamba --version

Environments are created on first run, so no manual micromamba create is needed. Micromamba is also used below to download the CheckM2 database, so it is worth installing either way.


4. Clone NosoGraph

git clone https://github.com/STTLab/NosoGraph.git
cd NosoGraph

The assembly/polish/QC module lives under modules/vendor/bacterial-assembly/ and carries both its conda environment and its container image. The KG exporters' conda environment is envs/kg_export.yaml.


5. Validate the wiring first (no data, no tools)

Before running real data, confirm the workflow DAG compiles end-to-end. The test profile turns off both containers and conda so this runs in seconds with no tools installed, and input paths are not checked for existence:

./nosograph assembly canu -stub-run -profile test \
    --sample_id BAC_S001 \
    --tech nanopore \
    --genome_size 5.5m \
    --long_reads dummy.fastq.gz \
    --read1 dummy_R1.fastq.gz \
    --read2 dummy_R2.fastq.gz \
    --racon_iter 2 \
    --pilon_iter 2 \
    --checkm2_db dummy.dmnd \
    --outdir /tmp/nf_test

Expected:

[PROCESS] BACTERIAL_ASSEMBLY:ASSEMBLY_CANU (1)
[PROCESS] BACTERIAL_ASSEMBLY:RACON_POLISH (1)
[PROCESS] BACTERIAL_ASSEMBLY:PILON_POLISH (1)
[PROCESS] ASSEMBLY_QC:QUAST (1)
[PROCESS] BACTERIAL_ASSEMBLY:CHECKM2 (1)
[PROCESS] KG_EXPORT (BAC_S001)

[SUCCESS] completed=6 failed=0 cached=0

canu, flye and unicycler all wire correctly. If you only want to confirm wiring, you can stop here.


6. Download the CheckM2 database (optional but recommended)

CheckM2 estimates assembly completeness and contamination. It needs the UniRef100/KO DIAMOND database. CheckM2 runs only when --pilon_iter > 0; skip this section if you are doing a long-read-only assembly without QC.

# Install CheckM2 into a throwaway env to get its downloader
micromamba create -n checkm2 -c bioconda -c conda-forge checkm2
micromamba run -n checkm2 checkm2 database --download --path /data/checkm2_db

After download you will have:

/data/checkm2_db/CheckM2_database/uniref100.KO.1.dmnd

Pass that file path to --checkm2_db.


7. Prepare your sample

path/to/data/reads/
├── sample_1_long.fastq.gz      # Oxford Nanopore long reads
├── sample_1_R1.fastq.gz        # Illumina short reads R1 (for hybrid polishing)
└── sample_1_R2.fastq.gz        # Illumina short reads R2

Use a sample_id that matches the Samples.csv you will load into the graph — here BAC_S001, which the bundled example/csv/Samples.csv already links to specimen SP003. The sample_id puts every output under <outdir>/BAC_S001/. Each assembly run goes one level deeper, in assembly/<run_name>/, where --run_name defaults to the assembler (flye here). Together they namespace the IDs: the assembly is BAC_S001_flye and its contigs BAC_S001:flye:contig_1, BAC_S001:flye:contig_2, … so they stay globally unique across samples and across assemblies of one sample.


8. Run the pipeline

Pipelines are run with the nosograph command from the repo root: ./nosograph assembly <assembler> ... or ./nosograph kraken2-classify .... It sets --pipeline (and --assembler) for you and passes everything else to nextflow run, so ./nosograph assembly flye ... is the same as nextflow run main.nf --assembler flye .... Add --dry-run to print the nextflow run command instead, or run ./nosograph assembly --help for details.

Profile and database paths once per installation. Copy .env.example to .env next to the nosograph script (e.g. /opt/NosoGraph/.env) and set checkm2_db, blast_db and kraken2_db there, one parameter=value per line; profile=<name> (e.g. profile=slurm) sets the default -profile. nosograph adds them to every run unless you pass them yourself: a -profile on the command line replaces the default one, and --<parameter> false turns a parameter off for a run (e.g. --blast_db false). .env is gitignored, and plain nextflow run doesn't read it.

Option A — Hybrid assembly with Flye (long + short reads)

Highest-quality consensus: Flye assembly, Racon long-read polishing, then Pilon short-read polishing, then CheckM2.

./nosograph assembly flye \
    --sample_id   sample_1 \
    --long_reads  path/to/data/reads/sample_1_long.fastq.gz \
    --read1       path/to/data/reads/sample_1_R1.fastq.gz \
    --read2       path/to/data/reads/sample_1_R2.fastq.gz \
    --tech        nanopore \
    --outdir      results \
    --threads     16 \
    --racon_iter  2 \
    --pilon_iter  2 \
    --checkm2_db  /data/checkm2_db/CheckM2_database/uniref100.KO.1.dmnd

With no -profile this runs from the container images, which are pulled on the first run and reused after that. Add -profile micromamba to use conda instead; the first run then builds the bacterial-assembly environment (~10–15 min), and later runs reuse it.

Option B — Long-read-only assembly with Canu

No short reads, so Pilon and CheckM2 are skipped (--pilon_iter 0). Canu requires a genome-size estimate:

./nosograph assembly canu \
    --sample_id   sample_1 \
    --long_reads  path/to/data/reads/sample_1_long.fastq.gz \
    --tech        nanopore \
    --genome_size 5.5m \
    --pilon_iter  0 \
    --outdir      results \
    --threads     32

Option C — Hybrid or long-read assembly with Unicycler

Unicycler runs a hybrid assembly when both --read1 and --read2 are given, and a long-read-only one when neither is. Giving only one of the pair is an error. It uses its own conda env (or the bioinf-unicycler image), separate from Flye/Canu:

./nosograph assembly unicycler \
    --sample_id      sample_1 \
    --long_reads     path/to/data/reads/sample_1_long.fastq.gz \
    --read1          path/to/data/reads/sample_1_R1.fastq.gz \
    --read2          path/to/data/reads/sample_1_R2.fastq.gz \
    --unicycler_mode normal \
    --tech           nanopore \
    --outdir         results \
    --threads        16 \
    --checkm2_db     /data/checkm2_db/CheckM2_database/uniref100.KO.1.dmnd

Racon and Pilon still run on Unicycler's output by default. Add --racon_iter 0 --pilon_iter 0 to keep Unicycler's own polished assembly. --unicycler_mode is conservative, normal (default) or bold: bolder modes join more of the graph at a higher risk of misassembly.

Option D — Read identity and contaminant screening (Kraken2)

A separate pipeline (nosograph kraken2-classify, i.e. --pipeline kraken2-classify) classifies a sample's long reads against a pre-built Kraken2 database, to estimate what the reads are and to screen for contaminants, and records the result in the knowledge graph — in a single Nextflow run. The vendored kraken2-classify module (modules/vendor/kraken2-classify/) produces the Kraken2 report; KRAKEN2_KG_EXPORT turns it into the kraken2/kg/ CSVs.

./nosograph kraken2-classify \
    --sample_id   sample_1 \
    --long_reads  path/to/data/reads/sample_1_long.fastq.gz \
    --kraken2_db  /data/k2_standard \
    --outdir      results \
    --threads     16

--kraken2_db must point at a Kraken2 DB directory containing hash.k2d, opts.k2d, and taxo.k2d. Kraken2 loads the whole DB into RAM, so size the request to the DB (--kraken2_mem, default 64 GB; raise for the full Standard DB). Outputs land in results/sample_1/kraken2/: sample_1.kraken2.report.txt plus kg/ (taxonomic_classification.csv, kraken2_reads.csv). Only species (rank S) and genus (G) rows are kept, and they are carried as a taxa_json QC blob on the TaxonomicClassification node — not as Organism nodes, because Kraken2 output is an untrusted per-run classification and isn't meant to be traversed in the graph. The blob is sorted by abundance and pre-filtered by an adaptive z-score bucket: low-abundance taxa (z below --kraken2_z_min, default -1.0) fold into a single "Other" row; filtering is skipped when there are fewer than --kraken2_min_taxa (default 3) taxa. See the Knowledge graph Tutorial for loading the taxonomic-classification subgraph (LOAD DATA steps 17–18 and the Read identity per sample (Kraken2) query).

Parameters

Parameter Description Default
--pipeline bacterial-assembly, autocycler, or kraken2-classify; set for you by nosograph assembly bacterial-assembly
--sample_id Sample identifier; scopes outputs and namespaces contig IDs required
--long_reads Long-read FASTQ (gzipped or plain) required
--assembler canu, flye or unicycler (bacterial-assembly only); set for you by nosograph assembly required
--unicycler_mode conservative, normal or bold (Unicycler only) normal
--tech nanopore, nanopore-hq, or pacbio nanopore
--read1 / --read2 Paired short reads (required when --pilon_iter > 0) —
--genome_size e.g. 5.5m, 2.6g (required for Canu) —
--racon_iter Racon polishing iterations 1
--pilon_iter Pilon polishing iterations (0 = skip Pilon + CheckM2) 1
--checkm2_db Path to uniref100.KO.1.dmnd —
--kraken2_db Kraken2 DB dir with hash.k2d/opts.k2d/taxo.k2d (kraken2-classify only) —
--kraken2_mem Memory request for Kraken2 (≈ DB size) 64 GB
--kraken2_z_min taxa_json z-score cutoff; taxa below fold into an "Other" bucket (kraken2-classify only) -1.0
--kraken2_min_taxa Keep all taxa (no bucketing) below this count (kraken2-classify only) 3
--outdir Output directory results
--threads Threads per process 1
--queue SLURM partition (-profile slurm only) —

9. Run on SLURM (HPC)

Add -profile slurm to submit each process as an independent job, and name your partition with --queue:

./nosograph assembly flye \
    -profile slurm \
    --queue       normal \
    --sample_id   BAC_S001 \
    --long_reads  /data/reads/BAC_S001_long.fastq.gz \
    --read1       /data/reads/BAC_S001_R1.fastq.gz \
    --read2       /data/reads/BAC_S001_R2.fastq.gz \
    --tech        nanopore \
    --outdir      results \
    --threads     16 \
    --racon_iter  2 \
    --pilon_iter  1 \
    --checkm2_db  /data/checkm2_db/CheckM2_database/uniref100.KO.1.dmnd

Default per-process resource requests (override in modules/vendor/bacterial-assembly/nextflow.config):

Process CPUs Memory Time
Assembly (Flye / Canu / Unicycler) --threads 32 GB 24 h
Racon iteration --threads 32 GB 24 h
Pilon iteration --threads 28 GB 12 h
CheckM2 --threads 32 GB 12 h

Failed processes retry once on common HPC kill signals (OOM 137, timeout 140/143, segfault 139).

Containers (Singularity / Apptainer)

Containers are the default engine: with no engine profile, or with -profile slurm alone, every tool runs from a Singularity/Apptainer image, so the compute nodes need Singularity or Apptainer but no conda. Pick the engine by adding a profile next to slurm:

-profile Engine
slurm or slurm,singularity Singularity/Apptainer images (default)
slurm,micromamba Conda envs resolved with micromamba on the nodes (see Step 3)

Images are pulled from <container_registry>/bioinf-<tool>:<container_tag> (default ghcr.io/minaminii, tag latest); set --container_registry / --container_tag to use another registry or to pin a digest. They are cached in $NXF_SINGULARITY_CACHEDIR, or ~/.singularity/cache if that is unset. Compute nodes without internet need the images in that cache before the run starts, so point it at a shared filesystem and pull once from a node that has access. Extra bind mounts (e.g. a database outside your home or project directory) go in --singularity_binds "-B /data/db".

The KG exporters are not containerised: under the container profiles they run on the host Python, so pip install -r requirements.txt into the environment you launch Nextflow from.

Resume after interruption

./nosograph assembly flye -resume ...    # same assembler and options as before; add -profile slurm if applicable

Resume reuses cached completed steps — only the failed/remaining steps re-run.


10. Inspect the outputs

After a successful run, everything for this assembly is under results/BAC_S001/assembly/flye/:

results/
└── BAC_S001/
    └── assembly/
        └── flye/                             # --run_name (default: the assembler)
            ├── 01_assembly/
            │   ├── assembly.contigs.fasta    # de novo assembly
            │   └── assembly_info.txt         # contig length / coverage / circularity (Flye)
            ├── 02_polish/
            │   ├── 01_racon/                 # Racon-polished intermediates
            │   └── 02_pilon/                 # Pilon-polished assembly (hybrid only)
            ├── quast_results/                # QUAST assembly statistics (report.tsv, report.html, …)
            ├── checkm2_results/
            │   └── quality_report.tsv        # CheckM2 completeness / contamination
            ├── versions/                     # tool versions (quast.txt; blast.txt with --blast_db)
            └── kg/                           # Neo4j-ready CSVs ← import these
                ├── sample.csv
                ├── assembly.csv
                ├── biodata_files.csv
                └── contigs.csv

With --blast_db, BLAST also adds blast/ (all hits and the best hit per contig) beside these.

Spot-check the assembly and the KG bundle:

run=results/BAC_S001/assembly/flye
grep -c "^>" $run/01_assembly/assembly.contigs.fasta   # number of contigs
column -s, -t $run/kg/contigs.csv | head               # contig table
cat $run/checkm2_results/quality_report.tsv            # CheckM2 metrics

To compare assemblers on the same sample, run another one into the same --outdir, e.g. ./nosograph assembly unicycler --sample_id BAC_S001 .... It lands in results/BAC_S001/assembly/unicycler/ beside the Flye run, with its own kg/. For two runs of the same assembler, give one a different --run_name.

The kg/ CSVs are what you copy into Neo4j in the next page. Continue to the Knowledge graph Tutorial.


11. Run your own samples (batch)

Because each run is one sample, loop in the shell for a batch:

while IFS=, read -r sid long r1 r2; do
  ./nosograph assembly flye \
    --sample_id  "$sid" \
    --long_reads "$long" \
    --read1      "$r1" \
    --read2      "$r2" \
    --tech       nanopore \
    --outdir     "results" \
    --threads    16 \
    --racon_iter 2 --pilon_iter 2 \
    --checkm2_db /data/checkm2_db/CheckM2_database/uniref100.KO.1.dmnd
done < samples.csv

Each sample lands in its own results/<sample_id>/assembly/flye/, and its kg/ folder is ready to copy into Neo4j's import directory at the matching <sample_id>/assembly/flye/kg/ path.


Troubleshooting

Symptom Cause / fix
Missing required param: --sample_id (or --long_reads, --assembler, --tech) The workflow validates required params before running — supply the missing flag.
Pilon polishing (pilon_iter > 0) requires --read1 and --read2 Either provide short reads or set --pilon_iter 0 for long-read-only assembly.
Canu errors about genome size Canu needs --genome_size (e.g. 5.5m).
First run is slow Image pulls (or, with -profile micromamba, conda environment creation) are one-off; later runs reuse them. Do a first run the day before a demo.
Want to validate without data Use -stub-run -profile test (Step 5).