Skip to content

Instantly share code, notes, and snippets.

@xiamaz
Forked from yannabraham/createFlowFrame.R
Created November 3, 2017 14:45
Show Gist options
  • Save xiamaz/008dd7c991d269e1ca9548868e4ed380 to your computer and use it in GitHub Desktop.
Save xiamaz/008dd7c991d269e1ca9548868e4ed380 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='.'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment