Data model#
anndata-fcs converts between AnnData objects and FCS files without losing metadata. This page describes where
each piece of information is stored.
FCS to AnnData#
anndata_fcs.read_fcs() creates the following layout:
AnnData |
FCS |
|---|---|
|
Event data as stored in the file, in the stored data type ( |
|
Only with |
|
Channel names ( |
|
Per-channel keywords as strings, one column per keyword: |
|
Global keywords of the TEXT segment as raw strings, with the names parsed by FlowIO (lower case, without
|
|
Keywords of the ANALYSIS segment. |
|
FCS version and file name of the source, and the version of this layout. |
Keywords describing the binary layout ($BEGINDATA, $DATATYPE, $BYTEORD, $PnB, …) are not stored,
since they are regenerated when writing.
Since per-channel keywords are var columns, they stay with their channel when channels are subset, reordered or
renamed, e.g. marker labels are adata.var["$PnS"].
Keywords containing / are stored with / escaped as %2F (and % as %25), because h5ad files do not
allow / in keys or column names.
AnnData to FCS#
anndata_fcs.write_fcs() stores:
AnnData |
FCS |
|---|---|
|
Event data as 32-bit float, the only data type FlowIO can write. Channels on log scale are converted to linear scale. |
|
|
|
Per-channel keywords. Values are written as strings, missing values are not written. Set marker labels with
e.g. |
|
Global keywords. |
|
JSON encoded in the |
Other |
JSON encoded in the |
Position of each observation |
Synthetic |
obs and var columns may be numeric, boolean, string or categorical (including nullable pandas dtypes).
Only X is written. layers["preprocessed"] is not written, since it is computed from X and the keywords.
raw is not written either. For scanpy objects holding the counts in raw, write adata.raw.to_adata().
uns entries other than uns["fcs"] are not written.
Any information that is lost when writing is reported by an anndata_fcs.FCSConversionWarning. To raise an
error instead, turn the warning into an exception:
import warnings
from anndata_fcs import FCSConversionWarning, write_fcs
with warnings.catch_warnings():
warnings.simplefilter("error", FCSConversionWarning)
write_fcs(adata, "out.fcs")
Warning
Use anndata_fcs.write_fcs() to write FCS files. flowio.FlowData.write_fcs() only keeps the
$CYT, $DATE and $SPILLOVER keywords by default.