Linux与R一些错误总结

1、cannot verify <mydomainname> certificate, issued by ‘/C=US/O=Let’s Encrypt/CN=R3’:

解决1:wget --no-check-certificate <website> //再运行一遍

解决2:sudo yum install -y ca-certificates  //之后再运行wget命令下载

也可参考https://www.openssl.org/blog/blog/2021/09/13/LetsEncryptRootCertExpire/

 

2、Archive:  fastqc_v0.11.9.zip  //解压zip文件式出现错误

解压zip文件出错一般有两种情况:

1.文件未完全下载(可在windows系统上试试能够能解压文件)

2.下载下来的文件并不是.zip格式

使用MD5校验:

md5sum fastqc_v0.11.9.zip
output: ee7901b681bb2762d75d5a56c7ec6958  fastqc_v0.11.9.zip

接下来,尝试文件类型:

file fastqc_v0.11.9.zip
output: fastqc_v0.11.9.zip: Zip archive data, at least v2.0 to extract

如果这两个输出结果不完全一样,可能是zip文件损坏。

对于文件损坏的情况,解决方法:

  1. 使用 curl -L 下载地址 > 自定义文件名.zip 命令进行下载
  2. 在下载地址的后面加上 ?raw=true

若文件没有损坏:可以安装使用jar、7z命令解压尝试。

 

3、wget下载速度奇慢

wget相对于浏览器来说,速度会比较偏慢,特别是国外的网站。

mwget是一个多线程下载应用,可以明显提高下载速度。

mwget安装步骤如下:

#!/bin/bash
wget http://jaist.dl.sourceforge.net/project/kmphpfm/mwget/0.1/mwget_0.1.0.orig.tar.bz2
yum install bzip2 gcc-c++ openssl-devel intltool -y #安装一个c++编译器
bzip2 -d mwget_0.1.0.orig.tar.bz2
tar -xvf mwget_0.1.0.orig.tar 
cd mwget_0.1.0.orig
./configure   #一般用来生成 Makefile,为下一步的编译做准备,你可以通过在 configure 后加上参数来对安装进行控制,比如代码:./configure –prefix=/usr 意思是将该软件安装在/usr下面
make       #编译,大多数的源代码包都需经过这一步进行编译
make install  #开始安装
#一般都需要在root权限下编译安装

类似的也有:CentOS7更换yum安装源

若安装mwget出现问题,可参考:mwget安装常见问题

mwget源码安装

安装系统需要的包就行,sudo yum install openssl-devel.x86_64

 

4、批量解压zip文件时报错

在尝试使用单个zip命令解压缩整个 zip 目录,可能会出现以上报错

*符号必须被转义,因此,需要添加转义符

unzip \*.zip

 你也可以参考文件名不匹配 寻找更多解决方法。

 

5、ImportError: /lib64/libc.so.6: version `GLIBC_2.25' 问题解决

安装OrthoFinder 后,打印帮助文件时报错如下

载入OrthoFinder时提示Glibc版本过低,需要升级到指定版本。

升级glibc版本前需要做好gcc,make,bison的升级。

gcc可以实现Linux上的多版本安装,高版本的gcc安装见后文。

# 安装gcc-4.8
sudo yum install gcc-4.8
# 设置gcc-4.8的优先级
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc 40
# 设置gcc-8.2的优先级 //笔者新版gcc-8.2安装至/usr/local/bin #此路径根据实际情况更改,不可覆盖/usr/bin/gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/gcc 50 #一般需要将新版本gcc安装到其他目录,在这一步写出即可
# 修改系统中的默认gcc版本
sudo update-alternatives --config gcc

说明: 执行sudo update-alternatives --config gcc之后,就会跳出选项,输入gcc版本对应的数字,就会选择对应的gcc版本作为默认版本,如下图。

#删除多余版本时我们可以使用 --remove加以删除
update-alternatives –remove java /usr/lib/jvm/jre1.6.0_20/bin/java

extra knowledge

上述update-alternatives的用于修改系统中命令的实际执行程序.

--install <链接> <名称> <路径> <优先级> 在系统中加入一组候选项

<链接>: /usr/bin/gcc 为系统中某命令的具体路径,本文中指的就是在终端中执行gcc命令,会调用/usr/bin/gcc.

<名称>: gcc 为在终端中执行的具体命令,本文中指gcc

<路径>: /usr/bin/gcc-4.8和/usr/bin/gcc-5 为在终端中输入命令后,具体的执行程序的路径.本文中指在终端中输入gcc,具体调用的程序路径

<优先级>: 40和50,是一个整数,在自动模式下,这个数字越高的选项,其优先级也就越高。

--config <名称> 列出 <名称> 替换组中的可选项,并就使用其中哪一个,征询用户的意见。

<名称>: 即上面说的终端中的具体命令, gcc

#首先要做好gcc,make,bison的更新
#尽量不要随意更新glibc,更新出错易导致系统崩溃。
#update to **gcc 8.2.0 :** 
$ gcc -v
$ yum -y install wget bzip2 gcc gcc-c++ glibc-headers
download package :https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc 
or
$ wget -c -P /software/ https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz

$ cd /software/
$ tar -zxvf gcc-8.2.0.tar.gz
$ cd gcc-8.2.0
$ ./contrib/download_prerequisites   
result:
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: OK
isl-0.18.tar.bz2: OK
All prerequisites downloaded successfully.
#如果上述这一步卡住,无反应,可以考虑手动下载依赖包到GCC源码根目录。如下:
wget http://ftp.gnu.org/pub/gnu/gmp/gmp-6.1.0.tar.bz2
wget http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.4.tar.bz2
wget http://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2

#再次执行:
./contrib/download_prerequisites --no-verify

$ mkdir build
$ cd bulid
$ ../configure --prefix=/usr/local/gcc-8.2.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib

$ make 
My system execute make command at least 3 hours, please waiting it complete.

then: 
$ make install

$ echo -e '\nexport PATH=/usr/local/gcc-8.2.0/bin:$PATH\n' >> /etc/profile.d/gcc.sh && source /etc/profile.d/gcc.sh
$ ln -sv /usr/local/gcc-8.2.0/include/ /usr/include/gcc
$  ldconfig -v    

$ ldconfig -p |grep gcc
result: 
libgcc_s.so.1 (libc6,x86-64) => /lib64/libgcc_s.so.1
##check version 
$  gcc -v 
------------------------------------
**make 4.2.1:**
First download make 4.2.1 from https://ftp.gnu.org/gnu/make/
$ make -v 
$ tar -zxvf make-4.2.1.tar.gz
$ cd make-4.2.1
$ mkdir build
$ cd build
$ ../configure --prefix=/usr
$ sh build.sh
$ make install
check result 
$make -v
----------------------------------------
**bison 3.0.4**
$ bison -V
if not found result ,need install:
$ yum install -y bison
--------------------------------------------------------
all complete , you can install glibc-2.28

download glibc-2.28 from http://ftp.gnu.org/gnu/glibc. 
put it into /software

You can adopt the following steps:

$ tar -xf glibc-2.28.tar.gz
$ cd glibc-2.28
$ mkdir build
$ cd build
$ ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

$ make
$ make install 
$ ls -l /lib64/libc.so.6

Last, check version : 
$ strings /lib64/libc.so.6 | grep GLIBC
.....
GLIBC_2.26
GLIBC_2.27
GLIBC_2.28
GLIBC_PRIVATE

It's completed .

Other : 
bootstarp Directus , maybe get error: 
Import Error: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found, you reed update CXXABI : 

$ strings /usr/lib64/libstdc++.so.6 | grep 'CXXABI'

download:[ libstdc++.so.6.0](https://www.02405.com/uploads/soft/201124/1-2011241A414.zip)
put it into /usr/lib64 

$  cd /usr/lib64
$ rm -rf libstdc++.so.6
$ ln -s libstdc++.so.6.0.22 libstdc++.so.6

注:解压gmp-6.1.0.tar.bz2这个文件时,可能会报错(未提前安装bzip2),如下:

因此需要安装 bzip2 解压。

yum install bzip2

如果还不行,可以考虑直接把 .bz2 的压缩包在 windows 上解压的目录拷贝到 CentOS GCC 源码根目录下解决。

再次执行:
./contrib/download_prerequisites --no-verify

运行成功,如下:
All prerequisites downloaded successfully.

编译安装glibc时报错

Reference

  1. ImportError: /lib64/libc.so.6: version `GLIBC_2.17' 问题解决
  2. 更新 GLIBC_2.17 到更高版本
  3. glibc的升级以及相关错误解决
  4. ./contrib/download_prerequisites没有反应
  5. 如何设置多个版本gcc
  6. Linux如何替换低版本gcc
  7. 使用update-alternatives命令进行版本的切换
  8. glibc安装完全版

 

 

