{ "cells": [ { "cell_type": "markdown", "id": "53cb155f", "metadata": {}, "source": [ "# Preparation of SpatialCOC" ] }, { "cell_type": "markdown", "id": "9eb357bd", "metadata": {}, "source": [ "We recommend using a dedicated conda environment to run SpatialCOC. Please download and install Anaconda3 from the official website.\n", "> https://www.anaconda.com/download" ] }, { "cell_type": "markdown", "id": "b288244b", "metadata": {}, "source": "## 1. Install SpatialCOC" }, { "cell_type": "markdown", "id": "bc6e53f5", "metadata": {}, "source": "### 1.1 Create a conda environment" }, { "cell_type": "markdown", "id": "5c5f0bb8", "metadata": {}, "source": "Please execute the following commands in the Anaconda Prompt:" }, { "cell_type": "code", "execution_count": null, "id": "e84b9497", "metadata": {}, "outputs": [], "source": [ "# Create a new environment named SpatialCOC with Python 3.11.5\n", "conda create -n SpatialCOC python=3.11.5\n", "\n", "# Activate the environment\n", "conda activate SpatialCOC" ] }, { "cell_type": "markdown", "id": "b771de8e", "metadata": {}, "source": "### 1.2 Install the SpatialCOC package" }, { "cell_type": "markdown", "id": "8c15183b", "metadata": {}, "source": [ "Download the SpatialCOC package from the GitHub repository.\n", "> https://github.com/xjtu-omics/SpatialCOC\n", "\n", "After downloading, navigate to the package directory and run the following command to install the package:" ] }, { "cell_type": "code", "id": "5fe12a07", "metadata": {}, "source": "pip install .", "outputs": [], "execution_count": null }, { "cell_type": "markdown", "id": "f3472660", "metadata": {}, "source": "Once the installation is complete, you can verify that SpatialCOC is imported successfully:" }, { "cell_type": "code", "id": "7d411eec", "metadata": { "ExecuteTime": { "end_time": "2026-04-01T06:22:06.369229200Z", "start_time": "2026-04-01T06:22:06.341752400Z" } }, "source": [ "try:\n", " import SpatialCOC\n", " print(\"✓ SpatialCOC imported successfully!\")\n", " print(f\" SpatialCOC version: {SpatialCOC.__version__}\")\n", "\n", "except ImportError as e:\n", " print(f\"✗ Import failed: {e}\")\n", " print(\" Please install SpatialCOC: pip install SpatialCOC\")\n", "except Exception as e:\n", " print(f\"✗ Other error: {e}\")" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "✓ SpatialCOC imported successfully!\n", " SpatialCOC version: 1.0.0\n" ] } ], "execution_count": 12 }, { "metadata": {}, "cell_type": "markdown", "source": "## 2. Configure the R Environment", "id": "ccd7c809a822e96f" }, { "metadata": {}, "cell_type": "markdown", "source": "SpatialCOC uses the mclust algorithm, which requires both the rpy2 Python package and the mclust R package.", "id": "14dd1ce8ebb07d3d" }, { "metadata": {}, "cell_type": "markdown", "source": [ "### 2.1 Install the R software\n", "Download and install R version 4.3.1 to a specific directory.\n", "> https://cran.r-project.org/bin/windows/base/old/4.3.1/" ], "id": "e1b312f91b54ce78" }, { "metadata": {}, "cell_type": "markdown", "source": "### 2.2 Install the rpy2 package", "id": "4ff9a83cc9e8c391" }, { "metadata": {}, "cell_type": "markdown", "source": "Please run the code below to install the rpy2 package:", "id": "849ceb99bc9e7499" }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "conda install -c conda-forge rpy2", "id": "fea324f8fe84b914" }, { "metadata": {}, "cell_type": "markdown", "source": "### 2.3 Set the correct paths", "id": "ce2d53e39f822441" }, { "metadata": {}, "cell_type": "markdown", "source": "To enable rpy2 to work properly, configure the following environment variables. Replace the placeholders with your actual paths:", "id": "c40f9fc2c105f668" }, { "metadata": { "ExecuteTime": { "end_time": "2026-04-01T06:22:56.777824700Z", "start_time": "2026-04-01T06:22:56.762719400Z" } }, "cell_type": "code", "source": [ "import os\n", "os.environ['RPY2_CFFI_MODE'] = 'ABI'\n", "\n", "os.environ['R_HOME'] = '***' # Path to the R installation, e.g., 'E:/R-4.3.1'\n", "os.environ['R_USER'] = '***' # Path to rpy2 within the virtual environment, e.g., 'E:/anaconda3/envs/SpatialCOC/Lib/site-packages/rpy2'" ], "id": "de8a26c77b50d176", "outputs": [], "execution_count": 16 }, { "metadata": {}, "cell_type": "markdown", "source": "Please run the following code to confirm that rpy2 is correctly installed and can communicate with R:", "id": "b8219cf9a35e7789" }, { "metadata": { "ExecuteTime": { "end_time": "2026-04-01T06:22:58.939724600Z", "start_time": "2026-04-01T06:22:58.921308Z" } }, "cell_type": "code", "source": [ "try:\n", " import rpy2.robjects as robjects\n", " import rpy2.robjects.numpy2ri\n", " print(\"✓ rpy2 imported successfully!\")\n", " print(f\" rpy2 version: {robjects.__version__}\")\n", "\n", " # Get R version\n", " r_version = robjects.r('R.version.string')[0]\n", " print(f\" R version: {r_version}\")\n", "\n", "except ImportError as e:\n", " print(f\"✗ Import failed: {e}\")\n", " print(\" Please install rpy2: pip install rpy2\")\n", "except Exception as e:\n", " print(f\"✗ Other error: {e}\")" ], "id": "a9dc4c768106f814", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "✓ rpy2 imported successfully!\n", " rpy2 version: 3.6.3\n", " R version: R version 4.3.1 (2023-06-16 ucrt)\n" ] } ], "execution_count": 17 } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }