The here provided examples are using the cooler Python API with version 0.8.9. Earlier versions do not support single-cell cooler files. The single-cell cooler format uses an HDF5 container and can therefore be accessed with any HDF5 library of any programming language. However, the programmer needs to take care of all the operations on his/her own and make sure the single-cell cooler definitions are met. Please consider our documentation on https://cooler.readthedocs.io/
import cooler
import os
path_file1 = 'data/single-cell/GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool'
path_file2 = 'data/single-cell/GSM2687249_41670_GGCTAC-R1-DpnII.100000.cool'
path_file3 = 'data/single-cell/GSM2687250_41671_TTAGGC-R1-DpnII.100000.cool'
cooler_file1 = cooler.Cooler(path_file1)
cooler_file2 = cooler.Cooler(path_file2)
cooler_file3 = cooler.Cooler(path_file3)
pixel1 = cooler_file1.pixels()[:]
pixel2 = cooler_file2.pixels()[:]
pixel3 = cooler_file3.pixels()[:]
bin1 = cooler_file1.bins()[:]
bin2 = cooler_file2.bins()[:]
bin3 = cooler_file3.bins()[:]
cell_name_list = [os.path.basename(cooler_file1.filename), os.path.basename(cooler_file2.filename), os.path.basename(cooler_file3.filename)]
Bins either as pandas pixels or as a dict of name:bins (as pandas pixels)
bins = bin1
bins_dictionary = {cell_name_list[0]:bin1, cell_name_list[1]:bin2, cell_name_list[2]:bin3}
Pixels as dictionary name:pixels
pixels_dictionary = {cell_name_list[0]:pixel1, cell_name_list[1]:pixel2, cell_name_list[2]:pixel3}
cooler.create_scool('outfile_test.scool', bins, pixels_dictionary)
/home/nezar/miniconda3/lib/python3.7/site-packages/dask/dataframe/utils.py:15: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead. import pandas.util.testing as tm
cooler.create_scool('outfile_test.scool', bins_dictionary, pixels_dictionary)
content_of_scool = cooler.fileops.list_scool_cells('outfile_test.scool')
content_of_scool
['/cells/GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool', '/cells/GSM2687249_41670_GGCTAC-R1-DpnII.100000.cool', '/cells/GSM2687250_41671_TTAGGC-R1-DpnII.100000.cool']
cell1 = cooler.Cooler('outfile_test.scool' + '::' + content_of_scool[0])
cell2 = cooler.Cooler('outfile_test.scool' + '::' + content_of_scool[1])
cell3 = cooler.Cooler('outfile_test.scool' + '::' + content_of_scool[2])
The bins are shared and for all cells identical
cell1.bins()[:10]
chrom | start | end | |
---|---|---|---|
0 | 1 | 0 | 100000 |
1 | 1 | 100000 | 200000 |
2 | 1 | 200000 | 300000 |
3 | 1 | 300000 | 400000 |
4 | 1 | 400000 | 500000 |
5 | 1 | 500000 | 600000 |
6 | 1 | 600000 | 700000 |
7 | 1 | 700000 | 800000 |
8 | 1 | 800000 | 900000 |
9 | 1 | 900000 | 1000000 |
cell2.bins()[:10]
chrom | start | end | |
---|---|---|---|
0 | 1 | 0 | 100000 |
1 | 1 | 100000 | 200000 |
2 | 1 | 200000 | 300000 |
3 | 1 | 300000 | 400000 |
4 | 1 | 400000 | 500000 |
5 | 1 | 500000 | 600000 |
6 | 1 | 600000 | 700000 |
7 | 1 | 700000 | 800000 |
8 | 1 | 800000 | 900000 |
9 | 1 | 900000 | 1000000 |
cell3.bins()[:10]
chrom | start | end | |
---|---|---|---|
0 | 1 | 0 | 100000 |
1 | 1 | 100000 | 200000 |
2 | 1 | 200000 | 300000 |
3 | 1 | 300000 | 400000 |
4 | 1 | 400000 | 500000 |
5 | 1 | 500000 | 600000 |
6 | 1 | 600000 | 700000 |
7 | 1 | 700000 | 800000 |
8 | 1 | 800000 | 900000 |
9 | 1 | 900000 | 1000000 |
The content of the pixels are in all cells different
cell1.pixels()[:10]
bin1_id | bin2_id | count | |
---|---|---|---|
0 | 30 | 30 | 1 |
1 | 30 | 901 | 1 |
2 | 30 | 11424 | 1 |
3 | 30 | 12923 | 1 |
4 | 31 | 31 | 2 |
5 | 32 | 32 | 12 |
6 | 32 | 33 | 1 |
7 | 32 | 35 | 1 |
8 | 32 | 16190 | 1 |
9 | 32 | 17939 | 1 |
cell2.pixels()[:10]
bin1_id | bin2_id | count | |
---|---|---|---|
0 | 32 | 277 | 1 |
1 | 33 | 33 | 1 |
2 | 33 | 25964 | 2 |
3 | 34 | 34 | 1 |
4 | 34 | 37 | 2 |
5 | 34 | 49 | 2 |
6 | 35 | 35 | 12 |
7 | 35 | 36 | 2 |
8 | 35 | 5992 | 1 |
9 | 35 | 8914 | 1 |
cell3.pixels()[:10]
bin1_id | bin2_id | count | |
---|---|---|---|
0 | 30 | 30 | 4 |
1 | 30 | 4486 | 1 |
2 | 30 | 9079 | 1 |
3 | 30 | 16001 | 1 |
4 | 31 | 31 | 4 |
5 | 31 | 32 | 2 |
6 | 31 | 53 | 6 |
7 | 31 | 54 | 5 |
8 | 31 | 190 | 1 |
9 | 31 | 23253 | 1 |