hms-dbmi / spp

SPP - R package for analysis of ChIP-seq and other functional sequencing data
39 stars 22 forks source link

tag.enrichment.clusters: Error in abs(NULL) : non-numeric argument to mathematical function #4

Open your-highness opened 8 years ago

your-highness commented 8 years ago

Hello,

I have a couple of histone ChIP-seq data sets mapped against GRCh37. These data contain chromosomes: 1-22,X,Y,MT,GL000...,hs37d5

I ran the following resulting in an error:

chip.data <- read.bam.tags(sig.file)
input.data <- read.bam.tags(ctrl.file)
binding.characteristics <- get.binding.characteristics(chip.data,srange=c(50,500),bin=5, accept.all.tags = T)

broad.clusters <- get.broad.enrichment.clusters(signal.data=chip.data$tags,control.data=input.data$tags,window.size=1e3,z.thr=3,tag.shift=round(binding.characteristics$peak$x/2))

Calls: get.broad.enrichment.clusters ... find.significantly.enriched.regions -> lapply -> FUN -> tag.enrichment.clusters -> diff Error in abs(signal) : non-numeric argument to mathematical function

The error is related to the function tag.enrichment.clusters:

1009 tag.enrichment.clusters <- function(signal,background,wsize=200,thr=3,mcs=1,bg.weight=1,min.tag.count.z=0,tag.av.den=NULL,min.tag.count.thr=0,min.tag.count.ratio=4,either=F,tag.shift=146/2) {
1010   if(is.null(tag.av.den)) {
1011     tag.av.den <- length(signal)/diff(range(abs(signal)));
1012   }

I went back to check chip.data and input.data. There were some list elements in chip.data$tags were NULL (no reads mapped to these chromosomes). I removed these and it fixed the issue:

idx.notnull <- !sapply(chip.data$tags, is.null)
chip.data <- lapply(chip.data, "[", idx.notnull)
input.data <- lapply(input.data, "[", idx.notnull)

Do you think this is an okay workaround? You might wanna check in tag.enrichment.clusters for is.null(signal).

Best, Johannes