Last updated: 2024-11-07

Checks: 5 2

Knit directory: locust-comparative-genomics/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20221025) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
/Users/maevatecher/Library/Mobile Documents/comappleCloudDocs/Documents/GitHub/locust-comparative-genomics/data data

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 9fb9741. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .RData
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/.Rhistory
    Ignored:    data/.DS_Store
    Ignored:    data/.Rhistory
    Ignored:    data/OLD/.DS_Store
    Ignored:    data/OLD/DEseq2_SCUBE_SCUBE_THORAX_STARnew_features/.DS_Store
    Ignored:    data/OLD/DEseq2_SGREG_SGREG_HEAD_STARnew_features/.DS_Store
    Ignored:    data/OLD/DEseq2_SGREG_SGREG_THORAX_STARnew_features/.DS_Store
    Ignored:    data/OLD/americana/.DS_Store
    Ignored:    data/OLD/americana/deg_counts/.DS_Store
    Ignored:    data/OLD/americana/deg_counts/STAR_newparams/.DS_Store
    Ignored:    data/OLD/cubense/deg_counts/STAR/cubense/featurecounts/
    Ignored:    data/OLD/cubense/deg_counts/STAR/gregaria/
    Ignored:    data/OLD/gregaria/.DS_Store
    Ignored:    data/OLD/gregaria/deg_counts/.DS_Store
    Ignored:    data/OLD/gregaria/deg_counts/STAR/.DS_Store
    Ignored:    data/OLD/gregaria/deg_counts/STAR/gregaria/.DS_Store
    Ignored:    data/OLD/gregaria/deg_counts/STAR_newparams/.DS_Store
    Ignored:    data/OLD/piceifrons/.DS_Store
    Ignored:    data/list/.DS_Store
    Ignored:    figures/
    Ignored:    tables/

Untracked files:
    Untracked:  data/03-americana-DESeq2-togregaria/
    Untracked:  data/03-cancellata-DESeq2-togregaria/
    Untracked:  data/03-cubense-DESeq2-togregaria/
    Untracked:  data/03-gregaria-DESeq2-togregaria/
    Untracked:  data/03-nitens-DESeq2-togregaria/
    Untracked:  data/03-piceifrons-DESeq2-togregaria/
    Untracked:  data/DEG-results/
    Untracked:  data/list/GO_Annotations/
    Untracked:  data/list/allspecies_geneid.csv
    Untracked:  data/list/allspecies_protein2geneid.tsv
    Untracked:  data/orthofinder/

Unstaged changes:
    Modified:   analysis/1_seq-data.Rmd
    Modified:   analysis/2_orthologs-prediction.Rmd
    Modified:   analysis/3_deseq2-results.Rmd
    Modified:   analysis/3_go-enrichment.Rmd
    Modified:   analysis/3_overlap-venn.Rmd
    Modified:   analysis/3_seq-data-qc.Rmd
    Modified:   analysis/_site.yml
    Deleted:    data/list/tx2gene.americana.csv

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/3_deseq2-results.Rmd) and HTML (docs/3_deseq2-results.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 9fb9741 Maeva TECHER 2024-11-04 update deseq2
html 9fb9741 Maeva TECHER 2024-11-04 update deseq2
html 200db58 Maeva TECHER 2024-11-01 Build site.
Rmd f763b3c Maeva TECHER 2024-11-01 workflowr::wflow_publish(c("../analysis/3_deseq2-results.Rmd"))
html 66ffff7 Maeva TECHER 2024-11-01 Build site.
Rmd bb5a302 Maeva TECHER 2024-11-01 workflowr::wflow_publish(c("../analysis/3_deseq2-results.Rmd"))
html 01490a8 Maeva TECHER 2024-11-01 Build site.
Rmd 4322067 Maeva TECHER 2024-11-01 workflowr::wflow_publish(c("../analysis/3_deseq2-results.Rmd",
html 1aaa476 Maeva TECHER 2024-11-01 push
Rmd f01f1cf Maeva TECHER 2024-11-01 Adding new files and docs
html f01f1cf Maeva TECHER 2024-11-01 Adding new files and docs

Load the libraries

We start by loading all the required R packages.

#(install first from CRAN or Bioconductor)
library("DESeq2")
library("tximport")
library("txdbmaker")
library("knitr")
library("rmdformats")
library("tidyverse")
library("data.table")
library("DT")  # for making interactive search table
library("plotly") # for interactive plots
library("ggthemes") # for theme_calc
library("reshape2")
library("ComplexHeatmap")
library("RColorBrewer")
library("circlize")
library("apeglm")
library("ggpubr")
library("ggplot2")
library("ggrepel")
library("EnhancedVolcano")
library("SARTools")
library("pheatmap")
library("clusterProfiler")
library("sva")
library("cowplot")
library("ashr")
library("vsn")
library("ggdist")
library("ggConvexHull")
library("kableExtra")
library("plotly")

# Path for all species
workDir <- "/Users/maevatecher/Library/Mobile Documents/com~apple~CloudDocs/Documents/GitHub/locust-comparative-genomics/data"
allspecies_path <- file.path(workDir, "/list/allspecies_geneid.csv")
allspecies_df <- read.table(allspecies_path, sep = ",", header = TRUE, quote = "", fill = TRUE, stringsAsFactors = FALSE)

## PARAMETERS for running DEseq2
tresh_logfold <- 1                    # Treshold for log2(foldchange) in final DE-files
tresh_padj <- 0.05                    # Treshold for adjusted p-valued in final DE-files
alpha_DEseq2 <- 0.05                  # threshold of statistical significance
pAdjustMethod_DEseq2 <- "BH"          # p-value adjustment method: "BH" (default) or "BY"
featuresToRemove <- c(NULL)           # names of the features to be removed, NULL if none or if using Idxstats
varInt <- "RearingCondition"          # factor of interest
condRef <- "Isolated"                 # reference biological condition
batch <- NULL                         # blocking factor: NULL (default) or "batch" for example  
fitType <- "parametric"               # mean-variance relationship: "parametric" (default) or "local"
cooksCutoff <- TRUE                   # TRUE/FALSE to perform the outliers detection (default is TRUE)
independentFiltering <- TRUE          # TRUE/FALSE to perform independent filtering (default is TRUE)
typeTrans <- "rlog"                   # transformation for PCA/clustering: "VST" or "rlog"
locfunc <- "median"

STRATEGY 1: One genome S. gregaria

1. DEGs in bulk Head tissues

gregaria



Total DEGs

rawDir <- file.path(workDir, "03-gregaria-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "gregaria"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, ".txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 5697

A total of 5,697 genes out of the pre-filtered 16,305 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 1,476 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 16305 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 2709, 17%
LFC < 0 (down)     : 2988, 18%
outliers [1]       : 99, 0.61%
low counts [2]     : 0, 0%
(mean count < 1)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 1476 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 814 , 55.15 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 662 , 44.85 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Head_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. gregaria","Isolated S. gregaria"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. gregaria Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. gregaria","Isolated S. gregaria"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. gregaria Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
# Create a new data frame for ggplot
de_shrink_df <- as.data.frame(de_shrink)
de_shrink_df$GeneID <- rownames(de_shrink_df)  # Add gene names as a new column
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = de_shrink_df$GeneID, top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. gregaria", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

piceifrons



Total DEGs

rawDir <- file.path(workDir, "03-piceifrons-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "piceifrons"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 750

A total of 750 genes out of the pre-filtered 13,325 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 385 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13325 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 375, 2.8%
LFC < 0 (down)     : 375, 2.8%
outliers [1]       : 25, 0.19%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 385 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 194 , 50.39 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 191 , 49.61 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Head_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. piceifrons", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

cancellata



Total DEGs

rawDir <- file.path(workDir, "03-cancellata-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "cancellata"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1445

A total of 1,445 genes out of the pre-filtered 13,407 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 687 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13407 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 689, 5.1%
LFC < 0 (down)     : 756, 5.6%
outliers [1]       : 26, 0.19%
low counts [2]     : 260, 1.9%
(mean count < 4)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 687 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 301 , 43.81 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 386 , 56.19 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Head_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cancellata","Isolated S. cancellata"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cancellata Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cancellata","Isolated S. cancellata"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cancellata Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. cancellata", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

americana



Total DEGs

rawDir <- file.path(workDir, "03-americana-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "americana"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1190

A total of 1,190 genes out of the pre-filtered 13,442 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 567 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13442 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 703, 5.2%
LFC < 0 (down)     : 487, 3.6%
outliers [1]       : 44, 0.33%
low counts [2]     : 782, 5.8%
(mean count < 5)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 567 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 311 , 54.85 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 256 , 45.15 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Head_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. americana","Isolated S. americana"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. americana Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. americana","Isolated S. americana"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. americana Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. americana", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

cubense



Total DEGs

rawDir <- file.path(workDir, "03-cubense-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "cubense"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 61

A total of 61 genes out of the pre-filtered 13,744 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 61 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13744 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 30, 0.22%
LFC < 0 (down)     : 31, 0.23%
outliers [1]       : 130, 0.95%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 61 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 30 , 49.18 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 31 , 50.82 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Head_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cubense","Isolated S. cubense"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cubense Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cubense","Isolated S. cubense"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cubense Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. cubense", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

nitens



Total DEGs

rawDir <- file.path(workDir, "03-nitens-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "nitens"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 454

A total of 454 genes out of the pre-filtered 13,406 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 311 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13406 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 189, 1.4%
LFC < 0 (down)     : 259, 1.9%
outliers [1]       : 120, 0.9%
low counts [2]     : 780, 5.8%
(mean count < 6)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 311 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 104 , 33.44 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 207 , 66.56 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Head_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. nitens","Isolated S. nitens"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. nitens Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. nitens","Isolated S. nitens"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. nitens Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. nitens", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

2. DEGs in bulk Thorax tissues

gregaria



Total DEGs

rawDir <- file.path(workDir, "03-gregaria-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "gregaria"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 5442

A total of 5,442 genes out of the pre-filtered 16,613 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 1,796 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 16613 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 2751, 17%
LFC < 0 (down)     : 2691, 16%
outliers [1]       : 112, 0.67%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 1796 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 622 , 34.63 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 1174 , 65.37 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. gregaria","Isolated S. gregaria"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. gregaria Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. gregaria","Isolated S. gregaria"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. gregaria Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. gregaria", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

piceifrons



Total DEGs

rawDir <- file.path(workDir, "03-piceifrons-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "piceifrons"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, ".txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 2690

A total of 2,690 genes out of the pre-filtered 13,117 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 770 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13117 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 1517, 12%
LFC < 0 (down)     : 1200, 9.1%
outliers [1]       : 29, 0.22%
low counts [2]     : 1018, 7.8%
(mean count < 5)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 770 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 549 , 71.3 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 221 , 28.7 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. piceifrons", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

cancellata



Total DEGs

rawDir <- file.path(workDir, "03-cancellata-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "cancellata"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1323

A total of 1,323 genes out of the pre-filtered 13,471 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 592 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13471 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 686, 5.1%
LFC < 0 (down)     : 648, 4.8%
outliers [1]       : 51, 0.38%
low counts [2]     : 1306, 9.7%
(mean count < 9)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 592 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 289 , 48.82 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 303 , 51.18 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cancellata","Isolated S. cancellata"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cancellata Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cancellata","Isolated S. cancellata"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cancellata Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. cancellata", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

americana



Total DEGs

rawDir <- file.path(workDir, "03-americana-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "americana"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1097

A total of 1,097 genes out of the pre-filtered 13,203 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 488 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13203 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 398, 3%
LFC < 0 (down)     : 699, 5.3%
outliers [1]       : 34, 0.26%
low counts [2]     : 256, 1.9%
(mean count < 3)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)


significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 488 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 149 , 30.53 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 339 , 69.47 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. americana","Isolated S. americana"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. americana Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. americana","Isolated S. americana"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. americana Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. americana", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

cubense



Total DEGs

rawDir <- file.path(workDir, "03-cubense-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "cubense"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 333

A total of 333 genes out of the pre-filtered 13,338 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 218 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13338 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 104, 0.78%
LFC < 0 (down)     : 218, 1.6%
outliers [1]       : 106, 0.79%
low counts [2]     : 518, 3.9%
(mean count < 5)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 218 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 64 , 29.36 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 154 , 70.64 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cubense","Isolated S. cubense"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cubense Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cubense","Isolated S. cubense"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cubense Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. cubense", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

nitens



Total DEGs

rawDir <- file.path(workDir, "03-nitens-DESeq2-togregaria") 

# Path and name of targetfile containing conditions and file names
species <- "nitens"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 0

A total of 0 genes out of the pre-filtered 13,130 features were showing significant (corrected p-value < 0.05) differences in expression levels. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13130 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 0, 0%
LFC < 0 (down)     : 0, 0%
outliers [1]       : 98, 0.75%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_togregaria_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 0 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 0 , NaN %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 0 , NaN %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_togregaria_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. nitens","Isolated S. nitens"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. nitens Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. nitens","Isolated S. nitens"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. nitens Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
#interactive_maplot <- ggplotly(maplot)
#interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. nitens", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
#interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
#  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
#interactive_volcano

STRATEGY 2: Own RefSeq genome

3. DEGs in bulk Head tissues

This follows the same code as for STRATEGY 1 except that we will change the RefSeq to the transcript species genome path.

gregaria



Total DEGs

rawDir <- file.path(workDir, "03-gregaria-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "gregaria"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, ".txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 5697

A total of 5,697 genes out of the pre-filtered 16,305 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 1,476 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 16305 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 2709, 17%
LFC < 0 (down)     : 2988, 18%
outliers [1]       : 99, 0.61%
low counts [2]     : 0, 0%
(mean count < 1)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 1476 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 814 , 55.15 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 662 , 44.85 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_head_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. piceifrons", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

piceifrons



Total DEGs

rawDir <- file.path(workDir, "03-piceifrons-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "piceifrons"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1053

A total of 1,053 genes out of the pre-filtered 13,527 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 564 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13527 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 538, 4%
LFC < 0 (down)     : 518, 3.8%
outliers [1]       : 43, 0.32%
low counts [2]     : 525, 3.9%
(mean count < 5)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 564 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 301 , 53.37 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 263 , 46.63 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_head_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. piceifrons", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

cancellata



Total DEGs

rawDir <- file.path(workDir, "03-cancellata-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "cancellata"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1628

A total of 1,628 genes out of the pre-filtered 13,547 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 854 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13547 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 751, 5.5%
LFC < 0 (down)     : 877, 6.5%
outliers [1]       : 26, 0.19%
low counts [2]     : 263, 1.9%
(mean count < 4)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 854 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 378 , 44.26 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 476 , 55.74 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_head_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cancellata","Isolated S. cancellata"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cancellata Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cancellata","Isolated S. cancellata"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cancellata Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. cancellata", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

americana



Total DEGs

rawDir <- file.path(workDir, "03-americana-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "americana"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1413

A total of 1,413 genes out of the pre-filtered 13,764 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 696 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13764 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 802, 5.8%
LFC < 0 (down)     : 619, 4.5%
outliers [1]       : 57, 0.41%
low counts [2]     : 534, 3.9%
(mean count < 5)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 696 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 357 , 51.29 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 339 , 48.71 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_head_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. americana","Isolated S. americana"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. americana Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. americana","Isolated S. americana"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. americana Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. americana", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

cubense



Total DEGs

rawDir <- file.path(workDir, "03-cubense-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "cubense"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 105

A total of 105 genes out of the pre-filtered 14,328 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 104 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 14328 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 49, 0.34%
LFC < 0 (down)     : 56, 0.39%
outliers [1]       : 173, 1.2%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 104 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 49 , 47.12 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 55 , 52.88 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_head_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cubense","Isolated S. cubense"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cubense Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cubense","Isolated S. cubense"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cubense Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. cubense", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

nitens



Total DEGs

rawDir <- file.path(workDir, "03-nitens-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "nitens"
targetFile <- file.path(workDir, "list", paste0("Head", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 540

A total of 540 genes out of the pre-filtered 13,510 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 367 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13510 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 233, 1.7%
LFC < 0 (down)     : 314, 2.3%
outliers [1]       : 124, 0.92%
low counts [2]     : 524, 3.9%
(mean count < 5)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Head_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 367 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 122 , 33.24 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 245 , 66.76 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_head_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. nitens","Isolated S. nitens"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. nitens Head tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. nitens","Isolated S. nitens"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. nitens Head tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Head tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#head(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Head tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Head S. nitens", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

4. DEGs in bulk Thorax tissues

gregaria



Total DEGs

rawDir <- file.path(workDir, "03-gregaria-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "gregaria"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 5442

A total of 5,442 genes out of the pre-filtered 16,613 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 1,796 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 16613 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 2751, 17%
LFC < 0 (down)     : 2691, 16%
outliers [1]       : 112, 0.67%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 1796 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 622 , 34.63 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 1174 , 65.37 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. gregaria","Isolated S. gregaria"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. gregaria Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. gregaria","Isolated S. gregaria"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. gregaria Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. gregaria", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

piceifrons



Total DEGs

rawDir <- file.path(workDir, "03-piceifrons-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "piceifrons"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, ".txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 3002

A total of 3,002 genes out of the pre-filtered 13,253 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 984 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13253 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 1641, 12%
LFC < 0 (down)     : 1361, 10%
outliers [1]       : 36, 0.27%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 984 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 652 , 66.26 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 332 , 33.74 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. piceifrons","Isolated S. piceifrons"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. piceifrons Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. piceifrons", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

cancellata



Total DEGs

rawDir <- file.path(workDir, "03-cancellata-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "cancellata"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1475

A total of 1,475 genes out of the pre-filtered 13,557 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 700 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13557 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 734, 5.4%
LFC < 0 (down)     : 738, 5.4%
outliers [1]       : 37, 0.27%
low counts [2]     : 526, 3.9%
(mean count < 6)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 700 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 324 , 46.29 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 376 , 53.71 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cancellata","Isolated S. cancellata"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cancellata Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cancellata","Isolated S. cancellata"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cancellata Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. cancellata", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

americana



Total DEGs

rawDir <- file.path(workDir, "03-americana-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "americana"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 1264

A total of 1,264 genes out of the pre-filtered 13,520 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 608 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13520 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 460, 3.4%
LFC < 0 (down)     : 798, 5.9%
outliers [1]       : 48, 0.36%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 608 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 181 , 29.77 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 427 , 70.23 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. americana","Isolated S. americana"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. americana Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. americana","Isolated S. americana"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. americana Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. americana", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

cubense



Total DEGs

rawDir <- file.path(workDir, "03-cubense-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "cubense"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 368

A total of 368 genes out of the pre-filtered 13,909 features were showing significant (corrected p-value < 0.05) differences in expression levels. However, we will only keep the ones with at least an absolute fold change > 1, so in reality we have 263 DEGs. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13909 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 127, 0.91%
LFC < 0 (down)     : 251, 1.8%
outliers [1]       : 137, 0.98%
low counts [2]     : 1079, 7.8%
(mean count < 7)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 263 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 78 , 29.66 %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 185 , 70.34 %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cubense","Isolated S. cubense"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cubense Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. cubense","Isolated S. cubense"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. cubense Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
interactive_maplot <- ggplotly(maplot)
interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. cubense", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
interactive_volcano

nitens



Total DEGs

rawDir <- file.path(workDir, "03-nitens-DESeq2") 

# Path and name of targetfile containing conditions and file names
species <- "nitens"
targetFile <- file.path(workDir, "list", paste0("Thorax", "_", species, "_nooutliers.txt")) 

sampletable <- fread(targetFile)
rownames(sampletable) <- sampletable$SampleName
sampletable$RearingCondition <- as.factor(sampletable$RearingCondition)
sampletable$Tissue <- as.factor(sampletable$Tissue)

## Import count files
satoshi <- DESeqDataSetFromHTSeqCount(sampleTable = sampletable,
                        directory = rawDir,
                        design = ~ RearingCondition )
#satoshi

smallestGroupSize <- 3
keep <- rowSums(counts(satoshi) >= 5) >= smallestGroupSize
satoshi <- satoshi[keep,]
#nrow(satoshi)
satoshi$RearingCondition <- relevel(satoshi$RearingCondition, ref = "Isolated")

# Fit the statistical model
shigeru <- DESeq(satoshi)
#cbind(resultsNames(shigeru))
res_shigeru <- results(shigeru)
sum(res_shigeru$padj < tresh_padj, na.rm = TRUE)
[1] 0

A total of 0 genes out of the pre-filtered 16,305 features were showing significant (corrected p-value < 0.05) differences in expression levels. The summary below showed how many were up-regulated and down-regulated in crowded compared to isolated it is possible to scroll it.

brock <- results(shigeru, name = "RearingCondition_Crowded_vs_Isolated", alpha = alpha_DEseq2)
summary(brock)

out of 13168 with nonzero total read count
adjusted p-value < 0.05
LFC > 0 (up)       : 0, 0%
LFC < 0 (down)     : 0, 0%
outliers [1]       : 132, 1%
low counts [2]     : 0, 0%
(mean count < 2)
[1] see 'cooksCutoff' argument of ?results
[2] see 'independentFiltering' argument of ?results
brock_df <- as.data.frame(brock)
brock_df$GeneID <- rownames(brock_df)

brock_df <- brock_df[!is.na(brock_df$padj) & (brock_df$padj < tresh_padj), ]
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_results_Thorax_", species, ".csv"))
write.csv(brock, file = outputFile, row.names = TRUE)

significant_brock_df <- brock_df[!is.na(brock_df$padj) & !is.na(brock_df$log2FoldChange) & 
                               (brock_df$padj < tresh_padj & abs(brock_df$log2FoldChange) > tresh_logfold), ]
# Summary similar to summary(brock)
upregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange > tresh_logfold, na.rm = TRUE)  # Upregulated count
downregulated <- sum(brock$padj < tresh_padj & brock$log2FoldChange < -tresh_logfold, na.rm = TRUE)  # Downregulated count
total_genes <- sum(upregulated, downregulated)  # Total non-zero count genes
cat("Total DEGs p-value < 0.05 and absolute logFoldChange > 1:", total_genes, "\n")
Total DEGs p-value < 0.05 and absolute logFoldChange > 1: 0 
cat("LFC > 0 (up)       :", upregulated, ",", round((upregulated / total_genes) * 100, 2), "%\n")
LFC > 0 (up)       : 0 , NaN %
cat("LFC < 0 (down)     :", downregulated, ",", round((downregulated / total_genes) * 100, 2), "%\n")
LFC < 0 (down)     : 0 , NaN %
meta_brock_df <- merge(significant_brock_df, allspecies_df, by.x = "GeneID", by.y = "GeneID", all.x = TRUE)
meta_brock_df <- meta_brock_df[, c("GeneID", "GeneType", "Description",  "Species", 
                                   "baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")]
numeric_cols <- c("baseMean", "log2FoldChange", "lfcSE", "stat", "pvalue", "padj")
meta_brock_df[numeric_cols] <- round(meta_brock_df[numeric_cols], 2)
meta_brock_df$row_color <- ifelse(meta_brock_df$log2FoldChange > 1, "red", 
                                  ifelse(meta_brock_df$log2FoldChange < -1, "blue", "black"))
meta_brock_df$row_weight <- ifelse(abs(meta_brock_df$log2FoldChange) > 1, "bold", "normal")
# Display the data table with italic formatting for Species column, color-coded, and bold text rows
datatable(meta_brock_df, options = list(
    pageLength = 10,       # Set initial page length
    scrollX = TRUE,        # Enable horizontal scrolling
    autoWidth = TRUE,      # Adjust column width automatically
    searchHighlight = TRUE # Highlight search matches
  ),
  rownames = FALSE,
  escape = FALSE  # Allows HTML formatting in table cells
) %>%
  formatStyle(
    'Species', target = 'cell',
    fontStyle = 'italic'
  ) %>%
  formatStyle(
    columns = names(meta_brock_df), 
    target = 'row',
    color = styleEqual(c("red", "blue", "black"), c("red", "blue", "black")), # Apply row color
    fontWeight = styleEqual(c("bold", "normal"), c("bold", "normal")), # Apply bold font for up/downregulated rows
    backgroundColor = styleEqual(c("red", "blue", "black"), c("white", "white", "white")) # Keep background white
  )
# Define the output file path
outputFile <- file.path(workDir, "DEG-results", paste0("DESeq2_sigresults_Thorax_", species, ".csv"))
write.csv(brock_df, file = outputFile, row.names = TRUE)

Normalization and PCA

# Try with the data transformation
shigeru_vst <- vst(shigeru)
shigeru_rlog <- rlog(shigeru)
shigeru_ntd <- normTransform(shigeru)
itadori <- meanSdPlot(assay(shigeru_ntd))

itadori2 <- itadori$gg + ggtitle("Transformation with ntd")
megumi <- meanSdPlot(assay(shigeru_vst))

megumi2 <- megumi$gg + ggtitle("Transformation with vst")
nobara <- meanSdPlot(assay(shigeru_rlog))

nobara2 <-nobara$gg + ggtitle("Transformation with rlog")

# Create the pca on the defined groups
pcaData1 <- plotPCA(object = shigeru_rlog, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData1, "percentVar"))
pcaData1$RearingCondition<-factor(pcaData1$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. nitens","Isolated S. nitens"))
#levels(pcaData1$RearingCondition)
p1 <- ggplot(pcaData1, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p1 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. nitens Thorax tissues", subtitle = "rlog transformation") 

pcaData2 <- plotPCA(object = shigeru_vst, intgroup = c("RearingCondition"),returnData=TRUE)
percentVar <- round(100 * attr(pcaData2, "percentVar"))
pcaData2$RearingCondition<-factor(pcaData2$RearingCondition,levels=c("Crowded","Isolated"), labels=c("Crowded S. nitens","Isolated S. nitens"))
#levels(pcaData2$RearingCondition)
p2 <-ggplot(pcaData2, aes(PC1, PC2, color= RearingCondition)) +
  geom_point(size=6) +
  xlab(paste0("PC1: ", percentVar[1], "% variance")) +
  ylab(paste0("PC2: ", percentVar[2], "% variance")) + 
  scale_color_manual(values = c("blue", "red")) +
  #coord_fixed() +
  theme_bw() +
  theme(legend.title = element_blank()) + 
  theme(legend.text = element_text(face="bold", size=16)) +
  theme(axis.text = element_text(size=14)) +
  theme(axis.title = element_text(size=14))
p2 + geom_convexhull(aes(fill = RearingCondition, color = RearingCondition), alpha = 0.5) +
    scale_fill_manual(values = c("blue", "red"))+ 
    ggtitle("PCA on S. nitens Thorax tissues", subtitle = "vst transformation") 

select <- order(rowMeans(counts(shigeru,normalized=TRUE)),
                decreasing=TRUE)[1:12]
df <- as.data.frame(colData(shigeru)[,c("RearingCondition","Tissue")])

Count matrix heatmap

# Count matrix
pheatmap(assay(shigeru_ntd)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after norm transformation")

pheatmap(assay(shigeru_vst)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after vst transformation")

pheatmap(assay(shigeru_rlog)[select,], cluster_rows=FALSE, show_rownames=FALSE,
         cluster_cols=FALSE, annotation_col=df, main = "Count Matrix after rlog transformation")

# calculate between-sample distance matrix
metadata <- sampletable[,c("RearingCondition", "Tissue")]
rownames(metadata) <- sampletable$SampleName
sampleDistMatrix.rlog <- as.matrix(dist(t(assay(shigeru_rlog))))
pheatmap(sampleDistMatrix.rlog, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")

sampleDistMatrix.vst<- as.matrix(dist(t(assay(shigeru_vst))))
pheatmap(sampleDistMatrix.vst, annotation_col=metadata, main = "Thorax tissue heatmap distance matrix, rlog transformation")


MA plot

The following plots are interactive and we can hover or Zoom on the locus of interest.

# Ma plot parameters after shrinkage
de_shrink <- lfcShrink(dds = shigeru, coef="RearingCondition_Crowded_vs_Isolated", type="apeglm")
#Thorax(de_shrink)
maplot <-ggmaplot(de_shrink, fdr = 0.05, fc = 1, size = 1, palette = c("#B31B21", "#1465AC", "darkgray"), genenames = as.vector(rownames(de_shrink$name)), top = 0,legend="top",label.select = NULL) +
  coord_cartesian(xlim = c(0, 20)) + 
  scale_y_continuous(limits=c(-12, 12)) + 
  theme(axis.text.x = element_text(size=12),axis.text.y = element_text(size=12),axis.title.x = element_text(size=14),axis.title.y = element_text(size=14),axis.line = element_line(size = 1, colour="gray20"),axis.ticks = element_line(size = 1, colour="gray20")) +
  guides(color = guide_legend(override.aes = list(size = c(3,3,3)))) + 
  theme(legend.position = c(0.70, 0.12),legend.text=element_text(size=14,face="bold"),legend.background = element_rect(fill="transparent")) +
  theme(plot.title = element_text(size=18, colour="gray30", face="bold",hjust=0.06, vjust=-5)) +
  labs(title="MA-plot for the shrunken log2 fold changes in the Thorax tissues")
#interactive_maplot <- ggplotly(maplot)
#interactive_maplot

Volcano plot

#Volcano plot
keyvals <-ifelse( 
  res_shigeru$log2FoldChange >= 1 & res_shigeru$padj <= 0.05, '#B31B21', 
  ifelse(res_shigeru$log2FoldChange <= -1 & res_shigeru$padj <= 0.05, '#1465AC', 'darkgray')) 

keyvals[is.na(keyvals)] <-'lightgray' 
names(keyvals)[keyvals == "#B31B21"] <-'Upregulated' 
names(keyvals)[keyvals == "#1465AC"] <-'Downregulated' 
names(keyvals)[keyvals == 'darkgray'] <-'NS'

res_shigeru$color <- keyvals
volcano_plot <- ggplot(res_shigeru, aes(x = log2FoldChange, y = -log10(padj), 
                                        color = color,  # Use the color column with keyvals
                                        text = rownames(res_shigeru))) +
  geom_point(size = 3, alpha = 0.8) +
  scale_color_identity() +  # Directly use the color values from `keyvals`
  guides(color = "none") +  # Hide the color legend
  labs(title = "Volcano Plot DEG Thorax S. nitens", x = "log2 Fold Change", y = "-log10 Adjusted P-Value") +
  theme_minimal()

# Convert to interactive plot with hover text for gene names
#interactive_volcano <- ggplotly(volcano_plot, tooltip = "text") %>%
#  layout(hoverlabel = list(namelength = -1))

# Display the interactive plot
#interactive_volcano

sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Chicago
tzcode source: internal

attached base packages:
[1] grid      stats4    stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] ggConvexHull_0.1.0          ggdist_3.3.2               
 [3] vsn_3.72.0                  cowplot_1.1.3              
 [5] sva_3.52.0                  BiocParallel_1.38.0        
 [7] genefilter_1.86.0           mgcv_1.9-1                 
 [9] nlme_3.1-166                clusterProfiler_4.12.6     
[11] pheatmap_1.0.12             SARTools_1.8.1             
[13] kableExtra_1.4.0            edgeR_4.2.2                
[15] limma_3.60.6                ashr_2.2-63                
[17] EnhancedVolcano_1.22.0      ggrepel_0.9.6              
[19] ggpubr_0.6.0                apeglm_1.26.1              
[21] circlize_0.4.16             RColorBrewer_1.1-3         
[23] ComplexHeatmap_2.20.0       reshape2_1.4.4             
[25] ggthemes_5.1.0              plotly_4.10.4              
[27] DT_0.33                     data.table_1.16.2          
[29] lubridate_1.9.3             forcats_1.0.0              
[31] stringr_1.5.1               dplyr_1.1.4                
[33] purrr_1.0.2                 readr_2.1.5                
[35] tidyr_1.3.1                 tibble_3.2.1               
[37] ggplot2_3.5.1               tidyverse_2.0.0            
[39] rmdformats_1.0.4            knitr_1.48                 
[41] txdbmaker_1.0.1             GenomicFeatures_1.56.0     
[43] AnnotationDbi_1.66.0        tximport_1.32.0            
[45] DESeq2_1.44.0               SummarizedExperiment_1.34.0
[47] Biobase_2.64.0              MatrixGenerics_1.16.0      
[49] matrixStats_1.4.1           GenomicRanges_1.56.2       
[51] GenomeInfoDb_1.40.1         IRanges_2.38.1             
[53] S4Vectors_0.42.1            BiocGenerics_0.50.0        

loaded via a namespace (and not attached):
  [1] fs_1.6.5                 bitops_1.0-9             enrichplot_1.24.4       
  [4] httr_1.4.7               doParallel_1.0.17        numDeriv_2016.8-1.1     
  [7] tools_4.4.1              backports_1.5.0          utf8_1.2.4              
 [10] R6_2.5.1                 lazyeval_0.2.2           GetoptLong_1.0.5        
 [13] withr_3.0.2              prettyunits_1.2.0        GGally_2.2.1            
 [16] gridExtra_2.3            preprocessCore_1.66.0    cli_3.6.3               
 [19] scatterpie_0.2.4         labeling_0.4.3           sass_0.4.9              
 [22] SQUAREM_2021.1           mvtnorm_1.3-2            mixsqp_0.3-54           
 [25] Rsamtools_2.20.0         systemfonts_1.1.0        yulab.utils_0.1.7       
 [28] gson_0.1.0               DOSE_3.30.5              svglite_2.1.3           
 [31] R.utils_2.12.3           invgamma_1.1             bbmle_1.0.25.1          
 [34] rstudioapi_0.17.1        RSQLite_2.3.7            gridGraphics_0.5-1      
 [37] generics_0.1.3           shape_1.4.6.1            BiocIO_1.14.0           
 [40] crosstalk_1.2.1          distributional_0.5.0     car_3.1-3               
 [43] GO.db_3.19.1             Matrix_1.7-1             fansi_1.0.6             
 [46] abind_1.4-8              R.methodsS3_1.8.2        lifecycle_1.0.4         
 [49] whisker_0.4.1            yaml_2.3.10              carData_3.0-5           
 [52] qvalue_2.36.0            SparseArray_1.4.8        BiocFileCache_2.12.0    
 [55] blob_1.2.4               promises_1.3.0           crayon_1.5.3            
 [58] bdsmatrix_1.3-7          lattice_0.22-6           annotate_1.82.0         
 [61] KEGGREST_1.44.1          pillar_1.9.0             fgsea_1.30.0            
 [64] rjson_0.2.23             codetools_0.2-20         fastmatch_1.1-4         
 [67] glue_1.8.0               ggfun_0.1.7              treeio_1.28.0           
 [70] vctrs_0.6.5              png_0.1-8                gtable_0.3.6            
 [73] emdbook_1.3.13           cachem_1.1.0             xfun_0.49               
 [76] S4Arrays_1.4.1           tidygraph_1.3.1          coda_0.19-4.1           
 [79] survival_3.7-0           iterators_1.0.14         statmod_1.5.0           
 [82] ggtree_3.12.0            bit64_4.5.2              progress_1.2.3          
 [85] filelock_1.0.3           rprojroot_2.0.4          bslib_0.8.0             
 [88] affyio_1.74.0            irlba_2.3.5.1            colorspace_2.1-1        
 [91] DBI_1.2.3                tidyselect_1.2.1         bit_4.5.0               
 [94] compiler_4.4.1           curl_6.0.0               git2r_0.35.0            
 [97] httr2_1.0.6              xml2_1.3.6               ggdendro_0.2.0          
[100] DelayedArray_0.30.1      shadowtext_0.1.4         bookdown_0.41           
[103] rtracklayer_1.64.0       scales_1.3.0             hexbin_1.28.4           
[106] affy_1.82.0              rappdirs_0.3.3           digest_0.6.37           
[109] rmarkdown_2.29           XVector_0.44.0           htmltools_0.5.8.1       
[112] pkgconfig_2.0.3          highr_0.11               dbplyr_2.5.0            
[115] fastmap_1.2.0            rlang_1.1.4              GlobalOptions_0.1.2     
[118] htmlwidgets_1.6.4        UCSC.utils_1.0.0         farver_2.1.2            
[121] jquerylib_0.1.4          jsonlite_1.8.9           GOSemSim_2.30.2         
[124] R.oo_1.27.0              RCurl_1.98-1.16          magrittr_2.0.3          
[127] ggplotify_0.1.2          Formula_1.2-5            GenomeInfoDbData_1.2.12 
[130] patchwork_1.3.0          munsell_0.5.1            Rcpp_1.0.13-1           
[133] ape_5.8                  viridis_0.6.5            stringi_1.8.4           
[136] ggraph_2.2.1             zlibbioc_1.50.0          MASS_7.3-61             
[139] plyr_1.8.9               ggstats_0.7.0            parallel_4.4.1          
[142] graphlayouts_1.2.0       Biostrings_2.72.1        splines_4.4.1           
[145] hms_1.1.3                locfit_1.5-9.10          igraph_2.1.1            
[148] ggsignif_0.6.4           biomaRt_2.60.1           XML_3.99-0.17           
[151] evaluate_1.0.1           BiocManager_1.30.25      tweenr_2.0.3            
[154] tzdb_0.4.0               foreach_1.5.2            httpuv_1.6.15           
[157] polyclip_1.10-7          clue_0.3-65              ggforce_0.4.2           
[160] broom_1.0.7              xtable_1.8-4             restfulr_0.0.15         
[163] tidytree_0.4.6           rstatix_0.7.2            later_1.3.2             
[166] viridisLite_0.4.2        truncnorm_1.0-9          aplot_0.2.3             
[169] memoise_2.0.1            GenomicAlignments_1.40.0 cluster_2.1.6           
[172] workflowr_1.7.1          timechange_0.3.0