Members
(constant) availableReaders
- Description:
All known dataset readers. Each entry contains a Dataset class with the key defined as the
formatreturn value.
- Source:
All known dataset readers.
Each entry contains a Dataset class with the key defined as the format return value.
Methods
analysisDefaults()
- Description:
Generate an object containing all of the default analysis parameters.
- Source:
Returns:
An object where each property corresponds to an analysis step and contains the default parameters for that step.
See the documentation for each step's compute method for more details:
inputsrna_quality_controladt_quality_controlcrispr_quality_controlcell_filteringrna_normalizationadt_normalizationcrispr_normalizationfeature_selectionrna_pcaadt_pcacrispr_pcaneighbor_indextsneumapkmeans_clustersnn_graph_clusterchoose_clusteringcell_labellingfeature_set_enrichment
See also configureBatchCorrection and configureApproximateNeighbors to synchronize certain parameter settings across multiple steps.
callScran(fun)
- Description:
Call a scran.js function. This allows client applications to operate in the same scran.js memory space as bakana functions, which is not guaranteed if applications import scran.js on their own (e.g., due to name mangling with Webpack).
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
fun |
function | A function that accepts the scran.js module object and presumably calls some of its functions. |
Returns:
The return value of fun.
configureApproximateNeighbors(parameters, approximate)
- Description:
Specify whether approximate neighbor searches should be performed across all affected steps. This is a convenient helper as it is generally unnecessary to switch between exact and approximate searches in different steps. Affected steps are BatchCorrectionState, CombineEmbeddingsState and NeighborIndexState.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
parameters |
object | Object containing parameters for all steps, e.g., from |
approximate |
boolean | Whether to perform approximate nearest neighbor searces. |
Returns:
parameters is modified with appropriate parameters in relevant steps, e.g., batch_correction, combine_embeddings and neighbor_index.
configureBatchCorrection(parameters, method)
- Description:
Set the batch correction parameters across multiple steps. This is a convenient helper as the correction process is split across the PCA and batch correction steps. For MNN, we project cells onto rotation vectors computed within each batch in the various PCA steps (e.g., PcaState) before performing MNN correction in BatchCorrectionState; for linear regression, we need to regress by block in the PCA without any additional correction in BatchCorrectionState; and for no correction, we need to turn off any block handling in the PCA as well as removing any additional correction in BatchCorrectionState.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
parameters |
object | Object containing parameters for all steps, e.g., from |
method |
string | Correction method to perform, one of |
Returns:
parameters is modified with appropriate parameters in batch_correction, pca and adt_pca.
createAnalysis()
- Description:
Create a new analysis state in preparation for calling
runAnalysis. Multiple states can be created and used interchangeably within the same Javascript runtime.
- Source:
Returns:
A promise that resolves to an object containing states for all analysis steps.
This object can be used as input into runAnalysis.
freeAnalysis(state)
- Description:
Free the contents of an analysis state. This releases memory on the scran.js Wasm heap and terminates any workers associated with this analysis.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
state |
An existing analysis state, produced by |
Returns:
A promise that resolves to null when all states are freed.
guessApproximateNeighborsConfig(parameters, optionsopt) → (nullable) {boolean}
- Description:
Guess the value of
approximatefromconfigureApproximateNeighborsbased on the parameter object. This effectively consolidates the various approximation parameters into a single setting.
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
parameters |
object | Object containing parameters for all steps, typically after |
|||||||||
options |
object |
<optional> |
Optional parameters. Properties
|
Returns:
Whether or not approximate neighbor search was used.
If strict = false and there is a mixture of approximate and exact matches, an approximate search is reported;
otherwise, if strict = true, null is returned.
- Type
- boolean
guessBatchCorrectionConfig(parameters, optionsopt) → (nullable) {string}
- Description:
Guess the
methodvalue fromconfigureBatchCorrectionbased on the parameter object. This effectively consolidates the various correction parameters into a single setting.
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
parameters |
object | Object containing parameters for all steps, typically after |
|||||||||
options |
object |
<optional> |
Optional parameters. Properties
|
Returns:
One of "mnn", "regress" or "none", based on the expected set of modifications from configureBatchCorrection.
If strict = false and there is no exact match to the expected set, the most appropriate method is returned;
otherwise, if strict = true, null is returned.
- Type
- string
initialize(optionsopt)
- Description:
Initialize the backend for computation. This is required prior to running any other bakana function.
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Optional parameters. Properties
|
Returns:
A promise that resolves to null when initialization is complete.
promoteToNumber(x) → (nullable) {Float64Array}
- Description:
Detect if an array contains only stringified numbers and, if so, convert it into a TypedArray. Conversion will still be performed for non-number strings corresponding to missing values or explicit not-a-number entries.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Array | Array of strings, usually corresponding to a column in a table read by |
Returns:
A Float64Array is returned if x contains stringified numbers.
Otherwise, null is returned if the conversion could not be performed.
- Type
- Float64Array
(async) readLines2(x, optionsopt) → {Array}
- Description:
Read lines of text from a file, possibly with decompression.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
x |
string | Uint8Array | SimpleFile | File | Contents of the file to be read. On Node.js, this may be a string containing a path to a file; on browsers, this may be a File object. |
|||||||||||||||||
options |
object |
<optional> |
{}
|
Optional parameters. Properties
|
Returns:
Array of strings where each entry contains a line in buffer.
The newline itself is not included in each string.
- Type
- Array
(async) readTable2(x, optionsopt) → {Array}
- Description:
Read a delimiter-separated table from a buffer, possibly with decompression. This assumes that newlines represent the end of each row of the table, i.e., there cannot be newlines inside quoted strings.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
x |
string | Uint8Array | SimpleFile | File | Contents of the file to be read. On Node.js, this may be a string containing a path to a file; on browsers, this may be a File object. |
||||||||||||||||||||||
options |
object |
<optional> |
{}
|
Optional parameters. Properties
|
Returns:
Array of length equal to the number of lines in buffer.
Each entry is an array of strings, containing the delim-separated fields for its corresponding line.
- Type
- Array
retrieveParameters(state) → {object}
- Description:
Retrieve analysis parameters from a state object.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
state |
object | Object containing the analysis state, produced by |
Returns:
Object containing the analysis parameters for each step, similar to that created by analysisDefaults.
- Type
- object
runAnalysis(state, datasets, params, optionsopt)
- Description:
Run a basic single-cell RNA-seq analysis with the specified files and parameters. This will cache the results from each step so that, if the parameters change, only the affected steps will be rerun.
- Source:
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
state |
object | Object containing the analysis state, produced by |
||||||||||||||||
datasets |
object | Object where each (arbitrarily named) property corresponds to an input dataset. Each dataset should be a object that satisfies the Dataset contract. Alternatively, |
||||||||||||||||
params |
object | An object containing parameters for all steps.
See |
||||||||||||||||
options |
object |
<optional> |
Optional parameters. Properties
|
Returns:
A promise that resolves to null when all asynchronous analysis steps are complete.
The contents of state are modified by reference to reflect the latest state of the analysis with the supplied parameters.
saveGenewiseResults(state, pathnullable, optionsopt) → (nullable) {Object}
- Description:
Save the per-gene analysis results as data frames in the takane format. This includes the marker tables for the clusters and custom selections, as well as the variance modelling statistics from the feature selection step. Each data frames has the same order of rows as the SingleCellExperiment saved by
saveSingleCellExperiment; for easier downstream use, we set the row names of each data frame to row names of the SingleCellExperiment (or if no row names are available, we set each data frame's row names to the first column of therowData).
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
state |
object | Existing analysis state containing results, after one or more runs of |
|||||||||||||||||||||||||||
path |
string |
<nullable> |
Local path in which to save all results.
If a local filesystem is present and |
||||||||||||||||||||||||||
options |
object |
<optional> |
{}
|
Optional parameters. Properties
|
Returns:
If directory is supplied and a local filesystem exists, the data frame components are saved to disk and null is returned.
Otherwise, if directory = null or a local filesystem does not exist, an object is returned where each key is a local path to a component file and each value is a Uint8Array with the file contents.
- Type
- Object
saveSingleCellExperiment(state, name, optionsopt) → (nullable) {Object}
- Description:
Save the analysis results into a SingleCellExperiment using the takane format. This uses a language-agnostic format mostly based on HDF5 and JSON, which can be read into a variety of frameworks like R and Python. The aim is to facilitate downstream analysis procedures that are not supported by bakana itself; for example, a bench scientist can do a first pass with kana before passing the results to a computational collaborator for deeper inspection.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
state |
object | Existing analysis state containing results, after one or more runs of |
||||||||||||||||||||||
name |
string | Name of the SingleCellExperiment.
This may also contain forward slashes, in which case it is treated as a local path.
If a local filesystem is present and |
||||||||||||||||||||||
options |
object |
<optional> |
{}
|
Optional parameters. Properties
|
Returns:
If directory is supplied and a local filesystem exists, the components are saved to disk and null is returned.
Otherwise, if directory = null or a local filesystem does not exist, an object is returned where each key is a local path to a component file and each value is a Uint8Array with the file contents.
- Type
- Object
searchZippedAlabaster(handle) → {Map}
- Description:
Search a ZIP file for SummarizedExperiments to use in ZippedAlabasterDataset or ZippedAlabasterResult.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
handle |
JSZip | A handle into the ZIP file, generated using the JSZip package. |
Returns:
Object where the keys are the paths/names of possible SummarizedExperiment objects, and each value is a 2-element array of dimensions.
- Type
- Map
searchZippedArtifactdb(handle) → {Map}
- Description:
Search a ZIP file for SummarizedExperiments to use in ZippedArtifactdbDataset or ZippedArtifactdbResult.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
handle |
JSZip | A handle into the ZIP file, generated using the JSZip package. |
Returns:
Object where the keys are the paths/names of possible SummarizedExperiment objects, and each value is a 2-element array of dimensions.
- Type
- Map
(async) serializeConfiguration(state, saver) → {object}
- Description:
Save the analysis configuration to file, including the parameters and datasets. This can be stringified and saved to file, or it can be used in
unserializeConfiguration.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
state |
object | State object produced by |
saver |
function | Function to save files, see |
Returns:
Object containing the serialized analysis configuration, with the following properties:
parameters, an object containing parameters that can be used inrunAnalysis.datasets, an object containing serialized datasets that can be used inunserializeDatasets.other, an object containing more parameters that need special handling outside ofparameters. This typically involves calling setter functions directly on the State objects:inputs.direct_subsetcontains a direct subset that can be used inInputsState.setDirectSubsetbefore callingrunAnalysis.custom_selections.selectionscontains selections that can be used inCustomSelectionsState.addSelectionafterrunAnalysis.
- Type
- object
(async) serializeDatasets(datasets, saver) → {object}
- Description:
Format a collection of Dataset objects so that they can be saved to file.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
datasets |
object | Object containing Dataset instances, just like that used in |
saver |
function | Function that converts a SimpleFile instance into an identifier string. Specifically, it should accept three arguments:
It should then return a string that uniquely identifies this file within |
Returns:
Object containing information about the files and datasets in datasets.
- Type
- object
setCreateLink(fun)
- Description:
Specify a function to create links for data files.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
fun |
function | Function that accepts:
It should return a string containing some unique identifier to the file. This is most typically used to register the file with some user-specified database system for later retrieval. |
Returns:
fun is set as the global link creator for this step.
The previous value of the creator is returned.
setResolveLink(fun)
- Description:
Specify a function to resolve links for data files.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
fun |
function | Function that accepts a string containing a linking idenfier and returns any value that can be used in the SimpleFile constructor i.e., a Uint8Array, File (on browser) or string containing a file path (on Node.js). This is most typically used to retrieve a file from some user-specified database system. |
Returns:
fun is set as the global resolver for this step.
The previous value of the resolver is returned.
setVisualizationAnimate(fun)
- Description:
Specify a function to handle animation iterations for the low-dimensional embeddings. The exact nature of this handling is arbitrary - developers may post the contents to another thread, save them to file, etc.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
fun |
function | Function to process each animation iteration. This should accept four arguments, in the following order:
|
Returns:
fun is set as the global animator function for t-SNE and UMAP.
The previous value of the animator is returned.
subsetInputs(state, indices, optionsopt) → {object}
- Description:
Create a new analysis state object consisting of a subset of cells from an existing analysis state. This assumes that the existing state already contains loaded matrix data in its
inputsproperty, which allows us to create a cheap reference without reloading the data into memory.
- Source:
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
state |
object | State object such as that produced by |
||||||||||||||||
indices |
TypedArray | Array | Array containing the indices for the desired subset of cells.
This should be sorted and non-duplicate.
Any existing subset in |
||||||||||||||||
options |
object |
<optional> |
Optional parameters. Properties
|
Returns:
A state object containing loaded matrix data in its inputs property.
Note that the other steps do not have any results, so this object should be passed through runAnalysis before it can be used.
- Type
- object
summarizeArray(array, optionsopt) → {object}
- Description:
Summarize an array, typically corresponding to a single column of per-cell annotation. This can be used as part of a preflight response in a Reader.
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
array |
Array | TypedArray | Per-cell annotation array of length equal to the number of cells for a given matrix. An Array is treated as categorical data and should contain strings, while TypedArrays are treated as continuous data. |
|||||||||||
options |
object |
<optional> |
Optional parameters. Properties
|
Returns:
Object containing type, a string indicating whether array was categorical or continuous.
If "categorical", the object will contain values, an array of unique values up to the length specified by limit.
It will also contain truncated, a boolean indicating whether the actual number of unique values exceeds limit.
If "continuous", the object will contain the numbers min and max specifying the minimum and maximum value in x, respectively.
min or max may be negative or positive infinity, respectively, if there is no bound on one or both ends.
If min > max, all values in array are NaNs such that no bound can be found.
- Type
- object
terminate()
- Description:
Terminate the backend, in particular shutting down all workers. This is typically necessary for a clean shutdown in Node.js applications.
- Source:
Returns:
A promise that resolves to null when all workers are terminated.
(async) unserializeConfiguration(serialized, loader, optionsopt) → {object}
- Description:
Load the analysis configuration from its serialized format. This is effectively the reverse operation of
serializeConfiguration.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
serialized |
object | Configuration object produced by |
||||||||||||||||||||||
loader |
function | Function to load files, see |
||||||||||||||||||||||
options |
object |
<optional> |
{}
|
Optional parameters. Properties
|
Returns:
State object containing analysis results.
This is identical to the state passed into serializeConfiguration.
If state is supplied, it is used directly as the return value.
- Type
- object
(async) unserializeDatasets(serialized, loader) → {object}
- Description:
Unserialize dataset information into their corresponding Dataset instances. This assumes that
availableReadershas been configured for all dataset formats that might be present.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
serialized |
object | Object containing the output of |
loader |
function | Function that accepts a single argument, the identifier string produced by |
Returns:
An object containing Dataset instances that can be directly used in InputsState.compute.
- Type
- object
Type Definitions
AlabasterProjectNavigator
- Description:
Any class that satisfies the AlabasterProjectNavigator contract, so called as it is intended to "navigate" an alabaster-formatted object directory. This should provide the following methods:
get(path, asBuffer), a (possibly async) method that accepts a stringpathcontaining a relative path to a file inside an object directory. This should return a string containing a path to the file on the local filesystem, or a Uint8Array containing the contents of the file if no local filesystem exists. IfasBuffer = true, a Uint8Array must be returned.exists(path), a (possibly async) method that accepts a stringpathcontaining a relative path to a file inside an object directory. This should return a boolean indicating whetherpathexists in the object directory.clean(localPath), a (possibly async) method that accepts a string containing a local path returned byget(). It should remove any temporary file that was created byget()atlocalPath. This will not be called ifget()returns a Uint8Array.
- Source:
Any class that satisfies the AlabasterProjectNavigator contract, so called as it is intended to "navigate" an alabaster-formatted object directory. This should provide the following methods:
get(path, asBuffer), a (possibly async) method that accepts a stringpathcontaining a relative path to a file inside an object directory. This should return a string containing a path to the file on the local filesystem, or a Uint8Array containing the contents of the file if no local filesystem exists. IfasBuffer = true, a Uint8Array must be returned.exists(path), a (possibly async) method that accepts a stringpathcontaining a relative path to a file inside an object directory. This should return a boolean indicating whetherpathexists in the object directory.clean(localPath), a (possibly async) method that accepts a string containing a local path returned byget(). It should remove any temporary file that was created byget()atlocalPath. This will not be called ifget()returns a Uint8Array.
ArtifactdbProjectNavigator
- Description:
Any class that satisfies the ArtifactdbProjectNavigator contract, so called as it is intended to "navigate" an ArtifactDB project directory. This should provide the following methods:
-
metadata(p), a (possibly async) method that accepts a stringpcontaining a relative path to a resource inside an ArtifactDB project directory, and returns an object containing the metadata for that object. Any redirections should be resolved by this method.Note that AbstractArtifactdbDataset will automatically cache the outputs of all
metadata()calls between any invocations ofclear, to improve efficiency when repeatedly accessing the same metadata. The same applies to AbstractArtifactdbResult. -
file(p), a (possibly async) method that accepts a stringpcontaining a relative path inside a project directory and returns the contents of the file at that path. The return value should typically be a Uint8Array; on Node.js, methods may alternatively return a string containing a path to the file on the local file system. The method does not need to handle redirections fromp.
Optionally, the ArtifactdbProjectNavigator class may implement a
clear()method to remove any cached content. This will be called byAbstractArtifactdbDataset.clearandAbstractArtifactdbResult.clear.-
- Source:
Any class that satisfies the ArtifactdbProjectNavigator contract, so called as it is intended to "navigate" an ArtifactDB project directory. This should provide the following methods:
-
metadata(p), a (possibly async) method that accepts a stringpcontaining a relative path to a resource inside an ArtifactDB project directory, and returns an object containing the metadata for that object. Any redirections should be resolved by this method.Note that AbstractArtifactdbDataset will automatically cache the outputs of all
metadata()calls between any invocations ofclear, to improve efficiency when repeatedly accessing the same metadata. The same applies to AbstractArtifactdbResult. -
file(p), a (possibly async) method that accepts a stringpcontaining a relative path inside a project directory and returns the contents of the file at that path. The return value should typically be a Uint8Array; on Node.js, methods may alternatively return a string containing a path to the file on the local file system. The method does not need to handle redirections fromp.
Optionally, the ArtifactdbProjectNavigator class may implement a clear() method to remove any cached content.
This will be called by AbstractArtifactdbDataset.clear and AbstractArtifactdbResult.clear.
Dataset
- Description:
Any class that satisfies the Dataset contract. Each class contains methods to load data from some arbitrary data source into ScranMatrix objects (for the counts) and DataFrame objects (for the feature or cell annotations). The default set of known dataset reader classes is listed in the
availableReadersobject and includes TenxHdf5Dataset, TenxMatrixMarketDataset, H5adDataset and SummarizedExperimentDataset instances.
- Source:
Any class that satisfies the Dataset contract.
Each class contains methods to load data from some arbitrary data source into ScranMatrix objects (for the counts)
and DataFrame objects (for the feature or cell annotations).
The default set of known dataset reader classes is listed in the availableReaders object
and includes TenxHdf5Dataset, TenxMatrixMarketDataset, H5adDataset and SummarizedExperimentDataset instances.