Members
(constant) availableReaders
- Description:
All known dataset readers. Each entry contains a Dataset class with the key defined as the
format
return 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:
inputs
rna_quality_control
adt_quality_control
crispr_quality_control
cell_filtering
rna_normalization
adt_normalization
crispr_normalization
feature_selection
rna_pca
adt_pca
crispr_pca
neighbor_index
tsne
umap
kmeans_cluster
snn_graph_cluster
choose_clustering
cell_labelling
feature_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
.
formatMarkerResults(results, group, rankEffect)
- Description:
Report marker results for a given group or cluster, ordered so that the strongest candidate markers appear first.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
results |
ScoreMarkersResults | The marker results object generated by the |
group |
number | Integer specifying the group or cluster of interest.
Any number can be used if it was part of the |
rankEffect |
string | Summarized effect size to use for ranking markers.
This should follow the format of |
Returns:
An object containing the marker statistics for the selection, sorted by the specified effect and summary size from rankEffect
.
This contains:
means
: a Float64Array of length equal to the number of genes, containing the mean expression within the selection.detected
: a Float64Array of length equal to the number of genes, containing the proportion of cells with detected expression inside the selection.lfc
: a Float64Array of length equal to the number of genes, containing the log-fold changes for the comparison between cells inside and outside the selection.delta_detected
: a Float64Array of length equal to the number of genes, containing the difference in the detected proportions between cells inside and outside the selection.
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
approximate
fromconfigureApproximateNeighbors
based 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
method
value fromconfigureBatchCorrection
based 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, path, optionsopt) → {Array}
- Description:
Save the per-gene analysis results into ArtifactDB data frames. 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 | Path to a subdirectory inside the project directory in which to save all results.
If |
||||||||||||||||||||||||||||||||
options |
object |
<optional> |
{}
|
Optional parameters. Properties
|
Returns:
Array of objects where each object corresponds to a data frame of per-gene statistics.
These data frames are grouped by analysis step, i.e., marker_detection
, custom_selections
and feature_selection
.
See saveSingleCellExperiment
for more details on the contents of each object inside the returned array.
- Type
- Array
saveSingleCellExperiment(state, name, optionsopt) → {Array}
- Description:
Save the analysis results into an ArtifactDB representation of a SingleCellExperiment. 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 to be saved. |
|||||||||||||||||||||||||||
options |
object |
<optional> |
{}
|
Optional parameters. Properties
|
Returns:
Array of objects where each object corresponds to a file in the SingleCellExperiment's representation.
Each inner object contains metadata
, another object containing the metadata for the corresponding file.
For files that are not purely metadata, the inner object will also contain contents
, the contents of the file.
The type of contents
depends on the context and optional parameters.
- If
forceBuffer = true
,contents
is a Uint8Array of the file contents. This is probably the most advisable setting for browser environments. - If
forceBuffer = false
,contents
may be either a Uint8Array or a string to a temporary file path. In a browser context, the temporary path is located on the scran.js virtual file system, see here to extract its contents and to clean up afterwards. - If the function is called from Node.js and
directory
is supplied,contents
is a string to a file path insidedirectory
. This overrides any expectations from the setting offorceBuffer
and is the most efficient approach for Node.js.
The SingleCellExperiment itself will be accessible from a top-level object at the path defined by name
.
- Type
- Array
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_subset
contains a direct subset that can be used inInputsState.setDirectSubset
before callingrunAnalysis
.custom_selections.selections
contains selections that can be used inCustomSelectionsState.addSelection
afterrunAnalysis
.
- 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
inputs
property, 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 NaN
s 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
availableReaders
has 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
zipFiles(files, optionsopt) → {Promise.<Uint8Array>}
- Description:
Zip a set of files, typically corresponding to the contents of an ArtifactDB project directory.
- Source:
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
files |
Array | Array of objects describing files in the project directory.
See the output of |
||||||||||||
options |
object |
<optional> |
{}
|
Optional parameters. Properties
|
Returns:
Uint8Array with the contents of the ZIP file containing all files
.
- Type
- Promise.<Uint8Array>
Type Definitions
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 stringp
containing 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 stringp
containing 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.clear
andAbstractArtifactdbResult.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 stringp
containing 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 stringp
containing 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
availableReaders
object 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.