How to append cluster and UMAP data to a flowSet?
1
0
Entering edit mode
@slucasblack-21475
Last seen 5.4 years ago

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?

flow cytometry flowSet UMAP .fcs files • 2.5k views
ADD COMMENT
2
Entering edit mode
@mikhaelmanurung-17423
Last seen 2.5 years ago
Netherlands

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!

ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 549 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