Skip to content

Commit

Permalink
add if statement to check if any DMPs before trying to plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Eilis Hannon committed Jan 9, 2025
1 parent 370b69e commit 8cbd693
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions array/DNAm/analysis/EWAS/summariseWithinCTDMPs.r
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,18 @@ dmpRes <- cbind(dmpRes, probeAnnot[match(rownames(dmpRes), probeAnnot$probeID),

for(each in cellTypes){
subRes <- dmpRes[which(dmpRes[,"DiscoveryCellType"] == each),]
pdf(file.path(resPath, "Plots", paste0("ViolinPlotDiscoveryDMPsWithin", each, "Models.pdf")), width = 6, height = 5)

for(i in 1:nrow(subRes)){
tmpDat<-data.frame("CellType" = QCmetrics$Cell.type, "Phenotype" = QCmetrics$Phenotype, "DNAm" = celltypeNormbeta[rownames(subRes)[i],])
p<-ggplot(tmpDat, aes(x=CellType, y=DNAm, fill = Phenotype)) +
geom_violin(position = pos, scale = 'width') + ggtitle(paste(rownames(subRes)[i], subRes$GeneNames[i])) +
stat_summary(fun = "mean",
geom = "point",
position = pos)
print(p)
}
dev.off()
if(nrow(subRes) > 0){
pdf(file.path(resPath, "Plots", paste0("ViolinPlotDiscoveryDMPsWithin", each, "Models.pdf")), width = 6, height = 5)

for(i in 1:nrow(subRes)){
tmpDat<-data.frame("CellType" = QCmetrics$Cell.type, "Phenotype" = QCmetrics$Phenotype, "DNAm" = celltypeNormbeta[rownames(subRes)[i],])
p<-ggplot(tmpDat, aes(x=CellType, y=DNAm, fill = Phenotype)) +
geom_violin(position = pos, scale = 'width') + ggtitle(paste(rownames(subRes)[i], subRes$GeneNames[i])) +
stat_summary(fun = "mean",
geom = "point",
position = pos)
print(p)
}
dev.off()
}
}

0 comments on commit 8cbd693

Please sign in to comment.