6、python查看库是否安装

如上图 python -c "import moudle"

即可查看相关模块是否安装[1]

之后可以使用pip 命令安装 -i加上国内镜像加快下载速度

pip install -i https://mirrors.cloud.tencent.com/pypi/simple numpy

注:其他国内镜像源:

源名 源地址
腾讯源 https://mirrors.cloud.tencent.com/pypi/simple
阿里源 http://mirrors.aliyun.com/pypi/simple/
豆瓣源 http://pypi.douban.com/simple/
清华源 https://pypi.tuna.tsinghua.edu.cn/simple/

 

 或者通过脚本自动查看

'''
Author: your name
Date: 2021-03-31 16:58:02
LastEditTime: 2021-03-31 18:02:00
LastEditors: your name
Description: In User Settings Edit
FilePath: \Eddy_Compare_data\检测第三方库是否存在_如果不存在则导入库.py
在导入第三方库的时候,
'''


import os 
libs = ['numpy']  #罗列需要使用的库名称,避免因为没有第三方库报错

url = r'https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/'  #清华镜像网站
try:
    import numpy as np

    print('Input library successful')
except ModuleNotFoundError:
	print('Failed SomeHow')
	for lib in libs:
		print("Start install {0}".format(lib))
		os.system('pip install %s -i %s'%(lib,url))
		print('{0} install successful'.format(lib))
	print('All install successful ')
	import numpy as np

for i in np.arange(10):
	print(i)

 

 

Rerfence:

  1. Python 安装和依赖管理

 

 

7、 error while loading shared libraries: libbz2.so.1.0

当时是安装了R包sleuth,安装完后出现了上图报错

发现libbz2 本来应该是sleuth依赖包 bzip2 安装时自动装到 anaconda 文件夹下 lib 里的动态库,老版本的 anaconda 由于下载源不同,导致了 libbz2 的缺失:

参考[1]时发现可以有以下解决方法,不过当时问题没有得到解决

解决方法[1]:

  1. 更新 anaconda,我之前用的是 3.3.2,直接更新到最新版,完美运行。
  2. conda config --remove channels 'bzip2的下载源',删除掉它
  3. 修改~/.condarc文件提高conda-forge的优先级,也就是把conda-forge 放在channels 列表的第一位

之后在/usr/lib64/文件夹下面找了找,看到了类似的文件,同样在lib文件下,名称类似,推测起着相同的作用

不过因为没有root权限,无法直接建立软链接,因此选择cp 复制

不过又发现了新的报错“undefined symbol: PC”

推测是在显示的“ /home/user/…/…/”路径下,libreadline.so.6文件出现了问题

使用locate libreadline.so.6 发现查看该文件出现的位置

采取前文步骤,试试cp复制后效果

问题解决。

好吧,发现重启之后又出现了类似问题,不想再修改了,因此选择用本机的R环境

安装sleuth[2]并进行后续差异基因分析

步骤如下:

#R包sleuth安装
source("http://bioconductor.org/biocLite.R")
biocLite("rhdf5")
install.packages("devtools")
devtools::install_github("pachterlab/sleuth")
#if error try next#

#基本安装框架
if (!require("BiocManager", quiet = TRUE))
  install.packages("BiocManager")

BiocManager::install("rhdf5")

if (!require("BiocManager", quietly = TRUE))
  install.packages("BiocManager")

BiocManager::install(version = "3.14")
BiocManager::install("devtools")

devtools::install_github("pachterlab/sleuth")
#基本安装框架

 之后就可以library (sleuth) 愉快的进行后续分析了。

 

Reference:

  1. error while loading shared libraries
  2. download r-sleuth

 

8、Makefile:148: recipe for target 'R.bin' failed

仔细检查,build的文件已经生成了,所以执行make clean 清除上一次生成的可执行文件,再次执行make命令,ok搞定了

注意:make报错的原因有很多种,make clean只是其中一种,如果make clean后,执行命令还不成功的话,就要考虑是否是编码空格等导致的问题

 

9、单细胞拟时序分析monocle软件error

1.第一个报错是在运行orderCells函数时,Error in if (class(projection) != "matrix") projection <- as.matrix(projection) :the condition has length > 1,解决办法:R退回<4.2版本即可,必应搜索也有修改函数的其他解决办法,可以自行尝试;

2.第二个报错是在reduceDimension函数运行,方法选择为DDRTree时会报错,具体错误记不清了,解决办法就是:把DDRTree这个包退回到0.1.4版本!具体版本可以去cran下载。

笔者在终端使用R环境时,常常因为没有root权限时而欲罢不能,且因为某些包只支持特定版本的R,非root权限下配置好服务器上的多版本R就成为了必需手段。除配置一个主要的R环境外,其余版本R建议在conda环境下配置,避免接踵而来的冲突问题。

R basic
 R-4.2.0.tar.gz ##下载R安装包
tar -xvf R-4.2.0.tar.gz ##解压
cd R-4.2.0 ##进入解压好的目录
./configure --prefix=/data5/tan/zengchuanj/Software/R-4.2.0 ##编译和安装
make  ##执行完后观察出现的信息,若出现报错则不需执行make install
make install ##完成安装

bzip2-latest.tar.gz ##下载bzip2
tar -xvf bzip2-latest.tar.gz  ##解压bzip2
cd bzip2-latest  ##进入解压好的bzip2路径
./configure --prefix=/data5/tan/zengchuanj/Software/bzip2 ##编译和安装
make
make install

pcre-8.41.zip  ##下载pcre
unzip -xvf pcre-8.41.zip ##解压pcre
cd pcre-8.41  ##进入解压好的pcre路径
./configure --prefix=/data5/tan/zengchuanj/Software/pcre ##编译和安装
make
make install

xz-5.2.5.tar.gz ##下载xz
tar -xvf xz-5.2.5.tar.gz ##解压xz
cd xz-5.2.5 ##进入解压好的xz路径
./configure --prefix=/data5/tan/zengchuanj/Software/xz ##编译和安装
make
make install

zlib-1.2.11.tar.gz ##下载zlib
tar -xvf zlib-1.2.11.tar.gz  ##解压zlib
cd zlib-1.2.11  ##进入解压好的zlib路径
./configure --prefix=/data5/tan/zengchuanj/Software/zlib  ##编译和安装
make
make install

##安装R包时报错不支持https,则需先安装openssl;再安装curl
openssl-1.1.1j.tar.gz ##下载openssl
tar -xvf openssl-1.1.1j.tar.gz ##解压openssl
cd openssl-1.1.1j ##进入解压好的openssl路径
./configure --prefix=/data5/tan/zengchuanj/Software/openssl ##编译和安装
make
make install 

##下载安装curl
cd curl-7.75.0
./configure --prefix=/data5/tan/zengchuanj/Software/curl --with-ssl=/data5/tan/zengchuanj/Software/openssl
make
make install
###特别注意:安装好curl后,需将curl加入到环境变量中,否则后面仍然会报错不支持https
export PATH="/data5/tan/zengchuanj/Software/curl:$PATH"
export LD_LIBRARY_PATH=/data5/tan/zengchuanj/Software/curl/lib:$LD_LIBRARY_PATH
export CFLAGS="-fPIC -I/data5/tan/zengchuanj/Software/curl/include"
export LDFLAGS="-fPIC -L/data5/tan/zengchuanj/Software/curl/lib"
export PATH=$PATH:$JAVA_HOME/bin:/data5/tan/zengchuanj/Softerware/curl/bin
export PATH="/data5/tan/zengchuanj/Software/curl/bin:$PATH"

此外配置好~/目录下的.Renviron和.Rprofile的相关信息,就基本完成了[1]

conda配置不同版本R的方法比较简单,这里就不赘述了。

switch_R.sh
#!/bin/bash
# switch R version
case $1 in
1)
export PATH="/usr/bin/Rscript:$PATH"
export PATH="/usr/bin/R:$PATH"
export R_HOME="/data5/tan/zengchuanj/pipeline/R_exercise"
;;
2)
export PATH="/data5/tan/zengchuanj/Software/R-4.2.0/bin:$PATH"
export R_HOME="/data5/tan/zengchuanj/pipeline/R_exercise"
echo R_LIBS_USER="/data5/tan/zengchuanj/Software/R-4.2.0/R_Packages" > ~/.Renviron
;;
3)
export PATH="/data5/tan/zengchuanj/miniconda3/envs/R4/envs/r1/bin/R:$PATH"
export PATH="/data5/tan/zengchuanj/miniconda3/envs/R4/envs/r1/bin/Rscript:$PATH"
export R_HOME="/data5/tan/zengchuanj/pipeline/R_exercise"
echo R_LIBS_USER="/data5/tan/zengchuanj/miniconda3/envs/R4/envs/r1/lib/R/library" > ~/.Renviron
;;
*)
echo "Invalid R version"
exit 1
;;
esac

 

大功告成!

Ref:

  1. 非root权限的情况下在linux服务器中安装R

 

10、CellChat ERROR

10.1 Error in unit(height, "cm") : 'x' and 'units' must have length > 0

Calls: netAnalysis_signalingRole_network -> Heatmap -> unit

#报错代码为
pdf(paste(output,"/",prefix,"/","Network_center_weight.pdf",sep = ""),width = width, height = height)
p <- netAnalysis_signalingRole_network(cellchat,signaling = pathways.show, font.size = 10,height=height,width=width)
dev.off()
这个错误表示在调用unit()函数转换单位时,参数x的长度为0导致错误。

unit()函数的使用格式是:

```r
unit(x, units)
```

这里:
- x: 需要转换单位的数值向量  
- units:目标的单位

根据错误信息,在netAnalysis_signalingRole_network函数中调用Heatmap时,传给unit()函数的height参数长度为0。

常见原因包括:

1. height参数在上游被错误设置为长度为0的向量
2. height参数在传递中丢失,变成了空向量
3. Heatmap内部逻辑错误,导致height被错误设置为空
4. pdf画布展开时如果已经设置了height与width,画图函数如果仍然设置相关内容,就可能引起此类报错

解决方法:

1. 打印height参数,确认其长度是否为0

2. 测试上游函数,确保正确传递height参数,如画图函数删除设置的width和height

3. 检查Heatmap内部逻辑,找到导致错误的位置

4. 确认visualization函数需要的height格式

5. 传入长度大于0的height参数

主要是需要跟踪参数传递,找到导致向量长度错误的位置,传入正确长度的height参数,才能解决该问题。

 

10.2 Error in UseMethod("grid.draw") :

no applicable method for 'grid.draw' applied to an object of class "list"

Calls: ggsave -> grid.draw

Execution halted

这个错误是因为试图将一个列表(list)对象传递给 ggsave 来保存图形,但是 ggsave 中的 grid.draw 函数不知道如何处理列表对象。

ggsave 的用法是:

输入一个 ggplot 对象
转换为 grob 对象
用 grid.draw 绘制 grob 对象
保存绘制结果
所以这里错误的原因是你传入的不是一个 ggplot 对象,而是一个列表,grid.draw 不知道如何处理列表并绘制图形。

解决方法是:

检查你传入 ggsave 的对象,需要是一个 ggplot 图形对象
打印出对象来检查它的类是否为 "ggplot"
如果是列表对象,需要先转换为 ggplot 对象
可以使用 ggplot2::last_plot() 来获取最后绘制的图形
将 last_plot() 传入 ggsave 来保存图形
也可以用其他函数将列表转换为 ggplot 对象
所以主要是需要确保 ggsave 接收到一个 ggplot 对象,而不是其他类型的对象,它才能正常保存图形。
#报错源码
cellchat <- aggregateNet(cellchat)
# 计算每种细胞各有多少个
groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1,2), xpd = TRUE)
p <- netVisual_circle(cellchat@net$count, vertex.weight = groupSize, weight.scale = T,
                 label.edge = F, title.name = "Number of interactions")
p <- netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T,
                 label.edge = F, title.name = "Interaction weights/strength")
ggsave(paste(output,"/",prefix,"/","Cells_count.summary.plot.pdf",sep = ""), 
       plot = p, width = width, height = height)
cellchat <- aggregateNet(cellchat)
# 计算每种细胞各有多少个
groupSize <- as.numeric(table(cellchat@idents))
par(mfrow = c(1,2), xpd = TRUE)
p <- replayPlot(netVisual_circle(cellchat@net$count, vertex.weight = groupSize, weight.scale = T,
                 label.edge = F, title.name = "Number of interactions"))
p <- replayPlot(netVisual_circle(cellchat@net$weight, vertex.weight = groupSize, weight.scale = T,
                 label.edge = F, title.name = "Interaction weights/strength"))
ggsave(paste(output,"/",prefix,"/","Cells_count.summary.plot.pdf",sep = ""), 
       plot = p, width = width, height = height)

p <- replayPlot(netVisual_aggregate(cellchat, signaling = pathways.show, 
                                    vertex.receiver = vertex.receiver))
ggsave(paste(output,"/",prefix,"/","signaling_pathway.Hierarchy.plot.pdf",sep = ""), plot = p, width = width, height = height)

# 网络图(circle plot)
par(mfrow = c(1,1))
p <- replayPlot(netVisual_aggregate(cellchat, signaling = pathways.show, 
                                    layout = 'circle'))
ggsave(paste(output,"/",prefix,"/","signaling_pathway.circle.plot.pdf",sep = ""), plot = p, width = width, height = height)

# 和弦图(chord diagram)
par(mfrow = c(1,1))
p <- replayPlot(netVisual_aggregate(cellchat, signaling = pathways.show, 
                                    layout = 'chord'))
ggsave(paste(output,"/",prefix,"/","signaling_pathway.chord.diagram.pdf",sep = ""), plot = p, width = width, height = height)
explanation
 在R中,你可以使用`recordedplot`对象中的数据来创建一个ggplot对象。以下是一个示例:
首先,创建一个`recordedplot`对象并绘制一个简单的散点图:

```R
library(ggplot2)

# 创建一个 recordedplot 对象
recorded_plot <- recordPlot({
  plot(mpg ~ hp, data = mtcars, pch = 19)
})
```

现在,你可以使用以下步骤将`recordedplot`对象转换为ggplot对象:
1. 使用`replayPlot()`函数从`recordedplot`对象中获取绘图数据:

```R
replayed_plot <- replayPlot(recorded_plot)
```

2. `replayPlot()`函数将返回一个`ggplot`对象,其中包含了与原始绘图相同的数据和图形参数。你可以对其进行进一步的自定义和修改。
例如,你可以在ggplot对象上添加其他图层或修改标签:

```R
replayed_plot +
  geom_smooth(method = "lm") +
  labs(
    title = "Scatterplot of MPG vs. Horsepower",
    x = "Horsepower",
    y = "MPG"
  )
```

在这个示例中,我们使用`geom_smooth()`函数添加了一个线性拟合的平滑曲线,并使用`labs()`函数修改了标题和轴标签。
通过这种方式,你可以从`recordedplot`对象创建一个可进一步自定义和修改的ggplot对象。这样你可以充分利用ggplot2库提供的丰富功能来创建精美的数据可视化。

 

10.3 Error in slot(object, slot.name)$prob[, , signaling] :

incorrect number of dimensions

Calls: replayPlot -> netVisual_heatmap

Execution halted

这个错误表示在访问一个对象的slot时,维度数量不正确。
从错误信息来看,问题出在:
1. replayPlot函数调用了netVisual_heatmap。
2. netVisual_heatmap试图访问object对象的名为slot.name的slot。
3. 然后对其中的prob向量进行了三维索引。
4. 但prob向量的维度不为3,因此报错。

出现这个错误的主要原因通常有:
1. slot中的向量和代码中的假设不匹配,例如slot是一维向量,但代码索引为二维或三维。
2. slot的名称填错,提取了错误的slot。
3. 对象被更改为NULL,丢失了slot信息。
4. 对象的类定义改变,slot名称或内容变了。

解决方法是:

