################################################################################
### R script to compare several conditions with the SARTools and DESeq2 packages
### Hugo Varet
### March 23rd, 2022
### designed to be executed with SARTools 1.8.1
################################################################################
################################################################################
### parameters: to be modified by the user ###
################################################################################
rm(list=ls()) # remove all the objects from the R session
workDir <- "C:/path/to/your/working/directory/" # working directory for the R session
projectName <- "projectName" # name of the project
author <- "Your name" # author of the statistical analysis/report
targetFile <- "target.txt" # path to the design/target file
rawDir <- "raw" # path to the directory containing raw counts files
featuresToRemove <- c("alignment_not_unique", # names of the features to be removed
"ambiguous", "no_feature", # (specific HTSeq-count information and rRNA for example)
"not_aligned", "too_low_aQual")# NULL if no feature to remove
varInt <- "group" # factor of interest
condRef <- "WT" # reference biological condition
batch <- NULL # blocking factor: NULL (default) or "batch" for example
fitType <- "parametric" # mean-variance relationship: "parametric" (default), "local" or "mean"
cooksCutoff <- TRUE # TRUE/FALSE to perform the outliers detection (default is TRUE)
independentFiltering <- TRUE # TRUE/FALSE to perform independent filtering (default is TRUE)
alpha <- 0.05 # threshold of statistical significance
pAdjustMethod <- "BH" # p-value adjustment method: "BH" (default) or "BY"
typeTrans <- "VST" # transformation for PCA/clustering: "VST" or "rlog"
locfunc <- "median" # "median" (default) or "shorth" to estimate the size factors
colors <- c("#f3c300", "#875692", "#f38400", # vector of colors of each biological condition on the plots
"#a1caf1", "#be0032", "#c2b280",
"#848482", "#008856", "#e68fac",
"#0067a5", "#f99379", "#604e97")
forceCairoGraph <- FALSE
################################################################################
### running script ###
################################################################################
setwd(workDir)
library(SARTools)
if (forceCairoGraph) options(bitmapType="cairo")
# checking parameters
checkParameters.DESeq2(projectName=projectName,author=author,targetFile=targetFile,
rawDir=rawDir,featuresToRemove=featuresToRemove,varInt=varInt,
condRef=condRef,batch=batch,fitType=fitType,cooksCutoff=cooksCutoff,
independentFiltering=independentFiltering,alpha=alpha,pAdjustMethod=pAdjustMethod,
typeTrans=typeTrans,locfunc=locfunc,colors=colors)
# loading target file
target <- loadTargetFile(targetFile=targetFile, varInt=varInt, condRef=condRef, batch=batch)
# loading counts
counts <- loadCountData(target=target, rawDir=rawDir, featuresToRemove=featuresToRemove)
# description plots
majSequences <- descriptionPlots(counts=counts, group=target[,varInt], col=colors)
# analysis with DESeq2
out.DESeq2 <- run.DESeq2(counts=counts, target=target, varInt=varInt, batch=batch,
locfunc=locfunc, fitType=fitType, pAdjustMethod=pAdjustMethod,
cooksCutoff=cooksCutoff, independentFiltering=independentFiltering, alpha=alpha)
# PCA + clustering
exploreCounts(object=out.DESeq2$dds, group=target[,varInt], typeTrans=typeTrans, col=colors)
# summary of the analysis (boxplots, dispersions, diag size factors, export table, nDiffTotal, histograms, MA plot)
summaryResults <- summarizeResults.DESeq2(out.DESeq2, group=target[,varInt], col=colors,
independentFiltering=independentFiltering,
cooksCutoff=cooksCutoff, alpha=alpha)
# save image of the R session
save.image(file=paste0(projectName, ".RData"))
# generating HTML report
writeReport.DESeq2(target=target, counts=counts, out.DESeq2=out.DESeq2, summaryResults=summaryResults,
majSequences=majSequences, workDir=workDir, projectName=projectName, author=author,
targetFile=targetFile, rawDir=rawDir, featuresToRemove=featuresToRemove, varInt=varInt,
condRef=condRef, batch=batch, fitType=fitType, cooksCutoff=cooksCutoff,
independentFiltering=independentFiltering, alpha=alpha, pAdjustMethod=pAdjustMethod,
typeTrans=typeTrans, locfunc=locfunc, colors=colors)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.