Reputation: 51
I'm trying to use the mclust method on an .FCS format file (which is a flow cytometry format file) and I read this file into R as flowFrame object.
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)
Editors note: some of these are Bioconductor packages and you should install according to the help pages for that environment.
However, mclust
does not accept the .fcs file as a matrix & I tried to convert it to a matrix with the function as.matrix, and I get this error:
Error in as.vector(data) :
no method for coercing this S4 class to a vector
I've found similar questions where they explain you have to add importMethodsFrom(S4Vectors,as.matrix)
into the NAMESPACE of mclust
, which I did. I also did importMethodsFrom(BiocGenerics,as.vector)
in the NAMESPACE of mclust. However, I'm still not able to use mclust
.
P.S. any advice or reading would be appreciated!
If, anyone knows other clustering methods that use GMM model that could accept .FCS format without converting, I'd be very happy.
Upvotes: 0
Views: 15504
Reputation: 263451
I've edited your question to show what you should have done originally and also didn't do later (instead of including code in a comment you should have responded by then editing the question as was specifically suggested.) My response is based on the first example in flowCore::read.FCS
(since you also did not include a pointer to the dataset you were loading from disk) so rather than "trial1" I will be referring to the "samp" object I get running that code.
The "samp" object is now returns this from class
and 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 -----------
So "samp" is not a rectangular objects in any sense but rather a complex list with lots of the associated information in attributes. My guess is that you want the information in the @ exprs
node which is a matrix.
A further difficulty is that there is no function mamed mclust
in the mclust package, although looking at ?mclust
we do see an example demonstrating the use of an Mclust
function. R is unforgiving in its insistence on correct capitalization of function names.
Mclust(exprs(samp)[1:100,])
#-----------
'Mclust' model object:
best model: ellipsoidal, equal orientation (VVE) with 4 components
Upvotes: 0