Skip to content

iscc.sample.Resection

Resection(tumor, compartment='primary')

A resected tumour specimen, cut into the samples the assays take.

Parameters:

Name Type Description Default
tumor GenotypeTumor

The grown (count-based) tumour standing in for the resected specimen.

required
compartment (primary, met, both)

Which grid the specimen is taken from. "primary" (default) resects only the primary tumour; "met" resects only the metastatic deposit (errors if the tumour has no metastasis); "both" resects both grids (falls back to the primary alone when there is no metastasis). This sets the deme set that :meth:bisect partitions and that :meth:dissociate / :meth:slice default to when region is None.

"primary"

Examples:

>>> spec = Resection(tumor)                          # primary by default
>>> cut, remainder = spec.bisect(frac=0.42)          # in-plane cut
>>> cd = spec.dissociate(cut, max_cells=50000)       # sequencing sample (full depth)
>>> section = spec.slice(remainder, depth_frac=0.5)  # imaging section (thin slice)
>>> met = Resection(tumor, compartment="met").dissociate()   # the metastasis instead
Notes

Both samplers leave tumor.cell_data untouched — take as many cuts as you like without redefining what the tumour itself exports.

Methods:

Name Description
bisect

In-plane cut: split the specimen into two disjoint 2-D parts.

dissociate

Dissociate a 2-D part into a per-cell table for the sequencing assays.

slice

Cut a thin histology / Visium section: a depth cut of a 2-D part.

bisect

bisect(frac=0.5, axis='x')

In-plane cut: split the specimen into two disjoint 2-D parts.

Cuts each grid of the resected :attr:compartment at frac of its side along axis and returns the deme indices on each side, ready to pass to :meth:dissociate / :meth:slice (or make_cell_data(region=)). For compartment="both" each grid is cut at the same fraction and the parts are unioned.

Parameters:

Name Type Description Default
frac float

Fraction of the grid (along axis) that falls in the first part.

0.5
axis (x, y)

Cut axis: "x" splits by column, "y" by row.

"x"

Returns:

Type Description
(list of int, list of int)

(part, remainder) deme-index lists partitioning the compartment.

dissociate

dissociate(region=None, max_cells=None, install=False)

Dissociate a 2-D part into a per-cell table for the sequencing assays.

Materialises the part at FULL column depth (all ~K cells/deme, subsampled to max_cells); the cells lose their spatial position, as in a real dissociation.

Parameters:

Name Type Description Default
region iterable of int

Deme indices of the part to dissociate (e.g. the first element of :meth:bisect). None dissociates the whole resected :attr:compartment (the primary by default).

None
max_cells int

Cap on materialised cells (a representative subsample above it).

None
install bool

Also make this sample the tumour's own cell_data. Off by default: a sample is not the tumour, and installing it would silently redefine what to_anndata(tumor) and tumor.write_h5ad(...) export. Turn it on when you want the tumour-level helpers that read tumor.cell_data (clones_from_clades, to_anndata(tumor)) to work on exactly these cells.

False

Returns:

Type Description
dict

The per-cell cell_data tables (pass to bulkDNA / scDNA / scRNA).

slice

slice(region=None, depth_frac=0.5, max_cells=None, install=False)

Cut a thin histology / Visium section: a depth cut of a 2-D part.

Keeps depth_frac of each deme's 3-D column (default half — "take away half"), leaving the 2-D field intact, so a spatial assay sees the whole structure at a realistic ~one-layer density.

Parameters:

Name Type Description Default
region iterable of int

Deme indices of the part to section (e.g. the remainder from :meth:bisect). None sections the whole resected :attr:compartment (the primary by default).

None
depth_frac float

Fraction of each deme's column kept in the slice. Note this thins the same 3-D column that Visium(section_frac=...) thins, so the two compose multiplicatively: keep one of them at 1.0 (the tutorials slice here and leave section_frac=1.0).

0.5
max_cells int

Cap on materialised cells (bounds the section at cm-scale).

None
install bool

Also make this section the tumour's own cell_data — see :meth:dissociate. Off by default, so taking a section never changes what the tumour itself exports.

False

Returns:

Type Description
dict

The per-cell cell_data tables of the thin section (pass to Visium).