# eddiejosef/protein_structure_prediction architecture

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

- Interactive diagram: https://gitdiagram.com/eddiejosef/protein_structure_prediction
- Repository: https://github.com/eddiejosef/protein_structure_prediction

## Overview

##### Main Components
- Input Data: The “input” directory which houses FASTA files.
- Workflow Orchestrator: The Snakemake pipeline (with the Snakefile, snake_env.yml, and associated logs) that drives the process.
- Environment Setup: Docker image (as defined in Dockerfile and the installation instructions) and the Conda environment (configured via snake_env.yml and setup_env.sh).
- LocalColabFold Pipeline: The part of the workflow handling AI-based structure prediction—this component takes the FASTA inputs, executes colabfold_batch (with parameters like recycling iterations, ensemble evaluation, AMBER refinement, etc.), and produces outputs in output/colab_fold_output.
- MODELLER Pipeline: This consists of several interconnected scripts (e.g., align2d.py, build_profile.py, convert_fasta.sh, fix_template.py, modeller_automodel.py, and associated shell scripts like split.sh) used for template-based homology modeling. Its outputs (organized in output/modeller_output) include alignments, multiple intermediate PDB models, scoring logs, and the final structure after rotamer sampling.
- Logging and Reports: Various log files (snakemake_full.log, run_colab_fold.log, and individual logs inside output folders) along with detailed analysis reports and theoretical documentation.

##### Relationships and Interactions
- Data Flow: Start with FASTA file input → then parallel processing by the two pipelines.
- Workflow Coordination: Snakemake acts as the “glue” orchestrating execution of modules/shell scripts, Python programs, and dependency setups (through Conda and Docker).
- Environment Dependencies: Docker encapsulates the full workflow while the Conda environment ensures all scripts have needed dependencies.
- Component Interaction:
- The Snakemake engine schedules tasks that invoke LocalColabFold and MODELLER tools.
- In the MODELLER branch, there is an internal sequence: file splitting → conversion of FASTA to .ali → template ranking and PDB download → fixing the template → alignment → 3D modeling and rotamer sampling.
- In the ColabFold branch, FASTA files lead to sequence alignments, prediction outputs (including predicted aligned error JSON, relaxed/unrelaxed PDBs), and per-sample output directories.
- Output Aggregation: The two pipelines organize their results into structured subdirectories under “output”, making it easier to verify results.

##### Architectural Patterns and Technologies
- Modular Pipeline Design: The separation between LocalColabFold and MODELLER pipelines emphasizes modularity and parallel processing.
- Automation and Reproducibility: Using Snakemake to manage dependency graph and execution, ensuring scalability (multiple FASTA files) and reproducibility.
- Containerization: Docker is used to package the entire environment, with additional Conda configurations ensuring the correct versions of libraries are installed.
- Scripting Mix: A combination of shell (Bash) scripts and Python tools (with specific scripts for data preparation & model building) is used to tie together the workflow’s pieces.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: Environment Setup and Input
    Environment["Docker/Conda Environment"]:::env
    InputData["Input FASTA Files"]:::input

    %% Middle Layer: Workflow Orchestration
    Workflow["Snakemake Orchestration"]:::orchestrator

    %% Connect Environment and Input to Workflow
    Environment -->|"Sets up dependencies"| Workflow
    InputData -->|"Provides sequence data"| Workflow

    %% Middle Layer: Branching into two parallel pipelines
    Workflow -->|"Schedules task"| LocalColabFold["LocalColabFold Pipeline"]:::pipeline
    Workflow -->|"Schedules task"| MODELLER["MODELLER Pipeline"]:::pipeline

    %% LocalColabFold Details Subgraph
    subgraph "LocalColabFold Details"
        direction TB
        C1["Sequence Alignments"]:::step
        C2["Prediction with colabfold_batch (recycling,ensemble,AMBER_ref)"]:::step
        C3["Per-sample Organized Output"]:::step
        C1 --> C2
        C2 --> C3
    end
    LocalColabFold --> C1
    C3 -->|"Generates"| ColabFoldOutput["ColabFold Outputs"]:::output

    %% MODELLER Details Subgraph
    subgraph "MODELLER Details"
        direction TB
        M1["File Splitting (split.sh)"]:::step
        M2["FASTA Conversion (convert_fasta.sh)"]:::step
        M3["Template Ranking & PDB Download"]:::step
        M4["Template Fixing (fix_template.py)"]:::step
        M5["Alignment (align2d.py)"]:::step
        M6["3D Modeling & Rotamer Sampling (modeller_automodel.py)"]:::step
        M1 --> M2
        M2 --> M3
        M3 --> M4
        M4 --> M5
        M5 --> M6
    end
    MODELLER --> M1
    M6 -->|"Generates"| ModellerOutput["MODELLER Outputs"]:::output

    %% Logging & Reports (aggregated from all components)
    Workflow -.->|"Logs: snakemake_full.log"| Logging["Logging & Reports"]:::logging
    LocalColabFold -.->|"Logs: run_colab_fold.log & others"| Logging
    MODELLER -.->|"Detailed logs in output"| Logging

    %% Click Events
    click InputData "https://github.com/eddiejosef/protein_structure_prediction/tree/master/input/"
    click Workflow "https://github.com/eddiejosef/protein_structure_prediction/tree/master/Snakefile"
    click Environment "https://github.com/eddiejosef/protein_structure_prediction/tree/master/Dockerfile"
    click LocalColabFold "https://github.com/eddiejosef/protein_structure_prediction/tree/master/output/colab_fold_output/"
    click MODELLER "https://github.com/eddiejosef/protein_structure_prediction/tree/master/modeller/"
    click ModellerOutput "https://github.com/eddiejosef/protein_structure_prediction/tree/master/output/modeller_output/"
    click Logging "https://github.com/eddiejosef/protein_structure_prediction/tree/master/.snakemake/log/"

    %% Styles
    classDef env fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef input fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef orchestrator fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#d1ecf1,stroke:#333,stroke-width:2px;
    classDef step fill:#e2eafc,stroke:#333,stroke-width:1px;
    classDef output fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef logging fill:#e2e3e5,stroke:#333,stroke-width:2px;
```
