Search
Question: Newbee question: how to output/write data (measureents) to a text file?
0
gravatar for Reinert Korsnes
22 months ago by
Norway
Reinert Korsnes0 wrote:

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                         

ADD COMMENTlink modified 22 months ago • written 22 months ago by Reinert Korsnes0

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

ADD REPLYlink modified 22 months ago • written 22 months ago by Gordon Smyth32k
0
gravatar for Mike Smith
22 months ago by
Mike Smith2.1k
EMBL Heidelberg / de.NBI
Mike Smith2.1k wrote:

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 COMMENTlink written 22 months ago by Mike Smith2.1k
0
gravatar for Reinert Korsnes
22 months ago by
Norway
Reinert Korsnes0 wrote:

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 COMMENTlink written 22 months ago by Reinert Korsnes0

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 REPLYlink modified 22 months ago • written 22 months ago by Mike Smith2.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 238 users visited in the last hour