花花写于2019-10-4
GEO踩坑进行时,高级课程上线指日可待。
GEO难搞的分组信息
前面提到过:有的GEO数据分组信息找起来比较麻烦
这是GSE58979的pdata信息,为了简化,直接读取文件吧。
library(tidyr)
pd = read.table("pd.txt")
pd$title
## [1] "FN52-NASHF52" "FN55-NASHF55" "FN69-NASHF69"
## [4] "FN71-NASHF71" "FN76-NASHF76-DupA" "FN77-NASHF77"
## [7] "FN56-NASHF56" "FN57-NASHF57" "FN73-NASHF73"
## [10] "FN79-NASHF79" "FN53-NASHF53" "FN61-NASHF61-DupA"
## [13] "FN64-NASHF64" "FN65-NASHF65" "FN70-NASHF70"
## [16] "SF52-NASHF52" "FN76-NASHF76-DupB" "SF56-NASHF56"
## [19] "V096-VIS96" "SF53-NASHF53" "FN61-NASHF61-DupB"
## [22] "C147-CUT147" "V147-VIS147" "SF55-NASHF55"
## [25] "V043-VIS43" "SF57-NASHF57" "V178-VIS178"
## [28] "SF65-NASHF65" "V119-VIS119" "C152-CUT152"
## [31] "V152-VIS152" "SF69-NASHF69" "V095-VIS95"
## [34] "SF73-NASHF73" "V210-VIS210" "SF70-NASHF70"
## [37] "V122-VIS122" "C198-CUT198" "V170-VIS170"
## [40] "C072-CUT72" "V190-VIS190" "C073-CUT73"
## [43] "C024-CUT24" "C205-CUT205" "V205-VIS205"
## [46] "C095-CUT95" "C096-CUT96" "C119-CUT119"
## [49] "C214-CUT214" "V214-VIS214" "C164-CUT164"
## [52] "C121-CUT121" "C177-CUT177"
目的是生成形如A,A,A,B,B,B这样的向量,A、B是组名,在后续分析中会用到。
结合文章看了一下,pd里面没有可用的分组,需要从title这一列提取。我知道有一组名叫NASH。
方法一:拆分列+删除数字
tidyr::separate可以分列,分隔符用“-”即可
zz=separate(pd,title,into = c("a","b"),"-")
## Warning: Expected 2 pieces. Additional pieces discarded in 4 rows [5, 12,
## 17, 21].
head(zz)[,1:3]
## a b geo_accession
## GSM1423267 FN52 NASHF52 GSM1423267
## GSM1423268 FN55 NASHF55 GSM1423268
## GSM1423269 FN69 NASHF69 GSM1423269
## GSM1423270 FN71 NASHF71 GSM1423270
## GSM1423271 FN76 NASHF76 GSM1423271
## GSM1423272 FN77 NASHF77 GSM1423272
留下b列。F以及后面的数字,其实是病人的id,都删掉就行。
library(stringr)
gr = str_replace_all(zz$b,"F\\d\\d","") %>%
str_replace_all("\\d","")
table(gr)
## gr
## CUT NASH VIS
## 14 26 13
方法二: ifelse
gr2 = ifelse(str_detect(pd$title, "NASH"),
"NASH",
ifelse(str_detect(pd$title, "CUT"), "CUT", "VIS"))
table(gr2)
## gr2
## CUT NASH VIS
## 14 26 13
identical(gr,gr2)
## [1] TRUE
如果方法二代码看不懂,回过去看:从前提到条件语句只知道if else