library(Seurat)
#packageVersion("Seurat")
library(sctransform)
library(tidyr)
library(dplyr)
library(patchwork)
library(viridis)
library(tidyverse)
library(ggplot2)
library(presto)
library(msigdbr)
library(fgsea)
# Load required libraries
library(SingleCellExperiment)
#read h5 from 10x cell ranger output
PC9.data <- Read10X_h5(filename = "filtered_feature_bc_matrix.h5")
PC9 <- CreateSeuratObject(counts = PC9.data, project = "PC9_sc", min.cells = 3, min.features = 200)
#create Seurat object
PC9_nofilter <- CreateSeuratObject(counts = PC9.data, project = "PC9_sc", min.cells = 3, min.features = 200)
TV_datapath <- 'Deseq_res_DvsND_capture_subsetP1E5_FC<m0.5.csv'
TV_data <- read.csv(TV_datapath,header = TRUE,row.names = "Gene")
PC9_nofilter[["percent.mt"]] <- PercentageFeatureSet(PC9_nofilter, pattern = "^MT-")
p_quality_bar_plot <- VlnPlot(PC9_nofilter, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
#ggsave(p_quality_bar_plot, filename = "/Users/chaoyuka/Desktop/Data/mRNAcap/PC9_single_cell/p_quality_bar_plot.pdf", height = 5, width = 8,dpi = 300)
#extract feature data from seurat
feature_data <- FetchData(PC9_nofilter, vars = c("nCount_RNA", "percent.mt"))
feature_data$color <- ifelse(feature_data$nCount_RNA > 2500 & feature_data$percent.mt < 15, "tomato", "grey")
#plot filtering
p_count_vs_mito <- ggplot(feature_data, aes(x = nCount_RNA, y = percent.mt, color = color)) +
geom_point() +
geom_vline(xintercept = 2500, color = "red", linetype = "dashed") +  # Vertical line at x=2500
geom_hline(yintercept = 15, color = "red", linetype = "dashed") +    # Horizontal line at y=15
geom_hline(yintercept = 0, color = "black", size = 1) +  # Horizontal line at y=0
geom_vline(xintercept = 0, color = "black", size = 1) +
scale_color_identity() +  # Use the color directly from the data
theme_minimal() +  # Optional: for a cleaner look
labs(title = "Feature Plot", x = "nCount_RNA", y = "percent.mt")+
theme(
text = element_text(size = 15),  # Increase text size
axis.title = element_text(size = 15),  # Increase axis titles size
axis.text = element_text(size = 15),  # Increase axis ticks text size
panel.grid.major = element_blank(),  # Remove major grid lines
panel.grid.minor = element_blank(),  # Remove minor grid lines
panel.background = element_blank(),    # Remove plot background
axis.ticks = element_line(color = "black", size = 1)  # Ensure tick marks are visible
)
#ggsave(p_count_vs_mito, filename = "/Users/chaoyuka/Desktop/Data/mRNAcap/PC9_single_cell/p_count_vs_mito.pdf", height = 10, width = 12,dpi = 300)
#filter based on plot
PC9 <- subset(PC9_nofilter, subset = nFeature_RNA > 2500 & percent.mt < 15 & nCount_RNA > 2500)
p_count_vs_mito
set.seed = 123
#read h5 from 10x cell ranger output
PC9.data <- Read10X_h5(filename = "filtered_feature_bc_matrix.h5")
output_path <- getwd()
#create Seurat object
PC9_nofilter <- CreateSeuratObject(counts = PC9.data, project = "PC9_sc", min.cells = 3, min.features = 200)
#read timevault experiment DEseq result for top persister genes (sorted by log2FC with excel, negative means enriched in persister)
TV_datapath <- 'Deseq_res_DvsND_capture_subsetP1E5_FC<m0.5.csv'
TV_data <- read.csv(TV_datapath,header = TRUE,row.names = "Gene")
#read saved rds
#PC9 <- readRDS("/Users/chaoyuka/Desktop/Data/mRNAcap/PC9_single_cell/PC9.rds")
PC9_nofilter[["percent.mt"]] <- PercentageFeatureSet(PC9_nofilter, pattern = "^MT-")
p_quality_bar_plot <- VlnPlot(PC9_nofilter, features = c("nFeature_RNA", "nCount_RNA", "percent.mt"), ncol = 3)
#ggsave(p_quality_bar_plot, filename = "/Users/chaoyuka/Desktop/Data/mRNAcap/PC9_single_cell/p_quality_bar_plot.pdf", height = 5, width = 8,dpi = 300)
#extract feature data from seurat
feature_data <- FetchData(PC9_nofilter, vars = c("nCount_RNA", "percent.mt"))
feature_data$color <- ifelse(feature_data$nCount_RNA > 2500 & feature_data$percent.mt < 15, "tomato", "grey")
#plot filtering
p_count_vs_mito <- ggplot(feature_data, aes(x = nCount_RNA, y = percent.mt, color = color)) +
geom_point() +
geom_vline(xintercept = 2500, color = "red", linetype = "dashed") +  # Vertical line at x=2500
geom_hline(yintercept = 15, color = "red", linetype = "dashed") +    # Horizontal line at y=15
geom_hline(yintercept = 0, color = "black", size = 1) +  # Horizontal line at y=0
geom_vline(xintercept = 0, color = "black", size = 1) +
scale_color_identity() +  # Use the color directly from the data
theme_minimal() +  # Optional: for a cleaner look
labs(title = "Feature Plot", x = "nCount_RNA", y = "percent.mt")+
theme(
text = element_text(size = 15),  # Increase text size
axis.title = element_text(size = 15),  # Increase axis titles size
axis.text = element_text(size = 15),  # Increase axis ticks text size
panel.grid.major = element_blank(),  # Remove major grid lines
panel.grid.minor = element_blank(),  # Remove minor grid lines
panel.background = element_blank(),    # Remove plot background
axis.ticks = element_line(color = "black", size = 1)  # Ensure tick marks are visible
)
#ggsave(p_count_vs_mito, filename = "/Users/chaoyuka/Desktop/Data/mRNAcap/PC9_single_cell/p_count_vs_mito.pdf", height = 10, width = 12,dpi = 300)
#filter based on plot
PC9 <- subset(PC9_nofilter, subset = nFeature_RNA > 2500 & percent.mt < 15 & nCount_RNA > 2500)
PC9 <- NormalizeData(PC9, normalization.method = "LogNormalize", scale.factor = 10000)
PC9 <- FindVariableFeatures(PC9, selection.method = "vst", nfeatures = 2000)
plot1 <- VariableFeaturePlot(PC9)
plot2 <- LabelPoints(plot = plot1, points = top10, repel = TRUE)
plot2
# Identify the 10 most highly variable genes
top10 <- head(VariableFeatures(PC9), 50)
# plot variable features with and without labels
plot1 <- VariableFeaturePlot(PC9)
plot2 <- LabelPoints(plot = plot1, points = top10, repel = TRUE)
plot1 + plot2
plot2
library(DESeq2)
library("dplyr")
library("ggplot2")
library('biomaRt')
library(stringr)
library(pheatmap)
library(RColorBrewer)
library(stats)
library(ggpubr)
library(ggpmisc)
library(ggpointdensity)
library(ggrepel)
library(EnhancedVolcano)
library(msigdbr)
library(clusterProfiler)
library("org.Hs.eg.db")
getwd()
