Add a custom feature distance matrix to the mmo object
AddCustomDist.RdStores any user-supplied pairwise feature distance matrix in the mmo object
so it can be used by GetBetaDiversity(), GetAlphaDiversity(),
and HeatmapPlot() via the distance argument.
Arguments
- mmo
The mmo object
- dist_matrix
A square numeric matrix of pairwise feature dissimilarities (see Details for format requirements).
- name
A short string used to identify this distance in downstream functions (e.g.
"tanimoto","npc"). The matrix is stored asmmo$<name>.dissimand referenced by passingdistance = "<name>"toGetBetaDiversity(),GetAlphaDiversity(), etc. Must not conflict with existing names:"dreams","cosine","m2ds".
Details
Required matrix format:
A square numeric matrix with equal row and column names.
Row and column names must be feature IDs matching the
idcolumn inmmo$feature_data(e.g."1234.56_2.34"or whatever identifier MZmine assigned).Values must be dissimilarities in the range
[0, 1], where 0 means identical and 1 means maximally different. If your source data are similarities (e.g. Tanimoto coefficients, cosine scores), convert first withdist_matrix <- 1 - sim_matrix.The diagonal should be 0 (a feature is identical to itself).
The matrix should be symmetric (
dist[i,j] == dist[j,i]). Non-symmetric matrices are accepted but may produce unexpected results in downstream ordination and Hill number calculations.Features not present in
mmo$feature_dataare retained in the matrix but will be silently ignored during analysis. Features inmmo$feature_datathat are absent from the matrix will be excluded from structure-aware calculations.
Examples
if (FALSE) {
# Example: add a Tanimoto-based structural distance
# tanimoto_sim is a feature x feature similarity matrix from an external tool
tanimoto_dist <- 1 - tanimoto_sim
mmo <- AddCustomDist(mmo, dist_matrix = tanimoto_dist, name = "tanimoto")
# Now use it anywhere a distance argument is accepted:
beta <- GetBetaDiversity(mmo, method = "CSCS", distance = "tanimoto")
alpha <- GetAlphaDiversity(mmo, mode = "weighted", distance = "tanimoto")
}