Skip to content

Commit 36a591f

Browse files
author
katarzyna.otylia.sikora@gmail.com
committed
spikein norm in csaw working in allele-specific mode
1 parent 9d8bac5 commit 36a591f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

snakePipes/shared/rscripts/CSAW.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ message(paste("FDR:", fdr, "\n"))
3939
message(paste("LFC:", lfc, "\n"))
4040
message(paste("paired-end? :", pairedEnd, "\n"))
4141
message(paste("allele-specific? :", allelic_info, "\n"))
42+
message(paste("spikein normalization requested :", useSpikeInForNorm, "\n"))
4243
message(paste("External bed? ;", external_bed, "\n"))
4344

45+
4446
## sampleInfo (setup of the experiment)
4547
sampleInfo <- read.table(sampleInfoFilePath, header = TRUE, colClasses = c("character", "character"))
4648
rownames(sampleInfo)<-sampleInfo$name
@@ -128,6 +130,9 @@ if (! external_bed) {
128130
})
129131
}
130132
# merge
133+
all_levels<-unique(unlist(lapply(allpeaks,function(X)seqlevels(X))))
134+
allpeaks<-lapply(allpeaks,function(X){seqlevels(X)<-all_levels
135+
return(X)})
131136
allpeaks <- Reduce(function(x,y) GenomicRanges::union(x,y), allpeaks)
132137

133138
} else {

snakePipes/shared/rscripts/DB_functions.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ makeQCplots_chip_PE <- function(bam.file, outplot, pe.param){
121121
}
122122
collected <- plotwc(bam.file)
123123
xranged <- as.integer(names(collected))
124-
125124
## plot
126125
message("Plotting")
127126
pdf(outplot)
@@ -136,12 +135,13 @@ makeQCplots_chip_PE <- function(bam.file, outplot, pe.param){
136135

137136
# cross correlation
138137
plot(0:max.delay, CCF, type = "l", ylab = "CCF", xlab = "Delay (bp)", main = "PE-Cross-correlation")
139-
138+
print(str(collected))
139+
if( any(is.null(collected)) | any(is.na(collected))){message("Skipping plotting cross correlation.")}else{
140140
# coverage in windows
141141
plot(xranged, collected, type = "l", col = "blue", xlim = c(-1000, 1000), lwd = 2,
142-
xlab = "Distance (bp)", ylab = "Relative coverage per base")
142+
xlab = "Distance (bp)", ylab = "Relative coverage per base")
143143
abline(v = c(-150,200), col = "dodgerblue", lty = 2)
144-
legend("topright", col = "dodgerblue", legend = "specified window size")
144+
legend("topright", col = "dodgerblue", legend = "specified window size")}
145145

146146
dev.off()
147147

@@ -204,7 +204,11 @@ tmmNormalize_chip <- function(chipCountObject, binsize, plotfile){
204204
wider <- csaw::windowCounts(bam.files, bin = TRUE, width = binsize, param = chipCountObject$pe.param)
205205
if(useSpikeInForNorm){
206206
tab<-read.table(scale_factors,sep="\t",header=TRUE,as.is=TRUE,quote="")
207-
normfacs<-1/(tab$scalingFactor[match(colnames(chipCountObject$windowCounts),tab$sample)]) }else{
207+
if(! allelic_info){
208+
normfacs<-1/(tab$scalingFactor[match(colnames(chipCountObject$windowCounts),tab$sample)])}else{
209+
normfacs<-1/(tab$scalingFactor[match(gsub(".genome[1-2]","",colnames(chipCountObject$windowCounts)),tab$sample)])
210+
}
211+
}else{
208212
normfacs <- csaw::normFactors(wider, se.out=FALSE)}
209213

210214
chipCountObject$normFactors <- normfacs

0 commit comments

Comments
 (0)