【记录】安装生信的代码编写环境

Last updated on January 20, 2024 pm

安装 vscode-web

1
2
mkdir -p ~/app/vscode && cd ~/app/vscode && nano docker-compose.yml
sudo docker-compose up -d && sudo docker-compose logs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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

安装nodejs

1
2
3
conda create -n node -c conda-forge nodejs
conda activate node
npm config set registry https://registry.npmmirror.com

使用git

1
2
3
4
5
6
7
8
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

1
2
3
4
---
const search = Astro.url.searchParams.get('search')! || '';
---
<h1>{search}</h1>
  • Enabling SSR in Your Project
  • 编辑 chatGPT/src/pages/index.astro
  • npm run dev
  • 访问 https://vscode.domain/proxy/3000/?search=hello%20world 进行测试

安装 Jupyter

持久化镜像存储

1
2
3
4
5
6
7
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
1
2
3
4
5
6
7
8
9
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='***'

启动镜像

1
2
3
4
nano docker-compose.yml
sudo chmod 777 -R /home/limour/upload/
sudo docker-compose up -d
sudo docker-compose logs
1
2
3
4
5
6
7
8
9
10
11
12
13
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='***'

R包镜像

1
2
3
nano .Rprofile
options()$repos ## 查看使用install.packages安装时的默认镜像
options()$BioC_mirror ##查看使用bioconductor的默认镜像
1
2
3
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 内核

1
2
3
4
5
6
7
8
9
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 内核

1
2
3
4
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 内核

1
2
3
4
5
6
7
8
9
10
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 内核

1
2
3
4
5
6
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
  • 启用拓展并配置端点和令牌
1
2
3
%load_ext jupyter_ai_magics
%env OPENAI_API_BASE=https://xxx/v1
%env OPENAI_API_KEY=sk-xxx
  • 示例
1
2
%%ai chatgpt -f code
解决汉诺塔问题的函数

安装 rstudio

1
2
mkdir -p ~/app/rstudio && cd ~/app/rstudio && nano docker-compose.yml
sudo docker-compose up -d && sudo docker-compose logs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 版本

1
2
3
4
5
6
7
8
9
10
11
12
13
# 容器内
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 进入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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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

1
2
mkdir -p ~/app/notebook && cd ~/app/notebook && nano docker-compose.yml
sudo docker-compose up -d && sudo docker-compose logs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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='***'
1
2
3
conda init
source activate
conda config --add envs_dirs /home/jovyan/upload/envs
1
2
3
4
proxy_connect_timeout   600s;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_buffering off;

【记录】安装生信的代码编写环境
https://hexo.limour.top/-ji-lu--an-zhuang-sheng-xin-de-dai-ma-bian-xie-huan-jing
Author
Limour
Posted on
July 9, 2023
Updated on
January 20, 2024
Licensed under