scmcp-shared 0.2.0__py3-none-any.whl → 0.2.5__py3-none-any.whl
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.
- scmcp_shared/__init__.py +1 -1
- scmcp_shared/schema/__init__.py +13 -1
- scmcp_shared/schema/io.py +4 -4
- scmcp_shared/schema/pl.py +2 -3
- scmcp_shared/schema/pp.py +15 -15
- scmcp_shared/schema/tl.py +18 -19
- scmcp_shared/schema/util.py +11 -11
- scmcp_shared/server/__init__.py +6 -6
- scmcp_shared/server/io.py +26 -16
- scmcp_shared/server/pl.py +171 -126
- scmcp_shared/server/pp.py +120 -104
- scmcp_shared/server/tl.py +168 -128
- scmcp_shared/server/util.py +72 -61
- scmcp_shared/util.py +32 -30
- {scmcp_shared-0.2.0.dist-info → scmcp_shared-0.2.5.dist-info}/METADATA +1 -1
- scmcp_shared-0.2.5.dist-info/RECORD +19 -0
- scmcp_shared/schema/base.py +0 -11
- scmcp_shared-0.2.0.dist-info/RECORD +0 -20
- {scmcp_shared-0.2.0.dist-info → scmcp_shared-0.2.5.dist-info}/WHEEL +0 -0
- {scmcp_shared-0.2.0.dist-info → scmcp_shared-0.2.5.dist-info}/licenses/LICENSE +0 -0
scmcp_shared/__init__.py
CHANGED
scmcp_shared/schema/__init__.py
CHANGED
@@ -1 +1,13 @@
|
|
1
|
-
from
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from pydantic import Field, BaseModel,ConfigDict
|
4
|
+
|
5
|
+
|
6
|
+
class AdataModel(BaseModel):
|
7
|
+
"""Input schema for the adata tool."""
|
8
|
+
sampleid: str | None = Field(default=None, description="adata sampleid")
|
9
|
+
adtype: str = Field(default="exp", description="The input adata.X data type for preprocess/analysis/plotting")
|
10
|
+
|
11
|
+
model_config = ConfigDict(
|
12
|
+
extra="ignore"
|
13
|
+
)
|
scmcp_shared/schema/io.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
from pydantic import (
|
2
2
|
Field,
|
3
3
|
field_validator,
|
4
|
-
model_validator,
|
4
|
+
model_validator, BaseModel
|
5
5
|
)
|
6
6
|
from typing import Optional, Literal
|
7
|
-
from .base import AdataModel
|
8
7
|
|
9
8
|
|
10
|
-
|
9
|
+
|
10
|
+
class ReadModel(BaseModel):
|
11
11
|
"""Input schema for the read tool."""
|
12
12
|
filename: str = Field(
|
13
13
|
...,
|
@@ -86,7 +86,7 @@ class ReadModel(AdataModel):
|
|
86
86
|
return v
|
87
87
|
|
88
88
|
|
89
|
-
class WriteModel(
|
89
|
+
class WriteModel(BaseModel):
|
90
90
|
"""Input schema for the write tool."""
|
91
91
|
filename: str = Field(
|
92
92
|
description="Path to save the file. If no extension is provided, the default format will be used."
|
scmcp_shared/schema/pl.py
CHANGED
@@ -7,7 +7,6 @@ from pydantic import (
|
|
7
7
|
model_validator,
|
8
8
|
BaseModel
|
9
9
|
)
|
10
|
-
from .base import AdataModel
|
11
10
|
|
12
11
|
# 创建 Mixin 类处理特定功能
|
13
12
|
class LegendMixin:
|
@@ -73,7 +72,7 @@ class FigureSizeMixin:
|
|
73
72
|
|
74
73
|
|
75
74
|
# 基础可视化模型,包含所有可视化工具共享的字段
|
76
|
-
class BaseVisualizationModel(
|
75
|
+
class BaseVisualizationModel(BaseModel, LegendMixin, ColorMappingMixin, FigureSizeMixin):
|
77
76
|
"""基础可视化模型,包含所有可视化工具共享的字段"""
|
78
77
|
pass
|
79
78
|
|
@@ -632,7 +631,7 @@ class RankGenesGroupsModel(BaseVisualizationModel):
|
|
632
631
|
|
633
632
|
|
634
633
|
# 重构 ClusterMapModel
|
635
|
-
class ClusterMapModel(
|
634
|
+
class ClusterMapModel(BaseModel):
|
636
635
|
"""Input schema for the clustermap plotting tool."""
|
637
636
|
|
638
637
|
obs_keys: Optional[str] = Field(
|
scmcp_shared/schema/pp.py
CHANGED
@@ -3,15 +3,15 @@ from pydantic import (
|
|
3
3
|
ValidationInfo,
|
4
4
|
computed_field,
|
5
5
|
field_validator,
|
6
|
-
model_validator,
|
6
|
+
model_validator,BaseModel
|
7
7
|
)
|
8
|
-
|
8
|
+
|
9
9
|
from typing import Optional, Union, List, Dict, Any
|
10
10
|
from typing import Literal
|
11
11
|
import numpy as np
|
12
12
|
|
13
13
|
|
14
|
-
class FilterCells(
|
14
|
+
class FilterCells(BaseModel):
|
15
15
|
"""Input schema for the filter_cells preprocessing tool."""
|
16
16
|
|
17
17
|
min_counts: Optional[int] = Field(
|
@@ -42,7 +42,7 @@ class FilterCells(AdataModel):
|
|
42
42
|
return v
|
43
43
|
|
44
44
|
|
45
|
-
class FilterGenes(
|
45
|
+
class FilterGenes(BaseModel):
|
46
46
|
"""Input schema for the filter_genes preprocessing tool."""
|
47
47
|
|
48
48
|
min_counts: Optional[int] = Field(
|
@@ -73,7 +73,7 @@ class FilterGenes(AdataModel):
|
|
73
73
|
return v
|
74
74
|
|
75
75
|
|
76
|
-
class SubsetCellModel(
|
76
|
+
class SubsetCellModel(BaseModel):
|
77
77
|
"""Input schema for subsetting AnnData objects based on various criteria."""
|
78
78
|
obs_key: Optional[str] = Field(
|
79
79
|
default=None,
|
@@ -109,7 +109,7 @@ class SubsetCellModel(AdataModel):
|
|
109
109
|
)
|
110
110
|
|
111
111
|
|
112
|
-
class SubsetGeneModel(
|
112
|
+
class SubsetGeneModel(BaseModel):
|
113
113
|
"""Input schema for subsetting AnnData objects based on various criteria."""
|
114
114
|
min_counts: Optional[int] = Field(
|
115
115
|
default=None,
|
@@ -145,7 +145,7 @@ class SubsetGeneModel(AdataModel):
|
|
145
145
|
)
|
146
146
|
|
147
147
|
|
148
|
-
class CalculateQCMetrics(
|
148
|
+
class CalculateQCMetrics(BaseModel):
|
149
149
|
"""Input schema for the calculate_qc_metrics preprocessing tool."""
|
150
150
|
|
151
151
|
expr_type: str = Field(
|
@@ -196,7 +196,7 @@ class CalculateQCMetrics(AdataModel):
|
|
196
196
|
|
197
197
|
|
198
198
|
|
199
|
-
class Log1PModel(
|
199
|
+
class Log1PModel(BaseModel):
|
200
200
|
"""Input schema for the log1p preprocessing tool."""
|
201
201
|
|
202
202
|
base: Optional[Union[int, float]] = Field(
|
@@ -233,7 +233,7 @@ class Log1PModel(AdataModel):
|
|
233
233
|
|
234
234
|
|
235
235
|
|
236
|
-
class HighlyVariableGenesModel(
|
236
|
+
class HighlyVariableGenesModel(BaseModel):
|
237
237
|
"""Input schema for the highly_variable_genes preprocessing tool."""
|
238
238
|
|
239
239
|
layer: Optional[str] = Field(
|
@@ -307,7 +307,7 @@ class HighlyVariableGenesModel(AdataModel):
|
|
307
307
|
return v
|
308
308
|
|
309
309
|
|
310
|
-
class RegressOutModel(
|
310
|
+
class RegressOutModel(BaseModel):
|
311
311
|
"""Input schema for the regress_out preprocessing tool."""
|
312
312
|
|
313
313
|
keys: Union[str, List[str]] = Field(
|
@@ -340,7 +340,7 @@ class RegressOutModel(AdataModel):
|
|
340
340
|
raise ValueError("keys must be a string or list of strings")
|
341
341
|
|
342
342
|
|
343
|
-
class ScaleModel(
|
343
|
+
class ScaleModel(BaseModel):
|
344
344
|
"""Input schema for the scale preprocessing tool."""
|
345
345
|
|
346
346
|
zero_center: bool = Field(
|
@@ -376,7 +376,7 @@ class ScaleModel(AdataModel):
|
|
376
376
|
return v
|
377
377
|
|
378
378
|
|
379
|
-
class CombatModel(
|
379
|
+
class CombatModel(BaseModel):
|
380
380
|
"""Input schema for the combat batch effect correction tool."""
|
381
381
|
|
382
382
|
key: str = Field(
|
@@ -405,7 +405,7 @@ class CombatModel(AdataModel):
|
|
405
405
|
return v
|
406
406
|
|
407
407
|
|
408
|
-
class ScrubletModel(
|
408
|
+
class ScrubletModel(BaseModel):
|
409
409
|
"""Input schema for the scrublet doublet prediction tool."""
|
410
410
|
|
411
411
|
adata_sim: Optional[str] = Field(
|
@@ -511,7 +511,7 @@ class ScrubletModel(AdataModel):
|
|
511
511
|
return v.lower()
|
512
512
|
|
513
513
|
|
514
|
-
class NeighborsModel(
|
514
|
+
class NeighborsModel(BaseModel):
|
515
515
|
"""Input schema for the neighbors graph construction tool."""
|
516
516
|
|
517
517
|
n_neighbors: int = Field(
|
@@ -589,7 +589,7 @@ class NeighborsModel(AdataModel):
|
|
589
589
|
return v
|
590
590
|
|
591
591
|
|
592
|
-
class NormalizeTotalModel(
|
592
|
+
class NormalizeTotalModel(BaseModel):
|
593
593
|
"""Input schema for the normalize_total preprocessing tool."""
|
594
594
|
|
595
595
|
target_sum: Optional[float] = Field(
|
scmcp_shared/schema/tl.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
from pydantic import Field, field_validator, ValidationInfo
|
1
|
+
from pydantic import Field, field_validator, ValidationInfo, BaseModel
|
2
2
|
from typing import Optional, Union, List, Dict, Any, Tuple, Literal, Mapping
|
3
3
|
|
4
|
-
from .base import AdataModel
|
5
4
|
|
6
|
-
class TSNEModel(
|
5
|
+
class TSNEModel(BaseModel):
|
7
6
|
"""Input schema for the t-SNE dimensionality reduction tool."""
|
8
7
|
n_pcs: Optional[int] = Field(
|
9
8
|
default=None,
|
@@ -60,7 +59,7 @@ class TSNEModel(AdataModel):
|
|
60
59
|
return v.lower()
|
61
60
|
|
62
61
|
|
63
|
-
class UMAPModel(
|
62
|
+
class UMAPModel(BaseModel):
|
64
63
|
"""Input schema for the UMAP dimensionality reduction tool."""
|
65
64
|
|
66
65
|
min_dist: Optional[float] = Field(
|
@@ -146,7 +145,7 @@ class UMAPModel(AdataModel):
|
|
146
145
|
return v.lower()
|
147
146
|
|
148
147
|
|
149
|
-
class DrawGraphModel(
|
148
|
+
class DrawGraphModel(BaseModel):
|
150
149
|
"""Input schema for the force-directed graph drawing tool."""
|
151
150
|
|
152
151
|
layout: str = Field(
|
@@ -200,7 +199,7 @@ class DrawGraphModel(AdataModel):
|
|
200
199
|
return v
|
201
200
|
|
202
201
|
|
203
|
-
class DiffMapModel(
|
202
|
+
class DiffMapModel(BaseModel):
|
204
203
|
"""Input schema for the Diffusion Maps dimensionality reduction tool."""
|
205
204
|
|
206
205
|
n_comps: int = Field(
|
@@ -230,7 +229,7 @@ class DiffMapModel(AdataModel):
|
|
230
229
|
return v
|
231
230
|
|
232
231
|
|
233
|
-
class EmbeddingDensityModel(
|
232
|
+
class EmbeddingDensityModel(BaseModel):
|
234
233
|
"""Input schema for the embedding density calculation tool."""
|
235
234
|
|
236
235
|
basis: str = Field(
|
@@ -258,7 +257,7 @@ class EmbeddingDensityModel(AdataModel):
|
|
258
257
|
return v
|
259
258
|
|
260
259
|
|
261
|
-
class LeidenModel(
|
260
|
+
class LeidenModel(BaseModel):
|
262
261
|
"""Input schema for the Leiden clustering algorithm."""
|
263
262
|
|
264
263
|
resolution: Optional[float] = Field(
|
@@ -330,7 +329,7 @@ class LeidenModel(AdataModel):
|
|
330
329
|
return v
|
331
330
|
|
332
331
|
|
333
|
-
class LouvainModel(
|
332
|
+
class LouvainModel(BaseModel):
|
334
333
|
"""Input schema for the Louvain clustering algorithm."""
|
335
334
|
|
336
335
|
resolution: Optional[float] = Field(
|
@@ -402,7 +401,7 @@ class LouvainModel(AdataModel):
|
|
402
401
|
return v
|
403
402
|
|
404
403
|
|
405
|
-
class DendrogramModel(
|
404
|
+
class DendrogramModel(BaseModel):
|
406
405
|
"""Input schema for the hierarchical clustering dendrogram tool."""
|
407
406
|
|
408
407
|
groupby: str = Field(
|
@@ -467,7 +466,7 @@ class DendrogramModel(AdataModel):
|
|
467
466
|
return v
|
468
467
|
|
469
468
|
|
470
|
-
class DPTModel(
|
469
|
+
class DPTModel(BaseModel):
|
471
470
|
"""Input schema for the Diffusion Pseudotime (DPT) tool."""
|
472
471
|
|
473
472
|
n_dcs: int = Field(
|
@@ -516,7 +515,7 @@ class DPTModel(AdataModel):
|
|
516
515
|
raise ValueError("min_group_size must be between 0 and 1")
|
517
516
|
return v
|
518
517
|
|
519
|
-
class PAGAModel(
|
518
|
+
class PAGAModel(BaseModel):
|
520
519
|
"""Input schema for the Partition-based Graph Abstraction (PAGA) tool."""
|
521
520
|
|
522
521
|
groups: Optional[str] = Field(
|
@@ -544,7 +543,7 @@ class PAGAModel(AdataModel):
|
|
544
543
|
return v
|
545
544
|
|
546
545
|
|
547
|
-
class IngestModel(
|
546
|
+
class IngestModel(BaseModel):
|
548
547
|
"""Input schema for the ingest tool that maps labels and embeddings from reference data to new data."""
|
549
548
|
|
550
549
|
obs: Optional[Union[str, List[str]]] = Field(
|
@@ -593,7 +592,7 @@ class IngestModel(AdataModel):
|
|
593
592
|
return v.lower()
|
594
593
|
|
595
594
|
|
596
|
-
class RankGenesGroupsModel(
|
595
|
+
class RankGenesGroupsModel(BaseModel):
|
597
596
|
"""Input schema for the rank_genes_groups tool."""
|
598
597
|
|
599
598
|
groupby: str = Field(
|
@@ -675,7 +674,7 @@ class RankGenesGroupsModel(AdataModel):
|
|
675
674
|
return v
|
676
675
|
|
677
676
|
|
678
|
-
class FilterRankGenesGroupsModel(
|
677
|
+
class FilterRankGenesGroupsModel(BaseModel):
|
679
678
|
"""Input schema for filtering ranked genes groups."""
|
680
679
|
|
681
680
|
key: Optional[str] = Field(
|
@@ -738,7 +737,7 @@ class FilterRankGenesGroupsModel(AdataModel):
|
|
738
737
|
return v
|
739
738
|
|
740
739
|
|
741
|
-
class MarkerGeneOverlapModel(
|
740
|
+
class MarkerGeneOverlapModel(BaseModel):
|
742
741
|
"""Input schema for the marker gene overlap tool."""
|
743
742
|
|
744
743
|
key: str = Field(
|
@@ -809,7 +808,7 @@ class MarkerGeneOverlapModel(AdataModel):
|
|
809
808
|
return v
|
810
809
|
|
811
810
|
|
812
|
-
class ScoreGenesModel(
|
811
|
+
class ScoreGenesModel(BaseModel):
|
813
812
|
"""Input schema for the score_genes tool that calculates gene scores based on average expression."""
|
814
813
|
|
815
814
|
ctrl_size: int = Field(
|
@@ -852,7 +851,7 @@ class ScoreGenesModel(AdataModel):
|
|
852
851
|
return v
|
853
852
|
|
854
853
|
|
855
|
-
class ScoreGenesCellCycleModel(
|
854
|
+
class ScoreGenesCellCycleModel(BaseModel):
|
856
855
|
"""Input schema for the score_genes_cell_cycle tool that scores cell cycle genes."""
|
857
856
|
|
858
857
|
s_genes: List[str] = Field(
|
@@ -902,7 +901,7 @@ class ScoreGenesCellCycleModel(AdataModel):
|
|
902
901
|
|
903
902
|
|
904
903
|
|
905
|
-
class PCAModel(
|
904
|
+
class PCAModel(BaseModel):
|
906
905
|
"""Input schema for the PCA preprocessing tool."""
|
907
906
|
|
908
907
|
n_comps: Optional[int] = Field(
|
scmcp_shared/schema/util.py
CHANGED
@@ -4,13 +4,13 @@ from pydantic import (
|
|
4
4
|
ValidationInfo,
|
5
5
|
computed_field,
|
6
6
|
field_validator,
|
7
|
-
model_validator,
|
7
|
+
model_validator,BaseModel
|
8
8
|
)
|
9
9
|
from typing import Optional, Union, List, Dict, Any, Callable, Collection, Literal
|
10
|
-
from .base import AdataModel
|
11
10
|
|
12
11
|
|
13
|
-
|
12
|
+
|
13
|
+
class MarkVarModel(BaseModel):
|
14
14
|
"""Determine or mark if each gene meets specific conditions and store results in adata.var as boolean values"""
|
15
15
|
|
16
16
|
var_name: str = Field(
|
@@ -32,15 +32,15 @@ class MarkVarModel(AdataModel):
|
|
32
32
|
)
|
33
33
|
|
34
34
|
|
35
|
-
class ListVarModel(
|
35
|
+
class ListVarModel(BaseModel):
|
36
36
|
"""ListVarModel"""
|
37
37
|
pass
|
38
38
|
|
39
|
-
class ListObsModel(
|
39
|
+
class ListObsModel(BaseModel):
|
40
40
|
"""ListObsModel"""
|
41
41
|
pass
|
42
42
|
|
43
|
-
class VarNamesModel(
|
43
|
+
class VarNamesModel(BaseModel):
|
44
44
|
"""ListObsModel"""
|
45
45
|
var_names: List[str] = Field(
|
46
46
|
default=None,
|
@@ -48,7 +48,7 @@ class VarNamesModel(AdataModel):
|
|
48
48
|
)
|
49
49
|
|
50
50
|
|
51
|
-
class
|
51
|
+
class ConcatBaseModel(BaseModel):
|
52
52
|
"""Model for concatenating AnnData objects"""
|
53
53
|
|
54
54
|
axis: Literal['obs', 0, 'var', 1] = Field(
|
@@ -89,7 +89,7 @@ class ConcatAdataModel(AdataModel):
|
|
89
89
|
)
|
90
90
|
|
91
91
|
|
92
|
-
class DPTIROOTModel(
|
92
|
+
class DPTIROOTModel(BaseModel):
|
93
93
|
"""Input schema for setting the root cell for diffusion pseudotime."""
|
94
94
|
diffmap_key: str = Field(
|
95
95
|
default="X_diffmap",
|
@@ -103,7 +103,7 @@ class DPTIROOTModel(AdataModel):
|
|
103
103
|
)
|
104
104
|
|
105
105
|
|
106
|
-
class CelltypeMapCellTypeModel(
|
106
|
+
class CelltypeMapCellTypeModel(BaseModel):
|
107
107
|
"""Input schema for mapping cluster IDs to cell type names."""
|
108
108
|
cluster_key: str = Field(
|
109
109
|
description="Key in adata.obs containing cluster IDs."
|
@@ -122,14 +122,14 @@ class CelltypeMapCellTypeModel(AdataModel):
|
|
122
122
|
|
123
123
|
|
124
124
|
|
125
|
-
class AddLayerModel(
|
125
|
+
class AddLayerModel(BaseModel):
|
126
126
|
"""Input schema for adding a layer to AnnData object."""
|
127
127
|
layer_name: str = Field(
|
128
128
|
description="Name of the layer to add to adata.layers."
|
129
129
|
)
|
130
130
|
|
131
131
|
|
132
|
-
class QueryOpLogModel(
|
132
|
+
class QueryOpLogModel(BaseModel):
|
133
133
|
"""QueryOpLogModel"""
|
134
134
|
n: int = Field(
|
135
135
|
default=10,
|
scmcp_shared/server/__init__.py
CHANGED
@@ -23,9 +23,9 @@ class AdataState:
|
|
23
23
|
self.cr_kernel = {}
|
24
24
|
self.cr_estimator = {}
|
25
25
|
|
26
|
-
def get_adata(self, sampleid=None, adtype="exp",
|
27
|
-
if
|
28
|
-
kwargs =
|
26
|
+
def get_adata(self, sampleid=None, adtype="exp", adinfo=None):
|
27
|
+
if adinfo is not None:
|
28
|
+
kwargs = adinfo.model_dump()
|
29
29
|
sampleid = kwargs.get("sampleid", None)
|
30
30
|
adtype = kwargs.get("adtype", "exp")
|
31
31
|
try:
|
@@ -38,9 +38,9 @@ class AdataState:
|
|
38
38
|
except Exception as e:
|
39
39
|
raise Exception(f"fuck {e} {type(e)}")
|
40
40
|
|
41
|
-
def set_adata(self, adata, sampleid=None, sdtype="exp",
|
42
|
-
if
|
43
|
-
kwargs =
|
41
|
+
def set_adata(self, adata, sampleid=None, sdtype="exp", adinfo=None):
|
42
|
+
if adinfo is not None:
|
43
|
+
kwargs = adinfo.model_dump()
|
44
44
|
sampleid = kwargs.get("sampleid", None)
|
45
45
|
sdtype = kwargs.get("adtype", "exp")
|
46
46
|
sampleid = sampleid or self.active_id
|
scmcp_shared/server/io.py
CHANGED
@@ -3,6 +3,8 @@ import inspect
|
|
3
3
|
from pathlib import Path
|
4
4
|
import scanpy as sc
|
5
5
|
from fastmcp import FastMCP , Context
|
6
|
+
from fastmcp.exceptions import ToolError
|
7
|
+
from ..schema import AdataModel
|
6
8
|
from ..schema.io import *
|
7
9
|
from ..util import filter_args, forward_request, get_ads, generate_msg
|
8
10
|
|
@@ -11,12 +13,15 @@ io_mcp = FastMCP("SCMCP-IO-Server")
|
|
11
13
|
|
12
14
|
|
13
15
|
@io_mcp.tool()
|
14
|
-
async def read(
|
16
|
+
async def read(
|
17
|
+
request: ReadModel,
|
18
|
+
adinfo: AdataModel = AdataModel()
|
19
|
+
):
|
15
20
|
"""
|
16
21
|
Read data from 10X directory or various file formats (h5ad, 10x, text files, etc.).
|
17
22
|
"""
|
18
23
|
try:
|
19
|
-
result = await forward_request("io_read", request)
|
24
|
+
result = await forward_request("io_read", request, adinfo)
|
20
25
|
if result is not None:
|
21
26
|
return result
|
22
27
|
kwargs = request.model_dump()
|
@@ -34,41 +39,46 @@ async def read(request: ReadModel):
|
|
34
39
|
else:
|
35
40
|
raise FileNotFoundError(f"{kwargs['filename']} does not exist")
|
36
41
|
|
37
|
-
sampleid = kwargs.get("sampleid", None)
|
38
|
-
adtype = kwargs.get("adtype", "exp")
|
39
42
|
ads = get_ads()
|
40
|
-
if sampleid is not None:
|
41
|
-
ads.active_id = sampleid
|
43
|
+
if adinfo.sampleid is not None:
|
44
|
+
ads.active_id = adinfo.sampleid
|
42
45
|
else:
|
43
|
-
ads.active_id = f"adata{len(ads.adata_dic[adtype])}"
|
46
|
+
ads.active_id = f"adata{len(ads.adata_dic[adinfo.adtype])}"
|
44
47
|
|
45
48
|
adata.layers["counts"] = adata.X
|
46
49
|
adata.var_names_make_unique()
|
47
50
|
adata.obs_names_make_unique()
|
48
|
-
ads.set_adata(adata,
|
49
|
-
return generate_msg(
|
51
|
+
ads.set_adata(adata, adinfo=adinfo)
|
52
|
+
return generate_msg(adinfo, adata, ads)
|
53
|
+
except ToolError as e:
|
54
|
+
raise ToolError(e)
|
50
55
|
except Exception as e:
|
51
56
|
if hasattr(e, '__context__') and e.__context__:
|
52
|
-
raise
|
57
|
+
raise ToolError(e.__context__)
|
53
58
|
else:
|
54
|
-
raise e
|
59
|
+
raise ToolError(e)
|
55
60
|
|
56
61
|
|
57
62
|
@io_mcp.tool()
|
58
|
-
async def write(
|
63
|
+
async def write(
|
64
|
+
request: WriteModel,
|
65
|
+
adinfo: AdataModel = AdataModel()
|
66
|
+
):
|
59
67
|
"""save adata into a file.
|
60
68
|
"""
|
61
69
|
try:
|
62
|
-
result = await forward_request("io_write", request)
|
70
|
+
result = await forward_request("io_write", request, adinfo)
|
63
71
|
if result is not None:
|
64
72
|
return result
|
65
73
|
ads = get_ads()
|
66
|
-
adata = ads.get_adata(
|
74
|
+
adata = ads.get_adata(adinfo=adinfo)
|
67
75
|
kwargs = request.model_dump()
|
68
76
|
sc.write(kwargs["filename"], adata)
|
69
77
|
return {"filename": kwargs["filename"], "msg": "success to save file"}
|
78
|
+
except ToolError as e:
|
79
|
+
raise ToolError(e)
|
70
80
|
except Exception as e:
|
71
81
|
if hasattr(e, '__context__') and e.__context__:
|
72
|
-
raise
|
82
|
+
raise ToolError(e.__context__)
|
73
83
|
else:
|
74
|
-
raise e
|
84
|
+
raise ToolError(e)
|