From d56bc25b1e83ba8fc9f4252634fc78f46c303fa6 Mon Sep 17 00:00:00 2001 From: zxBIB Schcolnicov Date: Mon, 11 Sep 2023 19:30:52 +0200 Subject: [PATCH] Addressing issues due to nan values, causing need finite 'ylim' values error --- scripts/makeGraph2.0.R | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/makeGraph2.0.R b/scripts/makeGraph2.0.R index fa44560..d4ff6c0 100644 --- a/scripts/makeGraph2.0.R +++ b/scripts/makeGraph2.0.R @@ -37,22 +37,23 @@ if (ratioFileInd) { #Plotting in the log scale: offset = 0.01 - + ratio$log2ratio <- log2(ratio$Ratio+offset) #added calculated column to main table so that the operation is only done once + png(filename = paste(args[ratioFileInd],".log2.png",sep = ""), width = 1180, height = 1180, units = "px", pointsize = 20, bg = "white", res = NA) plot(1:10) op <- par(mfrow = c(5,5)) for (i in c(1:22,'X','Y')) { - tt <- which(ratio$Chromosome==i) + tt <- which(ratio$Chromosome==i & is.na(ratio$log2ratio)==FALSE) #filtering rows with na values in log2ratio and it uses the calculated column instead of calculating it every time if (length(tt)>0) { - plot(ratio$Start[tt],log2(ratio$Ratio[tt]+offset),xlab = paste ("position, chr",i),ylab = "normalized copy number profile (log2)",pch = ".",col = colors()[88]) - tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy ) - points(ratio$Start[tt],log2(ratio$Ratio[tt]+offset),pch = ".",col = colors()[136]) + plot(ratio$Start[tt],ratio$log2ratio[tt],xlab = paste ("position, chr",i),ylab = "normalized copy number profile (log2)",pch = ".",col = colors()[88]) #it uses the calculated log2 column + tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy & is.na(ratio$log2ratio)==FALSE) #added the na filter to the points too and it uses the calculated column + points(ratio$Start[tt],ratio$log2ratio[tt],pch = ".",col = colors()[136]) - tt <- which(ratio$Chromosome==i & ratio$CopyNumbermaxLevelToPlot]=maxLevelToPlot - + for (i in c(1:22,'X','Y')) { tt <- which(ratio$Chromosome==i) if (length(tt)>0) { plot(ratio$Start[tt],ratio$Ratio[tt]*ploidy,ylim = c(0,maxLevelToPlot*ploidy),xlab = paste ("position, chr",i),ylab = "normalized copy number profile",pch = ".",col = colors()[88]) - tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy ) + tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy) points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[136]) tt <- which(ratio$Chromosome==i & ratio$Ratio==maxLevelToPlot & ratio$CopyNumber>ploidy) @@ -161,4 +162,4 @@ if (BAFfileInd) { } dev.off() -} else {cat ("WARNING: To get a .png image with BAF profile, you can provide as input a file with suffix 'BAF.txt'\n")} +} else {cat ("WARNING: To get a .png image with BAF profile, you can provide as input a file with suffix 'BAF.txt'\n")} \ No newline at end of file