SofieVG / FlowSOM

Using self-organizing maps for visualization and interpretation of cytometry data
60 stars 26 forks source link

CountGroups Error #4

Closed peterch405 closed 8 years ago

peterch405 commented 8 years ago

Tried running this:

groups <- CountGroups(fSOM_all, data_names, plot = TRUE, silent = FALSE)

and got this error:

Error in tapply(x, INDEX = factor(rep(names(groups), lapply(groups, length)),  : 
  arguments must have same length

traceback()
5: stop("arguments must have same length")
4: tapply(x, INDEX = factor(rep(names(groups), lapply(groups, length)), 
       levels = names(groups)), mean)
3: FUN(newX[, i], ...)
2: apply(pctgs, 2, function(x) {
       tapply(x, INDEX = factor(rep(names(groups), lapply(groups, 
           length)), levels = names(groups)), mean)
   })
1: CountGroups(fSOM_all, data_names, plot = TRUE, silent = FALSE)

The plots are produced but when trying to do:

PlotGroups(fSOM_all, groups, view = "MST")

I get:

Error in groups$means : object of type 'closure' is not subsettable

Does the error message imply that the flowframes supplied to ReadInput have to have equal number of events?

SofieVG commented 8 years ago

Hi Peter,

The flowframes certainly do not need to have an equal number of events. I'm not sure where this error comes from, could you let me know what your data_names variable contains?

Here you have an example of how to use the function, I will add this example to the documentation of the package as this was apparently still missing. (I'm using the sample file added to the package, so the generation of new files to compare is a bit forced, but this helps in demonstrating files with a differing number of cells)

library(FlowSOM) set.seed(1)

Build the FlowSOM tree on the example file

fileName <- system.file("extdata","lymphocytes.fcs",package="FlowSOM") flowSOM.res <- FlowSOM(fileName, compensate=TRUE,transform=TRUE, scale=TRUE,colsToUse=c(9,12,14:18),nClus = 10)

Have a look at the resulting tree

PlotStars(flowSOM.res[[1]],backgroundValues = as.factor(flowSOM.res[[2]]))

Select all cells except the branch that corresponds with automated cluster 7 (CD3+ TCRyd +)

and write te another file for the example

In practice you would not generate any new file but use your different files from your different groups

ff <- flowCore::read.FCS(fileName) ff_tmp <- ff[flowSOM.res[[1]]$map$mapping[,1] %in% which(flowSOM.res[[2]] != 7),] flowCore::write.FCS(ff_tmp,file="ff_tmp.fcs")

Make an additional file without cluster 7 and double amount of cluster 10

ff_tmp <- ff[c(which(flowSOM.res[[1]]$map$mapping[,1] %in% which(flowSOM.res[[2]] != 7)), which(flowSOM.res[[1]]$map$mapping[,1] %in% which(flowSOM.res[[2]] == 5))),] flowCore::write.FCS(ff_tmp,file="ff_tmp2.fcs")

Compare the original file with the two new files we made

groupRes <- CountGroups(flowSOM.res[[1]], groups=list("AllCells"=c(fileName),"Without_ydTcells"=c("ff_tmp.fcs","ff_tmp2.fcs"))) PlotGroups(flowSOM.res[[1]], groupRes)

Compare only the file with the double amount of cluster 10

groupRes <- CountGroups(flowSOM.res[[1]], groups=list("AllCells"=c(fileName),"Without_ydTcells"=c("ff_tmp2.fcs"))) PlotGroups(flowSOM.res[[1]], groupRes)

peterch405 commented 8 years ago

Thank you for the example. My data_names were wrong, which caused the error.