# panchyni/time_and_dose architecture

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

- Interactive diagram: https://gitdiagram.com/panchyni/time_and_dose
- Repository: https://github.com/panchyni/time_and_dose

## Overview

##### Project Type and Purpose
- Type: A data analysis pipeline in R for bioinformatics.
- Purpose: Sequential processing steps for single-cell sequencing and dose/time experiments leading to survival analysis (Cox models). It integrates steps for single-cell processing (using Seurat), visualization (UMAPs, bubble plots), statistical differential expression, and lastly, survival modeling using TCGA data and Cox regression techniques.

##### Analysis of the File Structure
- The top-level contains a README and a legacy Time_and_Dose.zip (first version) plus a main folder (Time_and_Dose_v2) that holds all current scripts.
- Scripts are numbered (0, 1a, 1b, 1c, … through 7) reflecting the sequential nature of the pipeline. Each script deals with a distinct analytical component:
- “0_… scripts”: Process single-cell data using Seurat (both integrated and non-integrated approaches).
- “1_…” scripts: Process dose and time data and merge/integrate these datasets.
- “3_…” scripts: Perform anticorrelation analyses.
- “4_…” scripts: Create bubble plots and conduct tests on principal components.
- “5_…”: Handle differential expression analysis.
- “6_…”: Prepare data for Cox modeling.
- “7_…”: Execute supplementary analyses (e.g., overlap checks, immune response, doublet checks).
- The CoxModels_Updated folder groups scripts, data files, and supplementary code for running multi-cancer Cox models along with the get_dataset utilities for pulling TCGA data.
- Additional archives and support files (e.g., DropOutGeneSets.zip, EMTGeneUpdate3.txt) likely serve as reference resources for the analysis.

a. Main Components:
- Data Input Layer:
- Raw single-cell sequencing data (obtained externally from GEO; not included due to size limitations).
- Dose/time raw experimental data.
- TCGA data retrieval (via get_dataset scripts).
- Preprocessing and Integration Module:
- Single-cell data processing with Seurat (scripts 0X, 0, etc.).
- Dose and Time data processing (scripts 1a, 1b, 1c).
- Visualization and Analytical Modules:
- Visualization and dimension reduction (UMAPs, boxplots from scripts 2a–2c).
- Anticorrelation analysis (scripts 3a–3o).
- Bubble plot generation and testing (scripts in 4 series).
- Differential expression analysis (script 5 series).
- Model Preparation & Cox Modeling:
- Data preparation for survival analysis (script 6).
- Survival model building (scripts within CoxModels_Updated, including multi-threading versions, get_dataset preparations, and RunCoxModel scripts).
- Output & Archive Layer:
- Final models, figures and analysis results that will be used in publications or further research.

b. Relationships and Interactions:
- The pipeline is sequential: output from one component feeds into the next.

c. Architectural Patterns:
- Pipeline/Sequential Processing: Since scripts are designed to run in a specific order (0 to 7, then CoxModels_Updated), arrange the components in a linear flow.

d. Relevant Technologies and Frameworks:
- R and Rscript: The primary language and runtime environment.
- Seurat: Used for single-cell analysis.
- Standard plotting libraries in R (for UMAP, bubble plots, boxplots).
- Multithreading components in R (as evidenced by scripts in the CoxModels_Updated directory).
- Integration with external data sources (GEO and TCGA).

- Components/Modules: Data Input, Single-Cell Processing (Seurat), Dose/Time Data Integration, Visualization (UMAPs/Boxplots/Bubble Plots), Differential Expression Analysis, and finally Cox Modeling.

