chatspatial 1.1.0__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.
Files changed (67) hide show
  1. chatspatial/__init__.py +11 -0
  2. chatspatial/__main__.py +141 -0
  3. chatspatial/cli/__init__.py +7 -0
  4. chatspatial/config.py +53 -0
  5. chatspatial/models/__init__.py +85 -0
  6. chatspatial/models/analysis.py +513 -0
  7. chatspatial/models/data.py +2462 -0
  8. chatspatial/server.py +1763 -0
  9. chatspatial/spatial_mcp_adapter.py +720 -0
  10. chatspatial/tools/__init__.py +3 -0
  11. chatspatial/tools/annotation.py +1903 -0
  12. chatspatial/tools/cell_communication.py +1603 -0
  13. chatspatial/tools/cnv_analysis.py +605 -0
  14. chatspatial/tools/condition_comparison.py +595 -0
  15. chatspatial/tools/deconvolution/__init__.py +402 -0
  16. chatspatial/tools/deconvolution/base.py +318 -0
  17. chatspatial/tools/deconvolution/card.py +244 -0
  18. chatspatial/tools/deconvolution/cell2location.py +326 -0
  19. chatspatial/tools/deconvolution/destvi.py +144 -0
  20. chatspatial/tools/deconvolution/flashdeconv.py +101 -0
  21. chatspatial/tools/deconvolution/rctd.py +317 -0
  22. chatspatial/tools/deconvolution/spotlight.py +216 -0
  23. chatspatial/tools/deconvolution/stereoscope.py +109 -0
  24. chatspatial/tools/deconvolution/tangram.py +135 -0
  25. chatspatial/tools/differential.py +625 -0
  26. chatspatial/tools/embeddings.py +298 -0
  27. chatspatial/tools/enrichment.py +1863 -0
  28. chatspatial/tools/integration.py +807 -0
  29. chatspatial/tools/preprocessing.py +723 -0
  30. chatspatial/tools/spatial_domains.py +808 -0
  31. chatspatial/tools/spatial_genes.py +836 -0
  32. chatspatial/tools/spatial_registration.py +441 -0
  33. chatspatial/tools/spatial_statistics.py +1476 -0
  34. chatspatial/tools/trajectory.py +495 -0
  35. chatspatial/tools/velocity.py +405 -0
  36. chatspatial/tools/visualization/__init__.py +155 -0
  37. chatspatial/tools/visualization/basic.py +393 -0
  38. chatspatial/tools/visualization/cell_comm.py +699 -0
  39. chatspatial/tools/visualization/cnv.py +320 -0
  40. chatspatial/tools/visualization/core.py +684 -0
  41. chatspatial/tools/visualization/deconvolution.py +852 -0
  42. chatspatial/tools/visualization/enrichment.py +660 -0
  43. chatspatial/tools/visualization/integration.py +205 -0
  44. chatspatial/tools/visualization/main.py +164 -0
  45. chatspatial/tools/visualization/multi_gene.py +739 -0
  46. chatspatial/tools/visualization/persistence.py +335 -0
  47. chatspatial/tools/visualization/spatial_stats.py +469 -0
  48. chatspatial/tools/visualization/trajectory.py +639 -0
  49. chatspatial/tools/visualization/velocity.py +411 -0
  50. chatspatial/utils/__init__.py +115 -0
  51. chatspatial/utils/adata_utils.py +1372 -0
  52. chatspatial/utils/compute.py +327 -0
  53. chatspatial/utils/data_loader.py +499 -0
  54. chatspatial/utils/dependency_manager.py +462 -0
  55. chatspatial/utils/device_utils.py +165 -0
  56. chatspatial/utils/exceptions.py +185 -0
  57. chatspatial/utils/image_utils.py +267 -0
  58. chatspatial/utils/mcp_utils.py +137 -0
  59. chatspatial/utils/path_utils.py +243 -0
  60. chatspatial/utils/persistence.py +78 -0
  61. chatspatial/utils/scipy_compat.py +143 -0
  62. chatspatial-1.1.0.dist-info/METADATA +242 -0
  63. chatspatial-1.1.0.dist-info/RECORD +67 -0
  64. chatspatial-1.1.0.dist-info/WHEEL +5 -0
  65. chatspatial-1.1.0.dist-info/entry_points.txt +2 -0
  66. chatspatial-1.1.0.dist-info/licenses/LICENSE +21 -0
  67. chatspatial-1.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,11 @@
