东方天意singlecell单细胞分析环境创建skill
下载地址
https://www.zhengdianxue.com/wp-content/uploads/skills/org-ekt13cme--create-singlecell-env.zip将提示词发送给你的 AI 安装该 skills
请根据 https://skillhub.cn/install/skillhub.md,安装 @org-ekt13cme/create-singlecell-env。创建基于R的常规单细胞分析conda环境,包含一系列用于常规单细胞分析的R包, 天意云简介: 天意云(dftianyi.com)是专注 AI 云、科研云、生信云领域,集专业、高效、安全于一体的全能科研平台,依托 AI 底座为科研工作赋能,陪伴科研人员科研探索之路。 平台为国家级科技型企业、广东省创新型企业,获得政府引导基金投资;现已服务 10W + 客户,与 500 + 高校及单位达成合作,完成 5000 + 项目交付,汇聚 100 + 生态成员。
业务产品覆盖 AI 工具、科研绘图、生信服务器、科学计算服务器、生信流程定制、数据库网站开发、软件开发,同时提供 PubMed 批量下载、科研云盘等多款科研实用工具。
阅读全文 (展开查看完整说明)
概述
Single Cell Analysis Environment Setup (Lite)
This is a trimmed-down version of create-singlecell-env. It installs only what's needed to run the standard Seurat workflow: QC → normalize → PCA → cluster → UMAP → marker genes → plot.
Skips: harmony/batchelor (integration), monocle3/slingshot/tradeSeq (trajectory), DoubletFinder (doublet detection), SingleR/scmap (annotation), DESeq2/edgeR/limma (bulk DE), clusterProfiler/fgsea/GSVA/enrichR (enrichment), CellChat (cell-cell communication), scran/scater/scuttle (Bioconductor alt framework), Python/scanpy integration, and example datasets. Install any of those later, on demand, with BiocManager::install('PackageName') inside the env — they're not needed to run the standard pipeline.
Step 0: Detect and Install Conda
CRITICAL: Always start by locating the real Conda executable. Do not rely only on command -v conda: desktop apps, non-interactive shells, and shells without conda init may have Conda installed without exposing it on PATH.
Set CONDA_EXE once and use "$CONDA_EXE" for every automated Conda command in this skill. Shell initialization is not required when invoking Conda by absolute path.
discover_conda() {
local candidate="" login_shell="${SHELL:-}"
if [[ -n "${CONDA_EXE:-}" ]] && [[ -x "$CONDA_EXE" ]]; then
candidate="$CONDA_EXE"
elif candidate="$(type -P conda 2>/dev/null)" && [[ -x "$candidate" ]]; then
:
else
candidate=""
fi
if [[ -z "$candidate" ]] && [[ -x "$login_shell" ]]; then
local login_env="" login_path=""
login_env="$("$login_shell" -lic env 2>/dev/null)"
candidate="$(printf '%sn' "$login_env" | sed -n 's/^CONDA_EXE=//p' | tail -n 1)"
if [[ ! -x "$candidate" ]]; then
candidate=""
login_path="$(printf '%sn' "$login_env" | sed -n 's/^PATH=//p' | tail -n 1)"
if [[ -n "$login_path" ]]; then
candidate="$(PATH="$login_path" type -P conda 2>/dev/null)"
fi
fi
[[ -x "$candidate" ]] || candidate=""
fi
[[ -n "$candidate" ]] || return 1
CONDA_EXE="$(cd "$(dirname "$candidate")" && pwd -P)/$(basename "$candidate")"
export CONDA_EXE
}
if discover_conda; then
echo "✓ Conda is installed: $CONDA_EXE"
"$CONDA_EXE" --version
else
echo "✗ Conda is not exposed by the current environment or the user's login shell"
fiThere is no universal Conda installation registry on macOS/Linux. If Conda is installed but neither PATH, CONDA_EXE, nor the login-shell configuration references it, do not crawl the whole filesystem or guess installation directories. Ask the user for the executable path, then verify it with /absolute/path/to/conda --version before offering to install another distribution.
If Conda is not installed at all, offer the standard Miniconda install (see create-singlecell-env Step 0 for the full OS-detection install script) or point the user to https://docs.anaconda.com/free/miniconda/index.html.
Step 1: Create Conda Environment
Detect architecture and create the environment. Use a distinct env name (scrnaseq-lite) so it never collides with a full scrnaseq environment the user may already have.
ARCH=$(uname -m)
if "$CONDA_EXE" env list | grep -q "^scrnaseq-lite"; then
echo "⚠️ Environment 'scrnaseq-lite' already exists."
echo " Activate with: conda activate scrnaseq-lite"
echo " To recreate, first run: conda env remove -n scrnaseq-lite"
fi
if [[ "$ARCH" == "arm64" ]]; then
"$CONDA_EXE" create -n scrnaseq-lite "r-base>=4.4,<4.5" r-essentials -c conda-forge -y
else
"$CONDA_EXE" create -n scrnaseq-lite "r-base>=4.4,<4.5" r-essentials -c conda-forge -y
fiVerify:
"$CONDA_EXE" env list | grep -q "^scrnaseq-lite"
&& echo "✓ Environment 'scrnaseq-lite' created successfully"
|| echo "✗ Environment creation failed"Step 2: Activate Environment
IMPORTANT: conda activate relies on shell hooks that are only loaded in an interactive login shell. In non-interactive contexts (scripts, CI, subprocesses) it can silently fail to update PATH, causing compiled-package installs to fail with errors like x86_64-conda-linux-gnu-cc: not found.
Always use "$CONDA_EXE" run -n scrnaseq-lite <command> for every automated command in this skill.
"$CONDA_EXE" run -n scrnaseq-lite R --version
"$CONDA_EXE" run -n scrnaseq-lite bash -c 'command -v ${CC:-cc} || command -v x86_64-conda-linux-gnu-cc || command -v gcc'
|| { echo "✗ No C compiler found on PATH inside the env — install one first: conda install -n scrnaseq-lite compilers -c conda-forge -y"; exit 1; }Step 3: Configure R Environment
Note on failure detection: install.packages(...) usually exits 0 even on failure. Always verify with installed.packages() after each install (see install_and_verify helper below).
"$CONDA_EXE" run -n scrnaseq-lite Rscript -e "
options(repos = c(CRAN = 'https://cloud.r-project.org'))
"Step 4: Install Core Packages Only
The minimal set needed to run the standard Seurat workflow (QC, normalization, PCA, clustering, UMAP, FindAllMarkers, plotting):
echo "Installing minimal single-cell package set..."
install_and_verify() {
local install_expr="$1"; shift
local pkgs=("$@")
"$CONDA_EXE" run -n scrnaseq-lite Rscript -e "$install_expr"
local check_expr="miss <- c($(printf "'%s'," "${pkgs[@]}" | sed 's/,$//'))[!c($(printf "'%s'," "${pkgs[@]}" | sed 's/,$//')) %in% installed.packages()[,1]]; if (length(miss)) { cat('MISSING:', paste(miss, collapse=', '), 'n'); quit(status=1) } else { cat('OKn') }"
"$CONDA_EXE" run -n scrnaseq-lite Rscript -e "$check_expr" || { echo "✗ Failed to install: ${pkgs[*]}"; return 1; }
echo "✓ Verified installed: ${pkgs[*]}"
}
# Core framework
install_and_verify "install.packages(c('Seurat', 'SeuratObject'), repos = 'https://cloud.r-project.org')" Seurat SeuratObject || exit 1
# Visualization + data wrangling
install_and_verify "install.packages(c('ggplot2', 'patchwork', 'dplyr'), repos = 'https://cloud.r-project.org')" ggplot2 patchwork dplyr || exit 1That's it — no Bioconductor packages, no BiocManager needed for this minimal set.
Verification
"$CONDA_EXE" run -n scrnaseq-lite Rscript -e "
suppressMessages({
library(Seurat); library(SeuratObject); library(ggplot2); library(patchwork); library(dplyr)
})
cat('R version:', R.version.string, 'n')
cat('Seurat version:', as.character(packageVersion('Seurat')), 'n')
cat('All core packages load OKn')
"Quick Reference Package List
| Category | Packages |
|---|---|
| Core Framework | Seurat, SeuratObject |
| Visualization | ggplot2, patchwork |
| Data wrangling | dplyr |
Total: 5 packages (vs. ~25 in the full create-singlecell-env skill).
Upgrading to the Full Environment
If the user later needs integration, trajectory inference, annotation, DE, enrichment, or cell-cell communication analysis, point them to the full create-singlecell-env skill, or install the specific Bioconductor package(s) they need directly into scrnaseq-lite:
"$CONDA_EXE" run -n scrnaseq-lite Rscript -e "
if (!requireNamespace('BiocManager', quietly = TRUE)) install.packages('BiocManager')
BiocManager::install('PackageName', ask = FALSE)
"Default Behavior When Invoked
- First: Run
discover_condafrom Step 0; never treat aPATHmiss alone as proof Conda is absent - If discovered: Verify with
"$CONDA_EXE" --versionand use that absolute path thereafter - If not discovered: Ask for a custom Conda path before offering installation instructions
- If installed: Check if
scrnaseq-litealready exists using"$CONDA_EXE" env list - If environment exists: Warn user and suggest how to proceed (use or recreate)
- If environment doesn't exist: Proceed with environment creation (Steps 1-4)
- Always: Verify each step completes successfully before moving to the next
- Report: Give clear feedback on the executable path, installation, and current progress