@nahisaho/satori 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Overview
9
9
 
10
- このディレクトリには、Exp-01〜13 で蓄積した科学データ解析技法を Agent Skills として体系化した **106 個**のスキルを格納しています。Copilot がプロンプトの文脈に応じて適切なスキルを自動ロードし、各実験で確立した解析パターンを再利用します。66 のスキルは [ToolUniverse](https://github.com/mims-harvard/ToolUniverse) SMCP 経由で 1,200 以上の外部科学データベースツールとも連携可能です。
10
+ このディレクトリには、Exp-01〜13 で蓄積した科学データ解析技法を Agent Skills として体系化した **116 個**のスキルを格納しています。Copilot がプロンプトの文脈に応じて適切なスキルを自動ロードし、各実験で確立した解析パターンを再利用します。70 のスキルは [ToolUniverse](https://github.com/mims-harvard/ToolUniverse) SMCP 経由で 1,200 以上の外部科学データベースツールとも連携可能です。
11
11
 
12
12
  ### パイプラインフロー
13
13
 
@@ -208,7 +208,7 @@ symbolic-mathematics ──→ systems-biology ──→ admet-pharmacokinetics
208
208
 
209
209
  ### ToolUniverse MCP ツール連携
210
210
 
211
- 66 のスキル(HIGH 13 + MEDIUM 9 + Phase 3: 20 + Phase 4: 8 + Phase 5: 9 + Phase 6: 7)は、[ToolUniverse](https://github.com/mims-harvard/ToolUniverse) SMCP サーバー経由で 1,200 以上の外部科学ツールを利用可能です。各 SKILL.md 内の `### 利用可能ツール` セクションに対応ツールが記載されています。
211
+ 70 のスキル(HIGH 13 + MEDIUM 9 + Phase 3: 20 + Phase 4: 8 + Phase 5: 9 + Phase 6: 7 + Phase 7: 4)は、[ToolUniverse](https://github.com/mims-harvard/ToolUniverse) SMCP サーバー経由で 1,200 以上の外部科学ツールを利用可能です。各 SKILL.md 内の `### 利用可能ツール` セクションに対応ツールが記載されています。
212
212
 
213
213
  ```
214
214
  SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・計算)
@@ -243,7 +243,11 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
243
243
  │ cell-line-resources │───MCP──│ Cellosaurus │
244
244
  │ regulatory-genomics │───MCP──│ RegulomeDB, ReMap, 4DN │
245
245
  │ biomedical-pubtator │───MCP──│ PubTator NER │
246
- ... (66 skills total) │ ... (1,200+ tools) │
246
+ chembl-assay-mining │───MCP──│ ChEMBL Assay/Activity/Target
247
+ │ ensembl-genomics │───MCP──│ Ensembl REST, VEP │
248
+ │ string-network-api │───MCP──│ STRING, BioGRID, STITCH │
249
+ │ expression-comparison│───MCP──│ Expression Atlas │
250
+ │ ... (70 skills total) │ │ ... (1,200+ tools) │
247
251
  └──────────────────────┘ └─────────────────────────────┘
248
252
  ```
249
253
 
@@ -256,8 +260,8 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
256
260
  | C. 機械学習・モデリング | 3 | 回帰・分類・特徴量重要度 |
257
261
  | D. 実験計画・プロセス最適化 | 2 | DOE・応答曲面法・ベイズ最適化 |
258
262
  | E. 信号・スペクトル・時系列 | 4 | スペクトル解析・生体信号・時系列分解・神経電気生理学 |
259
- | F. 生命科学・オミクス | 14 | バイオインフォ・メタボロ・ゲノム配列・マルチオミクス・ネットワーク・プロテオミクス・トランスクリプトミクス・パスウェイ濃縮・代謝物 DB・HPA・ゲノム配列ツール・非コード RNA・オントロジー・EBI DB |
260
- | G. 化学・材料・イメージング | 4 | ケモインフォ・材料特性評価・画像形態解析・計算材料科学 |
263
+ | F. 生命科学・オミクス | 18 | バイオインフォ・メタボロ・ゲノム配列・マルチオミクス・ネットワーク・プロテオミクス・トランスクリプトミクス・パスウェイ濃縮・代謝物 DB・HPA・ゲノム配列ツール・非コード RNA・オントロジー・EBI DB 群・Ensembl ゲノミクス・STRING/BioGRID PPI・発現比較・モデル生物 DB |
264
+ | G. 化学・材料・イメージング | 8 | ケモインフォ・材料特性評価・画像形態解析・計算材料科学・ChEMBL アッセイマイニング・MD シミュレーション・高度イメージング・深層化学 |
261
265
  | H. 臨床・疫学・メタ科学 | 5 | 生存解析・因果推論・メタアナリシス・臨床試験解析・臨床レポート |
262
266
  | I. Deep Research・文献検索 | 3 | 科学文献深層リサーチ・エビデンス階層評価・マルチ DB 文献検索・引用ネットワーク・プレプリント横断検索 |
263
267
  | J. 創薬・ファーマコロジー | 6 | 標的プロファイリング・ADMET/PK・ドラッグリポジショニング・分子ドッキング・薬理学的ターゲット・化合物スクリーニング |
@@ -270,7 +274,7 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
270
274
  | Q. 腫瘍学・疾患研究 | 5 | 精密腫瘍学 (CIViC/OncoKB)・疾患-遺伝子関連 (GWAS/Orphanet)・がんゲノミクス (COSMIC/DepMap)・希少疾患遺伝学・細胞株リソース |
271
275
  | R. 量子・先端計算 | 7 | 量子計算・GNN・ベイズ統計・説明可能 AI・深層学習・ヘルスケア AI・強化学習 |
272
276
  | S. 医用イメージング | 1 | DICOM/NIfTI・WSI 病理画像・Radiomics・MONAI |
273
- | T. シングルセル・空間・エピゲノミクス | 4 | scRNA-seq・Visium・MERFISH・CELLxGENE・RNA velocity・エピゲノミクス・レギュラトリーゲノミクス |
277
+ | T. シングルセル・空間・エピゲノミクス | 6 | scRNA-seq・Visium・MERFISH・CELLxGENE・RNA velocity・エピゲノミクス・レギュラトリーゲノミクス・摂動解析・scVI 統合 |
274
278
  | U. 免疫・感染症 | 2 | 免疫情報学・MHC 結合予測・病原体ゲノミクス・AMR・IEDB |
275
279
  | V. マイクロバイオーム・環境 | 3 | 16S/メタゲノム・α/β 多様性・SDM・OBIS・GBIF・系統解析 |
276
280
  | W. システム生物学 | 2 | SBML シミュレーション・FBA・GRN 推定・BioModels・代謝モデリング |
@@ -345,9 +349,9 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
345
349
  | 24 | [scientific-time-series](scientific-time-series/SKILL.md) | STL 分解・SARIMA 予測・変化点検出・FFT 周期解析・Granger 因果 | 汎用 |
346
350
  | 67 | [scientific-neuroscience-electrophysiology](scientific-neuroscience-electrophysiology/SKILL.md) | SpikeInterface/Kilosort4 スパイクソート・MNE EEG/ERP・NeuroKit2 HRV/EDA・脳機能結合 | 汎用 |
347
351
 
348
- ### F. 生命科学・オミクス(14 種)
352
+ ### F. 生命科学・オミクス(18 種)
349
353
 
350
- バイオ・オミクス・ネットワーク解析・オントロジー・EBI データベースを担うスキル群。
354
+ バイオ・オミクス・ネットワーク解析・オントロジー・EBI データベース・ゲノミクス・PPI・発現比較・モデル生物 DB を担うスキル群。
351
355
 
352
356
  | # | Skill | 説明 | 参照 Exp |
353
357
  |---|---|---|---|
@@ -365,10 +369,14 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
365
369
  | 92 | [scientific-noncoding-rna](scientific-noncoding-rna/SKILL.md) | Rfam RNA ファミリー・RNAcentral ncRNA ・共分散モデル・構造マッピング | 汎用 |
366
370
  | 99 | [scientific-ontology-enrichment](scientific-ontology-enrichment/SKILL.md) | EFO/OLS/Enrichr/UMLS オントロジー検索・遺伝子セット濃縮・用語マッピング | 汎用 |
367
371
  | 100 | [scientific-ebi-databases](scientific-ebi-databases/SKILL.md) | EBI Search/ENA/BioStudies/dbfetch/MetaboLights 統合データアクセス | 汎用 |
372
+ | 108 | [scientific-ensembl-genomics](scientific-ensembl-genomics/SKILL.md) | Ensembl REST API ゲノム解析・VEP バリアント効果予測・ホモロジー検索・制御領域 | 汎用 |
373
+ | 109 | [scientific-string-network-api](scientific-string-network-api/SKILL.md) | STRING v12/BioGRID/STITCH PPI ネットワーク・化学-タンパク質相互作用・トポロジー解析 | 汎用 |
374
+ | 110 | [scientific-expression-comparison](scientific-expression-comparison/SKILL.md) | EBI Expression Atlas 発現比較・ベースライン/差次的発現・組織横断ヒートマップ | 汎用 |
375
+ | 111 | [scientific-model-organism-db](scientific-model-organism-db/SKILL.md) | FlyBase/WormBase/ZFIN/RGD/MGI モデル生物データベース・種間オーソログ検索 | 汎用 |
368
376
 
369
- ### G. 化学・材料・イメージング(4 種)
377
+ ### G. 化学・材料・イメージング(8 種)
370
378
 
371
- 化学構造・材料特性評価・画像形態解析・計算材料科学を担うスキル群。
379
+ 化学構造・材料特性評価・画像形態解析・計算材料科学・ChEMBL アッセイマイニング・MD シミュレーション・高度イメージング・深層化学を担うスキル群。
372
380
 
373
381
  | # | Skill | 説明 | 参照 Exp |
374
382
  |---|---|---|---|
@@ -376,6 +384,10 @@ SATORI Skill (方法論・判断) ToolUniverse SMCP (データ取得・
376
384
  | 31 | [scientific-materials-characterization](scientific-materials-characterization/SKILL.md) | Thornton-Anders SZM・XRD Scherrer・Tauc プロット | 11, 12, 13 |
377
385
  | 32 | [scientific-image-analysis](scientific-image-analysis/SKILL.md) | Otsu/Watershed セグメンテーション・粒径分布・GLCM テクスチャ・蛍光合成 | 汎用 |
378
386
  | 70 | [scientific-computational-materials](scientific-computational-materials/SKILL.md) | pymatgen 結晶構造・Materials Project・相図・バンド構造/DOS・VASP/QE I/O | 汎用 |
387
+ | 107 | [scientific-chembl-assay-mining](scientific-chembl-assay-mining/SKILL.md) | ChEMBL REST API アッセイマイニング・生理活性・SAR 解析・選択性プロファイリング | 汎用 |
388
+ | 112 | [scientific-md-simulation](scientific-md-simulation/SKILL.md) | MDAnalysis/OpenFF 分子動力学シミュレーション・RMSD/RMSF/SASA/水素結合解析 | 汎用 |
389
+ | 114 | [scientific-advanced-imaging](scientific-advanced-imaging/SKILL.md) | Cellpose セグメンテーション・CellProfiler 形態プロファイリング・napari 3D 可視化 | 汎用 |
390
+ | 115 | [scientific-deep-chemistry](scientific-deep-chemistry/SKILL.md) | DeepChem GCN/MPNN/AttentiveFP 分子特性予測・MoleculeNet・ChemBERTa | 汎用 |
379
391
 
380
392
  ### H. 臨床・疫学・メタ科学(5 種)
381
393
 
@@ -503,9 +515,9 @@ DICOM・WSI 等の医用画像の解析・セグメンテーションを担う
503
515
  |---|---|---|---|
504
516
  | 56 | [scientific-medical-imaging](scientific-medical-imaging/SKILL.md) | DICOM/NIfTI 処理・MONAI U-Net/SwinUNETR・WSI パッチ抽出・Radiomics・3D 可視化 | 汎用 |
505
517
 
506
- ### T. シングルセル・空間・エピゲノミクス(4 種)
518
+ ### T. シングルセル・空間・エピゲノミクス(6 種)
507
519
 
508
- scRNA-seq・空間トランスクリプトミクス・エピゲノミクス・制御ゲノミクスの解析パイプラインを担うスキル群。
520
+ scRNA-seq・空間トランスクリプトミクス・エピゲノミクス・制御ゲノミクス・摂動解析・scVI 統合の解析パイプラインを担うスキル群。
509
521
 
510
522
  | # | Skill | 説明 | 参照 Exp |
511
523
  |---|---|---|---|
@@ -513,6 +525,8 @@ scRNA-seq・空間トランスクリプトミクス・エピゲノミクス・
513
525
  | 58 | [scientific-spatial-transcriptomics](scientific-spatial-transcriptomics/SKILL.md) | Visium/MERFISH 前処理・Squidpy SVG 検出・空間ドメイン・cell2location デコンボリューション | 汎用 |
514
526
  | 76 | [scientific-epigenomics-chromatin](scientific-epigenomics-chromatin/SKILL.md) | ChIP-seq MACS2/3・ATAC-seq・WGBS DMR・ChromHMM・Hi-C TAD・モチーフ濃縮 | 汎用 |
515
527
  | 102 | [scientific-regulatory-genomics](scientific-regulatory-genomics/SKILL.md) | RegulomeDB/ReMap/4DN 制御領域バリアント・三次元ゲノム構造解析 | 汎用 |
528
+ | 113 | [scientific-perturbation-analysis](scientific-perturbation-analysis/SKILL.md) | pertpy/Augur/scIB 摂動解析・CRISPR スクリーン・scGen 摂動予測・統合ベンチマーク | 汎用 |
529
+ | 116 | [scientific-scvi-integration](scientific-scvi-integration/SKILL.md) | scVI/scANVI/totalVI/SOLO シングルセル統合・半教師有りアノテーション・CITE-seq | 汎用 |
516
530
 
517
531
  ### U. 免疫・感染症(2 種)
518
532
 
@@ -665,13 +679,21 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
665
679
  │ ├── scientific-genome-sequence-tools/
666
680
  │ ├── scientific-noncoding-rna/
667
681
  │ ├── scientific-ontology-enrichment/
668
- └── scientific-ebi-databases/
682
+ ├── scientific-ebi-databases/
683
+ │ ├── scientific-ensembl-genomics/
684
+ │ ├── scientific-string-network-api/
685
+ │ ├── scientific-expression-comparison/
686
+ │ └── scientific-model-organism-db/
669
687
 
670
688
  │── [G] 化学・材料・イメージング
671
689
  │ ├── scientific-cheminformatics/
672
690
  │ ├── scientific-materials-characterization/
673
691
  │ ├── scientific-image-analysis/
674
- └── scientific-computational-materials/
692
+ ├── scientific-computational-materials/
693
+ │ ├── scientific-chembl-assay-mining/
694
+ │ ├── scientific-md-simulation/
695
+ │ ├── scientific-advanced-imaging/
696
+ │ └── scientific-deep-chemistry/
675
697
 
676
698
  ├── [H] 臨床・疫学・メタ科学
677
699
  │ ├── scientific-survival-clinical/
@@ -745,7 +767,9 @@ Skills は `.github/skills/` に配置されているため、Copilot が自動
745
767
  │ ├── scientific-single-cell-genomics/
746
768
  │ ├── scientific-spatial-transcriptomics/
747
769
  │ ├── scientific-epigenomics-chromatin/
748
- └── scientific-regulatory-genomics/
770
+ ├── scientific-regulatory-genomics/
771
+ │ ├── scientific-perturbation-analysis/
772
+ │ └── scientific-scvi-integration/
749
773
 
750
774
  │── [U] 免疫・感染症
751
775
  │ ├── scientific-immunoinformatics/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nahisaho/satori",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "SATORI — Agent Skills for Science. GitHub Copilot Agent Skills collection for scientific data analysis.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -0,0 +1,382 @@
1
+ ---
2
+ name: scientific-advanced-imaging
3
+ description: |
4
+ 高度バイオイメージング解析スキル。CellProfiler によるモフォロジカル
5
+ プロファイリング・Cell Painting 解析、Cellpose による深層学習
6
+ セルセグメンテーション、napari によるインタラクティブ 3D 可視化。
7
+ ---
8
+
9
+ # Scientific Advanced Imaging
10
+
11
+ CellProfiler / Cellpose / napari を活用した高度バイオイメージング
12
+ 解析パイプラインを提供する。セルセグメンテーション、形態学的
13
+ 特徴抽出、Cell Painting アッセイ解析、3D 画像可視化。
14
+
15
+ ## When to Use
16
+
17
+ - Cell Painting アッセイ画像を解析するとき
18
+ - 深層学習によるセルセグメンテーションが必要なとき (Cellpose)
19
+ - 形態学的特徴量 (面積、真円度、テクスチャ等) を定量するとき
20
+ - 蛍光顕微鏡スタック画像を 3D 可視化するとき
21
+ - カスタム Cellpose モデルを微調整するとき
22
+ - 高コンテンツスクリーニング (HCS) データを処理するとき
23
+
24
+ ---
25
+
26
+ ## Quick Start
27
+
28
+ ## 1. Cellpose セルセグメンテーション
29
+
30
+ ```python
31
+ from cellpose import models, io
32
+ import numpy as np
33
+ from pathlib import Path
34
+
35
+
36
+ def cellpose_segmentation(image_path, model_type="cyto2", diameter=None,
37
+ channels=None, gpu=True):
38
+ """
39
+ Cellpose で細胞セグメンテーション。
40
+
41
+ Parameters:
42
+ image_path: str — 画像ファイルパス
43
+ model_type: str — モデル ("cyto", "cyto2", "nuclei")
44
+ diameter: float — 細胞直径 (None で自動)
45
+ channels: list — チャネル [cytoplasm, nuclei]
46
+ gpu: bool — GPU 使用
47
+
48
+ K-Dense: cellpose
49
+ """
50
+ model = models.Cellpose(model_type=model_type, gpu=gpu)
51
+
52
+ if channels is None:
53
+ channels = [0, 0] # grayscale
54
+
55
+ img = io.imread(str(image_path))
56
+ masks, flows, styles, diams = model.eval(
57
+ img, diameter=diameter, channels=channels
58
+ )
59
+
60
+ n_cells = len(np.unique(masks)) - 1 # background除外
61
+ print(f"Cellpose: {n_cells} cells detected (model={model_type})")
62
+ print(f" Auto diameter: {diams:.1f}")
63
+ return masks, flows, styles
64
+ ```
65
+
66
+ ## 2. バッチセグメンテーション
67
+
68
+ ```python
69
+ def batch_segmentation(image_dir, output_dir, model_type="cyto2",
70
+ image_pattern="*.tif", diameter=None):
71
+ """
72
+ ディレクトリ内画像のバッチセグメンテーション。
73
+
74
+ Parameters:
75
+ image_dir: str — 入力画像ディレクトリ
76
+ output_dir: str — 出力ディレクトリ
77
+ model_type: str — Cellpose モデル
78
+ """
79
+ model = models.Cellpose(model_type=model_type, gpu=True)
80
+ image_dir = Path(image_dir)
81
+ output_dir = Path(output_dir)
82
+ output_dir.mkdir(parents=True, exist_ok=True)
83
+
84
+ image_files = sorted(image_dir.glob(image_pattern))
85
+ results = []
86
+
87
+ for img_path in image_files:
88
+ img = io.imread(str(img_path))
89
+ masks, flows, styles, diams = model.eval(
90
+ img, diameter=diameter, channels=[0, 0]
91
+ )
92
+ n_cells = len(np.unique(masks)) - 1
93
+
94
+ # マスク保存
95
+ out_path = output_dir / f"{img_path.stem}_masks.npy"
96
+ np.save(str(out_path), masks)
97
+
98
+ results.append({
99
+ "image": img_path.name,
100
+ "n_cells": n_cells,
101
+ "diameter": float(diams),
102
+ })
103
+
104
+ print(f"Batch: {len(results)} images, "
105
+ f"{sum(r['n_cells'] for r in results)} total cells")
106
+ return results
107
+ ```
108
+
109
+ ## 3. CellProfiler 形態学的プロファイリング
110
+
111
+ ```python
112
+ import skimage.measure as measure
113
+ import pandas as pd
114
+
115
+
116
+ def morphological_profiling(image, masks, channel_names=None):
117
+ """
118
+ CellProfiler スタイルの形態学的特徴量抽出。
119
+
120
+ Parameters:
121
+ image: np.ndarray — 画像 (H, W) or (H, W, C)
122
+ masks: np.ndarray — セグメンテーションマスク
123
+ channel_names: list — チャネル名
124
+
125
+ K-Dense: cellprofiler
126
+ """
127
+ if image.ndim == 2:
128
+ image = image[..., np.newaxis]
129
+ if channel_names is None:
130
+ channel_names = [f"ch{i}" for i in range(image.shape[-1])]
131
+
132
+ props = measure.regionprops(masks, intensity_image=image[..., 0])
133
+
134
+ features = []
135
+ for prop in props:
136
+ feat = {
137
+ "cell_id": prop.label,
138
+ "area": prop.area,
139
+ "perimeter": prop.perimeter,
140
+ "eccentricity": prop.eccentricity,
141
+ "solidity": prop.solidity,
142
+ "major_axis": prop.major_axis_length,
143
+ "minor_axis": prop.minor_axis_length,
144
+ }
145
+ # 真円度
146
+ if prop.perimeter > 0:
147
+ feat["circularity"] = (4 * np.pi * prop.area) / (prop.perimeter ** 2)
148
+ else:
149
+ feat["circularity"] = 0.0
150
+
151
+ # チャネルごと蛍光強度
152
+ for ch_idx, ch_name in enumerate(channel_names):
153
+ ch_props = measure.regionprops(
154
+ masks, intensity_image=image[..., ch_idx]
155
+ )
156
+ for cp in ch_props:
157
+ if cp.label == prop.label:
158
+ feat[f"{ch_name}_mean"] = cp.mean_intensity
159
+ feat[f"{ch_name}_max"] = cp.max_intensity
160
+ feat[f"{ch_name}_min"] = cp.min_intensity
161
+ break
162
+
163
+ features.append(feat)
164
+
165
+ df = pd.DataFrame(features)
166
+ print(f"Morphological profiling: {len(df)} cells, {len(df.columns)} features")
167
+ return df
168
+ ```
169
+
170
+ ## 4. Cell Painting 解析
171
+
172
+ ```python
173
+ def cell_painting_analysis(image_5ch, masks, normalize=True):
174
+ """
175
+ Cell Painting 5 チャネル解析。
176
+
177
+ Channels:
178
+ ch0: DNA (Hoechst), ch1: ER (ConA), ch2: RNA (SYTO14),
179
+ ch3: AGP (Phalloidin), ch4: Mito (MitoTracker)
180
+
181
+ Parameters:
182
+ image_5ch: np.ndarray — (H, W, 5) 画像
183
+ masks: np.ndarray — セグメンテーションマスク
184
+ normalize: bool — Z-score 正規化
185
+ """
186
+ channel_names = ["DNA", "ER", "RNA", "AGP", "Mito"]
187
+
188
+ # 形態 + 蛍光特徴量抽出
189
+ features_df = morphological_profiling(image_5ch, masks, channel_names)
190
+
191
+ # テクスチャ特徴量 (Haralick-like)
192
+ from skimage.feature import graycomatrix, graycoprops
193
+
194
+ texture_features = []
195
+ for prop in measure.regionprops(masks):
196
+ cell_mask = masks == prop.label
197
+ bbox = prop.bbox
198
+ cell_region = image_5ch[bbox[0]:bbox[2], bbox[1]:bbox[3], 0]
199
+ cell_mask_crop = cell_mask[bbox[0]:bbox[2], bbox[1]:bbox[3]]
200
+ cell_region = (cell_region * cell_mask_crop).astype(np.uint8)
201
+
202
+ if cell_region.max() > 0:
203
+ glcm = graycomatrix(cell_region, [1], [0], levels=256, symmetric=True)
204
+ texture_features.append({
205
+ "cell_id": prop.label,
206
+ "contrast": graycoprops(glcm, "contrast")[0, 0],
207
+ "homogeneity": graycoprops(glcm, "homogeneity")[0, 0],
208
+ "energy": graycoprops(glcm, "energy")[0, 0],
209
+ "correlation": graycoprops(glcm, "correlation")[0, 0],
210
+ })
211
+
212
+ texture_df = pd.DataFrame(texture_features)
213
+ combined = features_df.merge(texture_df, on="cell_id", how="left")
214
+
215
+ if normalize:
216
+ numeric_cols = combined.select_dtypes(include=[np.number]).columns
217
+ numeric_cols = [c for c in numeric_cols if c != "cell_id"]
218
+ combined[numeric_cols] = (
219
+ (combined[numeric_cols] - combined[numeric_cols].mean())
220
+ / combined[numeric_cols].std()
221
+ )
222
+
223
+ print(f"Cell Painting: {len(combined)} cells, {len(combined.columns)} features")
224
+ return combined
225
+ ```
226
+
227
+ ## 5. napari 3D 可視化
228
+
229
+ ```python
230
+ def napari_visualization(image, masks=None, points=None, labels=None):
231
+ """
232
+ napari でインタラクティブ 3D 可視化。
233
+
234
+ Parameters:
235
+ image: np.ndarray — 画像 (Z, Y, X) or (Z, Y, X, C)
236
+ masks: np.ndarray — セグメンテーションマスク
237
+ points: np.ndarray — 座標点 (N, 3)
238
+ labels: list — ポイントラベル
239
+
240
+ K-Dense: napari
241
+ """
242
+ import napari
243
+
244
+ viewer = napari.Viewer()
245
+
246
+ # 画像レイヤー
247
+ if image.ndim == 4:
248
+ for ch in range(image.shape[-1]):
249
+ viewer.add_image(
250
+ image[..., ch],
251
+ name=f"Channel-{ch}",
252
+ blending="additive",
253
+ )
254
+ else:
255
+ viewer.add_image(image, name="Image")
256
+
257
+ # マスクレイヤー
258
+ if masks is not None:
259
+ viewer.add_labels(masks, name="Segmentation")
260
+
261
+ # ポイントレイヤー
262
+ if points is not None:
263
+ properties = {"label": labels} if labels else None
264
+ viewer.add_points(
265
+ points,
266
+ properties=properties,
267
+ name="Points",
268
+ size=5,
269
+ )
270
+
271
+ print(f"napari viewer: {image.shape}, "
272
+ f"masks={'Yes' if masks is not None else 'No'}")
273
+ return viewer
274
+ ```
275
+
276
+ ## 6. Cellpose カスタムモデル微調整
277
+
278
+ ```python
279
+ def finetune_cellpose(train_dir, model_type="cyto2", n_epochs=100,
280
+ learning_rate=0.1):
281
+ """
282
+ Cellpose モデルの微調整。
283
+
284
+ Parameters:
285
+ train_dir: str — 訓練データ (画像 + _masks)
286
+ model_type: str — ベースモデル
287
+ n_epochs: int — エポック数
288
+ learning_rate: float — 学習率
289
+ """
290
+ from cellpose import train
291
+
292
+ train_dir = Path(train_dir)
293
+ image_files = sorted(train_dir.glob("*.tif"))
294
+ mask_files = sorted(train_dir.glob("*_masks.tif"))
295
+
296
+ images = [io.imread(str(f)) for f in image_files]
297
+ labels = [io.imread(str(f)) for f in mask_files]
298
+
299
+ model = models.CellposeModel(model_type=model_type, gpu=True)
300
+ model_path = model.train(
301
+ images, labels,
302
+ channels=[0, 0],
303
+ n_epochs=n_epochs,
304
+ learning_rate=learning_rate,
305
+ save_path=str(train_dir / "models"),
306
+ )
307
+
308
+ print(f"Fine-tuned model saved: {model_path}")
309
+ print(f" Base: {model_type}, Epochs: {n_epochs}")
310
+ return model_path
311
+ ```
312
+
313
+ ## 7. 統合イメージングパイプライン
314
+
315
+ ```python
316
+ def imaging_pipeline(image_dir, output_dir, model_type="cyto2",
317
+ channels_5=True):
318
+ """
319
+ セグメンテーション + 特徴量抽出 統合パイプライン。
320
+
321
+ Parameters:
322
+ image_dir: str — 入力画像ディレクトリ
323
+ output_dir: str — 出力ディレクトリ
324
+ model_type: str — Cellpose モデル
325
+ channels_5: bool — 5ch Cell Painting
326
+ """
327
+ output_dir = Path(output_dir)
328
+ output_dir.mkdir(parents=True, exist_ok=True)
329
+
330
+ # 1) バッチセグメンテーション
331
+ seg_results = batch_segmentation(
332
+ image_dir, output_dir / "masks", model_type=model_type
333
+ )
334
+
335
+ # 2) 特徴量抽出
336
+ all_features = []
337
+ for res in seg_results:
338
+ img_path = Path(image_dir) / res["image"]
339
+ mask_path = output_dir / "masks" / f"{img_path.stem}_masks.npy"
340
+
341
+ img = io.imread(str(img_path))
342
+ masks = np.load(str(mask_path))
343
+
344
+ if channels_5 and img.ndim == 3 and img.shape[-1] == 5:
345
+ feats = cell_painting_analysis(img, masks)
346
+ else:
347
+ feats = morphological_profiling(img, masks)
348
+
349
+ feats["image"] = res["image"]
350
+ all_features.append(feats)
351
+
352
+ combined = pd.concat(all_features, ignore_index=True)
353
+ combined.to_csv(output_dir / "features.csv", index=False)
354
+
355
+ print(f"Pipeline complete: {len(seg_results)} images, "
356
+ f"{len(combined)} cells profiled")
357
+ return combined
358
+ ```
359
+
360
+ ---
361
+
362
+ ## パイプライン統合
363
+
364
+ ```
365
+ image-analysis → advanced-imaging → medical-imaging
366
+ (OpenCV/基本) (Cellpose/CellProfiler) (DICOM/MONAI)
367
+ │ │ ↓
368
+ fluorescence-microscopy ──┘ drug-target-profiling
369
+ (蛍光画像取得) │ (Cell Painting hit)
370
+
371
+ cheminformatics
372
+ (Cell Painting → 化合物活性)
373
+ ```
374
+
375
+ ## パイプライン出力
376
+
377
+ | ファイル | 説明 | 次スキル |
378
+ |---------|------|---------|
379
+ | `results/masks/` | セグメンテーションマスク群 | → medical-imaging |
380
+ | `results/features.csv` | 形態学的特徴量マトリクス | → cheminformatics |
381
+ | `results/cell_painting.csv` | Cell Painting プロファイル | → drug-target-profiling |
382
+ | `results/model/` | 微調整 Cellpose モデル | — |