生信人

找回密码
立即注册
搜索
热搜: 活动 交友 discuz
发新帖

0

收听

12

听众

278

主题
发表于 2022-7-6 22:50:18 | 查看: 671| 回复: 0
本帖最后由 生信喵 于 2022-7-7 10:36 编辑

        R 语言已经广泛的应用与生物信息分析中,包括 RNAseq,单细胞,生物统计,绘图等都要用到 R 语言。R 语言是生物信息分析平台重要的组成部分。本章节中我们将在服务器中配置完整的 R 语言分析环境。
一、安装 R 软件
        默认的 CentOS 源中是没有 R 软件的,需要安装 epel 源,我们之前已经安装了,R 软件在里面的名字为R.x86_64,如果不知道这个名字,可以使用yum search进行搜索。由于yum search不能使用正则表达式进行限制范围,会将所有包含 R 字符的结果都列出来,这里我们利用一个技巧。
  1. (base) [root@mgt ~]# yum search R | grep "^R"
  2. R.x86_64 : A language for data analysis and graphics
  3. R-4.1.1.x86_64 : GNU R statistical computation and graphics system
  4. R-RInside.x86_64 : C++ Classes to Embed R in C++ (and C) Applications
  5. R-RInside-devel.x86_64 : RInside Development Files
  6. R-RInside-examples.x86_64 : RInside Examples
  7. R-RUnit.noarch : R Unit test framework
  8. R-Rcpp.x86_64 : Seamless R and C++ Integration
  9. R-Rcpp-devel.x86_64 : Rcpp Development Files
  10. R-Rcpp-examples.x86_64 : Rcpp Examples
  11. R-core.x86_64 : The minimal R components necessary for a functional runtime
  12. R-core-devel.x86_64 : Core files for development of R packages (no Java)
  13. R-devel.x86_64 : Full R development environment metapackage
  14. R-highlight.x86_64 : R Syntax Highlighter
  15. R-inline.noarch : Functions to Inline C, C++, Fortran Function Calls from R
  16. R-java.x86_64 : R with Fedora provided Java Runtime Environment
  17. R-java-devel.x86_64 : Development package for use with Java enabled R components
  18. R-littler.x86_64 : littler: R at the Command-Line via 'r'
  19. R-littler-examples.x86_64 : R-littler Examples
  20. R-qtl.x86_64 : Tools for analyzing QTL experiments
  21. R-rlecuyer.x86_64 : R interface to RNG with multiple streams
  22. R2spec.noarch : Python script to generate R spec file
  23. RBTools.noarch : Tools for use with ReviewBoard
  24. RabbIT.noarch : Proxy for a faster web
  25. RackTables.noarch : A data-center asset management system
  26. RdRand.x86_64 : Library for generating random numbers using the RdRand
  27. RdRand-devel.x86_64 : Development files for the RdRand
  28. ReviewBoard.noarch : Web-based code review tool
复制代码
       其中的 R.x86_64 就是要的结果,使用 yum info 可以查看 R 包的版本信息。
  1. #查看 R 版本
  2. yum info R.x86_64
复制代码
       但由于 R 软件更新较快,每半年就有一个较大的版本升级,且目前很多 R 包安装编译比较麻烦,这里我们推荐使用 bioconda 来安装 R 和相应的 R 包。
  1. #利用 bioconda 安装 R
  2. mamba install -y r-base
复制代码
       还可以编译安装R语言,之前介绍过
  1. #下载
  2. wget https://cloud.r-project.org/src/base/R-4/R-4.2.1.tar.gz
  3. tar -zxvf R-4.2.1.tar.gz
  4. cd R-4.2.1
  5. #检测配置
  6. ./configure
  7. #编译
  8. make
  9. make install
复制代码
  1. mv /usr/bin/R /usr/bin/R.bak #将系统3.6.0的R备份
  2. ln -s /share/Software/biosoft/R-4.2.1/bin/R /usr/bin/R #软连接新的4.2.1
  3. [root@mgt R-4.2.1]# ll /usr/bin/R
  4. lrwxrwxrwx 1 root root 37 Jul  6 16:49 /usr/bin/R -> /share/Software/biosoft/R-4.2.1/bin/R
