dozmorovlab / SpectralTAD

TAD Calling using spectral clustering in R
https://dozmorovlab.github.io/SpectralTAD/
Other
8 stars 3 forks source link

Error in rowSums(x) : 'x' must be an array of at least two dimensions #5

Closed kuba11 closed 2 years ago

kuba11 commented 2 years ago

Hello,

I was trying to call TADs on my LOESS normalised data with 3 levels "SpectralTAD(data, chr = chr, resolution = 25000, z_clust = FALSE, levels = 3)" and I got the following error:

Error in rowSums(x) : 'x' must be an array of at least two dimensions

I did some debugging and figured out that the problem is here:

tads = apply(coords, 1, function(x) cont_mat[x[1]:x[2], x[1]:x[2]]) zeros = which(unlist(lapply(tads, function(x) nrow(x) - sum(rowSums(x) == 0))) < min_size * 2)

In my situation 'coords' variable had just 1 entry (start and end). This resulted in 'tads' variable being a single column of values instead of n x n matrix. The 'cont_mat[x[1]:x[2], x[1]:x[2]]' part returns proper matrix, but the apply function does, causing the issue.

Below is a small piece of chr1 which reproduces the problem. data.txt

Take care, Kuba

mdozmorov commented 2 years ago

It seems data format is incorrect. Can you provide the code that reads in your data file and reproduces the error?

kuba11 commented 2 years ago

Hello,

Thank you very much for your quick answer. Here's the code:

Pn1=list() Pn2=list() chr.table=list() hic.table=list() samples=c('sample1, 'sample2') resolution = '25000'

for(i in c(1:22, 'X')){ samp1=read.csv(paste0(samples[1], '.chr', i, '.NONE.', resolution,'.txt'), sep='\t', header=F) samp2=read.csv(paste0(samples[2], '.chr', i, '.NONE.', resolution,'.txt'), sep='\t', header=F) chr.table <- create.hic.table(samp1, samp2, chr = paste0('chr', i)) hic.table[[i]] <- hic_loess(chr.table, Plot = F, Plot.smooth = FALSE) Pn1[[i]]=hic.table[[i]][,c(2,3,11)] Pn2[[i]]=hic.table[[i]][,c(5,6,12)] }

for(i in c(1:22, 'X')){ results1[[i]] <- SpectralTAD(Pn1[[i]], chr = paste0("chr", i), resolution = 25000, z_clust = FALSE, levels = 3) results2[[i]] <- SpectralTAD(Pn2[[i]], chr = paste0("chr", i), resolution = 25000, z_clust = FALSE, levels = 3) }

I am directly loading the data dumped with straw from the '.hic' file. Then I'm joining samples with create.hic.table() from 'HiCcompare'. Finally, I do the normalisation and extract the columns I need. I have created 2 subsets of chromosome 1 data for both samples that reproduce the issue. Everything works when I set levels to 1.

sample1.chr1.NONE.25000.txt sample2.chr1.NONE.25000.txt

Best wishes, Kuba

kuba11 commented 2 years ago

Hello,

I have found the issue, it looks like that I have extracted wrong coordinates for the matrix (I took start1-end1 instead of start1 - start2). Everything works now, so the issue isn't package related. Thanks for your help and sorry for the trouble :)