GO注释文件中多行变两列和两列变多行

test_Gene2GO.txt

ChrSy.fgenesh.gene.10   GO:0003676
ChrSy.fgenesh.gene.12   GO:0003676, GO:0004523, GO:0015074
ChrSy.fgenesh.gene.14   GO:0004674, GO:0005509, GO:0005515, GO:0005524, GO:0006468, GO:0016021, GO:0030247
ChrSy.fgenesh.gene.17   GO:0003676, GO:0004190, GO:0006508, GO:0008270, GO:0015074
ChrSy.fgenesh.gene.21   GO:0004672, GO:0006468
ChrSy.fgenesh.gene.22   GO:0003676, GO:0004523, GO:0015074
ChrSy.fgenesh.gene.26   GO:0006508, GO:0008234
ChrSy.fgenesh.gene.27   GO:001602

转换一列变多行

  • 方法①
test <- read.table("test_Gene2GO.txt", sep = "\t", header = F)
library(tidyverse)
test %>% separate_rows(V2, sep = ",")
## install.packages("splitstackshape")
## install_github("mrdwab/splitstackshape", ref = "devel")
## 不知道为什么我都不能安装好, 最后下载到本地安装好的
library(splitstackshape)
test %>% cSplit(., "V2", ",", 'long')
6223615-2c9379ced3bd0ed5.png

多行变两列

  • 方法①
 aggregate(test1, by = list(test1$V1), c) %>% transmute(Gene = .$Group.1, GOid = .$V2)
6223615-6fd99c638661c965.png
  • 方法②


    6223615-74c54714d808b40d.png

还有许多简单的命令。。。只是能解决就好了。

附带小惊喜

至于怎么下载, 大家心里都有万能的下载渠道。。

猜你喜欢

转载自blog.csdn.net/weixin_34223655/article/details/87119779
今日推荐