@nahisaho/satori 0.15.0 → 0.17.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.
@@ -0,0 +1,251 @@
1
+ ---
2
+ name: scientific-squidpy-advanced
3
+ description: |
4
+ 高度 Squidpy 空間解析スキル。空間自己相関・共起解析・空間
5
+ 近傍・リガンド受容体空間マッピング・ニッチ同定。
6
+ K-Dense 連携: squidpy-advanced。
7
+ tu_tools: []
8
+ kdense_ref: squidpy-advanced
9
+ ---
10
+
11
+ # Scientific Squidpy Advanced
12
+
13
+ Squidpy の高度な空間統計解析機能を活用した空間トランスクリプ
14
+ トミクス解析パイプラインを提供する。
15
+
16
+ ## When to Use
17
+
18
+ - 空間自己相関 (Moran's I, Geary's C) を計算するとき
19
+ - 細胞タイプの空間共起パターンを分析するとき
20
+ - 近傍エンリッチメント解析を実施するとき
21
+ - リガンド-受容体のペア空間マッピングを行うとき
22
+ - 空間ニッチ (組織微小環境) を同定するとき
23
+ - 空間グラフ中心性指標を計算するとき
24
+
25
+ ---
26
+
27
+ ## Quick Start
28
+
29
+ ## 1. 空間自己相関解析
30
+
31
+ ```python
32
+ import squidpy as sq
33
+ import scanpy as sc
34
+ import pandas as pd
35
+ import numpy as np
36
+
37
+
38
+ def squidpy_spatial_autocorrelation(adata, genes=None,
39
+ mode="moran", n_perms=100,
40
+ n_jobs=4):
41
+ """
42
+ Squidpy — 空間自己相関解析 (Moran's I / Geary's C)。
43
+
44
+ Parameters:
45
+ adata: AnnData — 空間トランスクリプトミクスデータ
46
+ genes: list[str] — 対象遺伝子 (None=HVG 使用)
47
+ mode: str — "moran" or "geary"
48
+ n_perms: int — 並べ替え検定回数
49
+ n_jobs: int — 並列ジョブ数
50
+ """
51
+ # 空間グラフ構築 (未構築の場合)
52
+ if "spatial_connectivities" not in adata.obsp:
53
+ sq.gr.spatial_neighbors(adata, coord_type="generic",
54
+ n_neighs=6)
55
+
56
+ if genes is None:
57
+ sc.pp.highly_variable_genes(adata, n_top_genes=200)
58
+ genes = adata.var_names[adata.var["highly_variable"]].tolist()
59
+
60
+ sq.gr.spatial_autocorr(adata, mode=mode, genes=genes,
61
+ n_perms=n_perms, n_jobs=n_jobs)
62
+
63
+ result_key = f"{mode}I" if mode == "moran" else f"{mode}C"
64
+ result = adata.uns[result_key].copy()
65
+ sig = result[result["pval_norm"] < 0.05]
66
+
67
+ print(f"Spatial autocorrelation ({mode}): "
68
+ f"{len(sig)}/{len(result)} significant genes")
69
+ return result.sort_values("pval_norm")
70
+ ```
71
+
72
+ ## 2. 空間共起解析
73
+
74
+ ```python
75
+ def squidpy_co_occurrence(adata, cluster_key="cell_type",
76
+ interval=50, n_splits=None):
77
+ """
78
+ Squidpy — 細胞タイプ空間共起解析。
79
+
80
+ Parameters:
81
+ adata: AnnData — 空間トランスクリプトミクスデータ
82
+ cluster_key: str — 細胞タイプアノテーションカラム
83
+ interval: int — 距離インターバル数
84
+ n_splits: int — 分割数 (大規模データ用, None=自動)
85
+ """
86
+ sq.gr.co_occurrence(adata, cluster_key=cluster_key,
87
+ interval=interval, n_splits=n_splits)
88
+
89
+ co_occ = adata.uns[f"{cluster_key}_co_occurrence"]
90
+ occ_scores = co_occ["occ"]
91
+ interval_vals = co_occ["interval"]
92
+ categories = adata.obs[cluster_key].cat.categories.tolist()
93
+
94
+ # 最近距離での共起スコアマトリクス
95
+ near_idx = 0
96
+ scores = occ_scores[near_idx]
97
+ co_df = pd.DataFrame(scores, index=categories, columns=categories)
98
+
99
+ # 有意な共起ペア
100
+ pairs = []
101
+ for i, cat_i in enumerate(categories):
102
+ for j, cat_j in enumerate(categories):
103
+ if i < j:
104
+ pairs.append({
105
+ "cell_type_a": cat_i,
106
+ "cell_type_b": cat_j,
107
+ "co_occurrence_score": scores[i, j],
108
+ })
109
+ pairs_df = pd.DataFrame(pairs).sort_values(
110
+ "co_occurrence_score", ascending=False)
111
+
112
+ print(f"Co-occurrence: {len(categories)} cell types, "
113
+ f"top pair: {pairs_df.iloc[0]['cell_type_a']} — "
114
+ f"{pairs_df.iloc[0]['cell_type_b']}")
115
+ return co_df, pairs_df
116
+ ```
117
+
118
+ ## 3. 近傍エンリッチメント & ニッチ同定
119
+
120
+ ```python
121
+ def squidpy_niche_identification(adata, cluster_key="cell_type",
122
+ n_neighs=15, n_niches=5,
123
+ seed=42):
124
+ """
125
+ Squidpy — 空間ニッチ同定。
126
+
127
+ Parameters:
128
+ adata: AnnData — 空間トランスクリプトミクスデータ
129
+ cluster_key: str — 細胞タイプカラム
130
+ n_neighs: int — 近傍数
131
+ n_niches: int — ニッチクラスタ数
132
+ seed: int — 乱数シード
133
+ """
134
+ # 近傍エンリッチメント
135
+ sq.gr.nhood_enrichment(adata, cluster_key=cluster_key)
136
+ nhood = adata.uns[f"{cluster_key}_nhood_enrichment"]
137
+ zscore_matrix = nhood["zscore"]
138
+ categories = adata.obs[cluster_key].cat.categories.tolist()
139
+ nhood_df = pd.DataFrame(zscore_matrix, index=categories,
140
+ columns=categories)
141
+
142
+ # 空間近傍グラフ
143
+ sq.gr.spatial_neighbors(adata, coord_type="generic",
144
+ n_neighs=n_neighs)
145
+
146
+ # 近傍組成プロファイル
147
+ from sklearn.cluster import KMeans
148
+ cell_types = adata.obs[cluster_key]
149
+ type_dummies = pd.get_dummies(cell_types)
150
+
151
+ # 各細胞の近傍組成
152
+ conn = adata.obsp["spatial_connectivities"]
153
+ nhood_composition = conn.dot(type_dummies.values)
154
+ nhood_comp_df = pd.DataFrame(
155
+ nhood_composition, columns=type_dummies.columns,
156
+ index=adata.obs_names)
157
+
158
+ # ニッチクラスタリング
159
+ km = KMeans(n_clusters=n_niches, random_state=seed, n_init=10)
160
+ adata.obs["spatial_niche"] = km.fit_predict(
161
+ nhood_comp_df.values).astype(str)
162
+
163
+ niche_summary = adata.obs.groupby("spatial_niche")[cluster_key]\
164
+ .value_counts(normalize=True).unstack(fill_value=0)
165
+
166
+ print(f"Niche identification: {n_niches} niches, "
167
+ f"{len(categories)} cell types")
168
+ return nhood_df, niche_summary
169
+ ```
170
+
171
+ ## 4. Squidpy 高度空間解析統合パイプライン
172
+
173
+ ```python
174
+ def squidpy_advanced_pipeline(adata, cluster_key="cell_type",
175
+ output_dir="results"):
176
+ """
177
+ Squidpy 高度空間解析統合パイプライン。
178
+
179
+ Parameters:
180
+ adata: AnnData — 空間トランスクリプトミクスデータ
181
+ cluster_key: str — 細胞タイプカラム
182
+ output_dir: str — 出力ディレクトリ
183
+ """
184
+ from pathlib import Path
185
+ output_dir = Path(output_dir)
186
+ output_dir.mkdir(parents=True, exist_ok=True)
187
+
188
+ # 1) 空間自己相関
189
+ autocorr = squidpy_spatial_autocorrelation(adata)
190
+ autocorr.to_csv(output_dir / "spatial_autocorrelation.csv")
191
+
192
+ # 2) 空間共起
193
+ co_df, pairs_df = squidpy_co_occurrence(adata,
194
+ cluster_key=cluster_key)
195
+ co_df.to_csv(output_dir / "co_occurrence_matrix.csv")
196
+ pairs_df.to_csv(output_dir / "co_occurrence_pairs.csv",
197
+ index=False)
198
+
199
+ # 3) ニッチ同定
200
+ nhood_df, niche_summary = squidpy_niche_identification(
201
+ adata, cluster_key=cluster_key)
202
+ nhood_df.to_csv(output_dir / "nhood_enrichment.csv")
203
+ niche_summary.to_csv(output_dir / "niche_composition.csv")
204
+
205
+ # 4) 中心性スコア
206
+ sq.gr.centrality_scores(adata, cluster_key=cluster_key)
207
+ centrality = adata.uns[f"{cluster_key}_centrality_scores"]
208
+ centrality_df = pd.DataFrame(centrality)
209
+ centrality_df.to_csv(output_dir / "centrality_scores.csv")
210
+
211
+ adata.write(output_dir / "adata_spatial.h5ad")
212
+
213
+ print(f"Squidpy advanced pipeline: {output_dir}")
214
+ return {
215
+ "autocorrelation": autocorr,
216
+ "co_occurrence": co_df,
217
+ "niches": niche_summary,
218
+ "centrality": centrality_df,
219
+ }
220
+ ```
221
+
222
+ ---
223
+
224
+ ## K-Dense 連携
225
+
226
+ | K-Dense Key | 参照内容 |
227
+ |-------------|---------|
228
+ | `squidpy-advanced` | 高度空間統計・ニッチ解析手法 |
229
+
230
+ ## パイプライン統合
231
+
232
+ ```
233
+ spatial-transcriptomics → squidpy-advanced → single-cell-genomics
234
+ (Visium/MERFISH) (空間統計) (scRNA-seq)
235
+ │ │ ↓
236
+ image-analysis ─────────────┘ cell-communication
237
+ (H&E/IF 画像) │ (リガンド-受容体)
238
+
239
+ multi-omics
240
+ (空間マルチモーダル)
241
+ ```
242
+
243
+ ## パイプライン出力
244
+
245
+ | ファイル | 説明 | 次スキル |
246
+ |---------|------|---------|
247
+ | `results/spatial_autocorrelation.csv` | 空間自己相関 | → gene-expression |
248
+ | `results/co_occurrence_matrix.csv` | 共起マトリクス | → cell-communication |
249
+ | `results/niche_composition.csv` | ニッチ組成 | → single-cell-genomics |
250
+ | `results/centrality_scores.csv` | 中心性スコア | → spatial-transcriptomics |
251
+ | `results/adata_spatial.h5ad` | AnnData (全結果) | → multi-omics |
@@ -0,0 +1,309 @@
1
+ ---
2
+ name: scientific-toxicology-env
3
+ description: |
4
+ 毒性学・環境衛生スキル。CTD (Comparative Toxicogenomics Database)
5
+ 化学-遺伝子-疾患関連・ToxCast/Tox21 高スループット毒性スクリーニング・
6
+ IRIS ヒトリスク評価・T3DB 食品/環境毒性物質・PubChem BioAssay 毒性データ。
7
+ ---
8
+
9
+ # Scientific Toxicology & Environmental Health
10
+
11
+ CTD / Tox21 / ToxCast / T3DB / IRIS を活用した毒性学・環境衛生
12
+ パイプラインを提供する。化学物質-遺伝子-疾患関連、高スループット
13
+ 毒性スクリーニング、ヒト健康リスク評価。
14
+
15
+ ## When to Use
16
+
17
+ - 化学物質が関連する遺伝子・疾患を調べるとき (CTD)
18
+ - Tox21/ToxCast アッセイデータで毒性メカニズムを解析するとき
19
+ - IRIS リスク評価データ (RfD/RfC/UR) を参照するとき
20
+ - 食品・環境毒性物質の詳細データベース (T3DB) を検索するとき
21
+ - PubChem BioAssay から毒性関連ハイスループットデータを取得するとき
22
+ - ADMET 毒性予測と実験毒性データを併用するとき
23
+
24
+ ---
25
+
26
+ ## Quick Start
27
+
28
+ ## 1. CTD 化学-遺伝子-疾患関連検索
29
+
30
+ ```python
31
+ import requests
32
+ import pandas as pd
33
+ import json
34
+
35
+ CTD_BASE = "https://ctdbase.org/tools"
36
+
37
+
38
+ def ctd_chemical_gene(chemical_name, limit=100):
39
+ """
40
+ CTD — 化学物質-遺伝子相互作用を検索。
41
+
42
+ Parameters:
43
+ chemical_name: str — 化学物質名 (例: "Bisphenol A")
44
+ limit: int — 最大取得数
45
+ """
46
+ url = f"{CTD_BASE}/batchQuery.go"
47
+ params = {
48
+ "inputType": "chem",
49
+ "inputTerms": chemical_name,
50
+ "report": "genes_curated",
51
+ "format": "json",
52
+ }
53
+ resp = requests.get(url, params=params, timeout=60)
54
+ resp.raise_for_status()
55
+ data = resp.json()[:limit]
56
+
57
+ results = []
58
+ for entry in data:
59
+ results.append({
60
+ "chemical": entry.get("ChemicalName", ""),
61
+ "gene": entry.get("GeneSymbol", ""),
62
+ "organism": entry.get("Organism", ""),
63
+ "interaction": entry.get("Interaction", ""),
64
+ "pubmed_ids": entry.get("PubMedIDs", ""),
65
+ })
66
+
67
+ df = pd.DataFrame(results)
68
+ print(f"CTD: {chemical_name} → {len(df)} gene interactions")
69
+ return df
70
+ ```
71
+
72
+ ## 2. CTD 化学-疾患関連検索
73
+
74
+ ```python
75
+ def ctd_chemical_disease(chemical_name, limit=100):
76
+ """
77
+ CTD — 化学物質-疾患関連を検索。
78
+
79
+ Parameters:
80
+ chemical_name: str — 化学物質名
81
+ limit: int — 最大取得数
82
+ """
83
+ url = f"{CTD_BASE}/batchQuery.go"
84
+ params = {
85
+ "inputType": "chem",
86
+ "inputTerms": chemical_name,
87
+ "report": "diseases_curated",
88
+ "format": "json",
89
+ }
90
+ resp = requests.get(url, params=params, timeout=60)
91
+ resp.raise_for_status()
92
+ data = resp.json()[:limit]
93
+
94
+ results = []
95
+ for entry in data:
96
+ results.append({
97
+ "chemical": entry.get("ChemicalName", ""),
98
+ "disease": entry.get("DiseaseName", ""),
99
+ "disease_id": entry.get("DiseaseID", ""),
100
+ "direct_evidence": entry.get("DirectEvidence", ""),
101
+ "inference_score": float(entry.get("InferenceScore", 0)),
102
+ })
103
+
104
+ df = pd.DataFrame(results)
105
+ df = df.sort_values("inference_score", ascending=False)
106
+ print(f"CTD: {chemical_name} → {len(df)} disease associations")
107
+ return df
108
+ ```
109
+
110
+ ## 3. Tox21/ToxCast アッセイデータ取得
111
+
112
+ ```python
113
+ COMPTOX_BASE = "https://comptox.epa.gov/dashboard/api"
114
+
115
+
116
+ def tox21_assay_search(chemical_identifier, assay_source="Tox21"):
117
+ """
118
+ CompTox Dashboard — Tox21/ToxCast アッセイ結果を取得。
119
+
120
+ Parameters:
121
+ chemical_identifier: str — DTXSID or CAS
122
+ assay_source: str — "Tox21" or "ToxCast"
123
+ """
124
+ # CompTox Dashboard API で化学物質のアッセイデータ取得
125
+ url = f"{COMPTOX_BASE}/chemical/search"
126
+ params = {"query": chemical_identifier}
127
+ resp = requests.get(url, params=params, timeout=30)
128
+ resp.raise_for_status()
129
+ chem_data = resp.json()
130
+
131
+ dtxsid = chem_data.get("dtxsid", chemical_identifier)
132
+
133
+ # アッセイエンドポイント取得
134
+ url_assay = f"{COMPTOX_BASE}/chemical/{dtxsid}/assays"
135
+ resp_assay = requests.get(url_assay, timeout=30)
136
+ resp_assay.raise_for_status()
137
+ assays = resp_assay.json()
138
+
139
+ results = []
140
+ for assay in assays:
141
+ if assay_source.lower() in assay.get("assaySource", "").lower():
142
+ results.append({
143
+ "assay_name": assay.get("assayName", ""),
144
+ "assay_source": assay.get("assaySource", ""),
145
+ "endpoint": assay.get("assayEndpoint", ""),
146
+ "activity": assay.get("activity", ""),
147
+ "ac50_um": assay.get("ac50", None),
148
+ "hit_call": assay.get("hitCall", ""),
149
+ })
150
+
151
+ df = pd.DataFrame(results)
152
+ n_active = (df["hit_call"] == "Active").sum() if len(df) > 0 else 0
153
+ print(f"Tox21/ToxCast: {dtxsid} → {len(df)} assays, {n_active} active")
154
+ return df
155
+ ```
156
+
157
+ ## 4. T3DB 毒性物質検索
158
+
159
+ ```python
160
+ T3DB_BASE = "https://t3db.ca/api"
161
+
162
+
163
+ def t3db_search(query, search_type="name"):
164
+ """
165
+ T3DB — 食品/環境毒性物質データベース検索。
166
+
167
+ Parameters:
168
+ query: str — 検索語
169
+ search_type: str — "name", "cas", "category"
170
+ """
171
+ url = f"{T3DB_BASE}/toxins/search"
172
+ params = {"query": query, "search_type": search_type}
173
+ resp = requests.get(url, params=params, timeout=30)
174
+ resp.raise_for_status()
175
+ data = resp.json()
176
+
177
+ results = []
178
+ for toxin in data.get("toxins", []):
179
+ results.append({
180
+ "name": toxin.get("name", ""),
181
+ "t3db_id": toxin.get("t3db_id", ""),
182
+ "cas_number": toxin.get("cas_number", ""),
183
+ "category": toxin.get("category", ""),
184
+ "toxicity_class": toxin.get("toxicity_class", ""),
185
+ "ld50_oral": toxin.get("ld50_oral", ""),
186
+ "target_organs": toxin.get("target_organs", []),
187
+ })
188
+
189
+ df = pd.DataFrame(results)
190
+ print(f"T3DB: '{query}' → {len(df)} toxins")
191
+ return df
192
+ ```
193
+
194
+ ## 5. EPA IRIS リスク評価
195
+
196
+ ```python
197
+ def iris_risk_assessment(chemical_name):
198
+ """
199
+ EPA IRIS — ヒト健康リスク評価データ取得。
200
+
201
+ Parameters:
202
+ chemical_name: str — 化学物質名
203
+ """
204
+ url = "https://iris.epa.gov/AtoZ"
205
+ resp = requests.get(url, timeout=30)
206
+
207
+ # IRIS は構造化 API なし — スクレイピングまたはローカルデータ
208
+ # 代替: CompTox Dashboard API 経由
209
+ url_comptox = f"{COMPTOX_BASE}/chemical/search"
210
+ params = {"query": chemical_name}
211
+ resp = requests.get(url_comptox, params=params, timeout=30)
212
+ resp.raise_for_status()
213
+ data = resp.json()
214
+
215
+ risk_data = {
216
+ "chemical": chemical_name,
217
+ "dtxsid": data.get("dtxsid", ""),
218
+ "rfd_oral_mg_kg_day": data.get("rfdOral", None),
219
+ "rfc_inhalation_mg_m3": data.get("rfcInhalation", None),
220
+ "cancer_classification": data.get("cancerClassification", ""),
221
+ "oral_slope_factor": data.get("oralSlopeFactor", None),
222
+ "inhalation_unit_risk": data.get("inhalationUnitRisk", None),
223
+ }
224
+
225
+ print(f"IRIS: {chemical_name}")
226
+ for k, v in risk_data.items():
227
+ if v and k != "chemical":
228
+ print(f" {k}: {v}")
229
+ return risk_data
230
+ ```
231
+
232
+ ## 6. 毒性パスウェイ解析
233
+
234
+ ```python
235
+ def toxicity_pathway_analysis(chemical_name, species="Homo sapiens"):
236
+ """
237
+ CTD + パスウェイ統合毒性解析。
238
+
239
+ Parameters:
240
+ chemical_name: str — 化学物質名
241
+ species: str — 生物種
242
+ """
243
+ # 1) CTD 遺伝子取得
244
+ gene_df = ctd_chemical_gene(chemical_name, limit=500)
245
+ if species:
246
+ gene_df = gene_df[gene_df["organism"] == species]
247
+
248
+ gene_list = gene_df["gene"].unique().tolist()
249
+
250
+ # 2) CTD 疾患取得
251
+ disease_df = ctd_chemical_disease(chemical_name, limit=100)
252
+
253
+ # 3) パスウェイ濃縮 (KEGG enrichment via Enrichr)
254
+ enrichr_url = "https://maayanlab.cloud/Enrichr"
255
+ add_resp = requests.post(
256
+ f"{enrichr_url}/addList",
257
+ files={"list": (None, "\n".join(gene_list))}
258
+ )
259
+ user_list_id = add_resp.json()["userListId"]
260
+
261
+ enrich_resp = requests.get(
262
+ f"{enrichr_url}/enrich",
263
+ params={"userListId": user_list_id, "backgroundType": "KEGG_2021_Human"}
264
+ )
265
+ pathways = enrich_resp.json().get("KEGG_2021_Human", [])
266
+
267
+ pathway_results = []
268
+ for pw in pathways[:20]:
269
+ pathway_results.append({
270
+ "pathway": pw[1],
271
+ "p_value": pw[2],
272
+ "adj_p_value": pw[6],
273
+ "genes": pw[5],
274
+ })
275
+
276
+ print(f"Toxicity pathway: {chemical_name}")
277
+ print(f" Target genes: {len(gene_list)}")
278
+ print(f" Diseases: {len(disease_df)}")
279
+ print(f" Pathways: {len(pathway_results)}")
280
+ return {
281
+ "genes": gene_df,
282
+ "diseases": disease_df,
283
+ "pathways": pd.DataFrame(pathway_results),
284
+ }
285
+ ```
286
+
287
+ ---
288
+
289
+ ## パイプライン統合
290
+
291
+ ```
292
+ admet-pharmacokinetics → toxicology-env → pharmacovigilance
293
+ (ADMET 毒性予測) (CTD/Tox21/IRIS) (市販後安全性)
294
+ │ │ ↓
295
+ cheminformatics ───────────────┘ disease-research
296
+ (RDKit 構造アラート) │ (疾患-遺伝子関連)
297
+
298
+ public-health-data
299
+ (CDC/WHO 公衆衛生)
300
+ ```
301
+
302
+ ## パイプライン出力
303
+
304
+ | ファイル | 説明 | 次スキル |
305
+ |---------|------|---------|
306
+ | `results/ctd_gene_interactions.csv` | CTD 化学-遺伝子関連 | → pathway-enrichment |
307
+ | `results/ctd_disease_associations.csv` | CTD 化学-疾患関連 | → disease-research |
308
+ | `results/tox21_assays.csv` | Tox21/ToxCast アッセイ結果 | → admet-pharmacokinetics |
309
+ | `results/toxicity_pathways.json` | 毒性パスウェイ解析結果 | → pharmacovigilance |