【发布时间】:2019-09-03 20:26:29
【问题描述】:
我有一个很大的列表,其中包含来自许多细胞系的表达基因。 Ensembl 基因通常带有版本后缀,但我需要删除它们。我找到了几个描述此here 或here 的参考资料,但它们对我不起作用,可能是因为我的数据结构(我认为它是列表中的嵌套数组?)。有人可以帮助我了解代码的细节以及我对自己的数据结构的理解吗?
这是一些示例数据
>listOfGenes_version <- list("cellLine1" = c("ENSG001.1", "ENSG002.1", "ENSG003.1"), "cellLine2" = c("ENSG003.1", "ENSG004.1"))
>listOfGenes_version
$cellLine1
[1] "ENSG001.1" "ENSG002.1" "ENSG003.1"
$cellLine2
[1] "ENSG003.1" "ENSG004.1"
而我想看到的是
>listOfGenes_trimmed
$cellLine1
[1] "ENSG001" "ENSG002" "ENSG003"
$cellLine2
[1] "ENSG003" "ENSG004"
以下是我尝试过的一些方法,但没有奏效
>listOfGenes_trimmed <- str_replace(listOfGenes_version, pattern = ".[0-9]+$", replacement = "")
Warning message:
In stri_replace_first_regex(string, pattern, fix_replacement(replacement), :
argument is not an atomic vector; coercing
>listOfGenes_trimmed <- lapply(listOfGenes_version, gsub('\\..*', '', listOfGenes_version))
Error in match.fun(FUN) :
'gsub("\\..*", "", listOfGenes_version)' is not a function, character or symbol
非常感谢!
【问题讨论】: