# ku-cbd/nphantom architecture

> Architecture diagram of the GitHub repository ku-cbd/nphantom, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ku-cbd/nphantom
- Repository: https://github.com/ku-cbd/nphantom

## Overview

##### Project type and purpose
- This is a bioinformatics workflow implemented as a Nextflow pipeline (NPhAnToM) for discovering and annotating bacteriophages from metagenomic Illumina reads.
- The purpose is to take raw or SRA-downloaded reads, preprocess them (trim, filter, QC), assemble contigs, predict viruses, assess completeness, annotate phages, predict hosts, and compile results into HTML and GenBank outputs.

##### File structure
- Top-level Nextflow scripts:
- NPhAnToM.nf (main pipeline)
- Assembly.nf, Trimming.nf, VirPredictions.nf, HostPredictor.nf, Pharokka.nf, TaxRemover.nf (modular pipeline stages)
- Python helper scripts for splitting, parsing, combination logic (e.g., fastasplitter.py, Pharo­kkaSplitter.py, offsetdetector.py, virextractor.py, TaxRemover.py, DeepVirExtractor.py).
- Shell scripts to launch on HPC: nphantom_2.sh, nphantom_copy.sh.
- Configuration: nextflow.config, custom.config.
- No “frontend/backend,” but a sequence of processes, external databases, and runtimes managed by Nextflow.

##### README for insights
- Describes each pipeline step and the tools used: fasterqdump/fastq dump, AdapterRemoval/FastP, Kraken, FastQC, metaSPAdes, DeepVirFinder/Seeker/Phager, CheckV, Pharokka, IPHOP, plus result compilation.
- Indicates profiles: local vs. cluster (SLURM scheduler), use of Singularity or Conda/Mamba environments, and external database paths.

##### Main components & their interactions
a. Input sources
- SRA (via fasterqdump) or local FastQ files.
b. Workflow engine
- Nextflow DSL orchestrates processes, channels, parallelism, and handles profiles (local/cluster).
c. Preprocessing
- Trimming (AdapterRemoval, FastP) → Eukaryotic read removal (Kraken) → FastQC.
d. Assembly & QC
- metagenomic SPAdes → assembly stats (stats.sh).
e. Virus prediction
- DeepVirFinder (dvf.py), Seeker, Phager → combined by virextractor.py using union/intersection logic.
f. Completeness & annotation
- CheckV → Pharokka annotation.
g. Host prediction
- IPHOP.
h. Results compilation
- Python scripts merge outputs → HTML + GenBank in CompiledResults.
i. External resources & services
- Database files (Kraken2, CheckV, Pharokka DB, IPHOP DB), container registry (Singularity cache), HPC scheduler (SLURM).

##### Architectural patterns & principles
- Modular pipeline: each logical stage is a separate Nextflow process (.nf file).
- Reproducibility: containerized or Conda/Mamba environments per process, versioned databases.
- Parallelism: Nextflow channels decouple producers (e.g., read trimmers) from consumers (assemblers).
- Config-driven: nextflow.config and custom.config specify profiles, paths, resources.

