# wjidea/defusion architecture

> Architecture diagram of the GitHub repository wjidea/defusion, 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/wjidea/defusion
- Repository: https://github.com/wjidea/defusion

## Overview

##### Project type and purpose
- This is an open-source, Python-based CLI pipeline (“deFusion”) whose sole purpose is to untangle fused gene predictions produced by the MAKER genome annotation suite.
- It orchestrates a linear set of steps (detect fused genes, extract them, prepare FASTA, re-run MAKER, generate a report) by invoking internal modules and the external MAKER tool.

##### File structure
- Top-level modules:
- defusion/1_detect_fused_gene.py through 5_generate_report.py – each implements one pipeline stage
- defusion/utility_functions.py & sync_gff_fasta.py – reusable routines and GFF/FASTA synchronization logic
- setup.py & requirements.txt – packaging and dependency declaration
- docs/ – Sphinx documentation (installation, file formats, tutorial)
- tests/ – unit tests covering basic and advanced cases
- Build/deployment artifacts: Makefile (to run the pipeline or build docs), LICENSE, demo_file.tgz

##### Pull architecture hints from README
- It calls out an external dependency: MAKER.

a. Main components
1. Input Data Layer
– Raw annotation files (.gff, .fasta)
2. Pipeline Modules (core library + CLI scripts)
– DetectFusedGenes
– ExtractToMaker
– ProcessFasta
– RunMakerStandard
– GenerateReport
– UtilityFunctions & GffFastaSync (shared code)
3. External Tool
– MAKER (invoked by RunMakerStandard)
4. Output Data Layer
– Final annotation GFF, FASTA, HTML/CSV report
5. Supporting Components
– Tests suite (unit tests)
– Documentation (Sphinx)

b. Relationships and data flow
[Input Files] → 1_detect_fused_gene → 2_extract_to_maker → 3_process_fasta → 4_run_maker_standard → 5_generate_report → [Final Output Files]

c. Architectural patterns & design principles
- Pipeline pattern: each script = one stage, clear hand-off by files
- Modularization: reusable utilities factored out
- CLI-driven: each module exposes a command-line interface
- File-based integration: no database layer, pure file I/O

d. Key technologies & libraries
- Language: Python
- Packaging: setuptools (setup.py), requirements.txt
- External tool: MAKER
- Testing: pytest/unittest (tests/test_*.py)
- Documentation: Sphinx (docs/)

##### Final pointers
- Be very detailed: capture each script as its own component, don’t lump everything into “backend.”
- Keep it simple and linear—this is a pure pipeline, not a microservice mesh.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Data Layer
    InputData["Input Data<br/>.gff /.fasta"]:::data

    %% Pipeline Stages
    subgraph "Pipeline Stages"
        direction TB
        D1["1_detect_fused_gene.py"]:::pipeline
        D2["2_extract_to_maker.py"]:::pipeline
        D3["3_process_fasta_file.py"]:::pipeline
        D4["4_run_maker_standard.py"]:::pipeline
        D5["5_generate_report.py"]:::pipeline
    end

    %% Shared Utilities
    subgraph "Shared Utilities"
        direction TB
        U1["utility_functions.py"]:::util
        U2["sync_gff_fasta.py"]:::util
    end

    %% External Tool
    MAKER["MAKER"]:::ext

    %% Output Data Layer
    OutputData["Final Output<br/>GFF / FASTA / Report"]:::data

    %% Documentation and Tests
    subgraph "Supporting"
        direction TB
        Docs["Documentation (Sphinx)"]:::docs
        Tests["Tests Suite"]:::tests
        subgraph "Packaging & Deployment"
            direction TB
            Setup["setup.py"]:::pkg
            Reqs["requirements.txt"]:::pkg
            MakefileNode["Makefile"]:::pkg
        end
    end

    %% Connections
    InputData -->|".gff /.fasta"| D1
    D1 -->|".gff (fused genes)"| D2
    D2 -->|".fasta to process"| D3
    D3 -->|".fasta"| D4
    D4 -->|".gff /.fasta"| D5
    D5 -->|"report.html /.csv"| OutputData

    %% Shared utilities dependencies
    D1 -.->|uses| U1
    D2 -.->|uses| U1
    D3 -.->|uses| U1
    D4 -.->|uses| U1
    D5 -.->|uses| U1

    D1 -.->|sync| U2
    D2 -.->|sync| U2
    D3 -.->|sync| U2
    D4 -.->|sync| U2
    D5 -.->|sync| U2

    %% External tool invocation
    D4 -.->|invokes| MAKER

    %% Click Events
    click D1 "https://github.com/wjidea/defusion/blob/master/defusion/1_detect_fused_gene.py"
    click D2 "https://github.com/wjidea/defusion/blob/master/defusion/2_extract_to_maker.py"
    click D3 "https://github.com/wjidea/defusion/blob/master/defusion/3_process_fasta_file.py"
    click D4 "https://github.com/wjidea/defusion/blob/master/defusion/4_run_maker_standard.py"
    click D5 "https://github.com/wjidea/defusion/blob/master/defusion/5_generate_report.py"
    click U1 "https://github.com/wjidea/defusion/blob/master/defusion/utility_functions.py"
    click U2 "https://github.com/wjidea/defusion/blob/master/defusion/sync_gff_fasta.py"
    click Docs "https://github.com/wjidea/defusion/tree/master/docs/"
    click Tests "https://github.com/wjidea/defusion/tree/master/tests/"
    click Setup "https://github.com/wjidea/defusion/blob/master/setup.py"
    click Reqs "https://github.com/wjidea/defusion/blob/master/requirements.txt"
    click MakefileNode "https://github.com/wjidea/defusion/tree/master/Makefile"

    %% Styles
    classDef pipeline fill:#ADD8E6,stroke:#000;
    classDef data fill:#98FB98,stroke:#000;
    classDef util fill:#FFA500,stroke:#000;
    classDef ext fill:#D3D3D3,stroke:#000,stroke-dasharray: 5 5;
    classDef docs fill:#FFE4B5,stroke:#000;
    classDef tests fill:#E6E6FA,stroke:#000;
    classDef pkg fill:#F0E68C,stroke:#000;
```
