ChenFengling / RHiCDB

detect and visualize contact domain boundaries (CDBs) or differential CDBs from Hi-C (R version)
8 stars 1 forks source link

Error in FUN(newX[, i], ...) : invalid 'type' (list) of argument #5

Open edf5 opened 4 years ago

edf5 commented 4 years ago

R version 4.0.0

I am working with data from rat so I had to create the CTCF and chrsizes files for the rn6 genomes. I had to exclude chrY (renamed chr22, as directed) because of an error when reading it: [1] "Processing chr22" Your input matrix is normalized matrix, skip KR normalization find local maximum Error in boundary[2, ] : incorrect number of dimensions

After ignoring chr22 (chrY), I could go ahead with the differential analysis: RHiCDB(list(c(sample1,sample1_rep),c(sample2, sample2_rep)), resolution=resolution, chrsizes=chrsizes, ref=ref, mind=mind, wd=wd, wdsize=wdsize,outdir=outdir)

which seemed to go well until the end, when it threw an error: [1] "B. Get CDBs in the first condition." [1] " " [1] " Write outputs: localmax.txt." [1] " " [1] " Decide cut off using enrichmentscore. Write outputs:EScurve1.png." [1] "C. Get CDBs in the second condition." [1] " " [1] " Write outputs: localmax.txt." [1] " " [1] " Decide cut off using enrichmentscore. Write outputs:EScurve2.png." [1] "D. Differential CDBs testing." [1] " Write outputs: allaRI.txt. genomic locus + normalized aRI score in each replicates" [1] "* Write outputs: CDB_merged.txt. genomic locus + score in merged data + normalized aRI score in each replicates +difference +pvalue" [1] "CDB annotation step is only for hg19 and hg38!" [1] "Write outputs without conservation annotation: CDB1.txt, CDB2.txt" [1] "CDB.txt format:#chr start end LRI avgRI consistent_or_differential" Error in FUN(newX[, i], ...) : invalid 'type' (list) of argument

It looks like the CDB_merged.txt file is complete (or almost complete), with entries for all chromosomes, including the last one processed (chr21, which corresponds to chrX).

Not sure what this error is.

edf5 commented 4 years ago

There are two issues with the code that give the stated error: Error in FUN(newX[, i], ...) : invalid 'type' (list) of argument

1- If the number of chromosomes in the data is NOT 23, as would happen if you are not working with human data, you get this error because there are several instances of a for loop hard-coded for 23 chromosomes. The simple solution is to change those lines, for example:

line 542: for(conchr in 1:23){ should read: for(conchr in 1: totalchr){ (the value of totalchr was assigned earlier in the code) I believe that all 'for' loops that go from 1:23 should be changed

2- Calls to mydist function, for example in line 553: pos=apply(mydist(CDBcenter3,CDBcenter1),2,min)<= resolution/2+1

both arguments, CDBcenter3 and CDBcenter1, are lists and neither can be empty. If one of them is an empty list this error will be triggered. I didn't go through all the code, but it can happen that for some chromosome, one of these lists is empty. A solution is to check the lengths of the parameters (in this example, CDBcenter3 and CDBcenter1) before calling the function. If either is zero then the function should not be called. Following this example, let's say that:

a = length(chrpos3) # chrpos3 was used earlier to define CDBcenter3 b = length(chrpos1) # chrpos1 was used earlier to define CDBcenter1

I believe that if b is zero then nothing should be done. If a is zero (and b is greater than zero) then pos should be set to: pos = rep(FALSE, b)

and call line 554 only if b > 0: CDB1[chrpos1,6]=1-as.numeric(pos)

Similar reasoning should be followed for lines 555 and 556.

NOTE: mydist is also called elsewhere in the program. The changes I described work for differential CDB calling with replicates AND with non-human samples, specifically, when the genome is NOT hg19 or hg38. Otherwise, you will probably face similar issues when this function is called, for example lines 353, 385 or 518, and many others. I just didn't have time to go and fix the entire code.

If the author does not fix this and you are interested in having these modifications, you can contact me.