1
+ """
2
+ ChatSpatial
3
+
4
+ Agentic workflow orchestration platform for spatial transcriptomics analysis.
5
+ Integrates 60 methods from Python and R ecosystems via Model Context Protocol.
6
+ """
7
+
8
+ __version__ = "1.0.0"
9
+
10
+ # Import configuration to set up environment
11
+ from . import config as config # noqa: F401
@@ -0,0 +1,141 @@
1
+ """
2
+ Entry point for ChatSpatial.
3
+
4
+ This module provides the command-line interface for starting the
5
+ ChatSpatial server using either stdio or SSE transport.
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ import traceback
11
+ import warnings
12
+ from pathlib import Path
13
+
14
+ import click
15
+
16
+ # Suppress warnings to speed up startup
17
+ warnings.filterwarnings("ignore", category=FutureWarning)
18
+ warnings.filterwarnings("ignore", category=UserWarning)
19
+
20
+ # CRITICAL: Disable all progress bars to prevent stdout pollution in MCP protocol
21
+ # MCP uses JSON-RPC over stdio, any non-JSON output breaks communication
22
+ os.environ["TQDM_DISABLE"] = "1" # Disable tqdm globally
23
+
24
+ # Configure scientific libraries to suppress output
25
+ try:
26
+ import scanpy as sc
27
+
28
+ sc.settings.verbosity = 0 # Suppress scanpy output
29
+ except ImportError:
30
+ pass # scanpy may not be installed yet
31
+
32
+ # IMPORTANT: Intelligent working directory handling
33
+ # Only change cwd when it's clearly problematic, otherwise respect user configuration
34
+ PROJECT_ROOT = Path(__file__).parent.resolve()
35
+ user_cwd = Path.cwd()
36
+
37
+ # Identify problematic working directories that should be changed
38
+ problematic_cwds = [
39
+ Path("/"), # Root directory
40
+ Path("/tmp"), # Temp directory
41
+ Path("/var"), # System directory
42
+ Path("/usr"), # System directory
43
+ Path("/etc"), # System directory
44
+ ]
45
+
46
+ # Check if current cwd is problematic
47
+ is_problematic = (
48
+ # Check exact match
49
+ user_cwd in problematic_cwds
50
+ or
51
+ # Check if cwd is a parent of problematic directories
52
+ any(user_cwd == p.parent for p in problematic_cwds)
53
+ or
54
+ # Check if directory doesn't exist
55
+ not user_cwd.exists()
56
+ or
57
+ # Check if it's a temporary npx directory (common MCP issue)
58
+ "_npx" in str(user_cwd)
59
+ or ".npm" in str(user_cwd)
60
+ )
61
+
62
+ if is_problematic:
63
+ print(
64
+ f"WARNING:Working directory appears problematic: {user_cwd}\n"
65
+ f" Changing to project root: {PROJECT_ROOT}\n"
66
+ f" (This ensures file operations work correctly)",
67
+ file=sys.stderr,
68
+ )
69
+ os.chdir(PROJECT_ROOT)
70
+ else:
71
+ print(
72
+ f"Using configured working directory: {user_cwd}\n"
73
+ f" (Project root: {PROJECT_ROOT})",
74
+ file=sys.stderr,
75
+ )
76
+ # Keep user's configured cwd - don't change it!
77
+
78
+ from .server import mcp # noqa: E402
79
+
80
+
81
+ @click.group()
82
+ def cli():
83
+ """ChatSpatial - AI-powered spatial transcriptomics analysis"""
84
+ pass
85
+
86
+
87
+ @cli.command()
88
+ @click.option("--port", default=8000, help="Port to listen on for SSE transport")
89
+ @click.option(
90
+ "--transport",
91
+ type=click.Choice(["stdio", "sse"]),
92
+ default="stdio",
93
+ help="Transport type (stdio or sse)",
94
+ )
95
+ @click.option(
96
+ "--host",
97
+ default="127.0.0.1", # nosec B104 - Default to localhost for security
98
+ help="Host to bind to for SSE transport",
99
+ )
100
+ @click.option(
101
+ "--log-level",
102
+ type=click.Choice(["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]),
103
+ default="INFO",
104
+ help="Logging level",
105
+ )
106
+ def server(port: int, transport: str, host: str, log_level: str):
107
+ """Start the ChatSpatial server.
108
+
109
+ This command starts the ChatSpatial server using either stdio or SSE transport.
110
+ For stdio transport, the server communicates through standard input/output.
111
+ For SSE transport, the server starts an HTTP server on the specified host and port.
112
+ """
113
+ try:
114
+ # Configure server settings
115
+ print(
116
+ f"Starting ChatSpatial server with {transport} transport...",
117
+ file=sys.stderr,
118
+ )
119
+
120
+ # Set server settings
121
+ mcp.settings.host = host
122
+ mcp.settings.port = port
123
+ mcp.settings.log_level = log_level
124
+
125
+ # Run the server with the specified transport
126
+ # This is the recommended way to run a FastMCP server
127
+ mcp.run(transport=transport)
128
+
129
+ except Exception as e:
130
+ print(f"Error starting MCP server: {e}", file=sys.stderr)
131
+ traceback.print_exc(file=sys.stderr)
132
+ sys.exit(1)
133
+
134
+
135
+ def main():
136
+ """Main entry point for ChatSpatial CLI"""
137
+ cli()
138
+
139
+
140
+ if __name__ == "__main__":
141
+ main()
@@ -0,0 +1,7 @@
1
+ """
2
+ ChatSpatial Command Line Interface module.
3
+
4
+ Provides the main CLI entry point for the ChatSpatial server.
5
+ """
6
+
7
+ __all__: list[str] = []
chatspatial/config.py ADDED
@@ -0,0 +1,53 @@
1
+ """
2
+ Configuration module for ChatSpatial
3
+ """
4
+
5
+ import os
6
+ import warnings
7
+
8
+ # Configure Dask to use new DataFrame implementation
9
+ os.environ.setdefault("DASK_DATAFRAME__QUERY_PLANNING", "True")
10
+
11
+ # Try to import and configure dask
12
+ try:
13
+ import dask
14
+
15
+ dask.config.set({"dataframe.query-planning": True})
16
+ except ImportError:
17
+ pass # Dask not installed
18
+
19
+
20
+ # Suppress specific warnings
21
+ def configure_warnings():
22
+ """Configure warning filters for known issues"""
23
+ # Suppress dask legacy dataframe warning
24
+ warnings.filterwarnings(
25
+ "ignore",
26
+ message="The legacy Dask DataFrame implementation is deprecated",
27
+ category=FutureWarning,
28
+ )
29
+
30
+ # Suppress spatialdata functools.partial warnings
31
+ warnings.filterwarnings(
32
+ "ignore",
33
+ message="functools.partial will be a method descriptor",
34
+ category=FutureWarning,
35
+ )
36
+
37
+ # Suppress numba nopython warning
38
+ warnings.filterwarnings(
39
+ "ignore",
40
+ message="nopython is set for njit and is ignored",
41
+ category=RuntimeWarning,
42
+ )
43
+
44
+ # Suppress anndata read_text warning
45
+ warnings.filterwarnings(
46
+ "ignore",
47
+ message="Importing read_text from `anndata` is deprecated",
48
+ category=FutureWarning,
49
+ )
50
+
51
+
52
+ # Configure on import
53
+ configure_warnings()
@@ -0,0 +1,85 @@
1
+ """
2
+ Data models for spatial transcriptomics analysis.
3
+ """
4
+
5
+ # Import result models from analysis module
6
+ from .analysis import (
7
+ AnnotationResult,
8
+ BaseAnalysisResult,
9
+ CellCommunicationResult,
10
+ CellTypeComparisonResult,
11
+ CNVResult,
12
+ ConditionComparisonResult,
13
+ DEGene,
14
+ DeconvolutionResult,
15
+ DifferentialExpressionResult,
16
+ EnrichmentResult,
17
+ IntegrationResult,
18
+ PreprocessingResult,
19
+ RNAVelocityResult,
20
+ SpatialDomainResult,
21
+ SpatialStatisticsResult,
22
+ SpatialVariableGenesResult,
23
+ TrajectoryResult,
24
+ )
25
+
26
+ # Import parameter models from data module
27
+ from .data import (
28
+ AnnotationParameters,
29
+ CellCommunicationParameters,
30
+ CNVParameters,
31
+ ColumnInfo,
32
+ ConditionComparisonParameters,
33
+ DeconvolutionParameters,
34
+ DifferentialExpressionParameters,
35
+ EnrichmentParameters,
36
+ IntegrationParameters,
37
+ PreprocessingParameters,
38
+ RNAVelocityParameters,
39
+ SpatialDataset,
40
+ SpatialDomainParameters,
41
+ SpatialStatisticsParameters,
42
+ SpatialVariableGenesParameters,
43
+ TrajectoryParameters,
44
+ VisualizationParameters,
45
+ )
46
+
47
+ __all__ = [
48
+ # Base class
49
+ "BaseAnalysisResult",
50
+ # Result models
51
+ "AnnotationResult",
52
+ "CellCommunicationResult",
53
+ "CellTypeComparisonResult",
54
+ "CNVResult",
55
+ "ConditionComparisonResult",
56
+ "DEGene",
57
+ "DeconvolutionResult",
58
+ "DifferentialExpressionResult",
59
+ "EnrichmentResult",
60
+ "IntegrationResult",
61
+ "PreprocessingResult",
62
+ "RNAVelocityResult",
63
+ "SpatialDomainResult",
64
+ "SpatialStatisticsResult",
65
+ "SpatialVariableGenesResult",
66
+ "TrajectoryResult",
67
+ # Parameter models
68
+ "AnnotationParameters",
69
+ "CellCommunicationParameters",
70
+ "CNVParameters",
71
+ "ColumnInfo",
72
+ "ConditionComparisonParameters",
73
+ "DeconvolutionParameters",
74
+ "DifferentialExpressionParameters",
75
+ "EnrichmentParameters",
76
+ "IntegrationParameters",
77
+ "PreprocessingParameters",
78
+ "RNAVelocityParameters",
79
+ "SpatialDataset",
80
+ "SpatialDomainParameters",
81
+ "SpatialStatisticsParameters",
82
+ "SpatialVariableGenesParameters",
83
+ "TrajectoryParameters",
84
+ "VisualizationParameters",
85
+ ]