As an expert bioinformatician, I can guide you through the steps you would generally follow to perform exploratory data analysis (EDA) on your RNA-seq count data using R and associated packages like DESeq2, ggplot2, and pheatmap. Unfortunately, I cannot run the actual code here, but I’ll provide you an example script that you can tailor and execute in your local R environment.
The steps below assume that you have your matrix file ready and the DESeq2, ggplot2, and factoextra (for PCA visualization) libraries installed in R.
Here's a step-by-step guide for the exploratory analysis:
# Load necessary libraries
library(DESeq2)
library(ggplot2)
library(pheatmap)
library(factoextra)
# Load your count matrix
count_data <- read.csv("path_to_your_matrix.csv", row.names=1)
# Assuming the first column of your matrix has gene IDs and the rest are samples
# Load or create a sample information data frame that matches your matrix columns
# It should have samples as rows and at least two columns: condition (e.g., "TB-positive", "control")
# and a unique identifier for each sample
colData <- data.frame(
sampleName = colnames(count_data),
condition = c(rep("TB-positive", times = num_TB_samples), rep("control", times = num_control_samples)),
row.names = colnames(count_data)
)
# Create a DESeqDataSet object
dds <- DESeqDataSetFromMatrix(countData = count_data, colData = colData, design = ~ condition)
# Normalize the data
dds <- DESeq(dds)
normalized_counts <- counts(dds, normalized=TRUE)
# PCA
# Calculate the variance-stabilizing transformation
vsd <- vst(dds, blind = FALSE)
# Run PCA
pca_res <- plotPCA(vsd, intgroup = "condition", returnData = TRUE)
# Visualize PCA
ggplot(pca_res, aes(PC1, PC2, color = condition)) + geom_point(size=3)
# Hierarchical clustering
# Compute the distance matrix
dist_matrix <- dist(t(assay(vsd)))
# Perform hierarchical clustering
hc <- hclust(dist_matrix)
# Draw the heatmap with clustering
pheatmap(normalized_counts, cluster_rows = hc, cluster_cols = hc, show_rownames = F, show_colnames = F)
# You may want to check the variance explained by PCA components (optional)
pca_data <- prcomp(t(assay(vsd)))
fviz_eig(pca_data)
Remember to change "path_to_your_matrix.csv" to the actual path of your CSV file containing the count matrix, and num_TB_samples and num_control_samples to the actual number of samples in each group. Also, modify the colData frame according to your specific sample information.
This code will perform PCA and hierarchical clustering on the normalized read count data, which can give you insight into the overall structure of your data and potential batch effects or outliers. PCA will help visualize the differences between TB-positive and control samples, while hierarchical clustering might further elucidate groupings within the sample.
Make sure to review and understand each step and adjust parameters to your specific dataset and research question. Data visualization and interpretation are critical at this stage, so you might spend some time tweaking the plots and the clustering to get meaningful and interpretable results.