1. 打印slot对象,检查其维度和名称是否与代码操作匹配。
2. 查阅相关类定义的文档,确认slot的格式。
3. 逐步检查replayPlot和netVisual_heatmap的代码。 
4. 确保每步操作对象的类和slot都无误。
5. 在访问slot前检查对象是否为NULL。
主要还是需要打印并验证对象、slot的实际维度和名称,与代码逻辑相符,才能避免此类错误。
#报错源码
par(mfrow = c(1,1))
pdf(paste(output,"/",prefix,"/","signaling_pathway.Heatmap.pdf",sep = ""), width = width, height = height)
p <- replayPlot(netVisual_heatmap(cellchat, signaling = pathways.show,
                                  color.heatmap = 'Reds'))
dev.off()

因而此错误需要删除replayPlot函数的引用。

 

10.4 error: trying to get slot "short_flag" from an object of a basic class ("NULL") with no slots

#报错源码
option_list <- list(
make_option(c("-p","--pattern"),type="character",default = NULL,
              action= "store",help="choose two patterns c(outgoing,incoming)"
  )
)

patterns <- eval(parse(text = opt$pattern))            
这个错误意味着代码试图从一个没有slot的基类对象NULL中获取名为"short_flag"的slot。
在R中,S3和S4对象可以包含名为slot的属性,但基类如NULL、numeric、character等就无法包含slot。

这个错误通常在以下情况下出现:
1. 代码假定某个对象包含slots,但实际上该对象为NULL。
2. 对一个基类对象错误地使用了@或slot()语法。
3. 一个函数期待获得一个S3/S4对象,但传入的参数是NULL。
4. 包中的类定义发生变化,原有的slot不再存在。

为了解决这个问题,可以检查:
1. 对象在传入函数前是否被错误地设置为了NULL。
2. 是否传入了错误的对象类型。
3. slot的名称是否正确。
4. 文档中类定义是否发生改变。
5. 是否可以处理对象为NULL的情况。
主要就是需要明确对象的类型,一个基类对象是不含slot的,如果需要获得slot,必须首先确保传入的是正确的S3或S4对象,否则会导致这种错误。

 此处需要将default设置为一字符串,如default="c(2,2)"的字符串格式。

 

10.5 Error: $ operator not defined for this S4 class

Execution halted

explanation
这个错误表示在一个S4类对象上使用$运算符时发生错误,因为该类没有定义$方法。
在R中,S4对象采用面向对象的方法进行设计,使用类和方法定义对象属性和操作。
与S3对象不同,S4对象的属性访问需要通过特定的get/set方法,不能直接使用$符号。

这个错误通常在以下情况发生:
1. 代码直接在S4对象上使用$访问属性,但类没有定义相应的get方法。
2. 假定对象是S3类,但其实是S4类。
3. 更新包后类定义发生改变,原有的$访问方式失效。
4. 没有通过@语法或get/set方法访问对象的slot。

解决方法是:
1. 使用对象的get方法访问属性,不要使用$。
2. 检查对象是否为S4类型并使用@或get/set方法。
3. 查阅文档以了解类的定义。
4. 将对象作为S4对象处理,不要假定其为S3。
5. 如果类定义改变,需要更新相应的代码。
主要是需要区分S3和S4对象,并使用对应类定义的方法进行属性访问,不要对S4对象直接使用$运算符。

 ???

10.6 cellchat采用信号网络的流行学习与分类

此处采用pip install umap-learn即可解决

如若有以下报错:No such strategy for futures: ‘multiprocess’ 

This issue can be solved to switch to an argument do.parallel = FALSE in the netClustering function.

 

10.7 Cellchat包安装错误

Error: package or namespace load failed for ‘CellChat’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/data5/tan/zengchuanj/miniconda3/envs/r4.2.3/lib/R/library/00LOCK-CellChat-1.5.0/00new/CellChat/libs/CellChat.so': /data5/tan/zengchuanj/miniconda3/envs/r4.2.3/lib/R/library/00LOCK-CellChat-1.5.0/00new/CellChat/libs/CellChat.so: invalid ELF header Error: loading failed Execution halted ERROR: loading failed * removing ‘/data5/tan/zengchuanj/miniconda3/envs/r4.2.3/lib/R/library/CellChat’ Warning message: In install.packages("CellChat-1.5.0.tar.gz") : installation of package ‘CellChat-1.5.0.tar.gz’ had non-zero exit status zengchuanj@bbdkmust3-TS860M5:~$ Rscript -e "devtools::install_github("sqjin/CellChat")" Error in lapply(repo, github_remote, ref = ref, subdir = subdir, auth_token = auth_token, : object 'sqjin' not found Calls: <Anonymous> -> <Anonymous> -> lapply Execution halted

 

错误消息中提到了一个名为`CellChat.so`的共享对象(shared object),它似乎存在问题,导致加载失败。这种问题通常与二进制兼容性有关,可能是因为共享对象编译时与当前系统不兼容。

以下是一些可能的解决方法:
1. **重新编译包**:
   尝试重新编译`CellChat`包,确保系统和R版本兼容。首先,确保R版本是最新的,并且你已经安装了编译工具和依赖项。然后,从源代码重新安装`CellChat`包,而不是从二进制文件安装。你可以使用以下命令:
   ```R
   install.packages("CellChat", type = "source")
   ```
   这将从源代码编译并安装`CellChat`包。

2. **检查R版本**:
   确保你正在使用的R版本与`CellChat`包的要求兼容。检查`CellChat`包的文档或官方网站,以获取有关支持的R版本的信息。
3. **清理旧文件**:
   有时旧的二进制文件或缓存文件可能会导致问题。尝试删除旧的`CellChat`包和缓存文件,然后重新安装:
   ```R
   remove.packages("CellChat")
   ```
   然后再次尝试安装。
4. **联系包的维护者**:
   如果上述方法都无法解决问题,可能需要联系`CellChat`包的维护者或社区,以获取进一步的支持和建议。他们可能已经遇到过类似的问题并提供了解决方法。
请注意,如果你在使用特殊的环境或操作系统(如容器、虚拟环境等),可能需要额外的步骤来确保包的兼容性。在这种情况下,查看相关环境的文档或社区支持也是一个好主意。

这一错误暂时不知道如何解决,只得从本地打包了一个CellChat

 

11、conda中的R包安装error

Error:/bin/sh: 1: x86_64-conda-linux-gnu-cc: Permission denied
 /bin/sh: 1: x86_64-conda-linux-gnu-cc: Permission denied
/data5/tan/zengchuanj/miniconda3/envs/R4/envs/r4.1.2/lib/R/etc/Makeconf:170: recipe for target 'base64.o' failed
make: *** [base64.o] Error 126
ERROR: compilation failed for package ‘jsonlite’
* removing ‘/data5/tan/zengchuanj/miniconda3/envs/R4/envs/r4.1.2/lib/R/library/jsonlite’
ERROR: dependency ‘jsonlite’ is not available for package ‘argparse’
* removing ‘/data5/tan/zengchuanj/miniconda3/envs/R4/envs/r4.1.2/lib/R/library/argparse’

The downloaded source packages are in
        ‘/tmp/Rtmpaf7TjS/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning messages:
1: In install.packages("argparse") :
  installation of package ‘jsonlite’ had non-zero exit status
2: In install.packages("argparse") :
  installation of package ‘argparse’ had non-zero exit status
(base) zengchuanj@bbdkmust3-TS860M5:~$ x86_64-conda-linux-gnu-cc
-bash: /data/anaconda3/bin/x86_64-conda-linux-gnu-cc: Permission denied
(base) zengchuanj@bbdkmust3-TS860M5:~$ conda env list
# conda environments:
#
                         /data5/tan/zengchuanj/miniconda3
base                  *  /data5/tan/zengchuanj/miniconda3/envs/R4
r4.1.2                   /data5/tan/zengchuanj/miniconda3/envs/R4/envs/r4.1.2
rstudio                  /data5/tan/zengchuanj/miniconda3/envs/R4/envs/rstudio

(base) zengchuanj@bbdkmust3-TS860M5:~$ cat .R/Makevars
#F77 = /usr/bin/gfortran
#FC = $F77
#FLIBS = -L/usr/bin/gfortran
#CC=/data5/tan/zecngahunj/miniconda3/envs/R4/envs/r4.1.2/bin/x86_64-conda-linux-gnu-cc
#CXX=/data5/tan/zengchuanj/miniconda3/envs/R4/envs/r4.1.2/bin/x86_64-conda-linux-gnu-c++

