CloupeReader
The main class for reading .cloupe files.
Static Methods
open()
Opens a .cloupe file and returns a CloupeReader instance.
static async open(source: File | Blob | string): Promise<CloupeReader>Parameters
| Name | Type | Description |
|---|---|---|
| source | File | Blob | string | .cloupe file as File/Blob or URL string |
Returns
Promise<CloupeReader> - CloupeReader instance
Examples
// From file input
const file = document.querySelector("input").files[0];
const reader = await CloupeReader.open(file);
// From URL (server must support Range Requests)
const reader = await CloupeReader.open("https://example.com/data.cloupe");
// From Blob
const blob = new Blob([arrayBuffer], { type: "application/octet-stream" });
const reader = await CloupeReader.open(blob);Errors
CloupeError(INVALID_HEADER): Invalid .cloupe file headerCloupeError(INVALID_INDEX): Corrupted index block
Properties
version
get version(): stringReturns the file format version.
fileSize
get fileSize(): numberReturns the file size in bytes.
barcodeCount
get barcodeCount(): numberReturns the number of cells (barcodes).
featureCount
get featureCount(): numberReturns the number of features (genes/proteins).
projectionNames
get projectionNames(): string[]Returns available projection names (e.g., ['UMAP', 't-SNE']).
cellTrackNames
get cellTrackNames(): string[]Returns available cell track names.
clusteringNames
get clusteringNames(): string[]Returns available clustering names.
hasMatrixData
get hasMatrixData(): booleanReturns whether expression matrix data is available.
rawIndex
get rawIndex(): IndexBlockReturns raw index block data. For advanced users.
rawHeader
get rawHeader(): CloupeHeaderReturns raw header data. For advanced users.
Specialized Reader Access
barcodes
get barcodes(): BarcodeReaderReturns BarcodeReader instance.
features
get features(): FeatureReaderReturns FeatureReader instance.
projections
get projections(): ProjectionReaderReturns ProjectionReader instance.
cellTracks
get cellTracks(): CellTrackReaderReturns CellTrackReader instance.
matrix
get matrix(): MatrixReaderReturns MatrixReader instance.
Data Reading Methods
getBarcodes()
async getBarcodes(options?: PaginationOptions): Promise<string[]>Reads barcodes (cell identifiers).
Parameters
| Name | Type | Description |
|---|---|---|
| options.offset | number | Start position (default: 0) |
| options.limit | number | Number to read (default: all) |
Examples
// Read all
const barcodes = await reader.getBarcodes();
// With pagination
const page = await reader.getBarcodes({ offset: 0, limit: 100 });getFeatures()
async getFeatures(options?: PaginationOptions): Promise<Feature[]>Reads feature (gene/protein) information.
Returns
interface Feature {
index: number; // Feature index
id: string; // Feature ID (e.g., ENSG00000167286)
name: string; // Feature name (e.g., CD3D)
type?: string; // Feature type (e.g., Gene Expression)
}getProjection()
async getProjection(name: string): Promise<Projection>Reads projection data by name.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | Projection name (e.g., 'UMAP', 't-SNE') |
Errors
CloupeError(NOT_FOUND): Projection with given name not found
getDefaultProjection()
async getDefaultProjection(): Promise<Projection | null>Returns the default projection. Usually the first projection.
getCellTrack()
async getCellTrack(name: string): Promise<CellTrack>Reads cell track by name.
Expression Data Methods
getFeatureExpression()
async getFeatureExpression(featureIndex: number): Promise<SparseRow>Reads expression data for a specific feature (gene).
Returns
interface SparseRow {
featureIndex: number; // Feature index
indices: Uint32Array; // Cell indices with non-zero values
values: Float64Array; // Expression values
}getCellExpression()
async getCellExpression(barcodeIndex: number): Promise<SparseColumn>Reads expression profile for a specific cell.
Returns
interface SparseColumn {
barcodeIndex: number; // Cell index
indices: Uint32Array; // Gene indices with expression
values: Float64Array; // Expression values
}getExpressionValue()
async getExpressionValue(featureIndex: number, barcodeIndex: number): Promise<number>Returns expression value for a specific gene-cell combination.
getExpressionMatrix()
async getExpressionMatrix(): Promise<SparseMatrix>Reads the full expression matrix in CSR (Compressed Sparse Row) format, optimized for gene-wise access.
Caution
May cause memory issues for large files. Use getExpressionSlice() instead.
getExpressionMatrixCSC()
async getExpressionMatrixCSC(): Promise<SparseMatrixCSC>Reads the full expression matrix in the native CSC (Compressed Sparse Column) format of the .cloupe file, without CSC→CSR conversion. Use this when you need CSC directly (e.g. handing off to scipy.sparse.csc_matrix, WASM kernels, or cell-wise batch processing).
Caution
May cause memory issues for large files. Returned typed arrays share storage with internal caches; treat them as read-only.
getExpressionSlice()
async getExpressionSlice(options: SliceOptions): Promise<SparseMatrix>Reads a portion of the expression matrix.
Parameters
interface SliceOptions {
rowStart?: number; // Start row (gene)
rowEnd?: number; // End row (exclusive)
colStart?: number; // Start column (cell)
colEnd?: number; // End column (exclusive)
}Advanced Analysis Methods
getExpressionByFeatureName()
async getExpressionByFeatureName(featureName: string): Promise<SparseRow | null>Gets expression data by gene name.
Examples
const expression = await reader.getExpressionByFeatureName("CD3D");
if (expression) {
console.log(`${expression.indices.length} cells express CD3D`);
}getCellsInCluster()
async getCellsInCluster(trackName: string, category: string | number): Promise<number[]>Returns cell indices belonging to a specific cluster/category.
getClusterExpression()
async getClusterExpression(
featureName: string,
trackName: string,
category: string | number
): Promise<{ cellIndices: number[]; values: Float64Array } | null>Gets expression data for a gene within a specific cluster.
getSummary()
async getSummary(): Promise<FileSummary>Returns file summary information.
Returns
interface FileSummary {
version: string;
fileSize: number;
barcodeCount: number;
featureCount: number;
projections: string[];
cellTracks: string[];
clusterings: string[];
matrixStats: {
shape: [number, number];
nnz: number; // Number of non-zero values
sparsity: number; // Sparsity (0-1)
} | null;
}Resource Management
clearCache()
clearCache(): voidClears all cached data.
close()
close(): voidCloses the reader and cleans up resources. Always call when done.
Examples
const reader = await CloupeReader.open(file);
try {
const summary = await reader.getSummary();
// ... work
} finally {
reader.close();
}