Skip to content

API Reference

Core Functions

rankGenesGroups

The main entry point for differential expression analysis.

typescript
async function rankGenesGroups(
  expression: ExpressionInput,
  groups: GroupInfo,
  options?: RankGenesGroupsOptions
): Promise<RankGenesResult>

Parameters

ParameterTypeDescription
expressionExpressionInputExpression matrix or chunked matrix
groupsGroupInfoGroup assignment for each cell
optionsRankGenesGroupsOptionsAnalysis options (optional)

Options

OptionTypeDefaultDescription
backend'auto' | 'webgpu' | 'webgl2''auto'GPU backend selection
referencenull | stringundefinedReference group for comparison (default: all other cells)
nGenesnumberallNumber of top genes to return
corrMethod'benjamini-hochberg' | 'bonferroni''benjamini-hochberg'P-value correction method
tieCorrectbooleanfalseApply tie correction to Z-scores
rankbyAbsbooleanfalseRank by absolute Z-score
logBasenumberMath.ELog base for fold change calculation
geneNamesstring[]['gene_0', ...]Names for each gene
groups'all' | string[]'all'Groups to analyze
streaming'auto' | boolean'auto'Enable streaming mode
maxMemoryMBnumber2048Maximum GPU memory usage (MB)
sortAlgorithm'auto' | 'bitonic' | 'radix''auto'Sorting algorithm (WebGPU only)
onProgress(progress: StreamingProgress) => void-Progress callback

Returns

typescript
interface RankGenesResult {
  groups: Map<string, GroupResult>;
  params: RankGenesParams;
}

Example

typescript
import { rankGenesGroups } from 'deg.js';

const result = await rankGenesGroups(expression, groups, {
  nGenes: 100,
  corrMethod: 'benjamini-hochberg',
  onProgress: (p) => console.log(`${p.genesProcessed}/${p.totalGenes}`),
});

Types

ExpressionMatrix

Standard expression matrix with all data in memory.

typescript
interface ExpressionMatrix {
  data: Float32Array;         // Expression values
  nCells: number;             // Number of cells
  nGenes: number;             // Number of genes
  layout?: 'row-major' | 'column-major';  // Default: 'row-major'
}

ChunkedExpressionMatrix

Lazy-loading expression matrix for large datasets.

typescript
interface ChunkedExpressionMatrix {
  nCells: number;
  nGenes: number;
  layout?: 'row-major' | 'column-major';
  getGeneChunk: (startGene: number, nGenes: number) => GeneChunkData | Promise<GeneChunkData>;
}

interface GeneChunkData {
  data: Float32Array;
  nGenes: number;
  layout?: 'row-major' | 'column-major';
}

GroupInfo

Group assignment information.

typescript
interface GroupInfo {
  groupLabels: Uint32Array;   // Group index (0-indexed) for each cell
  groupNames: string[];       // Human-readable group names
  nGroups: number;            // Total number of groups
}

GroupResult

Results for a single group.

typescript
interface GroupResult {
  names: string[];              // Gene names (sorted by score)
  scores: Float32Array;         // Z-scores
  pvals: Float64Array;          // P-values
  pvalsAdj: Float64Array;       // Adjusted p-values
  logFoldChanges: Float32Array; // Log2 fold changes
}

StreamingProgress

Progress information during streaming mode.

typescript
interface StreamingProgress {
  chunksProcessed: number;
  totalChunks: number;
  genesProcessed: number;
  totalGenes: number;
  elapsedMs: number;
  estimatedRemainingMs: number;
}

Utility Functions

isWebGPUAvailable

Check if WebGPU is available in the current environment.

typescript
function isWebGPUAvailable(): boolean

Type Guards

typescript
// Check if expression is chunked (lazy loading)
function isChunkedExpression(expr: ExpressionInput): expr is ChunkedExpressionMatrix

// Check if expression is full matrix (all data in memory)
function isFullExpression(expr: ExpressionInput): expr is ExpressionMatrix

See Also

Released under the MIT License.