# Load count data
count_data <- read.csv('count.csv', header = TRUE, row.names = 1)
# Filter low-count genes
count_data <- count_data[rowSums(count_data[, c('SRR15039666', 'SRR15039668', 'SRR22702939','SRR22702940','SRR22702946','SRR22702961','SRR22801652','SRR22801654')]) > 50, ]
# Define experimental conditions
condition <- factor(c("AD", "AD", ..., "H"))
# Create a data frame with sample IDs and conditions
coldata <- data.frame(row.names = colnames(count_data), condition)
# Remove rows with missing values
count_data_clean <- count_data[complete.cases(count_data), ]
# Create DESeq2 object
dds <- DESeqDataSetFromMatrix(countData = count_data_clean, colData = coldata, design = ~condition)
# Perform differential expression analysis
dds <- DESeq(dds)
# Transform count data
vsdata <- vst(dds, blind = FALSE)
# Generate PCA plot
plotPCA(vsdata, intgroup = "condition")
# Plot dispersion estimates
plotDispEsts(dds)
# Extract differential expression results
res <- results(dds, contrast = c("condition", "C", "H"))
# Filter significant results
sigs <- na.omit(res)
sigs <- sigs[sigs$padj < 0.05, ]
# Print significant results
sigs
# Extract expression matrix of significant genes
sig_expr_matrix <- assay(dds)[rownames(sigs), ]
# Log2 transform expression matrix
log_sig_expr_matrix <- log2(sig_expr_matrix + 1)
# Generate heatmap
heatmap <- pheatmap(log_sig_expr_matrix, cluster_rows = TRUE, cluster_cols = TRUE, color = colorRampPalette(c("blue", "white", "red"))(100))
# Save heatmap as TIFF file
tiff("heatmap.tiff", width = 10, height = 10, units = "in", res = 600)
print(heatmap)
dev.off()
# Plot MA plot
plotMA(res)
# Generate volcano plot
volcano_plot <- ggplot(res, aes(x = log2FoldChange, y = -log10(padj))) +
geom_point(aes(color = ifelse(padj < 0.05, "Significant", "Not significant")), size = 2, alpha = 0.8) +
scale_color_manual(values = c("Significant" = "red", "Not significant" = "gray")) +
labs(title = "Volcano Plot", x = "Log2 Fold Change", y = "log10(p-value)") +
theme_minimal() +
theme(
plot.margin = margin(20, 20, 20, 20),
axis.text.x = element_text(size = 10),
axis.text.y = element_text(size = 10),
legend.position = "bottom",
legend.direction = "vertical",
legend.box = "vertical",
legend.margin = margin(t = 20, r = 20, b = 0.5, l = 20, unit = "pt")
)
# Display volcano plot
print(volcano_plot)