20586

no method for coercing this S4 class to a vector for utilization of mclust

Question:

I'm trying to use the <strong>mclust</strong> method on an <strong>.FCS</strong> 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 <strong>as.matrix</strong>, 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.

Answer1:

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 <em>is</em> 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

Recommend

  • How to construct and plot uni-variate Gaussian Mixture using its parameters in Python
  • BigQuery - Clustered tables not reducing query size with multiple keys
  • Inserting special characters
  • Hybrid SOM (with MLP)
  • Cluster markers with osmdroid
  • Java catching exceptions and subclases
  • javascript XSLT nodes, selecting the first of a group (merge-like)
  • Do stored procedures have the ability to delete a file from the OS?
  • How to combine two lists together?
  • What is wrong with this emulation of CMPXCHG16B instruction?
  • Django Migrations fail during django initialization
  • send data back from jsp iterator to struts action class
  • Allocating a 2D contiguous array within a function
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Adding Object or changing its parameter programmatically in C# / ASP.Net
  • Implementing “partial void” in VB
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • Button text different than value submitted in query string
  • What's the purpose of QString?
  • Custom Tabgroup Appcelerator
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Projection media query: browser support and workarounds?
  • Different response to non-authenticated users and AJAX calls
  • swift auto completion not working in Xcode6-Beta
  • Finding past revisions of files in StarTeam w/ .NET SDK / C#
  • Sending data from AppleScript to FileMaker records
  • Knitr HTML Loop - Some HTML output, some R output
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Arrays break string types in Julia
  • Cannot Parse HTML Data Using Android / JSOUP
  • KeystoneJS: Relationships in Admin UI not updating
  • AngularJs get employee from factory
  • Load html files in TinyMce
  • C# - Getting references of reference
  • MATLAB: Piecewise function in curve fitting toolbox using fittype
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?