Methods
(static) doubleClustering(matrix, rowNames, colNames, metricopt) → {Object}
Performs double clustering on a matrix.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
matrix |
Array.<Array.<number>> | The matrix to be clustered. | ||
rowNames |
Array.<string> | The names of the rows in the matrix. | ||
colNames |
Array.<string> | The names of the columns in the matrix. | ||
metric |
function |
<optional> |
euclideanDistance | The distance metric to use for clustering. |
- Source:
Returns:
An object with three properties: matrix, rowNames, and colNames. matrix is the clustered matrix. rowNames and colNames are the names of the rows and columns in the clustered matrix, respectively.
- Type
- Object
(static) exports.kFoldCV(Xs, Ys, kopt, modelTypeopt) → {Object}
Performs k-fold stratified cross-validation for multivariate linear or MLP regression models.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
Xs |
Array | Array of input data. | ||
Ys |
Array | Array of output data. | ||
k |
number |
<optional> |
10 | Number of folds for cross-validation. |
modelType |
string |
<optional> |
"MLR" | Regression model type ("MLR" for multivariate linear regression or "MLP" for multilayer perceptron). |
- Source:
Throws:
-
- If an unknown model type is provided.
- Type
- Error
Returns:
- Object containing an array of trained regression models, an array of mean squared errors for each fold, and the average mean squared error across all folds.
- Type
- Object
(static) exports.preprocessData(mutationalData, exposureData, dataSource) → {Object}
Preprocesses mutational and exposure data for a given data source.
Currently only supports data from MSigDB portal.
Parameters:
Name | Type | Description |
---|---|---|
mutationalData |
Array | Array of mutational data. |
exposureData |
Array | Array of exposure data. |
dataSource |
string | Data source identifier. |
- Source:
Throws:
-
- If an unknown data source is provided.
- Type
- Error
Returns:
- Object containing input (Xs) and output (Ys) arrays for regression.
- Type
- Object
(async, static) fitMutationalSpectraToSignatures(mutationalSignatures, mutationalSpectra, optionsopt) → {Object}
Fits mutational spectra to known mutational signatures using non-negative least squares (NNLS).
This function calculates the exposure of mutational signatures for each sample by fitting
the observed mutational spectra to the reference mutational signatures. It then filters out
signatures whose contribution is below a fraction of the total exposure, by setting their
exposures to zero.
You can choose to return exposures as absolute values (raw counts from NNLS) or relative values
(sum to 1 for each sample). The filtering threshold is a fraction between 0 and 1.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
mutationalSignatures |
Object | Reference mutational signatures. Each key is a signature name, and each value is an object of mutation types (e.g., {"C>A": weight, "C>G": weight}). | |||||||||||||||||||||
mutationalSpectra |
Object | Mutational spectra for each sample. Each key is a sample ID, and each value is an object of mutation types with their counts (e.g., {"C>A": count, "C>G": count}). | |||||||||||||||||||||
options |
Object |
<optional> |
Configuration options for filtering and output.
Properties
|
Returns:
- An object with sample IDs as keys. Each value is an object of signature exposures.
- Type
- Object
Example
// Example usage:
// 1. Get mutational signatures (e.g., from the mSigPortal API)
const mutationalSignatures = await mSigPortal.mSigPortalData.getMutationalSignaturesData(
"WGS", "COSMIC_v3_Signatures_GRCh37_SBS96", "SBS", 96, 1000
);
// 2. Extract mutational spectra for each sample
const extractedSpectra = await mSigPortal.mSigPortalData.extractMutationalSpectra(
mutationalSignatures, "signatureName"
);
// 3. Fit spectra to signatures with post-fit filtering
const nnlsExposures = await mSigPortal.signatureFitting.fitMutationalSpectraToSignatures(
mutationalSignatures,
extractedSpectra,
{
exposureThreshold: 0.1,
exposureType: "relative",
renormalize: true
}
);
console.log(nnlsExposures);
// {
// Sample1: { SBS1: 0.75, SBS2: 0.25, SBS3: 0 },
// Sample2: { SBS1: 0.9, SBS2: 0.1, SBS3: 0 },
// ...
// }
(static) hierarchicalClustering(distanceMatrix, sampleNames) → {Object}
Performs hierarchical clustering on a distance matrix.
Parameters:
Name | Type | Description |
---|---|---|
distanceMatrix |
Array.<Array.<number>> | The distance matrix to be clustered. |
sampleNames |
Array.<string> | The names of the samples in the distance matrix. |
- Source:
Returns:
The final clustering result as a tree.
- Type
- Object
(async, static) nnls(A, b, maxiteropt) → {Object}
Solves argmin_x || Ax - b ||_2 for x>=0. A is a matrix, b is a vector.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
A |
Array.<Array.<number>> | The matrix A. | ||
b |
Array.<number> | The vector b. | ||
maxiter |
number |
<optional> |
3*A[0].length | Maximum number of iterations. |
- Source:
Returns:
An object with two properties: x and rnorm. x is a vector with the same length as b. rnorm is the residual || Ax - b ||^2.
- Type
- Object
(static) upgma(distanceMatrix) → {Array}
Performs UPGMA clustering on a distance matrix.
Parameters:
Name | Type | Description |
---|---|---|
distanceMatrix |
Array.<Array.<number>> | The distance matrix to be clustered. |
- Source:
Returns:
An array of arrays representing the clustering result. Each inner array contains three elements: two clusters being merged and their average distance.
- Type
- Array