Skip to content

scdef.pl.make_graph

make_graph(model: scDEF, hierarchy: Optional[Dict[str, Sequence[str]]] = None, show_all: Optional[bool] = False, factor_annotations: Optional[Dict[str, str]] = None, top_factor: Optional[str] = None, show_signatures: Optional[bool] = True, drop_factors: Optional[List[str]] = None, root_signature: Optional[List[str]] = None, root_ranking: Optional[List[str]] = None, enrichments: Optional[DataFrame] = None, show_enrichments: Optional[bool] = False, top_genes: Optional[Union[int, List[int]]] = None, show_batch_counts: Optional[bool] = False, filled: Optional[Union[str, Dict[str, float]]] = None, wedged: Optional[str] = None, assignments: Optional[bool] = True, color_edges: Optional[bool] = True, show_confidences: Optional[bool] = False, n_cells_label: Optional[bool] = False, n_cells: Optional[bool] = False, node_size_max: Optional[float] = 2.0, node_size_min: Optional[float] = 0.05, scale_level: Optional[bool] = False, show_label: Optional[bool] = True, gene_score: Optional[str] = None, gene_cmap: Optional[str] = 'viridis', gene_score_scale: str = 'factor', path: Optional[Union[Sequence[str], Dict[str, Any]]] = None, path_color: str = 'red', path_node_penwidth: float = 2.5, confident_assignments: bool = False, confident_key: str = 'confident', shell: Optional[bool] = False, r: Optional[float] = 2.0, r_decay: Optional[float] = 0.8, root_shape: Optional[str] = None, bottom_layer: int = 0, **fontsize_kwargs: Any) -> Graph

Make Graphviz-formatted scDEF graph.

Parameters:

Name Type Description Default
model scDEF

scDEF model instance

required
hierarchy Optional[Dict[str, Sequence[str]]]

dictionary containing the polytree to draw instead of the whole graph

None
show_all Optional[bool]

whether to show all factors even post filtering

False
factor_annotations Optional[Dict[str, str]]

factor annotations to include in the node labels

None
top_factor Optional[str]

only include factors below this factor

None
show_signatures Optional[bool]

whether to show the ranked gene signatures in the node labels

True
drop_factors Optional[List[str]]

list of factors to drop from the graph

None
root_signature Optional[List[str]]

root signature to display

None
root_ranking Optional[List[str]]

root ranking to display

None
enrichments Optional[DataFrame]

enrichment results dataframe to include in node labels

None
show_enrichments Optional[bool]

whether to show enrichment terms in node labels

False
top_genes Optional[Union[int, List[int]]]

number of genes from each signature to be shown in the node labels

None
show_batch_counts Optional[bool]

whether to show the number of cells from each batch that attach to each factor

False
filled Optional[Union[str, Dict[str, float]]]

key from model.adata.obs to use to fill the nodes with, or dictionary of factor scores

None
wedged Optional[str]

key from model.adata.obs to use to wedge the nodes with

None
assignments Optional[bool]

whether to use the assignments of cells to factors to wedge the nodes, rather than the scores

True
color_edges Optional[bool]

whether to color the graph edges according to the upper factors

True
show_confidences Optional[bool]

whether to show precomputed signature Jaccard confidence (from scd.tl.set_confident_signatures) for each factor

False
n_cells_label Optional[bool]

whether to show the number of cells that attach to the factor

False
n_cells Optional[bool]

whether to scale the node sizes by the number of cells that attach to the factor

False
node_size_max Optional[float]

maximum node size when scaled by cell numbers

2.0
node_size_min Optional[float]

minimum node size when scaled by cell numbers

0.05
scale_level Optional[bool]

whether to scale node sizes per level instead of across all levels

False
show_label Optional[bool]

whether to show labels on nodes

True
gene_score Optional[str]

color the nodes by the score they attribute to a gene. Overrides filled and wedged

None
gene_cmap Optional[str]

colormap to use for gene_score

'viridis'
gene_score_scale str

"factor" (default) colours each node by the score of the gene relative to the gene with the largest score in that factor, so a gene lights up the factors whose programme it leads. "layer" colours it relative to the largest score of the gene among the factors of the same layer, so the factors that use the gene most are brightest, whatever its rank within them.

'factor'
path Optional[Union[Sequence[str], Dict[str, Any]]]

ordered factor names along a path, or a dict with key "nodes" (e.g. differentiation or transition path nodes). Names outside the hierarchy view are dropped when hierarchy is set. Edge highlights map each consecutive pair to the drawn weight edge (coarser layer → adjacent finer layer), so coarse→fine chains match, and transition zigzags (e.g. L0→L1→L0→…) work when each hop is between adjacent layers. If hierarchy is set, a pair is highlighted when it is a tree edge in either direction; otherwise the same adjacent-layer rule applies. Sets Graphviz color (node border and edge stroke) to path_color; fillcolor is unchanged. With gene_score and color_edges, path edges use path_color instead of the parent gene-based edge color.

None
path_color str

stroke color for highlighted path nodes (border) and edges

'red'
path_node_penwidth float

Graphviz penwidth for nodes on path (border thickness). Ignored when path is not set. Default 2.5; use 1.0 for the usual thin border (no emphasis).

2.5
confident_assignments bool

if True, attach cells using adata.obs[f"{confident_key}_factor"] (cross-layer assignment from assign_confident) instead of per-layer adata.obs[layer_name]. Requires that column to exist.

False
confident_key str

key_added prefix used with assign_confident (default "confident").

'confident'
shell Optional[bool]

whether to use shell layout. If the model has a final width-1 root layer, shell layout omits that root and plots the remaining hierarchy.

False
r Optional[float]

radius parameter for shell layout

2.0
r_decay Optional[float]

radius decay parameter for shell layout

0.8
root_shape Optional[str]

Graphviz node shape for root-layer factors (e.g. "diamond", "box", "hexagon"). When None the default ellipse is used.

None
bottom_layer int

lowest layer index to include (default 0). Set to 1 to omit the finest layer (L0) when it has too many factors.

0
**fontsize_kwargs Any

keyword arguments to adjust the fontsizes according to the gene scores

{}

Returns:

Type Description
Graph

Graphviz Graph object