在给conda中的R环境安装R包时出现上述报错,在Makevars配置好C语言编译器后才能使用,但conda虚拟环境中的R编译器应为自动指定的

Solve ways
 conda install -c anaconda gcc_linux-64
conda install -c anaconda gxx_linux-64
conda install -c anaconda gfortran_linux-64

此报错与/bin/sh: x86_64-conda_cos6-linux-gnu-c++: command not found类似
C++ compiler do not work
checking whether the C++ compiler works... no
configure: error: in `/tmp/Rtmp55Xpue/R.INSTALL40bf8a6bd489/BiocParallel':
configure: error: C++ compiler cannot create executables
See `config.log' for more details
ERROR: configuration failed for package ‘BiocParallel’
* removing ‘/data5/tan/zengchuanj/miniconda3/envs/R4/envs/rstudio/lib/R/library/BiocParallel’
ERROR: dependency ‘BiocParallel’ is not available for package ‘BiocNeighbors’
* removing ‘/data5/tan/zengchuanj/miniconda3/envs/R4/envs/rstudio/lib/R/library/BiocNeighbors’

 

问题解决!

 

warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
warning  libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
Solving environment: | warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE failed
LibMambaUnsatisfiableError: Encountered problems while solving:
- cannot install both pin-1-1 and pin-1-1
- package python-3.12.0-hab00c5b_0_cpython requires ncurses >=6.4,<7.0a0, but none of the providers can be installed
Could not solve for environment specs
The following packages are incompatible
├─ samtools 1.11 would require

│ └─ htslib >=1.11,<1.19.0a0 , which cannot be installed (as previously explained);

├─ samtools 1.12 would require

│ └─ htslib >=1.12,<1.19.0a0 , which cannot be installed (as previously explained);

├─ samtools 1.13 would require

│ └─ htslib >=1.13,<1.19.0a0 , which cannot be installed (as previously explained);

├─ samtools [1.14|1.15|1.15.1] would require

│ └─ htslib [>=1.14,<1.19.0a0 |>=1.15,<1.19.0a0 ], which cannot be installed (as previously explained);

├─ samtools [1.15.1|1.16.1] would require

│ └─ htslib >=1.16,<1.19.0a0 , which cannot be installed (as previously explained);

├─ samtools [1.16.1|1.17|1.18] would require

│ └─ htslib [>=1.17,<1.18.0a0 |>=1.17,<1.19.0a0 ], which cannot be installed (as previously explained);

├─ samtools [1.3|1.3.1|1.6] would require

│ └─ openssl >=3.1.0,<4.0a0 , which conflicts with any installable versions previously reported;

├─ samtools [1.3|1.3.1|1.6] would require

│ ├─ curl >=7.81.0,<8.0a0 , which cannot be installed (as previously explained);

│ └─ openssl >=1.1.0,<=1.1.1 , which conflicts with any installable versions previously reported;

├─ samtools [1.3|1.3.1|1.6] would require

│ └─ openssl >=1.1.1l,<1.1.2a , which conflicts with any installable versions previously reported;

├─ samtools 1.9, which cannot be installed (as previously explained);

└─ samtools 1.9, which cannot be installed (as previously explained).

Pins seem to be involved in the conflict. Currently pinned specs:

- python 3.12.* (labeled as 'pin-1')

这个警告信息来自conda的libmamba库,在解决环境的时候添加了一个空的依赖关系来处理SOLVER_RULE_UPDATE类型的问题。
在conda安装或更新包时,它需要解决一个复杂的优化问题来确定包的最佳版本组合。libmamba是conda的优化求解器。
SOLVER_RULE_UPDATE类型可能表示在更新某个包时,需要处理其依赖关系。为了让求解器能继续运行,libmamba添加了一个空依赖作为补丁解决方案。

 此Warnings来自于conda安装deeptools等依赖python的包时出现,推测可能是python版本不适配

 回退python版本至3.10.0,此Warning解除,且不报错。

 

 

12、pyscenic的安装及使用问题

12.1 pyscenic的安装问题

conda create -n pyscenic
conda activate pyscenic
conda install mamba -y
mamba install python=3.7 -y
mamba install numpy cytoolz scanpy -y
#也可只用conda安装
#安装 pyscenic 
pip install pyscenic 

当未配置好pip的相关镜像时,会出现如下报错

#设置pip镜像
pip config set global.index-url http://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn

over!

 

12.2 pyscenic的使用问题

ValueError: Intersection of gene_names and tf_names is empty.
 preparing dask client
parsing input
not shutting down client, client was created externally
finished
Traceback (most recent call last):
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/bin/pyscenic", line 8, in 
sys.exit(main())
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/pyscenic/cli/pyscenic.py", line 713, in main
args.func(args)
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/pyscenic/cli/pyscenic.py", line 111, in find_adjacencies_command
seed=args.seed,
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/arboreto/algo.py", line 41, in grnboost2
early_stop_window_length=early_stop_window_length, limit=limit, seed=seed, verbose=verbose)
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/arboreto/algo.py", line 115, in diy
expression_matrix, gene_names, tf_names = _prepare_input(expression_data, gene_names, tf_names)
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/arboreto/algo.py", line 229, in _prepare_input
raise ValueError('Intersection of gene_names and tf_names is empty.')
ValueError: Intersection of gene_names and tf_names is empty.

这个错误是在使用pyscenic的find_adjacencies命令时触发的,错误原因是:
gene_names和tf_names的交集为空。
在pyscenic的GRN推断过程中,gene_names表示所有基因的名称,tf_names表示transcription factor(转录因子)的名称。
它要求tf_names必须是gene_names的一个子集,也就是二者需要有交集,而不能完全不相交。
但是这里gene_names和tf_names提供的基因名完全没有重叠,所以报错了。
解决方法是:
确认tf_names是否正确,包含了想考虑的转录因子。
检查gene_names是否对应了表达式矩阵里的所有基因。
确保tf_names是gene_names的子集,二者有重叠的转录因子。
如果不能确保有重叠,可以设置tf_names为空,让pyscenic自动检测。
升级pyscenic到最新版本以防bug。
总之,需要保证使用的转录因子列表是表达矩阵中所有基因的子集,这样pyscenic才能正常运行。
ValueError: Intersection of gene_names and tf_names is empty.2
preparing dask client
parsing input
not shutting down client, client was created externally
finished
Traceback (most recent call last):
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/bin/pyscenic", line 8, in <module>
sys.exit(main())
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/pyscenic/cli/pyscenic.py", line 713, in main
args.func(args)
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/pyscenic/cli/pyscenic.py", line 111, in find_adjacencies_command
seed=args.seed,
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/arboreto/algo.py", line 41, in grnboost2
early_stop_window_length=early_stop_window_length, limit=limit, seed=seed, verbose=verbose)
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/arboreto/algo.py", line 115, in diy
expression_matrix, gene_names, tf_names = _prepare_input(expression_data, gene_names, tf_names)
File "/data5/tan/zengchuanj/miniconda3/envs/pyscenic/lib/python3.7/site-packages/arboreto/algo.py", line 229, in _prepare_input
raise ValueError('Intersection of gene_names and tf_names is empty.')
ValueError: Intersection of gene_names and tf_names is empty.

根据错误堆栈,在运行 pyscenic aucell 命令时,读取签名(signatures)文件导致了空数据框错误。
最常见的原因有:
1、传入的签名文件路径 (reg.csv) 不正确。
2、签名文件为空文件或格式不正确,无法解析。
3、签名文件有空格或特殊字符,需要加引号。
4、没有权限读取签名文件。
5、签名文件是基因列表,而不是实际的motif签名。

解决方法:
1、打印并确认签名文件路径正确。
2、检查签名文件,是否有正确的motif id 和序列等内容。
3、用 pandas 读取签名文件,确认可以解析且不为空。
4、为签名文件路径加引号,处理空格问题。
5、添加读文件权限或用 sudo 运行。
6、提供正确的基于motif的签名文件,而不是基因列表。
7、试试其他已知正常的签名文件。
总之,确认传入的签名文件是正确的文件路径,并包含正常的基于motif的签名。如果签名文件本身就为空,则需要重新生成。

