Skip to content

Commit c0110a7

Browse files
committed
Update integration_of_tmeq_modules.py
1 parent 7a1395d commit c0110a7

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
"""
2+
Complete integration example showing all modules working together.
3+
"""
4+
5+
from tme_quant.core.project import TMEProject
6+
from tme_quant.cell_analysis import CellAnalyzer
7+
from tme_quant.fiber_analysis import FiberAnalyzer
8+
from tme_quant.tme_analysis import TMEAnalyzer
9+
10+
# ============================================================
11+
# STEP 1: Project Setup
12+
# ============================================================
13+
14+
project = TMEProject(name="Complete_TME_Analysis")
15+
16+
project.add_image(
17+
image_id="sample_001",
18+
channels={'nuclei': 0, 'collagen': 1},
19+
pixel_size=(0.5, 0.5)
20+
)
21+
22+
# ============================================================
23+
# STEP 2: Cell Analysis (Using cell_analysis module)
24+
# ============================================================
25+
26+
cell_analyzer = CellAnalyzer()
27+
28+
# Segment
29+
seg_result = cell_analyzer.segment_cells_2d(
30+
cell_image, seg_params
31+
)
32+
33+
# Classify
34+
class_result = cell_analyzer.classify_cells(
35+
seg_result, class_params, image
36+
)
37+
38+
# Quantify
39+
quant_result = cell_analyzer.quantify_cells(
40+
seg_result, quant_params, image
41+
)
42+
43+
# Add to project
44+
for cell_props in seg_result.cells:
45+
cell_obj = create_cell_object_from_segmentation(
46+
cell_props, parent_id="sample_001"
47+
)
48+
# Add classification
49+
cell_id = cell_props.cell_id
50+
if cell_id in class_result.cell_types:
51+
cell_obj.cell_type = class_result.cell_types[cell_id]
52+
53+
project.add_object(cell_obj)
54+
55+
# ============================================================
56+
# STEP 3: Fiber Analysis (Using fiber_analysis module)
57+
# ============================================================
58+
59+
fiber_analyzer = FiberAnalyzer()
60+
61+
# Extract
62+
fiber_result = fiber_analyzer.extract_fibers_2d(
63+
fiber_image, extract_params
64+
)
65+
66+
# Add to project
67+
for fiber_props in fiber_result.fibers:
68+
fiber_obj = create_fiber_object_from_extraction(
69+
fiber_props, parent_id="sample_001"
70+
)
71+
project.add_object(fiber_obj)
72+
73+
# ============================================================
74+
# STEP 4: TME Analysis (Using NEW tme_analysis module)
75+
# ============================================================
76+
77+
tme_analyzer = TMEAnalyzer()
78+
79+
# Detect tumor regions
80+
tumor_regions = tme_analyzer.detect_tumor_regions(
81+
project.get_objects_by_type("cell"),
82+
tumor_params
83+
)
84+
85+
for tumor in tumor_regions:
86+
project.add_object(tumor)
87+
88+
# Run TACS analysis
89+
tacs_result = tme_analyzer.analyze(
90+
cells=project.get_objects_by_type("cell"),
91+
fibers=project.get_objects_by_type("fiber"),
92+
tumor_regions=tumor_regions,
93+
params=tacs_params
94+
)
95+
96+
# ============================================================
97+
# STEP 5: Export Everything
98+
# ============================================================
99+
100+
# Export project
101+
project.save("output/project.tme")
102+
103+
# Export cell analysis
104+
cell_analyzer.export_results("output/cells/")
105+
106+
# Export fiber analysis
107+
fiber_analyzer.export_results("output/fibers/")
108+
109+
# Export TME analysis
110+
tme_analyzer.export_results("output/tme/")
111+
112+
print("Complete TME analysis pipeline finished!")

0 commit comments

Comments
 (0)