###############################################################
###############################################################
##--------------------------------------------------------------
##--------------------------------------------------------------
library(dplyr) library(tidyverse) library(ggplot2) library(ggrepel) library(patchwork) library(ggpubr)
library(Seurat) library(SeuratObject) library(glmGamPoi)
library(clusterProfiler) library(org.Mm.eg.db) library(DOSE) library(enrichR)
library(tibble) library(stringr) library(openxlsx) library(writexl) library(parallel) library(future) library(CellChat) library(monocle3) library(Nebulosa) library(pheatmap)
library(devtools)
##--------------------------------------------------------------
##--------------------------------------------------------------
tables_dir <- file.path(getwd(), "results", "tables") figures_dir <- file.path(getwd(), "results", "figures")
dir.create(tables_dir, recursive = TRUE, showWarnings = FALSE) dir.create(figures_dir, recursive = TRUE, showWarnings = FALSE)
##Check directory cat("Working directory:", getwd(), "\n") cat("Results directories initialized.\n")
##--------------------------------------------------------------
##--------------------------------------------------------------
base_path <- "/home/deekshas/R/7.R DATA and Scripts/Burness Data"
pymt_paths <- file.path(base_path, "PYMT DATA", paste0("11529-CH-", 1:6, "_sample_filtered_feature_bc_matrix"))
d2a1_paths <- file.path(base_path, "D2A1_CT1", paste0("11529-CH-", 7:12, "_sample_filtered_feature_bc_matrix"))
create_obj <- function(path) { CreateSeuratObject(counts = Read10X(data.dir = path)) }
all_paths <- c(pymt_paths, d2a1_paths) seurat_list <- lapply(all_paths, create_obj)
sample_names <- paste0("obj", seq_along(seurat_list)) names(seurat_list) <- sample_names
##--------------------------------------------------------------
##--------------------------------------------------------------
merged_samples <- merge( x = seurat_list[[1]], y = seurat_list[-1], add.cell.ids = sample_names )
cat("✅ Merged", length(seurat_list), "samples into one Seurat object.\n") print(merged_samples)
saveRDS(merged_samples, file = "all_1-merged-object.RDS")
merged_samples <- readRDS("all_1-merged-object.RDS")
##--------------------------------------------------------------
##--------------------------------------------------------------
obj <- JoinLayers(merged_samples)
rm(list = sample_names) gc() # Run garbage collection
saveRDS(obj, file = "all_1-joint-object.RDS")
obj <- readRDS("all_1-joint-object.RDS")
##--------------------------------------------------------------
##--------------------------------------------------------------
rownames(obj[[]]) # View structure sample.by.barcode <- word(rownames(obj[[]]), start = 1, end = 1, sep = fixed("_"))
obj$sample <- sample.by.barcode
cell.line <- rep(NA, length(sample.by.barcode)) cell.line[sample.by.barcode %in% paste0("11529-CH-", 1:6)] <- "PYMT" cell.line[sample.by.barcode %in% paste0("11529-CH-", 7:12)] <- "D2A1"
obj$cell_line <- cell.line
treatment <- rep(NA, length(sample.by.barcode)) treatment[sample.by.barcode %in% c("11529-CH-1", "11529-CH-2", "11529-CH-3", "11529-CH-7", "11529-CH-8", "11529-CH-9")] <- "Vehicle" treatment[sample.by.barcode %in% c("11529-CH-4", "11529-CH-5", "11529-CH-6", "11529-CH-10", "11529-CH-11", "11529-CH-12")] <- "ZBC260"
obj$treatment <- treatment
##--------------------------------------------------------------
##--------------------------------------------------------------
saveRDS(obj, file = "D2A1plus_PYMT_1-merged-object.RDS")
cat("✅ Final Seurat object saved with metadata annotations.\n")
print(obj) head(obj@meta.data)