cooler icon indicating copy to clipboard operation
cooler copied to clipboard

How to create a one chromosome cool matrix

Open LAlvarezGlez opened this issue 4 years ago • 6 comments

Hi,

I am quite new with the cool format and I am not able to understand how to do this. I have a genome-wide .cool matrix and to perform some analysis I want just a chromosome X .cool matrix. How do I do that?

Many thanks

Lucía

LAlvarezGlez avatar Oct 19 '21 11:10 LAlvarezGlez

I would also like an answer to lucia's question

nicholas-moskwa avatar Jul 26 '22 12:07 nicholas-moskwa

Apologies for not replying to the original question. I am wondering about the reason you need this? You can easily extract just one chromosome from a whole-genome cooler file for analysis.

Otherwise, @nvictus would know the best way to do this... It should be straightforward, you just need pixels and bins for the right chromosome, and then use cooler.create_cooler() in python API, or cooler load in CLI.

Phlya avatar Jul 26 '22 12:07 Phlya

Hi @Phlya , well I am trying to analyze my data using FIREcaller: https://yunliweb.its.unc.edu/FIREcaller/download.php This Rscript states that it can use .cool files but I haven't had any luck. Their tutorial actually uses a list of chromosome matrix files, so ultimately I think I am going to need to turn the .cool files into an uncompressed location to signal matrix.

nicholas-moskwa avatar Jul 28 '22 12:07 nicholas-moskwa

Looks to me like there's a missing function implementation: cooler2bedpe.

If you decide to try hacking the script to use a dataframe or matrix instead of a file, we recently discovered that you can very easily run the Python cooler package from within R using reticulate and extract what you need. In case it helps:

reticulate::use_condaenv("myenv")  # a conda environment with cooler installed
cooler <- reticulate::import("cooler")

clr <- cooler$Cooler("path/to/file.cool::resolutions/10000")
mat <- clr$matrix(balance = FALSE)$fetch("chr1")  # raw counts, unnormalized, as array
dat <- clr$matrix(balance = FALSE, as_pixels = TRUE)$fetch("chr1")   # raw counts, unnormalized, as dataframe

nvictus avatar Jul 28 '22 13:07 nvictus

You know @nvictus , you are so helpful and I want you to know I really appreciate the assistance. Your R code is generating the matrix I think I need for my analysis! One more question, I don't mind using R for sub-setting the .cool file, but does cooler have a CLI command for doing this?

nicholas-moskwa avatar Jul 28 '22 14:07 nicholas-moskwa

It sure does! cooler dump is what you are looking for. See the --range option.

nvictus avatar Jul 28 '22 15:07 nvictus