Skip to content

Instantly share code, notes, and snippets.

@yannabraham
Last active July 30, 2024 22:36
Show Gist options
  • Save yannabraham/c1f9de9b23fb94105ca5 to your computer and use it in GitHub Desktop.
Save yannabraham/c1f9de9b23fb94105ca5 to your computer and use it in GitHub Desktop.
A quick way to create FCS files from CSV
library(Biobase)
library(flowCore)
library(flowViz)
# simply replace the dummy dta below with your CSV data
dta <- matrix(rnorm(10000),ncol=10)
dimnames(dta)[[2]] <- LETTERS[1:10]
head(dta)
# you need to prepare some metadata
meta <- data.frame(name=dimnames(dta)[[2]],
desc=paste('this is column',dimnames(dta)[[2]],'from your CSV')
)
meta$range <- apply(apply(dta,2,range),2,diff)
meta$minRange <- apply(dta,2,min)
meta$maxRange <- apply(dta,2,max)
head(meta)
# all these are required for the following steps to work
# a flowFrame is the internal representation of a FCS file
ff <- new("flowFrame",
exprs=dta,
parameters=AnnotatedDataFrame(meta)
)
# a simple plot to check that it worked
xyplot(A~B,ff)
# now you can save it back to the filesystem
write.FCS(ff,paste(tempfile(),'FCS',sep='.'))
@vblanche
Copy link

Hi,
thanks for this script. How do I do step#5? replace dta with my own csv? thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment