[ PROMPT_NODE_26912 ]
Omero Integration 高级用法
[ SKILL_DOCUMENTATION ]
# 高级功能
本参考文档涵盖高级 OMERO 操作,包括权限、删除、文件集和管理任务。
## 删除对象
### 等待删除
python
# 删除对象并等待完成
project_ids = [1, 2, 3]
conn.deleteObjects("Project", project_ids, wait=True)
print("Deletion complete")
# 不等待删除 (异步)
conn.deleteObjects("Dataset", [dataset_id], wait=False)
### 使用回调监控删除
python
from omero.callbacks import CmdCallbackI
# 开始删除操作
handle = conn.deleteObjects("Project", [project_id])
# 创建回调以监控进度
cb = CmdCallbackI(conn.c, handle)
print("Deleting, please wait...")
# 轮询完成情况
while not cb.block(500): # 每 500ms 检查一次
print(".", end="", flush=True)
print("nDeletion finished")
# 检查错误
response = cb.getResponse()
if isinstance(response, omero.cmd.ERR):
print("Error occurred:")
print(response)
else:
print("Deletion successful")
# 清理
cb.close(True) # 同时关闭句柄
### 删除不同类型的对象
python
# 删除图像
image_ids = [101, 102, 103]
conn.deleteObjects("Image", image_ids, wait=True)
# 删除数据集
dataset_ids = [10, 11]
conn.deleteObjects("Dataset", dataset_ids, wait=True)
# 删除 ROI
roi_ids = [201, 202]
conn.deleteObjects("Roi", roi_ids, wait=True)
# 删除注释
annotation_ids = [301, 302]
conn.deleteObjects("Annotation", annotation_ids, wait=True)
### 级联删除
python
# 删除项目将级联到包含的数据集
# 此行为取决于服务器配置
project_id = 123
conn.deleteObjects("Project", [project_id], wait=True)
# 数据集和图像可能会被删除或成为孤立对象
# 取决于删除规范
## 文件集 (Filesets)
文件集代表原始导入文件的集合。它们是在 OMERO 5.0 中引入的。
### 检查图像是否有文件集
python
image = conn.getObject("Image", image_id)
fileset = image.getFileset()
if fileset:
print(f"Image is part of fileset {fileset.getId()}")
else:
print("Image has no fileset (pre-OMERO 5.0)")
### 访问文件集信息
python
image = conn.getObject("Image", image_id)
fileset = image.getFileset()
if fileset:
fs_id = fileset.getId()
print(f"Fileset ID: {fs_id}")
# 列出此文件集中的所有图像
print("Images in fileset:")
for fs_image in fileset.copyImages():
print(f" {fs_image.getId(")