Commit 185b7a65 authored by Stefano Beretta's avatar Stefano Beretta
Browse files

Upload New File

parent 387c08bc
library(scRepertoire)
library(Seurat)
library(openxlsx)
library(gridExtra)
library(data.table)
library(dplyr)
library(reshape2)
library(ggrepel)
library(dittoSeq)
library(RColorBrewer)
library(scales)
library(ggalluvial)
########################
### General Settings ###
########################
# Working dir
wdir <- "squadrito_livertumor2022_scrnaseq"
# Raw data dir (download from GEO)
raw_dir <- "GEO_data"
# Results dir
out_dir <- paste(wdir, "results", sep = "/")
dir.create(path = out_dir, showWarnings = F)
samples <- c("GG-11", "GG-18", "GG-22", "GG-23", "GG-25")
vdj <- list()
for (s in samples) {
vdj[[s]] <- read.csv(file = paste(wdir, "counts", paste0(s, "_counts"), "outs",
"per_sample_outs", paste0(s, "_counts"), "vdj_t",
"filtered_contig_annotations.csv", sep = "/"),
header = T)
vdj[[s]]$barcode <- gsub(pattern = "-1", replacement = "", x = vdj[[s]]$barcode)
vdj[[s]][vdj[[s]] == "true"] <- TRUE
vdj[[s]][vdj[[s]] == "false"] <- FALSE
}
# Step 1.
combined_full <- combineTCR(vdj, ID = samples, samples = samples, cells ="T-AB")
combined_full_df <- rbind.data.frame(combined_full[[names(combined_full)[1]]], combined_full[[names(combined_full)[2]]])
for(id in names(combined_full)[3:length(names(combined_full))]){
combined_full_df <- rbind.data.frame(combined_full_df, combined_full[[id]])
}
Full_obj <- readRDS(paste(out_dir, "Full_DBR", "Full_DBR_final_DBR_labeled.rds", sep = "/"))
combined <- list()
# Creating Cellid same to expression dataset
for(id in names(combined_full)){
combined_full[[id]]$cellID <- "ND"
for (k in 1:nrow(combined_full[[id]])) {
combined_full[[id]]$cellID[k] <- paste0(combined_full[[id]]$sample[k], "_", strsplit(combined_full[[id]]$barcode[k], split = "_")[[1]][3], "-1")
}
combined[[id]] <- subset(combined_full[[id]], subset = cellID %in% Cells(Full_obj)) # subsetting with only ids
combined[[id]] <- subset(combined[[id]], subset = !is.na(TCR2)) # removing TCR2 == NA
print(paste0("Sample ",id, " final cells: ", nrow(combined[[id]]) ))
}
combined_df <- rbind.data.frame(combined[[names(combined)[1]]], combined[[names(combined)[2]]])
for(id in names(combined)[3:length(names(combined))]){
combined_df <- rbind.data.frame(combined_df, combined[[id]])
}
##### Aggregated combining the samples ######
A <- combined_df %>%
group_by(sample, cdr3_aa2) %>%
mutate(ClonoFreq = n()) %>%
group_by(sample) %>%
mutate(PctClonotype = ClonoFreq / n()*100) %>%
mutate(ClonoRel = PctClonotype / 100)
G <- as.data.frame(A)
rownames(G) <- G$cellID
write.xlsx(x = list(VDJ = G), file = paste(out_dir, "Full_DBR", "Full_DBR_freq_by_sample_cdr3_aa2.xlsx", sep = "/"))
saveRDS(G, paste(out_dir, "Full_DBR", "Full_DBR_freq_by_sample_cdr3_aa2.rds", sep = "/"))
Full_obj <- AddMetaData(object = Full_obj, metadata = G)
saveRDS(object = Full_obj, file = paste(out_dir, "Full_DBR", "Full_DBR_final_DBR_labeled.rds", sep = "/"))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment