2011-09-09 47 views
2

我必須首先說我剛剛開始使用R編程。我無法創建我的數據的表達式集。當我試圖把assaydata和phenodata在一起,使expressionset,我得到一個錯誤:表達式集 - phenodata

Error in validObject(.Object) : " invalid class ""ExpressionSet"" object: sampleNames differ between assayData and phenoData"

請看一看樣本數據中,phenodata表我提出和R-程序。我想應該修改這個數據來得到這個工作。

請讓我知道如何解決這個問題,並改變phenodata。

AssayData              
    0h-1 0h-2 6h-1 6h-2 12h-1 12h-2 24h-1 24h-2 48h-1 48h-2 72h-1 72h-2 96h-1 96h-2 
171407 4.021342514 4.021342514 6.847201005 6.847201005 3.189312274 3.189312274 3.322687671 3.322687671 4.929574559 4.929574559 4.040127938 4.040127938 3.181587044 3.181587044 
171415 267.8091012 267.8091012 358.8511895 358.8511895 266.4562608 266.4562608 210.259177 210.259177 243.1496956 243.1496956 248.2780935 248.2780935 235.7079055 235.7079055 
171426 13.3620332 13.3620332 5.581083074 5.581083074 12.5236932 12.5236932 8.433621131 8.433621131 13.07390505 13.07390505 12.94673202 12.94673202 23.43214156 23.43214156 
171453 37.65310777 37.65310777 27.88942772 27.88942772 54.7409581 54.7409581 78.86045287 78.86045287 63.61655487 63.61655487 67.31327606 67.31327606 62.35426899 62.35426899 

PhenoData              
     condition time rep           
0h-1 Control 0 1           
0h-2 Control 0 2           
6h-1 treatment 6 1           
6h-2 treatment 6 2           
12h-1 treatment 12 1           
12h-2 treatment 12 2           
24h-1 treatment 24 1           
24h-2 treatment 24 2           
48h-1 treatment 48 1           
48h-2 treatment 48 2           
72h-1 treatment 72 1           
72h-2 treatment 72 2           
96h-1 treatment 96 1           
96h-2 treatment 96 2 

我的代碼:

library(""Biobase"")               
library(""betr"")                         
exprs <- as.matrix(read.table(""Timecourse-Assaydata.txt"", header=TRUE, sep=""\t"", row.names=1, as.is=TRUE))              
pData <- read.table(""Timecourse-Phenodata.txt"", row.names=1, header=TRUE, sep=""\t"")              
metadata <- data.frame(labelDescription = c(""Hour of treatment"", ""Treatment time"", ""number of replicates""), row.names = c(""condition"", ""time"", ""rep""))              
phenoData <- new(""AnnotatedDataFrame"", data = pData, varMetadata = metadata)             

exprspop <- new(""ExpressionSet"", exprs = exprs, phenoData = phenoData)  

Error in validObject(.Object) : " invalid class ""ExpressionSet"" object: sampleNames differ between assayData and phenoData"

+0

我試圖編輯您的問題弄成便於閱讀,但我無法破譯一切。請按照[這裏]的建議(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)寫一個可重現的問題,並注意代碼標記工具爲好。 – joran

回答

10

對這個問題的正確位置應該是在Bioconductor支持網站。最好提供一個可重現的例子來捕捉問題的本質;創建可重現的例子往往有助於確定問題的原因。

library(Biobase) 

exprs <- matrix(0, nrow=5, ncol=3, 
       dimnames=list(letters[1:5], LETTERS[1:3])) 
pData <- data.frame(id=c("foo", "bar", "baz"), 
        row.names=c("x", "y", "z")) 
phenoData <- AnnotatedDataFrame(data=pData) 

導致

> ExpressionSet(exprs, phenoData=phenoData) 
Error in validObject(.Object) : 
    invalid class "ExpressionSet" object: sampleNames differ between assayData and 
phenoData 

的問題是,的exprscolname(即,在實驗樣品的名稱)不同frrom的pDatarow.names(即,樣品的描述)

> row.names(pData) 
[1] "x" "y" "z" 
> colnames(exprs) 
[1] "A" "B" "C" 

和解決的辦法是讓他們同樣

> colnames(exprs) <- row.names(pData) 
> eset <- ExpressionSet(exprs, phenoData=phenoData) 
> eset 
ExpressionSet (storageMode: lockedEnvironment) 
assayData: 5 features, 3 samples 
    element names: exprs 
protocolData: none 
phenoData 
    sampleNames: x y z 
    varLabels: id 
    varMetadata: labelDescription 
featureData: none 
experimentData: use 'experimentData(object)' 
Annotation: 

附加元素可以被添加到使用assayDataReplace()現有ExpressionSet,例如,

> assayDataElement(eset, "foo") <- sqrt(exprs) 
> eset 
ExpressionSet (storageMode: lockedEnvironment) 
assayData: 5 features, 3 samples 
    element names: exprs, foo 
protocolData: none 
phenoData 
    sampleNames: x y z 
    varLabels: id 
    varMetadata: labelDescription 
featureData: none 
experimentData: use 'experimentData(object)' 
Annotation: 

或從一開始就

> env = new.env() 
> env$exprs = exprs 
> env$sqrt = sqrt(exprs) 
> lockEnvironment(env) 
> ExpressionSet(env, pData=pData) 
ExpressionSet (storageMode: environment) 
assayData: 5 features, 3 samples 
    element names: exprs, sqrt 
protocolData: none 
phenoData: none 
featureData: none 
experimentData: use 'experimentData(object)' 
Annotation: 
+0

感謝摩根博士,它工作。非常感謝您的幫助。 – Avin

+0

我知道這是一箇舊的帖子,但是有沒有一種方法來添加另一個矩陣的元素名稱具有類似dimensions.eg:** dat < - new(「」ExpressionSet「」,exprs = list(exprs,newData), phenoData = phenoData)**其中dim(newData)是5個特徵和3個樣本 – Mdhale