# mseidelfed/cosnet_i architecture

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

- Interactive diagram: https://gitdiagram.com/mseidelfed/cosnet_i
- Repository: https://github.com/mseidelfed/cosnet_i

## Overview

##### Project Type and Purpose
- COSNeti is a scientific data-analysis pipeline implemented in Python. It integrates omics data into spatial interactomes derived from cryo-EM or crystallographic structures (mmCIF files) of multiprotein complexes. Its primary use case is to identify regions within a protein complex that are significantly altered under different experimental conditions via random‐walk network analysis.

##### Key Architectural Components
a. Data Layer
- Input files:
- mmCIF structures (Data/*.cif)
- Name and significance text files (Data/*.txt, Data/significance_file_*)
- These are static, versioned sample data for pipeline validation and examples.
b. Pre‐processing Modules
- check_cif_completeness.py
- reindex_pdb.py / batch_reindex_pdb.py
- split_cif_by_entity.py
- extract_sequence.py
These scripts validate and normalize raw mmCIFs, split by chain/entity, and pull sequence data.
c. Distance and Contact Computation
- calculate_distance.py / batch_calc_dist.py
- contacts_from_dist.py
These compute pairwise atom/residue distances and identify physical contacts to build graph edges.
d. Network Construction & Analysis
- intcryomics.py (builds interaction network annotated with experimental changes)
- pimp_my_network.py (enhances network attributes, e.g., weights)
- Region_selection_infomap.py (runs random‐walk/Infomap community detection)
- intcryomics_sigassign.py (assigns significance metrics to detected regions)
e. Batch Workflow Orchestration
- Python_Modules/batch_*.py invoke each step across multiple input sets.
f. Packaging & CLI
- cosneti/pyproject.toml & setup.cfg define the installable package “cosneti.”
- cosneti/src/modules mirror Python_Modules scripts as importable functions.
- USAGE.md documents CLI commands and recommended invocation order.
g. Outputs & Visualization
- Text reports, network files (e.g., GraphML), significance summaries

##### Relationships & Data Flow
- Data Input → Pre‐processing → Distance Computation → Network Construction → Community Detection → Significance Assignment → Output Reports
- Batch scripts wrap the linear pipeline for high‐throughput runs.
- The cosneti package provides a programmatic API for each module, enabling users to build custom pipelines or integrate into larger workflows.

##### Architectural Patterns & Principles
- Pipeline / ETL (Extract-Transform-Load) pattern: each script/module transforms data and passes it downstream.
- Modular design: independent, single-responsibility scripts that can be invoked in series or in batch.
- Layered packaging: top-level scripts for quick runs; cosneti package for importable modules.
- Separation of concerns: data validation, computation, network analysis, and reporting are distinct steps.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data Layer"
        Data["Data Folder"]:::data
    end

    %% Pre-processing Modules
    subgraph "Pre-processing" 
        CCI_S["check_cif_completeness.py"]:::pre
        REI_S["reindex_pdb.py"]:::pre
        SPL_S["split_cif_by_entity.py"]:::pre
        EXT_S["extract_sequence.py"]:::pre
    end

    %% Distance & Contact Computation
    subgraph "Distance & Contact Computation"
        CALC_S["calculate_distance.py"]:::compute
        BATCH_DIST["batch_calc_dist.py"]:::compute
        CONT_S["contacts_from_dist.py"]:::compute
    end

    %% Network Construction & Enhancement
    subgraph "Network Analysis"
        INT_S["intcryomics.py"]:::analysis
        PIMP_S["pimp_my_network.py"]:::analysis
    end

    %% Community Detection & Significance
    subgraph "Community & Significance"
        REG_S["Region_selection_infomap.py"]:::analysis
        SIG_S["intcryomics_sigassign.py"]:::analysis
    end

    %% Outputs
    subgraph "Outputs & Visualization"
        Reports["Reports & GraphML"]:::output
        Images["images/"]:::output
    end

    %% Packaging & CLI
    subgraph "Packaging & CLI"
        Metadata["pyproject.toml / setup.cfg"]:::cli
        Usage["USAGE.md"]:::cli
        Dist["cosneti/dist/"]:::cli
    end

    %% Batch Workflow Orchestration
    Batch["Batch Workflow (batch_*.py)"]:::cli

    %% cosneti package boundary
    subgraph "cosneti Package"
        CCI_P["check_cif_completeness.py"]:::pre
        REI_P["reindex_pdb.py"]:::pre
        BATCH_REI_P["batch_reindex_pdb.py"]:::pre
        SPL_P["split_cif_by_entity.py"]:::pre
        EXT_P["extract_sequence.py"]:::pre
        CALC_P["calculate_distance.py"]:::compute
        BATCH_DIST_P["batch_calc_dist.py"]:::compute
        CONT_P["contacts_from_dist.py"]:::compute
        INT_P["intcryomics.py"]:::analysis
        PIMP_P["pimp_my_network.py"]:::analysis
        SIG_P["intcryomics_sigassign.py"]:::analysis
    end

    %% Data flow
    Data --> CCI_S --> REI_S --> SPL_S --> EXT_S --> CALC_S --> CONT_S --> INT_S --> PIMP_S --> REG_S --> SIG_S --> Reports
    Reports --> Images

    %% Batch orchestration loop
    Batch -.-> CCI_S
    SIG_S -.-> Batch

    %% Dual access via package
    CCI_S --- CCI_P
    REI_S --- REI_P
    REI_S --- BATCH_REI_P
    SPL_S --- SPL_P
    EXT_S --- EXT_P
    CALC_S --- CALC_P
    BATCH_DIST --- BATCH_DIST_P
    CONT_S --- CONT_P
    INT_S --- INT_P
    PIMP_S --- PIMP_P
    SIG_S --- SIG_P

    %% Packaging
    Metadata --> Dist
    Metadata --> Usage

    %% Styles
    classDef data fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef pre fill:#d0e1f9,stroke:#333,stroke-width:1px;
    classDef compute fill:#c8e6c9,stroke:#333,stroke-width:1px;
    classDef analysis fill:#ffe0b2,stroke:#333,stroke-width:1px;
    classDef output fill:#f0f0f0,stroke:#333,stroke-width:1px;
    classDef cli fill:#eeeeee,stroke:#333,stroke-width:1px;

    %% Click Events
    click Data "https://github.com/mseidelfed/cosnet_i/tree/master/Data/"
    click CCI_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/check_cif_completeness.py"
    click CCI_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/check_cif_completeness.py"
    click REI_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/reindex_pdb.py"
    click BATCH_REI_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/batch_reindex_pdb.py"
    click REI_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/reindex_pdb.py"
    click SPL_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/split_cif_by_entity.py"
    click SPL_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/split_cif_by_entity.py"
    click EXT_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/extract_sequence.py"
    click EXT_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/extract_sequence.py"
    click CALC_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/calculate_distance.py"
    click CALC_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/calculate_distance.py"
    click BATCH_DIST "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/batch_calc_dist.py"
    click BATCH_DIST_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/batch_calc_dist.py"
    click CONT_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/contacts_from_dist.py"
    click CONT_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/contacts_from_dist.py"
    click INT_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/intcryomics.py"
    click INT_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/intcryomics.py"
    click PIMP_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/pimp_my_network.py"
    click PIMP_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/pimp_my_network.py"
    click REG_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/Region_selection_infomap.py"
    click SIG_S "https://github.com/mseidelfed/cosnet_i/blob/master/Python_Modules/intcryomics_sigassign.py"
    click SIG_P "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/src/modules/intcryomics_sigassign.py"
    click Metadata "https://github.com/mseidelfed/cosnet_i/blob/master/cosneti/pyproject.toml"
    click Dist "https://github.com/mseidelfed/cosnet_i/tree/master/cosneti/dist/"
    click Usage "https://github.com/mseidelfed/cosnet_i/blob/master/USAGE.md"
```
