R包genfu比較風(fēng)險(xiǎn)預(yù)測模型(一)

研究需要,不得不斷的學(xué)習(xí)新的軟件包,R的突出特點(diǎn)即在于開源,和眾多的軟件包,其學(xué)習(xí)的難點(diǎn)也在于需要包太多,每用新的包都需要學(xué)習(xí),了解軟件的使用參數(shù)。該文記錄genefu包的學(xué)使用,我自己構(gòu)建的模型已經(jīng)有了一定的結(jié)果,最后希望與現(xiàn)有的多基因芯片模型比較,其實(shí)我也不知道自己基于測序的模型能否與現(xiàn)有的芯片模型比較,我也完全可以到現(xiàn)在就整理數(shù)據(jù),告一段落,然后繼續(xù)學(xué)習(xí)其它的套路。只是因?yàn)槲蚁肷钊胍恍?,真正的做一些有意義的工作,也許可以在時間的長河里留下痕跡,提醒自己時間的力量。

####genefu包的使用
##修改鏡像
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")  

if(FALSE){BiocManager::install("genefu")
}
##
library(genefu)
library(xtable)
library(rmeta)
library(Biobase)
library(caret)


##
if(FALSE){BiocManager::install("breastCancerMAINZ")
BiocManager::install("breastCancerTRANSBIG")
BiocManager::install("breastCancerUPP")
BiocManager::install("breastCancerUNT")
BiocManager::install("breastCancerNKI")
}
##加載各數(shù)據(jù)集
library(breastCancerMAINZ)
library(breastCancerTRANSBIG)
library(breastCancerUPP)
library(breastCancerUNT)
library(breastCancerNKI)

##case1比較風(fēng)險(xiǎn)預(yù)測模型
##5個芯片數(shù)據(jù)集已整合為R包
##
data(breastCancerData)

##查看數(shù)據(jù)結(jié)構(gòu)
str(nki7g)
dim(nki7g)
cinfo <- colnames(pData(mainz7g))

##整合數(shù)據(jù)到向量
data.all <- c("transbig7g"=transbig7g, "unt7g"=unt7g, "upp7g"=upp7g,
              "mainz7g"=mainz7g, "nki7g"=nki7g)

##mainz與NKI數(shù)據(jù)集無重復(fù)
idtoremove.all <- NULL
duplres <- NULL

##關(guān)注transbig7g數(shù)據(jù)集, unt7g upp7g
dim(pData(transbig7g))
dim(pData(unt7g))
dim(pData(upp7g))
##可觀察到都為21列的臨床信息,sample數(shù)不同
##rbind整合三個臨床信息,
demo.all <- rbind(pData(transbig7g), pData(unt7g), pData(upp7g))
dn2 <- c("TRANSBIG", "UNT", "UPP")

## 檢索VDXKIU, KIU, UPPU 三個series
ds2 <- c("VDXKIU", "KIU", "UPPU")
##is.element(A,B) A中元素屬于B返回TRUE or FALSE
##有完整series信息并且留下想要的
demot <- demo.all[complete.cases(demo.all[ , c("series")]) & is.element(demo.all[ , "series"], ds2), ]
dim(demot)#可見篩選留下了290個sample

## 找到 series中相同的病人
##因demot中包含21列信息
colnames(demot)
# 找到 series id中重復(fù)的id
duplid <- sort(unique(demot[duplicated(demot[ , "id"]), "id"]))
duplrest <- NULL
##for循環(huán)中提取出游完整id dataset,且滿足要求
for(i in 1:length(duplid)) {
  tt <- NULL
  for(k in 1:length(dn2)) {
    myx <- sort(row.names(demot)[complete.cases(demot[ , c("id", "dataset")]) &
                                   demot[ , "id"] == duplid[i] & demot[ , "dataset"] == dn2[k]])
    if(length(myx) > 0) { tt <- c(tt, myx) }
  }
  duplrest <- c(duplrest, list(tt))
}
##只要屬于我們關(guān)注的3個數(shù)據(jù)集
names(duplrest) <- duplid
duplres <- c(duplres, duplrest)

## 檢索 VVDXOXFU, OXFU series
ds2 <- c("VDXOXFU", "OXFU")
demot <- demo.all[complete.cases(demo.all[ , c("series")]) & is.element(demo.all[ , "series"], ds2), ]
# Find the duplicated patients in that series
duplid <- sort(unique(demot[duplicated(demot[ , "id"]), "id"]))
duplrest <- NULL
for(i in 1:length(duplid)) {
  tt <- NULL
  for(k in 1:length(dn2)) {
    myx <- sort(row.names(demot)[complete.cases(demot[ , c("id", "dataset")]) &
                                   demot[ , "id"] == duplid[i] & demot[ , "dataset"] == dn2[k]])
    if(length(myx) > 0) { tt <- c(tt, myx) }
  }
  duplrest <- c(duplrest, list(tt))
}
names(duplrest) <- duplid
duplres <- c(duplres, duplrest)

#### 得到完整的重復(fù)patients
##代碼較復(fù)雜拆解查看下
a<-lapply(duplres, function(x) { return(x[-1]) })##對列表每個元素操作
unlist(a)##解開列表
duPL <- sort(unlist(lapply(duplres, function(x) { return(x[-1]) } )))
str(duPL)#duPL屬于character
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 關(guān)于Mongodb的全面總結(jié) MongoDB的內(nèi)部構(gòu)造《MongoDB The Definitive Guide》...
    中v中閱讀 32,316評論 2 89
  • Docker是一個開源的容器運(yùn)行和管理引擎,可以輕松的為任何應(yīng)用創(chuàng)建一個輕量級的、可移植的、自給自足的容器。開發(fā)者...
    丁明威閱讀 2,461評論 2 6
  • 在這個物欲橫流、紛亂嘈雜的社會中,人們越來越不能忍受孤獨(dú)、寂寞、一個人,又活回了“群居生物”。尤其是身邊的人都成...
    長頸鹿不吃糖閱讀 172評論 0 0
  • 夜夢思人去,不見柳春綠。 春雪覆大地,淚濕滿衫白。 輾轉(zhuǎn)難眠夜,春寒被未暖。 千里郵相思,提筆寒梅放。
    扶巧閱讀 394評論 3 9
  • 敬告: 這篇文章關(guān)于廣島原子彈爆炸的有些描寫和圖片,可能會引起心里不適,請慎重閱讀。 在廣島,沒有像平時一樣住單人...
    80天旅行閱讀 627評論 0 0

友情鏈接更多精彩內(nèi)容