--- title: 【记录】安装生信的代码编写环境 urlname: -ji-lu--an-zhuang-sheng-xin-de-dai-ma-bian-xie-huan-jing date: 2023-07-09 20:01:33 tags: ['生信', 'docker', 'vscode', 'rstudio', 'jupyter'] --- ## 安装 vscode-web + 安装好 [docker](/DOCKER-an-zhuang-liu-cheng-ji-lu) + [QUIC 转 SOCKS5](/-ji-lu-SOCKS5-zhuan-QUIC) ```bash mkdir -p ~/app/vscode && cd ~/app/vscode && nano docker-compose.yml sudo docker-compose up -d && sudo docker-compose logs ``` ```yml version: "2.1" services: code-server: image: linuxserver/code-server:latest container_name: code-server environment: - PUID=1000 - PGID=1000 - TZ=Asia/Shanghai - PASSWORD=password - SUDO_PASSWORD=password - PROXY_DOMAIN=code-server.my.domain #optional - DEFAULT_WORKSPACE=/config/workspace #optional volumes: - ./config:/config ports: - 2441:8443 restart: unless-stopped ``` ### 配置代理和中文 + 打开Visual Studio Code,点击Manage,在列表中选择Settings + 在弹出的搜索框中输入"proxy",即可看到代理的配置项"Http:Proxy" + 宿主机获取docker0的ip: `ip address | grep docker0` + 然后docker内设置代理 `http://docker0的ip:port` 拓展内搜索zh-cn,安装中文界面拓展 ### 安装 conda + 回到WORKSPACE,ctrl+~ 调出终端 + `sudo sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list` + `sudo apt update` + `sudo apt install wget` + 安装 [conda](/-ji-lu--an-zhuang-conda-bing-geng-huan-qing-hua-yuan) ### 安装nodejs ```bash conda create -n node -c conda-forge nodejs conda activate node npm config set registry https://registry.npmmirror.com ``` ### 使用git ```bash npm create astro@latest git config --global user.email "youremail" git config --global user.name "yourname" git branch -M main && git add . && git commit -m 'Initial commit' git remote add origin https://github.com/Limour-dev/chatGPT.git git push --set-upstream origin main --force # Creating a personal access token git config --global credential.helper cache git push ``` ### hello world ```js --- const search = Astro.url.searchParams.get('search')! || ''; ---

{search}