##### Final Advice
- Don’t shy away from isolating every script stage, especially given the multiple R scripts in Time_and_Dose_v2 and CoxModels_Updated. Showing at least a high-level breakdown of each stage will provide a thorough view of the pipeline.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Data Input Layer
    subgraph "1. Data Input Layer"
        A1["Raw Experimental Data"]
        A2["External Data Retrieval (GEO/TCGA)"]
    end

    %% Preprocessing and Integration Module
    subgraph "2. Preprocessing and Integration"
        subgraph "Single-Cell Processing"
            B1["Seurat Integration"]
            B2["Seurat Non-Integrated Processing"]
            B3["Seurat Merge (Non-Integrated)"]
        end
        subgraph "Dose/Time Data Processing"
            C1["Dose Data Processing"]
            C2["Time Data Processing"]
            C3["Integrated Dose/Time Data Processing"]
        end
    end

    %% Visualization and Analytical Modules
    subgraph "3. Visualization and Analytical Modules"
        subgraph "Visualization: UMAPs, Boxplots and Bubble Plots"
            D1["Dose UMAPs & Boxplots"]
            D2["Integration UMAPs & Boxplots"]
            D3["Dose/Integration Comparison"]
            D4["Bubble Plot Generation"]
            D5["Principal Components Testing"]
        end
        subgraph "Anticorrelation Analysis"
            E1["Anticorrelation Analysis M1"]
            E2["Anticorrelation Analysis M2"]
            E3["Anticorrelation Analysis (TimeDose)"]
            E4["Anticorrelation Prep"]
        end
        subgraph "Differential Expression Analysis"
            F1["Differential Expression Analysis"]
            F2["Combined Bubble Figure"]
        end
    end

    %% Model Preparation Module
    subgraph "4. Model Preparation & Cox Modeling"
        G1["Cox Model Data Preparation"]
    end

    %% Supplementary Analyses
    subgraph "5. Supplementary Analyses"
        H1["Time vs Dose Overlap"]
        H2["Dose Without Cell Cycle"]
        H3["Immune Response"]
        H4["Check Dose Doublets"]
        H5["Check Time Doublets"]
    end

    %% Cox Modeling & Multi-Cancer Survival Analysis
    subgraph "6. Cox Modeling & Multi-Cancer Survival Analysis"
        subgraph "Cox Modeling Code"
            I1["cox_model.R"]
            I2["cox_model.R (Multithreading)"]
            I3["tcga_replicateFilter.R"]
        end
        subgraph "Cox Modeling Run Scripts"
            I4["RunCoxModels_Quads_Con_Limit10_LogP1_Alt"]
            I5["RunCoxModels_Quads_Limit10_LogP1_Alt"]
            I6["RunCoxModels_Quads_Time_Limit10_LogP1_Alt"]
        end
        subgraph "TCGA Data Retrieval"
            I7["get_dataset Scripts"]
        end
    end

    %% Output & Archive
    subgraph "7. Output & Archive"
        J1["Final Models, Figures and Results"]
        subgraph "Reference & Resources"
            J2["Dropout Gene Sets Archive"]
            J3["EMT Gene Reference"]
            J4["CBC_GBC Summary"]
            J5["Legacy Project Archive"]
            J6["Configuration Utility Script"]
        end
    end

    %% Connections for Sequential Data Flow
    A1 --> B1
    A2 --> C1
    B1 --> D1
    C1 --> D1
    D1 --> G1
    E1 --> G1
    F1 --> G1
    G1 --> H1
    H1 --> I1
    A2 --> I7
    I1 --> J1

    %% Additional connections inside modules (optional for clarity)
    B2 --> D1
    B3 --> D1
    C2 --> D1
    C3 --> D1
    D2 --> D1
    D3 --> D1
    D4 --> D5
    E2 --> E1
    E3 --> E1
    E4 --> E1
    F2 --> F1
    I2 --> I1
    I3 --> I1
    I4 --> I1
    I5 --> I1
    I6 --> I1

    %% Styles
    class A1,A2 input
    class B1,B2,B3,C1,C2,C3 preprocess
    class D1,D2,D3,D4,D5,E1,E2,E3,E4,F1,F2 viz
    class G1 modelprep
    class H1,H2,H3,H4,H5 supp
    class I1,I2,I3,I4,I5,I6,I7 modeling
    class J1,J2,J3,J4,J5,J6 output

    %% Class Definitions with Colors
    classDef input fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef preprocess fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef viz fill:#cfe2ff,stroke:#084298,stroke-width:2px;
    classDef modelprep fill:#e2e3e5,stroke:#41464b,stroke-width:2px;
    classDef supp fill:#f8d7da,stroke:#842029,stroke-width:2px;
    classDef modeling fill:#dbeafe,stroke:#1e40af,stroke-width:2px;
    classDef output fill:#d1c4e9,stroke:#512da8,stroke-width:2px;

    %% Click Events for Data Input
    click A1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/data_KazuConcentraiton/KazuConcentration_GBC_annotation_Samples.csv"
    click A2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/CoxModels_Updated/get_dataset_*.R"

    %% Click Events for Single-Cell Processing
    click B1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/0_Process_SingleCellSeurat_Integration_v2CC.R"
    click B2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/0_Process_SingleCellSeurat_NoIntegration_v2CC.R"
    click B3 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/0X_Process_SingleCellSeurat_NOIntegrationMergeData_v2CC.R"

    %% Click Events for Dose/Time Data Processing
    click C1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/1a_ProcessDoseData.R"
    click C2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/1b_ProcessTimeData.R"
    click C3 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/1c_ProcessIntegratedData_Server_V2.R"

    %% Click Events for Visualization Modules
    click D1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/2a_Dose_UMAPS_Boxplots_Progression.R"
    click D2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/2b_Integration_UMAPs_Boxplots_Progression.R"
    click D3 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/2c_Compare_Dose_and_Integration.R"
    click D4 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/4_BubblePlots.R"
    click D5 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/4a_TestRecalcPCs_Server.R"

    %% Click Events for Anticorrelation Analysis
    click E1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/3a_EMAnticorrelation_M1.R"
    click E2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/3b_EMAnticorrelation_M2.R"
    click E3 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/3c_EMAnticorrelation_acrossTimeDose.R"
    click E4 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/3o_EMAnticorrelation_Prep.R"

    %% Click Events for Differential Expression Analysis
    click F1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/5_DifferentialExpression.R"
    click F2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/5b_CombinedBubbleFigure.R"

    %% Click Event for Model Preparation
    click G1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/6_PrepCoxModelData.R"

    %% Click Events for Supplementary Analyses
    click H1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/7_suppX1_Time_vs_Dose_Overlap.R"
    click H2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/7_suppX2_DoseWithoutCellCycle.R"
    click H3 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/7_suppX3_ImmuneResponse.R"
    click H4 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/7_suppX4_CheckDoseDoublets.R"
    click H5 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/7_suppX4_CheckTimeDoublets.R"

    %% Click Events for Cox Modeling & Multi-Cancer Survival Analysis
    click I1 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/CoxModels_Updated/Code/cox_model.R"
    click I2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/CoxModels_Updated/Code/mutlithreading_nonwindows/cox_model.R"
    click I3 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/CoxModels_Updated/Code/tcga_replicateFilter.R"
    click I4 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/CoxModels_Updated/RunCoxModels_Quads_Con_Limit10_LogP1_Alt.R"
    click I5 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/CoxModels_Updated/RunCoxModels_Quads_Limit10_LogP1_Alt.R"
    click I6 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/CoxModels_Updated/RunCoxModels_Quads_Time_Limit10_LogP1_Alt.R"
    click I7 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/CoxModels_Updated/get_dataset_*.R"

    %% Click Events for Reference & Resources
    click J2 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/DropOutGeneSets.zip"
    click J3 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/EMTGeneUpdate3.txt"
    click J4 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/GBCannot/CBC_GBC_summary.txt.alt_names"
    click J5 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose.zip"
    click J6 "https://github.com/panchyni/time_and_dose/blob/master/Time_and_Dose_v2/NonOverlappingReplacement.R"
```
