# joon-klaps/viralgenie architecture

> Architecture diagram of the GitHub repository joon-klaps/viralgenie, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joon-klaps/viralgenie
- Repository: https://github.com/joon-klaps/viralgenie

## Overview

##### Main Components Identification

The system should be divided into these major components:
- Input Processing Layer
- Quality Control Layer
- Metagenomic Analysis Layer
- Assembly and Clustering Layer
- Mapping and Variant Analysis Layer
- Consensus Generation Layer
- Quality Assessment Layer
- Output Generation Layer

**Input → QC → Processing Branches → Output**

##### Key Relationships to Highlight

Create connection points showing:
- Data flow between components
- Optional workflow branches
- Parallel processing capabilities
- Input/Output relationships
- Database interactions

##### Specific Implementation Details

a) Input Section:
- Fastq file input handling
- Samplesheet processing
- Configuration validation

b) Processing Workflows:
- Read QC (FastQC)
- Pre-processing branch (fastp, Trimmomatic, HUMID)
- Metagenomic analysis (Kraken2, Bracken, Kaiju)
- Assembly processes (SPAdes, TRINITY, megahit)
- Clustering and scaffolding
- Variant calling (BCFTools, iVar)

c) Output Section:
- MultiQC reports
- Consensus sequences
- Variant calls
- Quality metrics

##### Technical Details

Integration with:
- Nextflow execution engine
- Container systems (Docker/Singularity)
- External databases
- Resource management

##### Implementation Notes

- Maintain consistent spacing and alignment
- Version information
- Document external dependencies
- Parallel execution paths

Remember to highlight the pipeline's key features:
- Flexible input handling
- Parallel processing capabilities
- Multiple tool options for each step
- Quality control integration
- Results aggregation and reporting

This will provide a clear understanding of the pipeline's architecture while maintaining the necessary detail for implementation and maintenance.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef input fill:#a8d1f0,stroke:#000
    classDef qc fill:#90EE90,stroke:#000
    classDef meta fill:#FFE5B4,stroke:#000
    classDef assembly fill:#FFD700,stroke:#000
    classDef variant fill:#DDA0DD,stroke:#000
    classDef output fill:#D3D3D3,stroke:#000
    classDef consensus fill:#FFA07A,stroke:#000
    classDef quality fill:#98FB98,stroke:#000

    %% Input Layer
    subgraph Input
        I1["Input Files"]:::input
        I2["Samplesheet"]:::input
        I3["Configuration"]:::input
    end
    click I2 "https://github.com/Joon-Klaps/viralgenie/blob/dev/assets/samplesheets/samplesheet.csv"
    click I1 "https://github.com/Joon-Klaps/viralgenie/blob/dev/assets/schemas/input.json"

    %% Quality Control Layer
    subgraph QC
        Q1["FastQC"]:::qc
        Q2["Trimmomatic"]:::qc
        Q3["UMITools"]:::qc
    end
    click Q1 "https://github.com/Joon-Klaps/viralgenie/blob/dev/modules/nf-core/fastqc/main.nf"
    click Q2 "https://github.com/Joon-Klaps/viralgenie/blob/dev/modules/nf-core/trimmomatic/main.nf"
    click QC "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/fastq_fastqc_umitools_trimmomatic.nf"

    %% Metagenomic Analysis Layer
    subgraph Meta
        M1["Kraken2"]:::meta
        M2["Kaiju"]:::meta
        M3["Bracken"]:::meta
    end
    click M1 "https://github.com/Joon-Klaps/viralgenie/blob/dev/modules/nf-core/kraken2/kraken2/main.nf"
    click M2 "https://github.com/Joon-Klaps/viralgenie/blob/dev/modules/nf-core/kaiju/kaiju/main.nf"
    click Meta "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/fastq_kraken_kaiju.nf"

    %% Assembly Layer
    subgraph Assembly
        A1["SPAdes"]:::assembly
        A2["Trinity"]:::assembly
        A3["Megahit"]:::assembly
        A4["Contig Clustering"]:::assembly
    end
    click A1 "https://github.com/Joon-Klaps/viralgenie/blob/dev/modules/nf-core/spades/main.nf"
    click A2 "https://github.com/Joon-Klaps/viralgenie/blob/dev/modules/nf-core/trinity/main.nf"
    click Assembly "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/fastq_assembly.nf"
    click A4 "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/fasta_contig_clust.nf"

    %% Mapping and Variant Analysis
    subgraph Variants
        V1["BCFTools"]:::variant
        V2["iVar"]:::variant
        V3["Read Mapping"]:::variant
    end
    click V1 "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/bam_variants_bcftools.nf"
    click V2 "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/bam_variants_ivar.nf"
    click V3 "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/map_reads.nf"

    %% Consensus Generation
    subgraph Consensus
        C1["BAM Consensus"]:::consensus
        C2["Iterative Consensus"]:::consensus
        C3["Map Consensus"]:::consensus
    end
    click C1 "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/bam_call_consensus.nf"
    click C2 "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/fastq_fasta_iterative_consensus.nf"
    click C3 "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/fastq_fasta_map_consensus.nf"

    %% Quality Assessment
    subgraph Quality
        QA1["MultiQC"]:::quality
        QA2["Consensus QC"]:::quality
    end
    click QA1 "https://github.com/Joon-Klaps/viralgenie/blob/dev/modules/local/custom_multiqc/main.nf"
    click QA2 "https://github.com/Joon-Klaps/viralgenie/blob/dev/subworkflows/local/consensus_qc.nf"

    %% Output Generation
    subgraph Output
        O1["Reports"]:::output
        O2["Email Templates"]:::output
        O3["Results Tables"]:::output
    end
    click O2 "https://github.com/Joon-Klaps/viralgenie/blob/dev/assets/email_template.html"
    click O3 "https://github.com/Joon-Klaps/viralgenie/blob/dev/assets/custom_table_headers.yml"

    %% Connections
    I1 & I2 & I3 --> QC
    QC --> Meta
    QC --> Assembly
    Assembly --> Variants
    Meta --> Variants
    Variants --> Consensus
    Consensus --> Quality
    Quality --> Output

    %% Legend
    subgraph Legend
        L1["Input/Output"]:::input
        L2["Quality Control"]:::qc
        L3["Metagenomic Analysis"]:::meta
        L4["Assembly"]:::assembly
        L5["Variant Analysis"]:::variant
        L6["Consensus Generation"]:::consensus
        L7["Quality Assessment"]:::quality
    end
```
