tilesig 0.1.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tilesig/__init__.py +124 -0
- tilesig/_bundle_data.py +76 -0
- tilesig/_bundle_metadata.py +199 -0
- tilesig/_gpu_linkage_worker.py +147 -0
- tilesig/_version.py +2 -0
- tilesig/algorithm_adapters.py +130 -0
- tilesig/algorithm_binding.py +157 -0
- tilesig/algorithm_types.py +251 -0
- tilesig/algorithms.py +55 -0
- tilesig/annotation.py +1152 -0
- tilesig/annotation_layout.py +104 -0
- tilesig/annotation_names.py +174 -0
- tilesig/annotation_ops.py +199 -0
- tilesig/annotations_extra.py +1573 -0
- tilesig/api.py +861 -0
- tilesig/appearance.py +707 -0
- tilesig/axes.py +146 -0
- tilesig/barplot.py +337 -0
- tilesig/block_heatmap.py +158 -0
- tilesig/block_summary.py +231 -0
- tilesig/bundle_io.py +92 -0
- tilesig/cell_labels.py +68 -0
- tilesig/cell_mask.py +70 -0
- tilesig/clustering.py +39 -0
- tilesig/comparison.py +158 -0
- tilesig/compatibility.py +199 -0
- tilesig/compatibility_extra.py +111 -0
- tilesig/composition_controls.py +132 -0
- tilesig/composition_layout.py +121 -0
- tilesig/config.py +343 -0
- tilesig/decoration_context.py +53 -0
- tilesig/decoration_selection.py +56 -0
- tilesig/decorations.py +166 -0
- tilesig/dendrograms.py +299 -0
- tilesig/diagonal.py +213 -0
- tilesig/distribution_heatmaps.py +164 -0
- tilesig/dot_heatmap.py +274 -0
- tilesig/genomic.py +87 -0
- tilesig/gpu_bridge.py +214 -0
- tilesig/gpu_raster.py +128 -0
- tilesig/graphics.py +92 -0
- tilesig/grouped_textboxes.py +133 -0
- tilesig/h5ad.py +742 -0
- tilesig/h5ad_subset.py +245 -0
- tilesig/helpers.py +246 -0
- tilesig/interval_sets.py +120 -0
- tilesig/item_display_tree.py +81 -0
- tilesig/legend_ticks.py +60 -0
- tilesig/legends.py +607 -0
- tilesig/matplotlib_integration.py +50 -0
- tilesig/matrix_scaling.py +40 -0
- tilesig/matrix_source.py +180 -0
- tilesig/name_layout.py +93 -0
- tilesig/object_ops.py +505 -0
- tilesig/options.py +44 -0
- tilesig/ordering_policy.py +91 -0
- tilesig/palettes.py +101 -0
- tilesig/parent_dendrogram.py +199 -0
- tilesig/pdf_renderer.py +717 -0
- tilesig/png_renderer.py +559 -0
- tilesig/preparation_cache.py +94 -0
- tilesig/prepared.py +179 -0
- tilesig/r_cluster_controls.py +138 -0
- tilesig/r_layout_controls.py +92 -0
- tilesig/r_raster.py +235 -0
- tilesig/renderer.py +3611 -0
- tilesig/renderer_old.py +2060 -0
- tilesig/reproducibility.py +88 -0
- tilesig/sets.py +407 -0
- tilesig/signal_heatmap.py +453 -0
- tilesig/single_cell.py +251 -0
- tilesig/slice_drawing.py +100 -0
- tilesig/slice_geometry.py +48 -0
- tilesig/slice_summary.py +80 -0
- tilesig/source_render.py +252 -0
- tilesig/specialized.py +520 -0
- tilesig/specialized_support.py +172 -0
- tilesig/streaming_pdf.py +118 -0
- tilesig/streaming_svg.py +72 -0
- tilesig/style.py +148 -0
- tilesig/text_boxes.py +158 -0
- tilesig/text_layout.py +45 -0
- tilesig/text_styles.py +83 -0
- tilesig/titles.py +191 -0
- tilesig/tree_styles.py +45 -0
- tilesig/unicode_pdf.py +119 -0
- tilesig/upset_annotations.py +58 -0
- tilesig/vector_grid.py +13 -0
- tilesig/within_block_order.py +167 -0
- tilesig-0.1.0.dev0.dist-info/METADATA +107 -0
- tilesig-0.1.0.dev0.dist-info/RECORD +94 -0
- tilesig-0.1.0.dev0.dist-info/WHEEL +5 -0
- tilesig-0.1.0.dev0.dist-info/licenses/LICENSE +21 -0
- tilesig-0.1.0.dev0.dist-info/top_level.txt +1 -0
tilesig/source_render.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"""Bounded numeric preparation feeding the project's existing native renderer."""
|
|
2
|
+
from dataclasses import fields
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from .matrix_source import MatrixSource, positions
|
|
6
|
+
from .renderer import ClusterMapPlotter
|
|
7
|
+
from .config import HeatmapConfig
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _budget(value,name):
|
|
11
|
+
if isinstance(value,bool) or not isinstance(value,(int,np.integer)) or value<1:raise ValueError(name+' must be a positive integer')
|
|
12
|
+
return int(value)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _SourceArray:
|
|
16
|
+
"""Read-only Cartesian block array; implicit whole-array copies are guarded."""
|
|
17
|
+
dtype=np.dtype('float32');ndim=2
|
|
18
|
+
def __init__(self,source,means=None,stds=None,clip=None,workspace_bytes=64*1024**2):
|
|
19
|
+
self.source=source;self.shape=source.shape;self.size=int(np.prod(self.shape))
|
|
20
|
+
self.means=means;self.stds=stds;self.clip=clip;self.workspace_bytes=workspace_bytes
|
|
21
|
+
self.max_gather_cells=0
|
|
22
|
+
def _transform(self,data,rowids):
|
|
23
|
+
data[np.isnan(data)]=0
|
|
24
|
+
if self.means is not None:
|
|
25
|
+
with np.errstate(divide='ignore',invalid='ignore',over='ignore'):
|
|
26
|
+
data-=self.means[rowids,None];data/=self.stds[rowids,None]
|
|
27
|
+
data[~np.isfinite(data)]=0
|
|
28
|
+
if self.clip is not None:np.clip(data,*self.clip,out=data)
|
|
29
|
+
return data
|
|
30
|
+
def blocks(self):
|
|
31
|
+
for r,c,data in self.source.blocks():
|
|
32
|
+
yield r,c,self._transform(data,np.arange(r,r+len(data)))
|
|
33
|
+
def __getitem__(self,key):
|
|
34
|
+
if not isinstance(key,tuple):key=(key,slice(None))
|
|
35
|
+
if len(key)!=2:raise IndexError('use two-dimensional Cartesian source indexing')
|
|
36
|
+
scalar=[np.isscalar(x) for x in key]
|
|
37
|
+
rr=positions(np.asarray(key[0]).ravel() if isinstance(key[0],np.ndarray) else key[0],self.shape[0])
|
|
38
|
+
cc=positions(np.asarray(key[1]).ravel() if isinstance(key[1],np.ndarray) else key[1],self.shape[1])
|
|
39
|
+
if len(rr)*len(cc)*8>self.workspace_bytes:raise MemoryError('display gather exceeds workspace budget')
|
|
40
|
+
self.max_gather_cells=max(self.max_gather_cells,len(rr)*len(cc))
|
|
41
|
+
rr,ri=np.unique(rr,return_inverse=True);cc,ci=np.unique(cc,return_inverse=True)
|
|
42
|
+
out=np.empty((len(rr),len(cc)),dtype=np.float32)
|
|
43
|
+
width=min(len(cc),self.source.max_block_cells,4096);height=max(1,min(256,self.source.max_block_cells//max(1,width)))
|
|
44
|
+
for r in range(0,len(rr),height):
|
|
45
|
+
for c in range(0,len(cc),max(1,width)):
|
|
46
|
+
rids,cids=rr[r:r+height],cc[c:c+width]
|
|
47
|
+
out[r:r+len(rids),c:c+len(cids)]=self._transform(self.source.read(rids,cids),rids)
|
|
48
|
+
out=out[np.ix_(ri,ci)]
|
|
49
|
+
return out[0,0] if all(scalar) else out[0] if scalar[0] else out[:,0] if scalar[1] else out
|
|
50
|
+
def __array__(self,dtype=None,copy=None):
|
|
51
|
+
limit=min(self.workspace_bytes,max(1024,self.source.block_bytes))
|
|
52
|
+
if self.size*max(8,np.dtype(dtype or np.float32).itemsize)>limit:raise MemoryError('whole source materialization exceeds workspace/implicit array budget; request bounded slices')
|
|
53
|
+
return np.asarray(self[:,:],dtype=dtype)
|
|
54
|
+
def __len__(self):return self.shape[0]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _keys(data):
|
|
58
|
+
bits=np.ascontiguousarray(data,dtype=np.float32).view(np.uint32)
|
|
59
|
+
return np.where(bits&np.uint32(0x80000000),~bits,bits^np.uint32(0x80000000)).astype(np.uint32)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _percentiles(view,quantiles):
|
|
63
|
+
"""Exact order statistics on finite float32 values, bounded radix histograms."""
|
|
64
|
+
high=np.zeros(65536,dtype=np.int64)
|
|
65
|
+
for _,_,data in view.blocks():high+=np.bincount((_keys(data).ravel()>>16),minlength=65536)
|
|
66
|
+
cumulative=np.cumsum(high);n=view.size
|
|
67
|
+
indices=np.asarray(quantiles,dtype=float)/100*(n-1)
|
|
68
|
+
ranks=sorted(set(int(r) for x in indices for r in (np.floor(x),np.ceil(x))))
|
|
69
|
+
buckets={rank:int(np.searchsorted(cumulative,rank,side='right')) for rank in ranks};found={}
|
|
70
|
+
for bucket in set(buckets.values()):
|
|
71
|
+
low=np.zeros(65536,dtype=np.int64)
|
|
72
|
+
for _,_,data in view.blocks():
|
|
73
|
+
keys=_keys(data).ravel();selected=keys[(keys>>16)==bucket]&65535
|
|
74
|
+
low+=np.bincount(selected,minlength=65536)
|
|
75
|
+
cumlow=np.cumsum(low);before=int(cumulative[bucket-1]) if bucket else 0
|
|
76
|
+
for rank,b in buckets.items():
|
|
77
|
+
if b!=bucket:continue
|
|
78
|
+
lowkey=int(np.searchsorted(cumlow,rank-before,side='right'));key=(bucket<<16)|lowkey
|
|
79
|
+
bits=key^0x80000000 if key&0x80000000 else (~key)&0xffffffff
|
|
80
|
+
found[rank]=np.asarray([bits],dtype=np.uint32).view(np.float32)[0]
|
|
81
|
+
result=[]
|
|
82
|
+
for x in indices:
|
|
83
|
+
lo,hi=int(np.floor(x)),int(np.ceil(x));frac=x-lo
|
|
84
|
+
# NumPy's two-point percentile retains its float32 interpolation rules.
|
|
85
|
+
result.append(float(np.percentile(np.asarray([found[lo],found[hi]],dtype=np.float32),frac*100)))
|
|
86
|
+
return result
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _area(view,shape):
|
|
90
|
+
"""Area integration equivalent to cv2.INTER_AREA, without a source-sized copy."""
|
|
91
|
+
out=np.zeros(shape,dtype=np.float64)
|
|
92
|
+
sy,sx=view.shape[0]/shape[0],view.shape[1]/shape[1]
|
|
93
|
+
for r,c,data in view.blocks():
|
|
94
|
+
rr=np.arange(r,r+data.shape[0]);cc=np.arange(c,c+data.shape[1])
|
|
95
|
+
ry=np.minimum((rr/sy).astype(int),shape[0]-1);cx=np.minimum((cc/sx).astype(int),shape[1]-1)
|
|
96
|
+
wr=np.minimum(rr+1,(ry+1)*sy)-rr;wc=np.minimum(cc+1,(cx+1)*sx)-cc
|
|
97
|
+
for yi,yw in ((ry,wr/sy),(np.minimum(ry+1,shape[0]-1),(1-wr)/sy)):
|
|
98
|
+
if not np.any(yw):continue
|
|
99
|
+
for xi,xw in ((cx,wc/sx),(np.minimum(cx+1,shape[1]-1),(1-wc)/sx)):
|
|
100
|
+
if np.any(xw):np.add.at(out,(yi[:,None],xi[None,:]),data*yw[:,None]*xw[None,:])
|
|
101
|
+
return out.astype(np.float32)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class SourceHeatmap(ClusterMapPlotter):
|
|
105
|
+
"""Opt-in source heatmap; bounded unclustered path, preflighted legacy fallback.
|
|
106
|
+
|
|
107
|
+
Uses existing HeatmapConfig names (row_cluster/col_cluster), not R aliases.
|
|
108
|
+
Whole-memory clustering keeps original algorithms and needs a permitted
|
|
109
|
+
max_clustering_bytes workspace. Simple indexed annotations stay lazy;
|
|
110
|
+
data-dependent annotations, splits and legacy style use that same preflight.
|
|
111
|
+
Input source must remain open/stable until the last render.
|
|
112
|
+
Use ``rasterized`` and ``raster_resize_mat`` to override automatic raster
|
|
113
|
+
selection and numeric reduction, respectively.
|
|
114
|
+
"""
|
|
115
|
+
def __init__(self,source,*,row_order=None,column_order=None,workspace_bytes=64*1024**2,
|
|
116
|
+
max_clustering_bytes=None,height_mm=None,config=None,raster_resize_mat=None,**kwargs):
|
|
117
|
+
if not isinstance(source,MatrixSource):raise TypeError('source must be a MatrixSource; use as_matrix_source or H5Data.matrix_source')
|
|
118
|
+
if source.dtype!=np.dtype('float32'):raise ValueError('SourceHeatmap requires float32 blocks; explicitly select dtype=float32 for rendering, or use float64 sources for aggregate_groups')
|
|
119
|
+
from .r_raster import extract as extract_raster_controls, validate_resolved
|
|
120
|
+
extract_raster_controls(self, kwargs, raster_resize_mat, config=config)
|
|
121
|
+
allowed={f.name for f in fields(HeatmapConfig)}|{'df_filter','annotations','row_cluster_map','col_cluster_map','cell_fun','layer_fun'}
|
|
122
|
+
if set(kwargs)-allowed:raise TypeError('unsupported SourceHeatmap options: '+', '.join(sorted(set(kwargs)-allowed)))
|
|
123
|
+
if max_clustering_bytes is None:max_clustering_bytes=config.max_clustering_bytes if config is not None else 256*1024**2
|
|
124
|
+
self.workspace_bytes=_budget(workspace_bytes,'workspace_bytes')
|
|
125
|
+
self._source_tile_edge=min(1024,max(1,int(np.sqrt(self.workspace_bytes//8))))
|
|
126
|
+
self.source_clustering_bytes=_budget(max_clustering_bytes,'max_clustering_bytes')
|
|
127
|
+
rr=positions(row_order,source.shape[0]);cc=positions(column_order,source.shape[1])
|
|
128
|
+
if len(rr)!=source.shape[0] or len(cc)!=source.shape[1] or len(np.unique(rr))!=len(rr) or len(np.unique(cc))!=len(cc):raise ValueError('orders must be complete zero-based permutations')
|
|
129
|
+
if row_order is not None:kwargs['row_cluster']=False
|
|
130
|
+
if column_order is not None:kwargs['col_cluster']=False
|
|
131
|
+
self._input_source=source
|
|
132
|
+
self._source_order_axes = frozenset(
|
|
133
|
+
axis for axis, order in (('row', row_order), ('col', column_order)) if order is not None
|
|
134
|
+
)
|
|
135
|
+
self._source_rows=rr;self._source_columns=cc;self._source=source.subset(rr,cc)
|
|
136
|
+
self._source_options=dict(kwargs);self._source_config=config
|
|
137
|
+
super().__init__(df=self._source,config=config,**kwargs)
|
|
138
|
+
validate_resolved(self)
|
|
139
|
+
if height_mm is not None:
|
|
140
|
+
if not np.isscalar(height_mm) or not np.isfinite(height_mm) or height_mm<=0:raise ValueError('height_mm must be positive finite')
|
|
141
|
+
if self._visual_options.get('output_width') is not None:raise ValueError('height_mm requires width_mm instead of output_width')
|
|
142
|
+
self._shared_body=(self._appearance.mm(self._appearance.body_width_mm),self._appearance.mm(height_mm))
|
|
143
|
+
self.memory_report={'input_kind':source.kind,'block_bytes':source.block_bytes,'workspace_bytes':self.workspace_bytes,'max_clustering_bytes':self.source_clustering_bytes,'path':None,'max_read_cells':0,'storage_io':source.io_report}
|
|
144
|
+
def __deepcopy__(self,memo):
|
|
145
|
+
raise TypeError('source-backed plots share external data; use MatrixSource.subset() and a new SourceHeatmap instead of independent copy/resize/composition operations')
|
|
146
|
+
|
|
147
|
+
def _compute_clustering(self):
|
|
148
|
+
if self._matrix_sorted is not None:return
|
|
149
|
+
source=self._source;source._ensure_open()
|
|
150
|
+
if self.df_filter is not None:
|
|
151
|
+
rows=np.flatnonzero(source.index.str.strip().isin(self.df_filter))
|
|
152
|
+
if not len(rows):raise ValueError('No valid rows after source row-ID filtering')
|
|
153
|
+
source=source.subset(rows,None);self._source_rows=self._source_rows[rows]
|
|
154
|
+
self._source=source;self.df_filter=None
|
|
155
|
+
nr,nc=source.shape
|
|
156
|
+
reasons=[]
|
|
157
|
+
if self.row_cluster or self.col_cluster:reasons.append('clustering')
|
|
158
|
+
if self.style=='legacy':reasons.append('legacy style')
|
|
159
|
+
if self.row_split is not None or self.col_split is not None or self.row_cluster_map is not None or self.col_cluster_map is not None:reasons.append('split/order groups')
|
|
160
|
+
if any(h.df is None for h in self.all_annotations):reasons.append('data-dependent annotations')
|
|
161
|
+
layer_callback=self._visual_options.get('layer_fun') is not None
|
|
162
|
+
if layer_callback:reasons.append('layer_fun callback coordinates')
|
|
163
|
+
if reasons:
|
|
164
|
+
pairs=(nr*(nr-1)//2 if self.row_cluster else 0)+(nc*(nc-1)//2 if self.col_cluster else 0)
|
|
165
|
+
estimate=(80 if layer_callback else 64)*nr*nc+24*pairs+128*(nr+nc)
|
|
166
|
+
if estimate>self.source_clustering_bytes:raise MemoryError(f'{", ".join(reasons)} full-memory workspace estimate {estimate:,} exceeds max_clustering_bytes={self.source_clustering_bytes:,}; explicitly disable row_cluster/col_cluster or reduce/subset the source, supply simpler tracks, or raise the budget')
|
|
167
|
+
frame=np.empty(source.shape,dtype=np.float32)
|
|
168
|
+
for r,c,data in source.blocks():frame[r:r+len(data),c:c+data.shape[1]]=data
|
|
169
|
+
self.raw_matrix=pd.DataFrame(frame,index=source.index,columns=source.columns)
|
|
170
|
+
self.memory_report.update(path='preflighted original dense engine',estimated_workspace_bytes=estimate)
|
|
171
|
+
super()._compute_clustering();self.memory_report['max_read_cells']=self._input_source.max_read_cells
|
|
172
|
+
self._source_rows=self._source_rows[source.index.get_indexer(self.row_names)]
|
|
173
|
+
self._source_columns=self._source_columns[source.columns.get_indexer(self.col_names)]
|
|
174
|
+
return
|
|
175
|
+
if self.z_score and nc>source.max_block_cells:
|
|
176
|
+
raise MemoryError(f'exact legacy z-score reductions require one complete row: raise block_bytes to at least {32*nc:,}, subset columns or explicitly use z_score=False')
|
|
177
|
+
axis_bytes=128*(nr+nc);hist_bytes=2*1024**2
|
|
178
|
+
target=(int(np.ceil(nr/self.row_compression)),int(np.ceil(nc/self.col_compression)))
|
|
179
|
+
compression=self.row_compression>1 or self.col_compression>1
|
|
180
|
+
required=axis_bytes+hist_bytes+(24*target[0]*target[1] if compression else 0)
|
|
181
|
+
if required>self.workspace_bytes:raise MemoryError(f'axis/statistics/compressed display workspace estimate {required:,} exceeds workspace_bytes={self.workspace_bytes:,}; reduce/subset or raise workspace')
|
|
182
|
+
keep_r=np.zeros(source.shape[0],dtype=bool);keep_c=np.zeros(source.shape[1],dtype=bool)
|
|
183
|
+
nonzero=0
|
|
184
|
+
for r,c,data in source.blocks():
|
|
185
|
+
if np.isinf(data).any():raise ValueError('source values must be finite float32 or NaN; infinities/overflow require explicit preprocessing')
|
|
186
|
+
valid=~np.isnan(data);keep_r[r:r+len(data)]|=valid.any(axis=1);keep_c[c:c+data.shape[1]]|=valid.any(axis=0)
|
|
187
|
+
nonzero+=int(np.count_nonzero(np.where(valid,data,0)))
|
|
188
|
+
if not keep_r.any() or not keep_c.any():raise ValueError('No valid numeric data in source')
|
|
189
|
+
self._source_rows=self._source_rows[keep_r];self._source_columns=self._source_columns[keep_c]
|
|
190
|
+
source=source.subset(np.flatnonzero(keep_r),np.flatnonzero(keep_c));nr,nc=source.shape
|
|
191
|
+
use_sp=self.use_sparse if self.use_sparse is not None else 1-nonzero/(nr*nc)>.5
|
|
192
|
+
if not self.z_score:
|
|
193
|
+
means=np.zeros(nr,dtype=np.float32);stds=np.ones(nr,dtype=np.float32)
|
|
194
|
+
elif nc<=source.max_block_cells:
|
|
195
|
+
means=np.empty(nr,dtype=np.float32);stds=np.empty(nr,dtype=np.float32)
|
|
196
|
+
# Preserve the original float32 reduction order exactly whenever
|
|
197
|
+
# complete rows fit a bounded read, including its cancellation rules.
|
|
198
|
+
import bottleneck as bn
|
|
199
|
+
from scipy import sparse
|
|
200
|
+
step=max(1,source.max_block_cells//nc)
|
|
201
|
+
for start in range(0,nr,step):
|
|
202
|
+
data=source.read(slice(start,min(nr,start+step)),None);data[np.isnan(data)]=0
|
|
203
|
+
if use_sp:
|
|
204
|
+
sp=sparse.csr_matrix(data);mu=np.asarray(sp.mean(axis=1),dtype=np.float32).ravel()
|
|
205
|
+
sq=sp.copy();sq.data**=2
|
|
206
|
+
second=np.asarray(sq.mean(axis=1),dtype=np.float32).ravel()
|
|
207
|
+
sigma=np.sqrt(np.maximum(second-mu**2,np.float32(1e-10)))
|
|
208
|
+
else:
|
|
209
|
+
mu=bn.nanmean(data,axis=1).astype(np.float32)
|
|
210
|
+
sigma=bn.nanstd(data,axis=1,ddof=1).astype(np.float32)
|
|
211
|
+
means[start:start+len(data)]=mu;stds[start:start+len(data)]=sigma
|
|
212
|
+
stds[stds==0]=1
|
|
213
|
+
self._source=source
|
|
214
|
+
raw=_SourceArray(source,workspace_bytes=self.workspace_bytes)
|
|
215
|
+
values=_SourceArray(source,means if self.z_score else None,stds if self.z_score else None,workspace_bytes=self.workspace_bytes)
|
|
216
|
+
if self.z_score or (use_sp and (self.vmin is None or self.vmax is None)):
|
|
217
|
+
p=self.z_clip_percentile
|
|
218
|
+
if not 0<=p<=50:raise ValueError('bounded source z_clip_percentile must be between0 and50')
|
|
219
|
+
lo,hi=_percentiles(values,[p,100-p])
|
|
220
|
+
elif self.vmin is not None and self.vmax is not None:lo,hi=float(self.vmin),float(self.vmax)
|
|
221
|
+
else:
|
|
222
|
+
lo=np.inf;hi=-np.inf
|
|
223
|
+
for _,_,data in values.blocks():lo=min(lo,float(data.min()));hi=max(hi,float(data.max()))
|
|
224
|
+
self.vmin,self.vmax=lo,hi;self._limit=max(abs(lo),abs(hi))
|
|
225
|
+
if self.z_score:
|
|
226
|
+
values.clip=(-self._limit,self._limit)
|
|
227
|
+
if self.symmetric:self._limit=self._limit or 1;self.vmin=-self._limit;self.vmax=self._limit
|
|
228
|
+
elif use_sp or (self._visual_options.get('vmin') is not None and self._visual_options.get('vmax') is not None):values.clip=(lo,hi)
|
|
229
|
+
if self.reverse_columns:
|
|
230
|
+
reverse=np.arange(nc-1,-1,-1);source=source.subset(None,reverse);self._source_columns=self._source_columns[reverse]
|
|
231
|
+
raw=_SourceArray(source,workspace_bytes=self.workspace_bytes)
|
|
232
|
+
values=_SourceArray(source,values.means,values.stds,values.clip,self.workspace_bytes)
|
|
233
|
+
self._source=source
|
|
234
|
+
self._display_order_steps = {'col': [{'method': 'reverse_columns', 'backend': 'native'}]}
|
|
235
|
+
self.row_names=source.index.to_numpy();self.col_names=source.columns.to_numpy()
|
|
236
|
+
self._dendrogram_source_row_ids=tuple(self.row_names);self._dendrogram_source_column_ids=tuple(self.col_names)
|
|
237
|
+
self._row_order=np.arange(nr);self._col_order=np.arange(nc)
|
|
238
|
+
self._row_cluster_labels=np.full(nr,'',dtype=object);self._col_cluster_labels=np.full(nc,'',dtype=object)
|
|
239
|
+
self._raw_numeric=raw
|
|
240
|
+
if compression:
|
|
241
|
+
target=(int(np.ceil(nr/self.row_compression)),int(np.ceil(nc/self.col_compression)))
|
|
242
|
+
self._matrix_sorted=_area(values,target);self._matrix_raw_sorted=_area(raw,target)
|
|
243
|
+
ri=np.linspace(0,nr-1,target[0]).astype(int);ci=np.linspace(0,nc-1,target[1]).astype(int)
|
|
244
|
+
self.row_names=self.row_names[ri];self.col_names=self.col_names[ci]
|
|
245
|
+
self._source_rows=self._source_rows[ri];self._source_columns=self._source_columns[ci]
|
|
246
|
+
self._row_order=np.arange(target[0]);self._col_order=np.arange(target[1])
|
|
247
|
+
self._row_cluster_labels=self._row_cluster_labels[ri];self._col_cluster_labels=self._col_cluster_labels[ci]
|
|
248
|
+
else:self._matrix_sorted=values;self._matrix_raw_sorted=raw
|
|
249
|
+
self.memory_report.update(path='bounded source',estimated_workspace_bytes=required,zero_fraction=1-nonzero/(nr*nc),use_sparse_statistics=bool(use_sp),max_read_cells=self._input_source.max_read_cells)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
__all__=['SourceHeatmap']
|