library(stringi)
source_from_github(repositoy = "DEG_functions",version = "0.2.47")
source_from_github(repositoy = "cNMF_functions",version = "0.4.0",script_name = "cnmf_functions_V3.R")
source_from_github(repositoy = "sc_general_functions",version = "0.1.28",script_name = "functions.R")
library("readxl")
acc_all = readRDS(file = "./Data/acc_tpm_nCount_mito_no146_15k_alldata.rds")
acc_cancer_pri = readRDS(file = "./Data/acc_cancer_no146_primaryonly15k_cancercells.rds")
acc_cancer = readRDS(file = "./Data/acc_tpm_nCount_mito_no146_15k_cancercells.rds")
neuronal_signatures <- read_excel("./Data/Neuronal Signatures.xlsx",col_names =F)
neuronal_signatures %<>% t() %>% as.data.frame() %>% janitor::row_to_names(1) %>% filter(!row_number() == 1)
rownames(neuronal_signatures) <- NULL
colnames(neuronal_signatures) %<>% gsub(replacement = "", pattern = "_\\d.*") #remove any _numbers
colnames(neuronal_signatures) %<>% gsub(replacement = "", pattern = "\\(.*") #rename "(" to the end
colnames(neuronal_signatures) %<>% gsub(replacement = "_", pattern = " ") #rename all spaces
neuronal_pathways <- read_excel("./Data/Pathway analysis Gene sets.xlsx",col_names =F)
neuronal_pathways %<>% t() %>% as.data.frame() %>% janitor::row_to_names(1) %>% filter(!row_number() == 1) %>% as.list()
neuronal_pathways = lapply(neuronal_pathways, na.omit)
neuronal_pathways = lapply(neuronal_pathways, as.character)
for (neural_name in colnames(neuronal_signatures)) {
genes = neuronal_signatures[,neural_name,drop=T]
# Assuming df is your data frame
pathways_scores = FetchData(object = acc_all,vars = genes,slot = "data") %>%
mutate_all(~ 2^.)%>% mutate_all(~ .-1) %>% #covert log(TPM+1) to TPM
rowwise() %>% mutate(score = mean(c_across(everything()))) #mean
acc_all %<>% AddMetaData(metadata = pathways_scores$score,col.name = neural_name)
}
Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = “data”) : The following requested variables were not found: SNHG29, NOP53 Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = “data”) : The following requested variables were not found: NOP53 Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = “data”) : The following requested variables were not found: NOP53
plt = VlnPlot(object = acc_all,features = colnames(neuronal_signatures))
plt[[1]] = plt[[1]]+ ylab("TPM")
plt[[4]] = plt[[4]]+ ylab("TPM")
plt[[7]] = plt[[7]]+ ylab("TPM")
print_tab(plt = plt,title = "expression with RP genes",subtitle_num = 3)
NA
rp_genes = lapply(neuronal_signatures %>% as.list(), function(x) {x[startsWith(x = x,prefix = "RP")]}) %>% unlist() %>% unique() %>% as.data.frame()
print_tab(rp_genes,title = " RP genes names",subtitle_num = 3)
NA
neuronal_signatures_no_RP = lapply(neuronal_signatures %>% as.list(), function(x) {x[!startsWith(x = x,prefix = "RP")]})
names(neuronal_signatures_no_RP) = paste0(names(neuronal_signatures_no_RP),"_noRP")
for (neural_name in names(neuronal_signatures_no_RP)) {
genes = neuronal_signatures_no_RP[[neural_name]]
# Assuming df is your data frame
pathways_scores = FetchData(object = acc_all,vars = genes,slot = "data") %>%
mutate_all(~ 2^.)%>% mutate_all(~ .-1) %>% #covert log(TPM+1) to TPM
rowwise() %>% mutate(score = mean(c_across(everything()))) #mean
acc_all %<>% AddMetaData(metadata = pathways_scores$score,col.name = neural_name)
}
plt = VlnPlot(object = acc_all,features = names(neuronal_signatures_no_RP))
for (i in 1:(length(plt$patches$plots)+1)) {
plt[[i]] = plt[[i]] + theme(plot.title = element_text(size=12))
if (i %in% c(1,4,7)) {
plt[[i]] = plt[[i]]+ylab("TPM")
}
}
print_tab(plt = plt,title = "expression without RP genes",subtitle_num = 3)
NA
plt1 = FeaturePlot(object = acc_all,features = colnames(neuronal_signatures))& theme(plot.title = element_text(size=13))
plt2 = FeaturePlot(object = acc_all,features = names(neuronal_signatures_no_RP)) & theme(plot.title = element_text(size=12))
print_tab(plt = plt1,title = "UMAP with RP",subtitle_num = 3)
print_tab(plt = plt2,title = "UMAP without RP",subtitle_num = 3)
NA
high_cholinergic_neuron = list( high_cholinergic_neuron = colnames(acc_all)[acc_all$Sympathetic_cholinergic_neuron_noRP>1000])
DimPlot(object = acc_all, cells.highlight = high_cholinergic_neuron, cols.highlight = "red", cols = "gray", order = TRUE)
for (pathway_name in names(neuronal_pathways)) {
genes = neuronal_pathways[[pathway_name]]
pathways_scores = FetchData(object = acc_all,vars = genes,slot = "data") %>%
mutate_all(~ 2^.)%>% mutate_all(~ .-1) %>% #covert log(TPM+1) to TPM
rowwise() %>% mutate(score = mean(c_across(everything()))) #mean
acc_all %<>% AddMetaData(metadata = pathways_scores$score,col.name = pathway_name)
}
Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = "data") :
The following requested variables were not found: ADORA3
Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = "data") :
The following requested variables were not found: ADORA3
Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = "data") :
The following requested variables were not found: ASCL1, PHOX2B
Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = "data") :
The following requested variables were not found: ASCL1, PHOX2B
Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = "data") :
The following requested variables were not found: ARX, HOXB1, ASCL1, PRLH, PHOX2B, ISX
Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = "data") :
The following requested variables were not found: HOXB1, PHOX2B
Warning in FetchData.Seurat(object = acc_all, vars = genes, slot = "data") :
The following requested variables were not found: DRD3, MIR1-1, MIR133A1
plt = FeaturePlot(object = acc_all,features = names(neuronal_pathways),pt.size = 0.5)
for (i in 1:(length(plt$patches$plots)+1)) {
plt[[i]] = plt[[i]] + theme(plot.title = element_text(size=10.5))+ labs(color='TPM') + scale_color_gradientn(colours = rainbow(5))
}
Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale.
print_tab(plt,title = "TPM",subtitle_num = 3)
NA
for (pathway_name in names(neuronal_pathways)) {
genes = neuronal_pathways[[pathway_name]]
pathways_scores = FetchData(object = acc_all,vars = genes,slot = "data") %>%
rowwise() %>% mutate(score = mean(c_across(everything()))) #mean
acc_all %<>% AddMetaData(metadata = pathways_scores$score,col.name = pathway_name)
}
plt1 = FeaturePlot(object = acc_all,features = names(neuronal_pathways),pt.size = 0.5)&
theme(plot.title = element_text(size=10.5)) & labs(color='log (TPM+1)') & scale_color_gradientn(colours = rainbow(5))
Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale.
plt2 = FeaturePlot(object = acc_all,features = names(neuronal_pathways),pt.size = 0.5)&
theme(plot.title = element_text(size=10.5)) & labs(color='log (TPM+1)')
print_tab(plt2,title = "log(TPM+1) ",subtitle_num = 3)
print_tab(plt1,title = "log(TPM+1) rainbow",subtitle_num = 3)
NA
b2r_genes = c("RAF1", "PAMPK1", "PRKACA", "PIK3CA", "AKT1", "AKT2", "AKT3", "CREB1", "CREBBP", "BCL2", "BAD", "JUN", "FOS", "MYC")
tpm_1 = FeaturePlot(object = acc_tpm,features = b2r_genes[1:9],pt.size = 0.5,slot = "counts") & scale_color_gradientn(colours = rainbow(5)) & labs(color='TPM')
Warning in FetchData.Seurat(object = object, vars = c(dims, “ident”, features), : The following requested variables were not found: PAMPK1 Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale.
tpm_2 = FeaturePlot(object = acc_tpm,features = b2r_genes[10:length(b2r_genes)],pt.size = 0.5,slot = "counts") & scale_color_gradientn(colours = rainbow(5)) & labs(color='TPM')
Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale. Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale.
logTPM1 = FeaturePlot(object = acc_all,features = b2r_genes[1:9],pt.size = 0.5) & labs(color='log(TPM+1)')
Warning in FetchData.Seurat(object = object, vars = c(dims, “ident”, features), : The following requested variables were not found: PAMPK1
logTPM2 = FeaturePlot(object = acc_all,features = b2r_genes[10:length(b2r_genes)]) & labs(color='log(TPM+1)')
print_tab(plt = tpm_1,title = "TPM part 1",subtitle_num = 3)
print_tab(plt = tpm_2,title = "TPM part 2",subtitle_num = 3)
print_tab(plt = logTPM1,title = "log TPM part 1",subtitle_num = 3)
print_tab(plt = logTPM2,title = "log TPM part 2",subtitle_num = 3)
NA
pathways_scores = FetchData(object = acc_all,vars = b2r_genes,slot = "data") %>%
mutate_all(~ 2^.)%>% mutate_all(~ .-1) %>% #covert log(TPM+1) to TPM
rowwise() %>% mutate(score = mean(c_across(everything()))) #mean
Warning in FetchData.Seurat(object = acc_all, vars = b2r_genes, slot = “data”) : The following requested variables were not found: PAMPK1
acc_all %<>% AddMetaData(metadata = pathways_scores$score,col.name = "b2r_signature_TPM")
tpm = FeaturePlot(object = acc_all,features ="b2r_signature_TPM",pt.size = 0.5,slot = "counts") & scale_color_gradientn(colours = rainbow(5)) & labs(color='TPM')
Scale for ‘colour’ is already present. Adding another scale for ‘colour’, which will replace the existing scale.
pathways_scores = FetchData(object = acc_all,vars = b2r_genes,slot = "data") %>%
rowwise() %>% mutate(score = mean(c_across(everything()))) #mean
Warning in FetchData.Seurat(object = acc_all, vars = b2r_genes, slot = “data”) : The following requested variables were not found: PAMPK1
acc_all %<>% AddMetaData(metadata = pathways_scores$score,col.name = "b2r_signature")
logTPM = FeaturePlot(object = acc_all,features ="b2r_signature",pt.size = 0.5,slot = "counts") & labs(color='log TPM')
print_tab(plt = tpm,title = "TPM",subtitle_num = 3)
print_tab(plt = logTPM,title = "log TPM",subtitle_num = 3)
NA