``` + [Enabling SSR in Your Project](https://docs.astro.build/en/guides/server-side-rendering/#enabling-ssr-in-your-project) + 编辑 chatGPT/src/pages/index.astro + `npm run dev` + 访问 `https://vscode.domain/proxy/3000/?search=hello%20world` 进行测试 ## 安装 Jupyter ### 持久化镜像存储 ```bash mkdir -p ~/datascience && cd ~/datascience nano docker-compose.yml sudo docker-compose up -d sudo docker-compose logs sudo docker cp -a jupyterR:/opt /home/limour/upload/opt sudo docker cp -a jupyterR:/home/jovyan /home/limour/upload/home sudo docker-compose down && sudo docker volume prune ``` ```yml version: '3.3' services: datascience-notebook: ports: - '57002:8888' container_name: jupyterR restart: always image: 'jupyter/datascience-notebook:r-4.3.1' command: start-notebook.sh --NotebookApp.token='***' ``` ### 启动镜像 ```bash nano docker-compose.yml sudo chmod 777 -R /home/limour/upload/ sudo docker-compose up -d sudo docker-compose logs ``` ```yml version: '3.3' services: datascience-notebook: ports: - '57002:8888' container_name: jupyterR restart: always volumes: - '/home/limour/upload:/home/jovyan/upload' - '/home/limour/upload/opt:/opt' - '/home/limour/upload/home:/home/jovyan' image: 'jupyter/datascience-notebook:r-4.3.1' command: start-notebook.sh --NotebookApp.token='***' ``` + [NPS内网穿透加NPM面板反代](/-ji-lu--an-zhuang-npsfrp-fu-wu-duan-yu-ke-hu-duan) ### R包镜像 ```bash nano .Rprofile options()$repos ## 查看使用install.packages安装时的默认镜像 options()$BioC_mirror ##查看使用bioconductor的默认镜像 ``` ```R options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/") ##指定镜像,这个是中国科技大学镜像 options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")) ##指定install.packages安装镜像,这个是清华镜像 options(ggrepel.max.overlaps = Inf) ``` ### 安装 R 内核 ```bash conda create -n seurat -c conda-forge r-seurat=4.1.1 -y conda activate seurat conda install -c conda-forge r-tidyverse -y conda install -c conda-forge r-irkernel -y Rscript -e "IRkernel::installspec(name='seurat', displayname='r-seurat')" conda install -c conda-forge r-devtools -y Rscript -e "BiocManager::install('glmGamPoi')" wget -e "https_proxy=http://172.17.0.1:8580" https://github.com/chris-mcginnis-ucsf/DoubletFinder/archive/refs/heads/master.zip -O DoubletFinder-master.zip Rscript -e "devtools::install_local('DoubletFinder-master.zip')" ``` ### 安装 python 内核 ```bash conda create -n markdown2pptx -c conda-forge python -y conda install -n markdown2pptx ipykernel -c conda-forge -y conda run -n markdown2pptx python -m ipykernel install --user --name markdown2pptx conda run -n markdown2pptx pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple ``` ### 安装 Golang 内核 + 项目地址 [gophernotes](https://github.com/gopherdata/gophernotes) ```bash conda create -n golang -c conda-forge go -y conda activate golang go env -w GO111MODULE=on go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/ go install github.com/gopherdata/gophernotes@v0.7.5 #去仓库查看最新版本号 mkdir -p ~/.local/share/jupyter/kernels/golang cd ~/.local/share/jupyter/kernels/golang cp "$(go env GOPATH)"/pkg/mod/github.com/gopherdata/gophernotes@v0.7.5/kernel/* "." chmod +w ./kernel.json sed "s|gophernotes|$(go env GOPATH)/bin/gophernotes|" < kernel.json.in > kernel.json ``` ### 安装 jupyter-ai 内核 + [获取端点和令牌](/Aggregating-Azure-and-OpenAI-APIs-with-OneAPI) + 填写端点时尾部需要加上 `/v1` ```bash conda create -n jupyter-ai -c conda-forge jupyter-ai-magics -y conda install -n jupyter-ai -c conda-forge openai -y conda install -n jupyter-ai ipykernel -c conda-forge -y conda run -n jupyter-ai python -m ipykernel install --user --name jupyter-ai # pip install --upgrade jupyterlab -i https://pypi.tuna.tsinghua.edu.cn/simple # 升级到 JupyterLab 4 # pip install jupyter_ai -i https://pypi.tuna.tsinghua.edu.cn/simple ``` + 启用拓展并配置端点和令牌 ```ipython %load_ext jupyter_ai_magics %env OPENAI_API_BASE=https://xxx/v1 %env OPENAI_API_KEY=sk-xxx ``` + 示例 ```ipython %%ai chatgpt -f code 解决汉诺塔问题的函数 ``` ![](https://img.limour.top/2023/10/05/651e61bcdb7a1.webp) ## 安装 rstudio ```bash mkdir -p ~/app/rstudio && cd ~/app/rstudio && nano docker-compose.yml sudo docker-compose up -d && sudo docker-compose logs ``` ```yml version: '3' services: rstudio: image: dceoy/rstudio-server container_name: Rstudio deploy: resources: limits: cpus: '0.50' memory: 500M reservations: cpus: '0.25' memory: 200M restart: always ports: - 57022:8787 volumes: - /home/gene/zl_liu/rstudio:/home/rstudio - /home/gene/upload:/home/rstudio/upload working_dir: /home/rstudio ``` ### 更改 R 版本 + 安装 [conda](/-ji-lu--an-zhuang-conda-bing-geng-huan-qing-hua-yuan) ```bash # 容器内 conda create -n r_4_1_3 -c conda-forge r-base=4.1.3 -y conda activate r_4_1_3 whereis R # /home/rstudio/miniconda3/envs/r_4_1_3/bin/R # 容器外 docker exec -it Rstudio /bin/bash chmod 777 -R /etc/rstudio/ exit nano -K /etc/rstudio/rserver.conf # Server Configuration File rsession-which-r=/home/rstudio/miniconda3/envs/r_4_1_3/bin/R sudo docker-compose restart ``` ### 安装 seurat ```bash # 进入terminal,以下操作均在terminal中进行 export R_LIBS_SITE="" # 在terminal中进入R .libPaths('/home/rstudio/miniconda3/envs/r_4_1_3/lib/R/library') .libPaths() 确保没有其他路径 remove.packages("vctrs") install.packages("vctrs") install.packages('Seurat') remove.packages("cli") install.packages("cli") install.packages("tidyverse") install.packages("plotly") 重启R session library(tidyverse) library(Seurat) ``` ### 绘制 3D-umap ```R library(plotly) library(Seurat) sample13 <- readRDS("~/upload/zl_liu/work/Prognosis/scRNA/sample13.rds") sample13 <- RunUMAP(sample13, dims = 1:10, n.components = 3L) plot.data <- FetchData(object = sample13, vars = c("UMAP_1", "UMAP_2", "UMAP_3", "seurat_clusters")) plot.data$label <- paste(rownames(plot.data)) # Plot your data, in this example my Seurat object had 21 clusters (0-20) plot_ly(data = plot.data, x = ~UMAP_1, y = ~UMAP_2, z = ~UMAP_3, color = ~seurat_clusters, colors = c("lightseagreen", "gray50", "darkgreen", "red4", "red", "turquoise4", "black", "yellow4", "royalblue1", "lightcyan3", "peachpuff3", "khaki3", "gray20", "orange2", "royalblue4", "yellow3", "gray80", "darkorchid1", "lawngreen", "plum2", "darkmagenta")[1:7], type = "scatter3d", mode = "markers", marker = list(size = 5, width=2), # controls size of points text=~label, #This is that extra column we made earlier for which we will use for cell ID hoverinfo="text") #When you visualize your plotly object, hovering your mouse pointer over a point shows cell names ``` ## 安装 notebook ```bash mkdir -p ~/app/notebook && cd ~/app/notebook && nano docker-compose.yml sudo docker-compose up -d && sudo docker-compose logs ``` ```yml version: '3' services: notebook: image: jupyter/r-notebook container_name: notebook restart: unless-stopped environment: - DOCKER_STACKS_JUPYTER_CMD=nbclassic - TZ=Asia/Shanghai - JUPYTER_GATEWAY_REQUEST_TIMEOUT=600 - JUPYTER_GATEWAY_CONNECT_TIMEOUT=600 ports: - '57002:8888' volumes: - '/home/limour/upload:/home/jovyan/upload' - '/home/limour/upload/home:/home/jovyan' command: start-notebook.py --NotebookApp.token='***' ``` ```bash conda init source activate conda config --add envs_dirs /home/jovyan/upload/envs ``` ```nginx proxy_connect_timeout 600s; proxy_read_timeout 600s; proxy_send_timeout 600s; proxy_buffering off; ```