Skip to content

Commit 0bbf48a

Browse files
author
Suraj Mishra
committed
added support for local reading of missing mesh files
1 parent 057e17c commit 0bbf48a

1 file changed

Lines changed: 42 additions & 9 deletions

File tree

EMT_data_analysis/analysis_scripts/Nuclei_localization.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,50 @@ def nuclei_localization(
6666

6767
# import pdb; pdb.set_trace()
6868
segmentations = BioImage(seg_path)
69-
70-
# download meshes into temporary directory from s3 bucket
71-
mesh_path = df['CollagenIV Segmentation Mesh Folder'].values[0].replace('s3://allencell/', '')
72-
bucket = q3.Bucket("s3://allencell")
73-
bucket.fetch(
74-
mesh_path + '/',
75-
str(tmp_dir) + '/'
76-
)
69+
70+
# Check for local mesh files first, then fall back to S3 bucket
71+
# Local mesh directory for resubmission data
72+
local_mesh_base = Path("//allen/aics/emt/basement_membrane_segmentation/Resubmission/compile")
73+
local_mesh_folder = local_mesh_base / f"{data_id}_collagenIV_segmentation_mesh"
74+
75+
mesh_fn = None
76+
use_local_mesh = False
77+
78+
# Check if local mesh folder exists with VTM file
79+
if local_mesh_folder.exists():
80+
local_vtm_files = list(local_mesh_folder.glob('*.vtm'))
81+
if local_vtm_files:
82+
mesh_fn = local_vtm_files[0]
83+
use_local_mesh = True
84+
print(f"Using local mesh: {mesh_fn}")
85+
86+
if not use_local_mesh:
87+
# Download meshes into temporary directory from s3 bucket
88+
mesh_path = df['CollagenIV Segmentation Mesh Folder'].values[0].replace('s3://allencell/', '')
89+
bucket = q3.Bucket("s3://allencell")
90+
try:
91+
bucket.fetch(
92+
mesh_path + '/',
93+
str(tmp_dir) + '/'
94+
)
95+
except Exception as e:
96+
print(f"Failed to download mesh for {data_id}: {e}")
97+
rmtree(tmp_dir, ignore_errors=True)
98+
return
99+
100+
# load meshes - handle both naming conventions:
101+
# 1. DataID-prefixed: {data_id}_collagenIV_segmentation_mesh.vtm
102+
# 2. Generic: collagenIV_segmentation_mesh.vtm
103+
vtm_files = list(tmp_dir.glob('*.vtm'))
104+
if not vtm_files:
105+
print(f"No VTM mesh file found for {data_id} in {tmp_dir}")
106+
rmtree(tmp_dir, ignore_errors=True)
107+
return
108+
mesh_fn = vtm_files[0] # Use the first (and typically only) VTM file
109+
print(f"Using S3 mesh: {mesh_fn}")
110+
77111

78112
# load meshes
79-
mesh_fn = tmp_dir / (mesh_path.split('/')[-1] + '.vtm')
80113
meshes = pv.read(mesh_fn)
81114

82115
# localize nuclei for each timepoint

0 commit comments

Comments
 (0)