Error from FlowSom to Cytofast
0
0
Entering edit mode
@domenicosomma-12703
Last seen 4.1 years ago

I am trying to use Cytofast. According to the manual I need to create a clustering with FlowSom and then use it as base to feed cytofast. I create my flowsom object and seems fine:

#Compensated from FlowJo
fSOM <- FlowSOM(samples,
                # Input options:
                compensate = FALSE,
                transform = TRUE,
                toTransform=channels.needed,
                scale = TRUE,
                # SOM options:
                colsToUse = channels.needed, xdim = 7, ydim = 7,
                # Metaclustering options:
                nClus = 6)

#Plot
PlotStars(fSOM[[1]], backgroundValues = as.factor(fSOM[[2]]))

#CD4
PlotMarker(fSOM[[1]],marker = "FJComp.APC.A")

Then, there is not just a simple command to import it in cytofast.

#imprt metadata
sample_meta <- read_excel("metadata.xls")
sample_meta$sampleID <- as.factor(sample_meta$sampleID)
sample_meta$Group <- as.factor(sample_meta$Group)
sample_meta$Name <- as.factor(sample_meta$Name)

#get the clusterID from fSOM object
clusterID <- as.factor(fSOM$FlowSOM$map$mapping[,1])
levels(clusterID) <- fSOM$metaclustering

#I need to have a list of "file name" "from" "to". The original one from here https://www.jove.com/t/60525/visualization-quantification-high-dimensional-cytometry-data-using was not working for me so I adapted it
test <- function(counter = 0) {
  result = list()
  while (counter < length(fSOM$FlowSOM$metaData)) {
    counter = counter + 1
    print(counter)
    result[[counter]] <- c(substr(names(fSOM$FlowSOM$metaData[counter]), start=85, stop=129), fSOM$FlowSOM$metaData[[counter]])
    #print(substr(names(fSOM$FlowSOM$metaData[counter]), start=85, stop=129))
  }
  return(result)
}

l = test()
sampleID <- lapply(l, function(x){rep(x[1], each = length(x[2]:x[3]))})

#now sampleID is a "list of lists"
#to make it one column
attr(sampleID, 'names') <- NULL
sampleID <- as.factor(unlist(sampleID))

#dataframe with ClusterID, sampleID and fSOM data made before
library(plyr)
sampleID <- mapvalues(sampleID, from = levels(sampleID), to = 1:177)
df <- data.frame(clusterID, sampleID, fSOM$FlowSOM$data[, channels.needed])
#Assign each cell to its identified subset and sample ID.
#subset_id <- as.factor(fSOM$FlowSOM$map$mapping[,1])
#levels(subset_id) <- fSOM$metaclustering
#head(subset_id) #OK

#FINALLY make cfList (cytofast file)
 cfData <- cfList(samples = sample_meta ,expr = df)
 cfData <- cellCounts(cfData, frequency = TRUE, scale = TRUE)

Seems it worked, but when I try to make a plot:

> cytoHeatmaps (cfData, group="Group", legend=TRUE)
Error in if (xi > xj) 1L else -1L : missing value where TRUE/FALSE needed
In addition: Warning message:
In Ops.factor(xi, xj) : ‘>’ not meaningful for factors

If I ignore the group it is working:

cytoHeatmaps (cfData,legend=FALSE) #Workes

And the groups exist:

> cfData@samples$Group
  [1] Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1
 [12] Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1
 [23] Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1
 [34] Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1 Batch1
 [45] Batch1 Batch1 Batch1 Batch1 Batch1 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2
 [56] Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2
 [67] Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2
 [78] Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2
 [89] Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch2 Batch3 Batch3
[100] Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3
[111] Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3
[122] Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3
[133] Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3
[144] Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3
[155] Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3
[166] Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3 Batch3
[177] Batch3
Levels: Batch1 Batch2 Batch3

I tried to make Group as charather instead of factor, but I get another error:

> cfData@samples$Group <- as.character(cfData@samples$Group)
> cytoHeatmaps (cfData,legend=FALSE) #Works
> cytoHeatmaps (cfData, group="Group", legend=TRUE)
Error: Must request at least one colour from a hue palette.

Any idea?? Thanks!

Cytofast FlowSom CyTOF fcs files • 1.6k views
ADD COMMENT

Login before adding your answer.

Traffic: 983 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6