Question: How to append cluster and UMAP data to a flowSet?
0
11 weeks ago by
s.lucasblack0 wrote:

I have an R workflow that loads a folder of 24 .fcs files that have already been cleaned up and downsampled to 10,000 events into a formal class flowSet. The R script then transforms the @exprs matrix, runs flowSOM and UMAP on these data. These algorithms produce data frames that as 240,000 rows long (24 files x 10,000 events).

How do I get these three extra columns added to the 24 flowFrames within the flowSet?

Some of my code is below:

#Add data
path = "~/Desktop/Test"
files <- list.files(
path = path, pattern = "\\.fcs$", full.names = TRUE ) d_flowSet <- read.flowSet( files, transformation = FALSE, truncate_max_range = FALSE ) setwd("~/Desktop/Test") cols_lineage <- c(7,9:34) ################# ### Run UMAP ### ################ umap.out<-umap(somedata[cols_lineage]) head(umap.out) plot.umap<-as.data.frame(umap.out$layout)
# Basic scatter plot of mpg according to cyl
plot(plot.umap,type="p",main="UMAP data", xlab='UMAP_X',ylab='UMAP_Y')

#################
### Export Data ###
################

cluster<-rowData(out_DA$d_se) cluster<-cluster[,4] UMAP_X<-umap.out$layout[,1]
UMAP_Y<-umap.out\$layout[,2]

app.data<-as.matrix(cbind(cluster,UMAP_X,UMAP_Y))


How do I add this final app.data to the original slowSet?

modified 11 weeks ago by mikhael.manurung190 • written 11 weeks ago by s.lucasblack0
Answer: How to append cluster and UMAP data to a flowSet?
2
11 weeks ago by
Netherlands
mikhael.manurung190 wrote:

If you don't mind a little detour, you can use fr_append_cols from the flowCore package to append those columns.

new_frame <- fr_append_cols(d_flowset[[1]], app.data)


Note that you need to provide the flowFrame (i.e. single FCS file) instead of the flowSet. You can then iterate with for-loop or apply functions to do it for all flowFrame that you have. Don't forget to name the columns of your app.data!

Thanks Mikheal, that worked a treat! I just had to play around with a for loop to get it working automatically. :)