In todays session we will work with some of Kindey and HindBrain ATAC-seq data.
I have already produced a summarisedexperiment of counts and put this in the data directory.
data/KidneyBrainCounts.RData
load("data/KidneyBrainCounts.RData")
newDDS <- kindeyBrainCounts
Group <- factor(c("HindBrain","HindBrain","Kidney","Kidney"))
colData(newDDS) <- DataFrame(data.frame(Group,row.names=colnames(kindeyBrainCounts)))
require(DESeq2)
require(tidyverse)
atacDDS <- DESeqDataSet(newDDS,design=~Group)
atacDDS <- DESeq(atacDDS)
myRes <- results(atacDDS,contrast = c("Group","Kidney","HindBrain"),format = "GRanges")
myRes <- myRes[order(myRes$padj),]
upRegions <- myRes[!is.na(myRes$log2FoldChange) & myRes$log2FoldChange > 0][1:1000]
downRegions <- myRes[!is.na(myRes$log2FoldChange) & myRes$log2FoldChange < 0,][1:1000]library(BSgenome.Mmusculus.UCSC.mm10)
upStrings <- getSeq(BSgenome.Mmusculus.UCSC.mm10,resize(upRegions,fix = "center",width = 100))
downStrings <- getSeq(BSgenome.Mmusculus.UCSC.mm10,resize(downRegions,fix = "center",width = 100))
names(upStrings) <- as.character(resize(upRegions,fix = "center",width = 100))
names(downStrings) <- as.character(resize(downRegions,fix = "center",width = 100))
writeXStringSet(upStrings,file="UpRegions.fa")
writeXStringSet(downStrings,file="DownStrings.fa")require(motifmatchr)
require(JASPAR2020)
db <- file.path(system.file("extdata", package="JASPAR2020"),
"JASPAR2020.sqlite")
opts <- list()
opts[["tax_group"]] <- "vertebrates"
opts[["collection"]] <- "CORE"
opts[["all_versions"]] <- FALSE
require(TFBSTools)
motifs <- getMatrixSet(db,opts)
newDDS <- newDDS[rowSums(assay(newDDS)) > 5,]
require(BSgenome.Mmusculus.UCSC.mm10)
newDDS <- addGCBias(newDDS,
genome = BSgenome.Mmusculus.UCSC.mm10)
motif_ix <- matchMotifs(motifs, newDDS,
genome = BSgenome.Mmusculus.UCSC.mm10)
deviations() <- computeDeviations(object = newDDS, annotations = motif_ix)
devZscores <- deviationScores(deviations)
variability_Known <- computeVariability(dev_Known)
variability_Known <- variability_Known[order(variability_Known$p_value),]
topVariable <- variability_Known[1:20,]
devTop <- merge(topVariable[,1,drop=FALSE],devZscores,by=0)
devTop[1:2,]
devToPlot <- as.matrix(devTop[,-c(1:2)])
rownames(devToPlot) <- devTop[,2]
library(pheatmap)
pheatmap(devToPlot)