pyscenic ctx \
adj.sample.tsv \
hg38__refseq-r80__10kb_up_and_down_tss.mc9nr.feather \
--annotations_fname motifs-v9-nr.hgnc-m0.001-o0.0.tbl \
--expression_mtx_fname sample1.loom \
--mode "dask_multiprocessing" \
--output reg.csv \
--num_workers 3 \
--mask_dropouts

 

13、hdWGCNA的使用

13.1 Error in MetacellsByGroups

(seurat_obj = seurat_obj, group.by = c("cell_type", :

Invalid reduction (pca). Reductions in Seurat object: harmony, umap

Execution halted

此错误应为调用 MetacellsByGroups() 之前,PCA 没有正确运行并保存到 Seurat 对象中。
在运行MetacellsByGroups() 之前,先进行如下处理:
#对每一种基因在所有细胞中的标准化
seurat_obj <- NormalizeData(seurat_obj, normalization.method = "LogNormalize", scale.factor = 10000)
# 鉴定表达高变基因(2000个),用于下游分析,如PCA主成分分析
seurat_obj <- FindVariableFeatures(seurat_obj, selection.method = "vst", nfeatures = 2000)
top10 <- head(VariableFeatures(seurat_obj), 10)
## 对每个细胞中所有基因进行缩放标准化,实现不同细胞间的可比性。
seurat_obj <- ScaleData(seurat_obj, features =  rownames(seurat_obj))
#回归去除线粒体表达百分比的影响。
#seurat_obj <- ScaleData(seurat_obj, vars.to.regress = "percent.mt")
#线性降维(PCA),默认用高变基因集,可通过features指定
seurat_obj <- RunPCA(seurat_obj, features = VariableFeatures(object = seurat_obj))

 

13.2 Error: None of the requested variables to regress are present in the object.

这个错误意味着在运行SCaleData()时,想要回归(regress out)的变量在Seurat对象中不存在。

需要检查的几个方面:
确保要回归的变量已经存储在Seurat对象的metadata中。
例如,如果要回归"percent.mito",需要确保这个变量作为一列存在于seurat_object@meta.data中。
如果变量存在,请确认它们被存储为数值/连续型变量,不是factor。ScaleData只能回归连续变量。
检查后发现seurat_obj数据中不包含percent.mt的信息

故而
seurat_obj[["percent.mt"]] <- PercentageFeatureSet(seurat_obj, pattern = "^MT-")#鼠源的选择^mt-
seurat_obj <- ScaleData(seurat_obj, vars.to.regress = "percent.mt")

 

13.3 Error in TestSoftPowers

Error in TestSoftPowers(seurat_obj, networkType = "signed") :

unused argument (networkType = "signed")

在调用Seurat的TestSoftPowers()函数时,传递了一个无效的参数networkType="signed"。
这个错误的主要原因是:
TestSoftPowers()函数本身不存在“networkType”这个参数。所以传递networkType="signed"会导致未使用的参数错误。
因而此处对TestSoftPowers源码做如下处理:

TestSoftPowers <- function (seurat_obj, powers = c(seq(1, 10, by = 1),
seq(12, 30, by = 2)), setDatExpr = TRUE, use_metacells = TRUE, group.by = NULL,
          group_name = NULL,networkType='signed')
{
  if (!("datExpr" %in% names(GetActiveWGCNA(seurat_obj))) |
      setDatExpr == TRUE) {
    seurat_obj <- SetDatExpr(seurat_obj, use_metacells = use_metacells,
                             group.by = group.by, group_name = group_name)
  }
  datExpr <- GetDatExpr(seurat_obj)
  powerTable = list(data = WGCNA::pickSoftThreshold(datExpr,
        powerVector = powers, verbose = 100,
        networkType = networkType,
          corFnc = "bicor")[[2]])
  seurat_obj <- SetPowerTable(seurat_obj, powerTable$data)
  seurat_obj
}

 

13.4 Error in if (!(group.by %in% colnames

(seurat_obj@meta.data))) { :

argument is of length zero

Calls: TestSoftPowers -> SetDatExpr

In addition: Warning message:

In SetDatExpr(seurat_obj, use_metacells = use_metacells, group.by = group.by, :

assay not specified, trying to use assay RNA

Execution halted

这个错误意味着在调用TestSoftPowers()函数时,传递的group.by参数存在问题。

需要检查几个方面:
- 确保group.by是一个向量,包含在Seurat对象metadata中存在的一个或多个分组变量。比如 c("cell_type", "batch")。
- 通过检查colnames(seurat_obj@meta.data)来验证这些分组变量是否存在于seurat对象中。
- 错误信息“argument is of length zero”意味着group.by为空。确保您传递了一个有内容的向量给group.by。
- “assay not specified” 的警告信息意味着默认使用RNA assay。请确保这个assay存在且是您要使用的。

Should:
- 向group.by传递一个存在于metadata中的分组变量向量。
- 检查group.by不为空。
- 验证默认的RNA assay存在且适合使用。
解决group.by相关问题后,TestSoftPowers()函数就可以正常使用了。

 

13.5 Error in RunHarmony.Seurat

(seurat_obj, group.by.vars = group.by.vars, :

argument 3 matches multiple formal arguments

Calls: ModuleEigengenes -> ComputeModuleEigengene -> <Anonymous>

Execution halted

在运行Seurat的RunHarmony函数时出现了这个错误,它表示传递的参数中的第3个参数与该函数定义中的多个正式参数相匹配。
具体的错误信息是:"参数3匹配多个正式参数"。这暗示传给RunHarmony的第3个参数,匹配了这个函数的2个或更多的正式参数名称。 

需要检查的几件事:
- 在调用RunHarmony时,请尽量通过参数名称而不是位置来传递参数,这可以避免歧义。
- 查看RunHarmony的文档,确认期待的参数是什么,确保您传递的第3个参数没有意外地匹配到多个正式参数。
- 尝试通过参数名称明确指定每个参数,这样可以消除歧义。
- 确认调用RunHarmony的是正确版本的Seurat包,不同版本可能会导致参数匹配问题。 
- 检查环境中是否同时加载了多个Seurat版本,产生冲突。
总之,把RunHarmony调用参数和函数文档进行比较,很可能可以发现第3个参数的歧义所在,并帮助解决这个问题。
# seurat_obj <- ModuleEigengenes(
#   seurat_obj,
#   group.by.vars="Sample"
# ) #时间较长
删除group.by.vars="Sample"的参数传递

 

14、R Packages error

14.1 Error: 载入了名字空间‘Matrix’ 1.6-0,但需要的是>= 1.6.1

Error:package or namespace load failed for ‘SeuratObject’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):

Matrix导入错误
Error: package or namespace load failed for ‘SeuratObject’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 载入了名字空间‘Matrix’ 1.6-0,但需要的是>= 1.6.1
 
> remove.packages("Matrix")
从‘D:/Bioinformat/R/R-4.2.3/library’中删除程序包
(因为没有指定‘lib’)
> sessionInfo()
R version 4.2.3 (2023-03-15 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8  LC_CTYPE=Chinese (Simplified)_China.utf8   
[3] LC_MONETARY=Chinese (Simplified)_China.utf8 LC_NUMERIC=C                               
[5] LC_TIME=Chinese (Simplified)_China.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sp_2.1-1

loaded via a namespace (and not attached):
Error in x[["Version"]] : subscript out of bounds
In addition: Warning message:
In FUN(X[[i]], ...) :
  程序包'Matrix'里要么没有DESCRIPTION这个文件,要么出了错

> install.packages("Matrix")
trying URL 'https://mirrors.sjtug.sjtu.edu.cn/cran/bin/windows/contrib/4.2/Matrix_1.6-2.zip'
Content type 'application/zip' length 4523207 bytes (4.3 MB)
downloaded 4.3 MB

 

14.2 libiconv的导入问题

这个错误表示加载tidyverse包时,其依赖的haven包无法正常加载,具体是haven包中的haven.so共享库出现了无法找到"libiconv"符号的问题。
libiconv是编码转换库,一般系统自带。这个错误通常是由于R环境缺少libiconv库导致的。
可以尝试以下方法解决:

1. 在R中安装libiconv库:
```r
install.packages("libiconv")
```
2. 确保系统已经安装了libiconv库和开发文件,在Ubuntu下可以用:
```
sudo apt-get install libiconv libiconv-dev
```
3. 设置LD_LIBRARY_PATH环境变量,将libiconv库路径加到其中,如:
```
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
```
4. 为R配置rpath,让其可以找到依赖的共享库,通常在~/.Rprofile中设置:
```
R_LD_LIBRARY_PATH=${R_HOME}/lib:${R_LD_LIBRARY_PATH}
```
5.或者安装tidyverse包。

检查haven的依赖并确保相关库文件可被找到,一般可以解决这个问题。

 

14.3 Error in validObject(object = value) : 

invalid class “Graph” object: superclass "mMatrix" not defined in the environment of the object's class

 此问题是出现在运行Seurat的FindMultiModalNeighbors函数时的报错,初步分析是由于Matrix包和SeuratObject包的版本与当前Seurat版本不适配的原因。

#将SeuratObject回退一个版本
install.packages("SeuratObject", repos = c("https://mojaveazure.r-universe.dev/bin/linux/jammy/4.3/", getOption("repos")))
#将Matrix包回退到1.6.1或1.6.2版本
remotes::install_version("Matrix", "1.6.1")

 

 

14.4 Error in irlba::irlba(L, nv = n, nu = 0, maxit = iters) :

function 'as_cholmod_sparse' not provided by package 'Matrix'

这一报错应当是由于Matrix版本过高导致,回退Matrix至1.6.1,但实际仍有相同报错,回退irlba,同样,故而选择重新配置Seurat包

#remove Matrix
remove.packages("Matrix")

#remove irlba
remove.packages("irlba")

#remove Seurat
remove.packages("Seurat")

#reinstall Seurat
remotes::install_version("Seurat", version = "4.3.0")
BiocManager::install('Seurat')

 

14.5 Error in FindClusters.Seurat(E35_1.doublet, resolution = 0.1) :

Provided graph.name not present in Seurat object

这条错误信息表示在调用FindClusters时,提供的graph.name在Seurat对象中不存在。
FindClusters需要一个预先计算的共表达网络图(graph)来进行聚类。这个网络图的名称应该通过graph.name参数提供。
但是这里在调用FindClusters时没有指定graph.name,所以报错说无法找到相应的图。
这条错误信息表示在调用FindClusters时,提供的graph.name在Seurat对象中不存在。
FindClusters需要一个预先计算的共表达网络图(graph)来进行聚类。这个网络图的名称应该通过graph.name参数提供。
但是这里在调用FindClusters时没有指定graph.name,所以报错说无法找到相应的图。

常见的解决办法有:
1. 显式指定graph.name参数:

```r
FindClusters(object, graph.name = "rna_snn", resolution = 0.1)
E35_1 <- FindNeighbors(E35_1, dims = 1:10)
```
这里"rna_snn"是默认构建的共表达网络图的名称。

2. 先运行SCTransform()和FindNeighbors()来构建图:

```r
object <- SCTransform(object) 
object <- FindNeighbors(object)
```
这样就会默认构建名为"rna_snn"的网络图。

3. 指定重新构建网络图:

```r
FindClusters(object, graph.build = TRUE, resolution = 0.1)
```
总之,需要确保在FindClusters之前构建或指定了共表达网络图,否则会因为无法找到相应的graph导致错误。

 

14.5 Error: missing binary operator before token "("

When I install R-package ‘ragg’,it return this error.

sessioninfo() below

这个错误信息是在尝试安装 R 包 `ragg` 时出现的,错误指出编译器遇到了语法问题,这通常是由于编译环境的配置不正确或者编译器的兼容性问题。

1. **编译器语法错误**:
   ```
   /usr/include/x86_64-linux-gnu/sys/cdefs.h:492:49: error: missing binary operator before token "("
   ```
   这个错误表明编译器在处理 `sys/cdefs.h` 头文件时遇到了语法问题。这可能是因为编译器的版本与代码期望的版本不兼容。

2. **编译环境问题**:
   ```
   ERROR: configuration failed for package ‘ragg’
   ```
   这个错误表明在配置 `ragg` 包时失败了。`ragg` 是一个用于绘制图形的 R 包,它可能需要特定的依赖库和编译器版本。

### 解决方案:

1. **更新编译器**:
   确保编译器(如 gcc)的版本适配与否???通过运行 `gcc --version` 来检查当前版本,并使用包管理器(如 `apt` 或 `yum`)来更新它。
   Configuration failed to find one of freetype2 libpng libtiff-4. Try installing:
   * deb: libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev (Debian, Ubuntu, etc)
   * rpm: freetype-devel libpng-devel libtiff-devel libjpeg-turbo-devel (Fedora, CentOS, RHEL)
   * csw: libfreetype_dev libpng16_dev libtiff_dev libjpeg_dev (Solaris)
   一般需要root权限,操作不了啊!!!

2. **检查依赖库**:
   确保所有必要的依赖库都已安装,并且是最新版本。对于 `ragg` 包,可能需要安装 libpng-dev 和 libjpeg-dev。
   依赖库都安装好后,建议从师兄师姐的R-lib里cp一个过来,基本没问题了奥。

3. **使用 Conda 管理 R 环境**:
   当前我使用的是conda环境,尝试使用 Conda 来安装 R 和 R 包。

 暂时还是不能根本解决该问题,待续......

 

15、CellPhoneDB的使用[1,2]

  CellPhoneDB作为处理细胞通讯分析的基本软件,是公开的人工校正的,储存受体、配体以及两种相互作用的数据库。

CellPhoneDB 是目前使用最广泛的细胞通讯分析软件,CellPhoneDB的配体-受体数据库集成于UniProt、Ensembl、PDB、IUPHAR等,共存储978种蛋白质:其中501种是分泌蛋白,而585种是膜蛋白,这些蛋白质参与1,396种相互作用。CellPhoneDB数据库还考虑了配体和受体的亚基结构,准确地表示了异聚体复合物,有466个是异聚体,对于准确研究多亚基复合物介导的细胞通讯很关键。CellPhoneDB有474种相互作用涉及分泌蛋白,而490种相互作用涉及膜蛋白,总共有250个涉及整合素的相互作用。[1]

目前CellphoneDB version > 4.0.0是只能在python里使用。version 3以前的版本可以基于linux终端直接操作。
 
#cpdb环境配置
conda create -n cpdb python=3.8
conda activate cpdb#激活环境
python3.8 -m pip3 install cellphonedb -i https://pypi.tuna.tsinghua.edu.cn/simple
python
import cellphonedb
cellphonedb.version  #4.0.0
from cellphonedb.src.core.methods import cpdb_statistical_analysis_method
import cellphonedb

cpdb_file_path = './example_data/cellphonedb-data-master/cellphonedb.zip'
test_meta_file_path = './example_data/cellphonedb_meta.txt'
test_counts_file_path = './example_data/cellphonedb_count.txt'
outpath = './degs'
degs_file_path = './degs/cellphone_degs.txt'

from cellphonedb.src.core.methods import cpdb_statistical_analysis_method
#deconvoluted, means, pvalues,
cpdb_statistical_output = cpdb_statistical_analysis_method.call(
  cpdb_file_path = cpdb_file_path,
  meta_file_path = test_meta_file_path,
  counts_file_path = test_counts_file_path,
  counts_data = 'gene_name',#注意[ensembl | gene_name | hgnc_symbol] Type of gene 
  iterations = 100,
  threshold = 0.1,
  threads = 6,
  output_suffix = "macaque",
  output_path = "./")
  
  
from cellphonedb.src.core.methods import cpdb_degs_analysis_method

cpbb_degs_output = cpdb_degs_analysis_method.call(
         cpdb_file_path = cpdb_file_path,
         meta_file_path = test_meta_file_path,
         counts_file_path = test_counts_file_path,
         degs_file_path = degs_file_path,
         counts_data = 'hgnc_symbol',
         threshold = 0.1,
         output_path = outpath)

图:输出文件

rm(list=ls())
gc()
setwd('/data5/tan/chenchen/ZCJ/Results/All-scRNA_YS/HM/cellchat/monkey/example_data/')
library(Seurat)
library(dplyr)
library(psych)
library(qgraph)
library(igraph)
library(tidyverse)
library(ktplots)
library(SingleCellExperiment)
library(reticulate)

library(RColorBrewer)
cols <- c(brewer.pal(8,"Set2") , 
          brewer.pal(9,"Set3"), brewer.pal(9,"BrBG"),
          brewer.pal(9,"PiYG"), brewer.pal(9,"RdGy"),
          brewer.pal(9,"OrRd"),brewer.pal(9,"GnBu"),
          brewer.pal(9,"PuBu"),brewer.pal(9,"YlGn"),brewer.pal(9,"PuRd"))


data(cpdb_output)

load("/data5/tan/chenchen/ZCJ/Results/All-scRNA_YS/HM/HM.celltype0.5.RData")
all_sample.combined <- JoinLayers(all_sample.combined,assay = 'RNA')
monkey <- subset(all_sample.combined,orig.ident == 'macaque')
counts <- as.matrix(monkey@assays$RNA$data)
meta_data <- cbind(rownames(monkey@meta.data), monkey@meta.data[,'celltype0.5', drop=F])  
meta_data <- as.matrix(meta_data)
meta_data[is.na(meta_data)] = "Unkown"

sce <- SingleCellExperiment(assays = list(counts = counts),colData = meta_data)

write.table(meta_data, 'cellphonedb_meta.txt', sep='\t', quote=F, row.names=F)

write.table(counts,'cellphonedb_count.txt' ,sep='\t',quote=F)

pvals <- read.delim("../statistical_analysis_pvalues_macaque.txt", check.names = FALSE)
means <- read.delim("../statistical_analysis_means_macaque.txt", check.names = FALSE)
unique(monkey$celltype0.5)
#这里的cell_type1、2指定互作细胞,如果不指定则默认所有细胞,split.by用于分组数据的
unique(pvals$gene_a)

plot_cpdb(cell_type1 = 'Endoderm', cell_type2 = '',scdata = sce,celltype_key = 'celltype0.5', # column name where the cell ids are located in the metadata
          #split.by = 'Experiment', # column name where the grouping column is. Optional.
          means = means, pvals = pvals,
          genes = c('WNT')) +
          theme(text = element_text(size = 15))

unique(interaction_annotation$role)


plot_cpdb(cell_type1 = 'Endoderm', cell_type2 = '', scdata = sce,
          celltype_key = 'celltype0.5', means = means, pvals = pvals,
          gene_family = 'Inhibitory',keep_significant_only = F) + 
  small_guide() + small_axis() + small_legend(keysize=.5)

deconvoluted <- read.delim('../statistical_analysis_deconvoluted_macaque.txt', check.names = FALSE)
#interaction_annotation <- read.delim('statistical_analysis')#由于打不开网站,因此没有下载到这个文件,在前面可以通过data(cpdb_output)加载出该文件的
unique(all_sample.combined$celltype0.5)
p <- plot_cpdb2(cell_type1 = 'Fibroblast', cell_type2 = 'Endothelium',
           scdata = sce,
           celltype_key ='celltype0.5', # column name where the cell ids are located in the metadata
           means = means,
           pvals = pvals,
           deconvoluted = deconvoluted, # new options from here on specific to plot_cpdb2
           desiredInteractions = list(
             c('Fibroblast', 'Endothelium')),
           interaction_grouping = interaction_annotation,
           edge_group_colors = c(
             "Activating" = "#e15759",
             "Chemotaxis" = "#59a14f",
             "Inhibitory" = "#4e79a7",
             "Intracellular trafficking" = "#9c755f",
             "DC_development" = "#B07aa1",
             "Unknown" = "#e7e7e7"),
           node_group_colors = c(
             "Fibroblast" = "red",
             "Endothelium" = "blue"),
           keep_significant_only = TRUE,
           standard_scale = TRUE,
           remove_self = TRUE)+theme(text = element_text(size = 15))

p <- plot_cpdb3(cell_type1 = 'Mesthelium', cell_type2 = 'Endothelium',
           scdata = sce,
           celltype_key = 'celltype0.5', # column name where the cell ids are located in the metadata
           means = means,
           pvals = pvals,
           deconvoluted = deconvoluted,
           keep_significant_only = TRUE,
           standard_scale = TRUE,
           remove_self = TRUE)


plot_cpdb4(
  interaction = 'TF-TFRC',
  cell_type1 = 'Fibroblast', cell_type2 = 'Endoderm',
  scdata = sce,
  celltype_key = 'celltype',
  means = means,
  pvals = pvals,
  deconvoluted = decon,
  keep_significant_only = TRUE,
  standard_scale = TRUE)

Error:

1、Error in UseMethod("grid.draw") :    no applicable method for 'grid.draw' applied to an object of class "recordedplot"

这个错误信息指出,`ggsave` 函数在尝试保存图像时遇到了问题,因为要保存的对象 `p` 是一个 "recordedplot" 类的对象,而 `ggsave` 函数不知道如何将这个类的对象转化为可以保存的图形格式。

"recordedplot" 类的对象通常是通过 `recordPlot` 函数创建的,该函数用于记录一个图形的绘制过程,以便可以重新播放或修改。但是,并不是所有的图形对象都可以简单地用 `ggsave` 保存。如果一个图形对象是通过 `ggplot2` 或其他图形系统创建的,并且已经绘制到屏幕上或设备上,它通常可以直接保存。但如果是一个记录的图形,就需要先将其回放(replay)为一个可以保存的图形对象。

1. 确保图形对象是通过 `ggplot` 或其他图形函数创建的:如果 `p` 是一个 `ggplot` 对象,你应该能直接使用 `ggsave`。

    ```r
    p <- ggplot(...) + ...
    ggsave("Endothe-Mesthe.pdf", p, width = 10, height = 10)
    ```

2. 如果 `p` 是一个记录的图形,使用 `grid.draw` 将其绘制到 `grid` 上:然后使用 `ggsave` 保存 `grid`。

    ```r
    grid.newpage()
    grid.draw(p) # 将 recordedplot 对象绘制到 grid
    ggsave("Endothe-Mesthe.pdf", width = 10, height = 10)
    ```

3. 使用 `grid.export` 直接保存 `grid` 对象:如果你已经将图形绘制到了 `grid` 上,你可以使用 `gridExtra` 包的 `grid.export` 函数来保存它。

    ```r
    library(gridExtra)
    grid.export("Endothe-Mesthe.pdf", width = 10, height = 10)
    ```

4. 检查对象 `p` 的内容:如果 `p` 不是预期的图形对象,可能需要重新审视生成它的代码。

5. 使用 `print` 函数:如果 `p` 是一个 `ggplot` 对象或其他可以打印的图形对象,使用 `print(p)` 将其打印到屏幕上,然后再尝试保存。

    ```r
    print(p)
    ggsave("Endothe-Mesthe.pdf", plot = p, width = 10, height = 10)
    ```

6. 确保 `ggplot2` 和相关图形包是最新的:有时候,包的更新可以解决兼容性问题。

请注意,如果 `p` 是一个 `ggplot` 对象,并且你之前使用了 `print(p)` 来显示它,那么你应该能够直接使用 `ggsave` 来保存它,而不需要使用 `grid.draw`。如果 `p` 是一个通过 `recordPlot` 创建的 `recordedplot` 对象,那么你需要先将其绘制到 `grid`,然后再保存。

 

2、Error in plot_cpdb or Error in `dplyr::left_join()`:3

前者可能是挑选到了不在指定细胞类型表达的gene,后者可能是因为mean和pval文件的行名不太一致,若一致可以直接删除argument gene_family,则无报错。

 

Ref:

  1. https://www.jianshu.com/p/38a9376f5286
  2. https://www.jianshu.com/p/74a5d18ffcdb
  3. https://github.com/zktuong/ktplots/issues/110

 

16、Cellranger报错总结

16.1 ERROR: We detected a mixture of different R1 lengths ([26-150])

针对此种报错,可能是测序公司在切除接头时,导致的长度不一致。

可附加上--r1-length参数

cellranger count --id=xxx --transcriptome=/data5/tan/zengchuanj/pipeline/cellranger/refdata-gex-mm10-2020-A --fastqs=/data5/tan/zengchuanj/pipeline/Cui/20240118/01.CleanData/ --r1-length 26

不过也可以直接用未去接头的rawdata运行,产生的细胞数不会相差太多。

cellranger count --id=xxx --transcriptome=/data5/tan/zengchuanj/pipeline/cellranger/refdata-gex-mm10-2020-A --fastqs=/data5/tan/zengchuanj/pipeline/Cui/20240118/00.RawData/ --r1-length 26

 

17、inferCNV的使用

Later

 

 

 

posted @ 2022-07-22 10:55  相遂  阅读(2116)  评论(0编辑  收藏  举报