![](/img/trans.png)
[英]Error in as.vector(data) : no method for coercing this S4 class to a vector
[英]no method for coercing this S4 class to a vector for utilization of mclust
我正在嘗試在.FCS格式文件(流式細胞術格式文件)上使用mclust方法,並將該文件作為 flowFrame 對象讀入 R。
install.packages("openCyto") # since the old version sefaulted my R session
library( openCyto )
library( flowCore)
library( mclust)
trial1=read.FCS("export_Alcina TregMAIT_AV 10-1974 P1_CD4.fcs")
a=as.matrix(trial1)
編者注:其中一些是 Bioconductor 軟件包,您應該根據該環境的幫助頁面進行安裝。
但是, mclust
不接受 .fcs 文件作為矩陣,我嘗試使用as.matrix函數將其轉換為矩陣,但出現此錯誤:
Error in as.vector(data) :
no method for coercing this S4 class to a vector
我發現了類似的問題,他們解釋說您必須將importMethodsFrom(S4Vectors,as.matrix)
添加到mclust
的 NAMESPACE 中,我這樣做了。 我還在 mclust 的 NAMESPACE 中做了importMethodsFrom(BiocGenerics,as.vector)
。 但是,我仍然無法使用mclust
。
PS任何建議或閱讀將不勝感激!
如果有人知道其他使用 GMM 模型的聚類方法可以接受 .FCS 格式而不進行轉換,我會非常高興。
我已經編輯了您的問題,以顯示您最初應該做的事情以及后來沒有做的事情(而不是在評論中包含代碼,您應該在按照具體建議編輯問題時做出回應。)我的回答是基於flowCore::read.FCS
中的第一個示例(因為您也沒有包含指向您從磁盤加載的數據集的指針),所以我將指的是運行該代碼的“samp”對象,而不是“trial1”。
“samp”對象現在從class
和str
返回:
> class(samp)
[1] "flowFrame"
attr(,"package")
[1] "flowCore"
str(samp)
Formal class 'flowFrame' [package "flowCore"] with 3 slots
..@ exprs : num [1:10000, 1:8] 382 628 1023 373 1023 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : Named chr [1:8] "FSC-H" "SSC-H" "FL1-H" "FL2-H" ...
.. .. .. ..- attr(*, "names")= chr [1:8] "$P1N" "$P2N" "$P3N" "$P4N" ...
.. ..- attr(*, "ranges")= num [1:8] 1023 1023 10000 10000 10000 ...
..@ parameters :Formal class 'AnnotatedDataFrame' [package "Biobase"] with 4 slots
.. .. ..@ varMetadata :'data.frame': 5 obs. of 1 variable:
.. .. .. ..$ labelDescription: chr [1:5] "Name of Parameter" "Description of Parameter" "Range of Parameter" "Minimum Parameter Value after Transforamtion" ...
.. .. ..@ data :'data.frame': 8 obs. of 5 variables:
.. .. .. ..$ name :Class 'AsIs' Named chr [1:8] "FSC-H" "SSC-H" "FL1-H" "FL2-H" ...
.. .. .. .. .. ..- attr(*, "names")= chr [1:8] "$P1N" "$P2N" "$P3N" "$P4N" ...
.. .. .. ..$ desc :Class 'AsIs' Named chr [1:8] "FSC-H" "SSC-H" NA NA ...
.. .. .. .. .. ..- attr(*, "names")= chr [1:8] "$P1S" "$P2S" "$P3S" "$P4S" ...
.. .. .. ..$ range : num [1:8] 1024 1024 1024 1024 1024 ...
.. .. .. ..$ minRange: num [1:8] 0 0 1 1 1 0 1 0
.. .. .. ..$ maxRange: num [1:8] 1023 1023 10000 10000 10000 ...
.. .. ..@ dimLabels : chr [1:2] "rowNames" "columnNames"
.. .. ..@ .__classVersion__:Formal class 'Versions' [package "Biobase"] with 1 slot
.. .. .. .. ..@ .Data:List of 1
.. .. .. .. .. ..$ : int [1:3] 1 1 0
..@ description:List of 164
.. ..$ FCSversion : chr "2"
.. ..$ $BYTEORD : chr "4,3,2,1"
.. ..$ $DATATYPE : chr "F"
#----- output truncated -----------
所以“samp”在任何意義上都不是一個矩形對象,而是一個復雜的列表,其中包含許多屬性中的相關信息。 我的猜測是你想要@ exprs
節點中的信息,它是一個矩陣。
另一個困難是在 mclust 包中沒有 mamed mclust
函數,盡管查看?mclust
我們確實看到了一個演示Mclust
函數使用的示例。 R 在堅持函數名稱的正確大寫方面是無情的。
Mclust(exprs(samp)[1:100,])
#-----------
'Mclust' model object:
best model: ellipsoidal, equal orientation (VVE) with 4 components
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.