Frequently asked questions¶
Your own data¶
What input does M3 take?¶
Raw counts for each modality (rna, adt, atac) and a per-cell table with a
batch column and one or two condition columns. The donor-level tasks (donor
prediction, attribution, augmentation) also need a cell-type column and a donor
column. The "Use your own data" tutorial goes from files or objects to a trained model, in
Python and in R.
My RNA and ADT (or ATAC) are in separate files¶
Pass one file per modality:
m3.read_h5ad({"rna": "rna.h5ad", "adt": "adt.h5ad"}) in Python
(m3.read_h5ad) or
m3_read_h5ad(list(rna = "rna.h5ad", adt = "adt.h5ad")) in R. For AnnData
objects already in memory, use m3.from_anndata
the same way. The cells are matched by name, so the files may order them
differently; within a batch, both files must have the same cells. See
Use your own data.
A MuData can be passed as m3.from_anndata(mdata.mod). Only the obs of each
modality is read, not the joint mdata.obs, so the batch and condition columns
must be in the modalities' obs.
My batch column is not called batch¶
Leave it as it is and name it when you build the model: batch_key="run" in
m3.M3 or m3_train(). Until then
the printed dataset shows batches=not set. A model built without a batch
column stops with an error that lists the columns to choose from. When reading
one file per modality, pass the same batch_key="run" to read_h5ad /
from_anndata as well.
My batches do not all measure the same modalities¶
Pass one file per modality, each holding only the cells measured for it, as in
the entry above: a cell missing from a file is marked as not measured for that
modality. See Mosaic integration.
In R, m3_read_h5ad() takes the same named list; section 5 of
Use your own data (R) shows how to stack batches
built from in-memory objects with m3_concat().
My .X is normalised¶
M3 needs raw counts. Reading one file per modality stops at non-integer
values; a single file or a matrix gives a warning. If the counts are in a layer,
pass layer="counts" to read_h5ad /
from_anndata, or
layer={"rna": "counts"} for one modality only.
I have no cell-type labels¶
The embedding does not need them: leave celltype_key out, and train() fits
the cell-level model from the condition and batch columns alone. The donor
predictor, attribution and augmentation use cell types and need the column.
My study has one condition, or more than two¶
condition_keys is required and takes one or two columns. A column with a
single value is accepted.
I have a modality other than RNA, ADT or ATAC¶
Not supported. The model uses the modalities named rna, adt and atac, and
one with any other name is left out without an error.
My data is a Seurat or SingleCellExperiment object¶
Write each modality to its own .h5ad in R, for example with the Bioconductor
package zellkonverter, then continue in Python with
Use your own data,
which shows the conversion for both object types.
Training and results¶
How long does training take?¶
At the default 300 epochs on a laptop CPU, a few minutes for 3,000 cells and 15 to 20 minutes for the 30,534-cell demo. A CUDA GPU is used automatically when present.
How do I know training has run long enough?¶
Training prints the validation loss after every epoch, and max_epochs sets the
number of epochs (default 300). The number of update steps is the number of
epochs times the number of mini-batches per epoch, so with fewer cells the same
number of epochs gives fewer steps. If the validation loss is still falling at
the last epoch, raise max_epochs.
The embedding has 28 columns, not 30¶
embedding_dim (default 30) is the size of the whole latent. Its last two
dimensions are the batch factor, which the "bio" embedding leaves out.
Cells separate by condition in the embedding¶
part="bio" is the intrinsic factor plus the condition factors, so it keeps the
differences between conditions. Use part="intrinsic" for an embedding without
them: that is the one to look at for how well cell types line up across batches.
To judge "bio", use labels that combine cell type and condition.
How do I make a run reproducible?¶
Training is seeded (seed, default 0). The same data in the same cell order,
with the same settings and software versions, gives an identical embedding. A
different cell order or different software versions change the numbers.
Can I save a trained model?¶
Yes. model.save("model.m3") writes the trained weights
and settings, and m3.M3.load("model.m3", data) reads
them back without training again. The file does not hold the data, so load
needs the same Dataset the model was trained on. In R:
m3_save() and m3_load().
The embedding rows are not in my cell order¶
Read-outs are grouped by batch and follow model.cell_metadata, not the input.
Match them by the obs_names column, as in Use your own data
(Python, R).
Are the reconstruct() values counts?¶
No. They are on the scale the model trains on: log2(count / size + 1), where
size is the cell's total count in that modality divided by the mean total over
all cells.