sciduck package

Submodules

sciduck.annotation_table module

sciduck.annotation_table.add_dominant_library_info(adata: AnnData, mapping_summary: dict, library_metadata_column: str = 'load_name') dict

Add dominant library information to the mapping summary.

Parameters:
  • adata – Anndata object with annotations in obs.

  • mapping_summary – A pre-existing mapping summary dictionary to add information on dominant library.

  • library_metadata_column – Defaults to load_name and describes the sequencing batch.

Returns:

A mapping_summary containing dominant library information.

sciduck.annotation_table.build_annotation_table(adata: AnnData, group_by='cluster', categorical_annotations: list = ['donor_name', 'load_name', 'roi'], numeric_annotations: list = ['doublet_score', 'pct_counts_mt'], min_percent: float = 0.05, annotation_alerts: dict = {'donor_name': 0.9, 'load_name': 0.95, 'roi': 0.95}, mapping_summary: dict = {}) dict

Build a standardized table of annotations describing each cluster to be used for taxonomy development or communication.

Parameters:
  • adata – Anndata object with annotations in obs.

  • group_by – Anndata.obs to use for grouping cells.

  • categorical_annotations – List of categorical metadata to include.

  • numeric_annotations – List of numeric metadata to include.

  • min_percent – Minimal percentrage to print annotation.

  • mapping_summary – A dictionary to store the mapping summary. User can pass in an existing dictionary to append to if desired.

Returns:

A mapping_summary containing character and numeric summaries along with donor/lib/roi composition alerts.

sciduck.basic_qc module

sciduck.basic_qc.add_exclude_constraint(adata: AnnData, column: str, exclude_values: list, subset: str | None = None, subset_values: list | None = None)

Adds an exclude constraint to a specific column in the AnnData object.

This function filters out cells where the value in the specified column is in ‘exclude_values’. Subsetting based on another column is supported.

Parameters:
  • adata – The AnnData object where constraints will be added.

  • column – The column in ‘adata.obs’ for which the exclude constraint will be applied.

  • exclude_values – The list of values that should be excluded from ‘column’.

  • subset – The column in ‘adata.obs’ to use for subsetting the data.

  • subset_values – A list of values for subsetting, applied to the ‘subset’ column.

sciduck.basic_qc.add_group_level_constraint(adata: AnnData, column: str, groupby: str, gt: float | None = None, lt: float | None = None, agg_func: str = 'mean')

Adds a group-level constraint to a specific column in the AnnData object.

Cells are grouped by ‘groupby’, and an aggregation function (e.g., ‘mean’) is applied to each group for the specified column. Cells in groups that meet the ‘gt’ and ‘lt’ conditions are kept.

Parameters:
  • adata – The AnnData object where constraints will be added.

  • column – The column in ‘adata.obs’ for which the group-level constraint will be applied.

  • groupby – The column in ‘adata.obs’ used to group the cells (e.g., cluster ID).

  • gt – The lower bound for the aggregated group value. If None, the lower bound is open.

  • lt – The upper bound for the aggregated group value. If None, the upper bound is open.

  • agg_func – The aggregation function to apply to the groups. Can be ‘mean’, ‘sum’, ‘std’, or ‘median’. Default is ‘mean’.

sciduck.basic_qc.add_range_constraint(adata: AnnData, column: str, gt: float | None = None, lt: float | None = None, subset: str | None = None, subset_values: list | None = None)

Adds a range constraint to a specific column in the AnnData object.

This function filters cells where values in the specified column fall within the range [gt, lt]. Subsetting based on another column is supported.

Parameters:
  • adata – The AnnData object where constraints will be added.

  • column – The column in ‘adata.obs’ for which the range constraint will be applied.

  • gt – The lower bound of the range (inclusive). If None, the lower bound is open.

  • lt – The upper bound of the range (inclusive). If None, the upper bound is open.

  • subset – The column in ‘adata.obs’ to use for subsetting the data.

  • subset_values – A list of values for subsetting, applied to the ‘subset’ column.

sciduck.basic_qc.apply_constraints(adata: AnnData, inplace: bool = False) AnnData

Applies all quality control (QC) constraints stored in ‘adata.uns[“qc_constraints”]’ to ‘adata.obs’ and filtered indices in ‘adata.uns[“qc_filtered”]’.

This function handles both individual cell-level constraints (range, exclude) and group-level constraints (using a ‘groupby’ column). The resulting ‘keeper_cells’ column in ‘adata.obs’ indicates which cells passed the constraints.

Parameters:
  • adata – The AnnData object where constraints are applied.

  • inplace – If True, only the cells passing the constraints will be retained in ‘adata’. If False (default), the ‘keeper_cells’ column will be added to ‘adata.obs’ to indicate which cells passed the filtering.

Returns:

The filtered AnnData object with the ‘keeper_cells’ column added to ‘adata.obs’. If ‘inplace=True’,

the returned object will only contain the filtered cells.

Return type:

AnnData

sciduck.entropy_qc module

sciduck.entropy_qc.cell_entropy(adata: AnnData, annotation_columns: list, nearest_neighbors: int = 15, dim: str = 'X_scVI') AnnData

Compute entropy (mixing) of annotations within a cells local neighborhood.

Parameters:
  • adata – AnnData object with annotations

  • annotation_columns – Cell level annotations.

  • nearest_neighbors – Number of nearest neighbors.

  • dim – Dimensionality reduction

Returns:

Returns the updated AnnData object.

sciduck.entropy_qc.cluster_entropy(adata: AnnData, group_by: str, annotation_columns: list) AnnData

Compute entropy (mixing) of annotations within a cell set (group_by).

Parameters:
  • adata – AnnData object with annotations

  • group_by – AnnData.obs column that groups cells.

  • annotation_columns – Cell level annotations.

Returns:

Returns the updated AnnData object.

sciduck.plotting module

sciduck.plotting.violin(adata: AnnData, y: str, groupby: str | None = None, log: bool = True, scale: Literal['area', 'count', 'width'] = 'width', order: Sequence[str] | None = None, xlabel: str = '', size: int = 4, x_label_rotation: float = 0, ylines: Sequence[float] = []) tuple

Compute entropy (mixing) of annotations within a cells local neighborhood.

Parameters:
  • adata – Annotated data matrix.

  • y – columns in .obs to plot for y axis.

  • groupby – The key of the observation grouping to use for x axis.

  • log – Use log scale for y.

  • scale – The method used to scale the width of each violin.

  • order – Order of x.

  • xlabel – Label of the x axis. Defaults to groupby.

  • size – Size of the x labels.

  • x_label_rotation – Rotation of xtick labels.

  • ylines – Add horizontal lines to the plot.

Returns:

Tuple[Axes, Axes]

sciduck.templates module

sciduck.templates.allen_institute_basic(adata: AnnData)

Adds Allen Institute basic QC standards to the AnnData object. Does not perform the filtering.

Parameters:

adata – The AnnData object where constraints will be added.

Module contents

sciduck

single cell data analyis unification and communication toolkit