tissue_workflow¶
tissue_simulator.tissue_workflow ¶
Complete workflow for tissue simulation with graph-based cell type assignment.
This module provides a unified interface for the complete workflow: 1. Generate 3D tissue 2. Slice tissue section 3. Build network graph 4. Assign cell types using simulated annealing 5. Visualize and export results 6. Evaluate against target statistics
TissueNetworkWorkflow ¶
Complete workflow manager for tissue simulation with network-based cell type assignment.
Initialize the workflow manager.
Source code in tissue_simulator/tissue_workflow.py
set_tissue ¶
Set the tissue for the workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tissue
|
TissueSection
|
TissueSection object |
required |
create_slice ¶
create_slice(z_position: float = None, point: Tuple[float, float, float] = None, normal: Tuple[float, float, float] = None, angle_x: float = 0.0, angle_y: float = 0.0) -> int
Create a 2D slice from the tissue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z_position
|
float
|
Z-position for horizontal slice (simplified) |
None
|
point
|
Tuple[float, float, float]
|
Point on the slice plane |
None
|
normal
|
Tuple[float, float, float]
|
Normal vector to the plane |
None
|
angle_x
|
float
|
Rotation angle around X-axis (degrees) |
0.0
|
angle_y
|
float
|
Rotation angle around Y-axis (degrees) |
0.0
|
Returns:
| Type | Description |
|---|---|
int
|
Number of cells in the slice |
Source code in tissue_simulator/tissue_workflow.py
build_network ¶
Build a network graph from the tissue slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
"contact" for touching cells, "radius" for proximity |
'radius'
|
radius
|
float
|
Distance threshold for "radius" mode (micrometers) |
None
|
Returns:
| Type | Description |
|---|---|
Graph
|
NetworkX graph |
Source code in tissue_simulator/tissue_workflow.py
load_target_statistics ¶
Load target statistics for cell type assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to CSV file with target statistics |
None
|
statistics
|
Dict
|
Dictionary with pre-computed statistics |
None
|
cell_types
|
List[str]
|
List of cell type names |
None
|
Source code in tissue_simulator/tissue_workflow.py
assign_cell_types ¶
assign_cell_types(initial_temp: float = 100.0, final_temp: float = 0.1, cooling_rate: float = 0.995, max_iterations: int = 100000, verbose: bool = True, seed: Optional[int] = None, initial_coloring: Optional[Dict] = None) -> Dict
Assign cell types to network nodes using simulated annealing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_temp
|
float
|
Starting temperature for annealing |
100.0
|
final_temp
|
float
|
Final temperature for annealing |
0.1
|
cooling_rate
|
float
|
Rate of temperature decrease |
0.995
|
max_iterations
|
int
|
Maximum iterations |
100000
|
verbose
|
bool
|
Whether to print progress |
True
|
seed
|
Optional[int]
|
Optional integer seed forwarded to GraphColorizer for bit-reproducible simulated annealing. When None (default), behavior is unchanged. |
None
|
initial_coloring
|
Optional[Dict]
|
Optional dict mapping node IDs to cell types to use as the warm-start coloring instead of a random assignment. When None (default), a random initial coloring is used. |
None
|
Returns:
| Type | Description |
|---|---|
Dict
|
Dictionary mapping node IDs to cell types |
Source code in tissue_simulator/tissue_workflow.py
generate_colored_replicates ¶
generate_colored_replicates(num_replicates: int, seed: Optional[int] = None, warm_start: bool = False, initial_temp: float = 100.0, final_temp: float = 0.1, cooling_rate: float = 0.995, max_iterations: int = 100000, verbose: bool = True) -> List[Dict]
Generate multiple cell-type colorings of the current network.
Each replicate is an independent simulated-annealing colorization of the same target graph against the loaded target statistics, producing diverse cell-type assignments that all match the target. This is the cell-type-assignment analogue of replicate generation: use it to draw several statistically-equivalent-but-distinct labelings of one tissue slice.
By default each replicate cold-starts from its own deterministic
per-replicate seed (derived from seed via numpy.random.SeedSequence,
matching ReplicateGenerator), so the replicates are genuinely
independent. Benchmarks show cold replicates both converge quickly and
remain diverse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_replicates
|
int
|
Number of colorings to generate (>= 1). |
required |
seed
|
Optional[int]
|
Optional base seed. When provided, replicate |
None
|
warm_start
|
bool
|
When True, each replicate after the first warm-starts from the previous replicate's coloring instead of cold-starting. This speeds convergence on strongly-structured targets but collapses replicate diversity — subsequent replicates become near-identical to the first. Intended for refining a coloring, not for generating independent replicates. Default False. |
False
|
initial_temp
|
float
|
Starting temperature for annealing. |
100.0
|
final_temp
|
float
|
Final temperature for annealing. |
0.1
|
cooling_rate
|
float
|
Rate of temperature decrease. |
0.995
|
max_iterations
|
int
|
Maximum iterations per replicate. |
100000
|
verbose
|
bool
|
Whether to print per-replicate progress. |
True
|
Returns:
| Type | Description |
|---|---|
List[Dict]
|
List of |
List[Dict]
|
to cell types. |
List[Dict]
|
first replicate so the downstream |
List[Dict]
|
|
Source code in tissue_simulator/tissue_workflow.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
apply_cell_types_to_slice ¶
Apply the assigned cell types back to the slice cells. Updates the cell_type attribute of each SliceCell.
Source code in tissue_simulator/tissue_workflow.py
get_statistics ¶
Get statistics for the colored graph.
Returns:
| Type | Description |
|---|---|
Dict
|
Dictionary of graph statistics |
Source code in tissue_simulator/tissue_workflow.py
compare_statistics ¶
Compare generated statistics with target statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbose
|
bool
|
Whether to print comparison details |
True
|
Returns:
| Type | Description |
|---|---|
Dict
|
Dictionary of differences |
Source code in tissue_simulator/tissue_workflow.py
evaluate ¶
Comprehensive evaluation of the cell type assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
print_report
|
bool
|
Whether to print detailed evaluation report |
True
|
Returns:
| Type | Description |
|---|---|
Dict
|
Dictionary of evaluation metrics |
Source code in tissue_simulator/tissue_workflow.py
visualize_slice ¶
Visualize the 2D tissue slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_path
|
str
|
Path to save figure (optional) |
None
|
figsize
|
Tuple[int, int]
|
Figure size |
(10, 10)
|
Source code in tissue_simulator/tissue_workflow.py
visualize_network ¶
visualize_network(layout: str = 'spring', save_path: str = None, figsize: Tuple[int, int] = (12, 10))
Visualize the network graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layout
|
str
|
Layout algorithm ("spring", "kamada_kawai", "circular") |
'spring'
|
save_path
|
str
|
Path to save figure (optional) |
None
|
figsize
|
Tuple[int, int]
|
Figure size |
(12, 10)
|
Source code in tissue_simulator/tissue_workflow.py
export_slice_csv ¶
Export slice data to CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output filename |
'tissue_slice.csv'
|
include_3d
|
bool
|
Whether to include 3D coordinates |
True
|
Source code in tissue_simulator/tissue_workflow.py
export_network ¶
Export network graph to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output filename |
'tissue_network.graphml'
|
format
|
str
|
File format ("graphml", "gexf", "gml", "edgelist") |
'graphml'
|
Source code in tissue_simulator/tissue_workflow.py
export_statistics_csv ¶
Export statistics to CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output filename |
'tissue_statistics.csv'
|
Source code in tissue_simulator/tissue_workflow.py
export_all ¶
Export all results (slice, network, statistics).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
str
|
Base directory for outputs |
'.'
|
prefix
|
str
|
Prefix for filenames |
'tissue'
|
Source code in tissue_simulator/tissue_workflow.py
run_complete_workflow ¶
run_complete_workflow(tissue: TissueSection, z_position: float = None, network_radius: float = 50.0, target_stats_file: str = None, target_stats_dict: Dict = None, cell_types: List[str] = None, annealing_params: Dict = None, export_dir: str = 'results', visualize: bool = True, seed: Optional[int] = None) -> Dict
Run the complete workflow from tissue to cell type assignment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tissue
|
TissueSection
|
TissueSection object |
required |
z_position
|
float
|
Z-position for slice (default: middle of tissue) |
None
|
network_radius
|
float
|
Radius for network building (micrometers) |
50.0
|
target_stats_file
|
str
|
Path to target statistics CSV |
None
|
target_stats_dict
|
Dict
|
Pre-computed target statistics |
None
|
cell_types
|
List[str]
|
List of cell type names |
None
|
annealing_params
|
Dict
|
Parameters for simulated annealing (optional) |
None
|
export_dir
|
str
|
Directory for exports |
'results'
|
visualize
|
bool
|
Whether to create visualizations |
True
|
seed
|
Optional[int]
|
Optional integer seed forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
Dict
|
Dictionary with evaluation metrics |
Source code in tissue_simulator/tissue_workflow.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
quick_workflow ¶
quick_workflow(tissue: TissueSection, cell_types: List[str], target_stats_file: str = None, network_radius: float = 50.0, z_position: float = None, output_dir: str = 'results', seed: Optional[int] = None) -> TissueNetworkWorkflow
Convenience function to run the complete workflow with minimal configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tissue
|
TissueSection
|
TissueSection object |
required |
cell_types
|
List[str]
|
List of cell type names |
required |
target_stats_file
|
str
|
Path to target statistics CSV |
None
|
network_radius
|
float
|
Radius for network building |
50.0
|
z_position
|
float
|
Z-position for slice (default: middle) |
None
|
output_dir
|
str
|
Directory for outputs |
'results'
|
seed
|
Optional[int]
|
Optional integer seed forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
TissueNetworkWorkflow
|
TissueNetworkWorkflow object with completed workflow |