Newbee question: how to output/write data (measureents) to a text file?
2
0
Entering edit mode
@reinert-korsnes-9492
Last seen 8.2 years ago
Norway

Hello, to speed up learning to use bioconductor tools, I would  like to see a simple example on writing out data from a fcs file and to a simple text file (maybe only the first 1000 events/measurements).  I can use flowViz to plot and flowStats to make analysis, but I would like to use for example my own program or linux/gnuplot to confirm I have understood.

Given the example below (the fcs-file is here calles "rkut1.fcs"), how I print out FITC-A values to a text file (one value each line):

> library(flowCore)
> x <- read.FCS("rkut1.fcs", transformation=FALSE)
> x
flowFrame object 'rkut1.fcs'
with 54289 cells and 10 observables:
      name          desc range   minRange maxRange
$P1  HDR-T         HDR-T   128  0.0000000      127
$P2  FSC-A         FSC-A  1024  0.0000000     1023
$P3  SSC-A         SSC-A  1024  0.0000000     1023
$P4   V1-A     VioBlue-A  1024 -0.7600108     1023
$P5   B1-A        FITC-A  1024 -0.3138263     1023
$P6   B2-A          PE-A  1024 -0.3507906     1023
$P7   B3-A PI/PE-Cy5.5-A  1024 -0.3008470     1023
$P8   B4-A      PE-Cy7-A  1024 -0.4390466     1023
$P9   R1-A         APC-A  1024 -0.3781420     1023
$P10  R2-A     APC-Cy7-A  1024 -1.3673245     1023
144 keywords are stored in the 'description' slot                                                                                                                                 
>    

Thanks in advance, Reinert                         

packages • 1.5k views
ADD COMMENT
0
Entering edit mode

If you'd like to attract help from the flowCore authors, enter 'flowCore' as a tag for your question.

ADD REPLY
0
Entering edit mode
Mike Smith ★ 6.5k
@mike-smith
Last seen 19 hours ago
EMBL Heidelberg

You can use the function exprs() to access the matrix of measured intensities in a flowFrame, and then write.table() to write this to file.  exprs() transforms the data so that columns correspond to the different measurement channels, so you can select the column you want using R's usual subsetting.  An example for your data might look something like:

ff1 <- read.FCS("rkut1.fcs", transformation=FALSE)
inten <- exprs(ff1)
write.table( inten[, "FITC-A"], file = "~/my-file.txt", row.names = FALSE )
ADD COMMENT
0
Entering edit mode
@reinert-korsnes-9492
Last seen 8.2 years ago
Norway

Thanks a lot.  You saved me hours of confusion !

I had to replace the "userfriendly" term "FITC-A" with "B1-A".  I assume there is a possibility to use "alias" or similar so "FITC-A"  can be used to make code better readable and reusable.

 

 

ADD COMMENT
0
Entering edit mode

As I understand it the exprs() function will always use the 'name' column from the flowFrame, which I assume is defined in the .fcs file you're reading in.  If you have a one-to-one mapping between the name and desc columns you could do something like:

## get the name and desc columns from the metadata
mapping <- pData(parameters(ff1))[, c("name", "desc")]
## find which row in the metadata each column is
col.idx <- match(colnames(inten), mapping[,"name"])
## replace column names with the appropriate row drom 'desc'
colnames(inten) <- mapping[ col.idx, "desc" ]
## write data using the new column name
write.table( inten[, "FITC-A"], file = "~/my-file.txt", row.names = FALSE )
ADD REPLY

Login before adding your answer.

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