##### Detail level & clarity
- Use consistent iconography for “script,” “tool,” “database,” and “workflow engine.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Workflow Engine and Config
    Engine["Nextflow Engine"]:::engine
    Config1["nextflow.config"]:::config
    Config2["custom.config"]:::config
    README["README.md"]:::metadata
    Adapters["Adapters.txt"]:::metadata

    Engine -->|reads config| Config1
    Engine -->|reads config| Config2

    %% Input Sources
    subgraph "Input Sources"
        InputFASTQ["Local FASTQ"]:::data
        InputSRA["SRA (fasterq-dump)"]:::data
    end
    Engine -->|"fetch reads"| InputFASTQ
    Engine -->|"fetch reads"| InputSRA

    %% Preprocessing
    subgraph "Preprocessing"
        Trim["Trimming"]:::process
        EukRem["Eukaryotic Removal"]:::process
        QC["FastQC"]:::process
    end
    Engine -->|"start trimming"| Trim
    Trim -->|"output trimmed reads"| EukRem
    EukRem -->|"clean reads"| QC

    %% Assembly and QC
    subgraph "Assembly/QC"
        Assemble["Assembly (metaSPAdes)"]:::process
        Stats["Assembly Stats"]:::process
    end
    QC -->|reads| Assemble
    Assemble -->|contigs| Stats
    Stats -->|stats data| Engine

    %% Prediction
    subgraph "Virus Prediction"
        VirPredStage["Prediction Orchestration"]:::process
        DVF["DeepVirFinder"]:::process
        Seeker["Seeker"]:::process
        Phager["Phager"]:::process
        Combine["Results Combination"]:::process
    end
    Engine -->|"invoke prediction"| VirPredStage
    VirPredStage -->|run DVF| DVF
    VirPredStage -->|run Seeker| Seeker
    VirPredStage -->|run Phager| Phager
    DVF --> Combine
    Seeker --> Combine
    Phager --> Combine

    %% Completeness & Annotation
    subgraph "Completeness & Annotation"
        CheckV["CheckV"]:::external
        Pharokka["Pharokka Annotation"]:::process
        PSplit["PharokkaSplitter"]:::utility
    end
    Combine -->|contigs| CheckV
    CheckV -->|QC'd contigs| Pharokka
    Pharokka -->|annotations| PSplit

    %% Host Prediction
    subgraph "Host Prediction"
        HostPred["HostPrediction (IPHOP)"]:::process
    end
    PSplit --> HostPred

    %% Post-processing & Output
    subgraph "Post-processing"
        FastaSplit["FASTA Splitter"]:::utility
        OffsetDet["Offset Detector"]:::utility
        Compile["Results Compilation"]:::process
    end
    HostPred --> FastaSplit
    Stats --> OffsetDet
    FastaSplit --> Compile
    OffsetDet --> Compile
    Compile --> Outputs["HTML & GenBank"]:::data

    %% External Dependencies
    subgraph "Databases" 
        KrakenDB["Kraken2 DB"]:::db
        CheckVDB["CheckV DB"]:::db
        PharokkaDB["Pharokka DB"]:::db
        IPHOPDB["IPHOP DB"]:::db
    end
    EukRem --> KrakenDB
    CheckV --> CheckVDB
    Pharokka --> PharokkaDB
    HostPred --> IPHOPDB

    %% Infrastructure
    subgraph "Infrastructure"
        Container["Containers / Conda"]:::infra
        Scheduler["SLURM Scheduler"]:::infra
    end
    Engine --> Container
    Engine --> Scheduler

    %% Metadata
    Engine --> README
    Engine --> Adapters

    %% Click Events
    click Engine "https://github.com/ku-cbd/nphantom/blob/main/NPhAnToM.nf"
    click Config1 "https://github.com/ku-cbd/nphantom/blob/main/nextflow.config"
    click Config2 "https://github.com/ku-cbd/nphantom/blob/main/custom.config"
    click Trim "https://github.com/ku-cbd/nphantom/blob/main/Trimming.nf"
    click EukRem "https://github.com/ku-cbd/nphantom/blob/main/TaxRemover.py"
    click Stats "https://github.com/ku-cbd/nphantom/blob/main/offsetdetector.py"
    click Assemble "https://github.com/ku-cbd/nphantom/blob/main/Assembly.nf"
    click VirPredStage "https://github.com/ku-cbd/nphantom/blob/main/VirPredictions.nf"
    click DVF "https://github.com/ku-cbd/nphantom/blob/main/DeepVirExtractor.py"
    click Combine "https://github.com/ku-cbd/nphantom/blob/main/virextractor.py"
    click HostPred "https://github.com/ku-cbd/nphantom/blob/main/HostPredictor.nf"
    click Pharokka "https://github.com/ku-cbd/nphantom/blob/main/Pharokka.nf"
    click PSplit "https://github.com/ku-cbd/nphantom/blob/main/PharokkaSplitter.py"
    click FastaSplit "https://github.com/ku-cbd/nphantom/blob/main/fastasplitter.py"
    click OffsetDet "https://github.com/ku-cbd/nphantom/blob/main/offsetdetector.py"
    click Compile "https://github.com/ku-cbd/nphantom/blob/main/nphantom_compilation.py"
    click Scheduler "https://github.com/ku-cbd/nphantom/blob/main/nphantom_2.sh"
    click Container "https://github.com/ku-cbd/nphantom/blob/main/nphantom_copy.sh"
    click README "https://github.com/ku-cbd/nphantom/blob/main/README.md"
    click Adapters "https://github.com/ku-cbd/nphantom/blob/main/Adapters.txt"

    %% Styles
    classDef engine fill:#D8BFD8,stroke:#800080;
    classDef config fill:#E6E6FA,stroke:#A9A9A9;
    classDef data fill:#ADD8E6,stroke:#00008B;
    classDef process fill:#87CEFA,stroke:#4682B4;
    classDef utility fill:#90EE90,stroke:#006400;
    classDef external fill:#FFE4B5,stroke:#CD853F;
    classDef db fill:#FFDEAD,stroke:#DAA520,shape:cylinder;
    classDef infra fill:#D3D3D3,stroke:#696969;
    classDef metadata fill:#FFFACD,stroke:#BDB76B;
```
