Skip to content

Commit c63d6fe

Browse files
authored
Merge pull request #58 from mirnylab/print_zoom_levels
Add function to print zoom resolutions
2 parents 0327403 + 90eba2d commit c63d6fe

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

cooler/contrib/higlass.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,30 @@ def get_info(file_path):
136136
}
137137

138138
return info
139+
140+
141+
def get_quadtree_depth(chromsizes, binsize):
142+
"""
143+
Depth of quad tree necessary to tesselate the concatenated genome with quad
144+
tiles such that linear dimension of the tiles is a preset multiple of the
145+
genomic resolution.
146+
147+
"""
148+
tile_size_bp = TILE_SIZE * binsize
149+
min_tile_cover = np.ceil(sum(chromsizes) / tile_size_bp)
150+
return int(np.ceil(np.log2(min_tile_cover)))
151+
152+
153+
def get_zoom_resolutions(chromsizes, base_res):
154+
return [base_res * 2**x for x in range(get_quadtree_depth(chromsizes, base_res)+1)]
155+
156+
157+
def print_zoom_resolutions(chromsizes_file, base_res):
158+
"""
159+
Print comma-separated list of zoom resolutions for a given genome
160+
and base resolution.
161+
162+
"""
163+
chromsizes = cooler.util.read_chromsizes(chromsizes_file, all_names=True)
164+
resolutions = get_zoom_resolutions(chromsizes, base_res)
165+
print(','.join(str(res) for res in resolutions))

0 commit comments

Comments
 (0)