复制代码
       还可以使用rstudio官网上的rpm安装(推荐)
  1. export R_VERSION=4.2.1
  2. curl -O https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
  3. sudo yum install R-${R_VERSION}-1-1.x86_64.rpm
  4. mv /usr/local/bin/R /usr/local/bin/R.bak
  5. mv /usr/local/bin/Rscript /usr/local/bin/Rscript.bak
  6. sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
  7. sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
复制代码

二、安装 Rstudio-server
        Rstudio 是 R 的集成开发环境,非常的好用,在服务器端安装 Rstudio-server 之后就可以通过浏览器访问 R,非常的方便。在配置 Rstudio-server 之前需要注意,首先需要安装 R 软件。另外使用免费版本的 rstudio-server 软件只能使用一个版本的 R 语言。且只能通过管理员安装和配置,个人用户无法配置 rstudio-server。
2.1 安装 rstudio-server
        https://www.rstudio.com/products/rstudio/download-server/
  1. #安装rstudio-server
  2. wget https://download2.rstudio.org/server/centos8/x86_64/rstudio-server-rhel-2021.09.2-382-x86_64.rpm
  3. yum install rstudio-server-rhel-2021.09.2-382-x86_64.rpm

  4. #检查是否安装成功
  5. rstudio-server verify-installation
  6. rstudio-server status
复制代码
       默认 rstudio-server 使用的是/usr/bin/下的 R,现在我要切换默认使用 bioconda 的 R。需要
        修改 rstudio-server 的配置文件。或者将 R 软连接到/usr/bin 下。
  1. #修改rstudio-server配置,配置R版本的地址,前面我们软链接了,所有省去这一步
  2. # vim /etc/rstudio/rserver.conf
  3. # Server Configuration File
  4. #rsession-which-r=/usr/local/bin/R
复制代码
2.2 开启 8787 端口
       CentOS7 系统采用新的防火墙策略,因此,安装完成 Rstudio 之后,还不能通过浏览器访问,需要进行防火墙设置才行,ubuntu 系统可以直接访问,下面的设置非常重要。
  1. systemctl start rstudio-server.service
  2. systemctl enable rstudio-server.service
  3. systemctl status rstudio-server
  4. firewall-cmd --permanent --add-port=8787/tcp
  5. firewall-cmd --permanent --add-port=8787/udp
  6. firewall-cmd --reload
复制代码
      完成以上步骤,rstudio-server 就配置完成了。利用浏览器输入 ip 地址:8787 就可以愉快的访问了。后面需要安装 R 包,都可以通过 bioconda 进行安装了,非常的方便。

2.3 配置 R 包
       可以在 R 中安装 R 包,我们需要注意下载的位置,安装到库的位置,大家都可以做下了解,以防文件混乱
       也可以使用 bioconda 进行配置,需要注意 R 包的名字在 bioconda中以 r-为前缀,Bioconductor 包的名字为 bioconductor-前缀。
  1. .libPaths(c("/opt/R/4.2.1/lib/R/library"))#查看R包库位置
  2. "/home/xhs/R/x86_64-pc-linux-gnu-library/4.1" "/opt/R/4.2.1/lib/R/library"
  3. #上面有两个,我们想安装到第二个路径中
  4. #先在命令行给到目录修改权限、doc为包的介绍html存放目录也需要权限
  5. sudo chmod -R 777 /opt/R/4.2.1/lib/R/library
  6. sudo chmod -R 777 /opt/R/4.2.1/lib/R/doc
  7. #/home/xhs/Rpack/download创建,用于存放下载的R包
  8. R中安装命令
  9. install.packages('ggplot2',lib = "/opt/R/4.2.1/lib/R/library",destdir = '/home/xhs/Rpack/download')
复制代码

您需要登录后才可以回帖 登录 | 立即注册

QQ|Archiver|手机版|小黑屋|生信人

GMT+8, 2024-4-30 03:12 , Processed in 0.033424 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表