Read FCS files#

In this notebook, we load an fcs file into the anndata format, move the forward scatter (FCS) and sideward scatter (SSC) information to the .obs section of the anndata file and perform compensation on the data.

import readfcs
import pytometry as pm
%load_ext autoreload
%autoreload 2

Read data from readfcs package example.

from urllib.request import urlretrieve

path_data, _ = urlretrieve(readfcs.datasets.example(), "example.fcs")
adata = pm.io.read_fcs(path_data)
adata
AnnData object with n_obs × n_vars = 65016 × 16
    var: 'channel'
    uns: 'meta'

The .var section of the AnnData object contains the channel information. We set the marker names as var_names by default. In addition, we save the channel information in the "channel" column.

adata.var
channel
FSC-A FSC-A
FSC-H FSC-H
SSC-A SSC-A
KI67 KI67
CD3 CD3
CD28 CD28
CD45RO CD45RO
CD8 CD8
CD4 CD4
CD57 CD57
VIVID / CD14 VIVID / CD14
CCR5 CCR5
CD19 CD19
CD27 CD27
CCR7 CCR7
CD127 CD127

The .uns['meta'] section contains the header information from the FCS file.

adata.uns["meta"]
{'filename': '100715.fcs',
 'sys': 'Windows XP 5.1',
 'total_events': 65016,
 'tube_name': 'Tube_025',
 'exp_name': '070717_AB02_tb',
 'cytometer': 'Main Aria (FACSAria)',
 'creator': 'LYSYS',
 'operator': 'Administrator',
 'cst_pass': False,
 'threshold': {'channel': 'FSC', 'threshold': '27000'},
 'processing_date': '2007-07-17T15:38:06',
 'spill':           B515-A    R780-A    R710-A    R660-A    V800-A    V655-A    V585-A  \
 B515-A  1.000000  0.000000  0.000000  0.000088  0.000249  0.000645  0.007198   
 R780-A  0.000000  1.000000  0.071188  0.148448  0.338903  0.009717  0.000000   
 R710-A  0.000000  0.331405  1.000000  0.061965  0.120979  0.004053  0.000000   
 R660-A  0.000000  0.088621  0.389424  1.000000  0.029759  0.065553  0.000000   
 V800-A  0.000000  0.136618  0.010757  0.000000  1.000000  0.000156  0.000000   
 V655-A  0.000000  0.000124  0.019463  0.218206  0.004953  1.000000  0.003583   
 V585-A  0.000000  0.000000  0.000000  0.000000  0.001056  0.002287  1.000000   
 V450-A  0.000000  0.000000  0.000000  0.000000  0.000000  0.008118  0.170066   
 G780-A  0.003122  0.008526  0.001024  0.001163  0.125401  0.018142  0.193646   
 G710-A  0.002015  0.069645  0.194715  0.001008  0.151611  0.001270  0.007133   
 G660-A  0.001685  0.054340  0.277852  0.343008  0.061753  0.077523  0.004263   
 G610-A  0.000000  0.008713  0.048213  0.073190  0.150563  0.386293  0.101896   
 G560-A  0.001684  0.000000  0.000000  0.000095  0.003463  0.015712  0.174122   
 
         V450-A    G780-A    G710-A    G660-A    G610-A    G560-A  
 B515-A     0.0  0.000000  0.000131  0.000067  0.000582  0.002520  
 R780-A     0.0  0.301380  0.007478  0.012354  0.000000  0.000000  
 R710-A     0.0  0.109117  0.100314  0.005832  0.000000  0.000000  
 R660-A     0.0  0.031294  0.039306  0.091375  0.000396  0.000057  
 V800-A     0.0  0.483235  0.014858  0.000000  0.000000  0.000000  
 V655-A     0.0  0.001311  0.029646  0.408902  0.006506  0.000119  
 V585-A     0.0  0.000389  0.000194  0.000000  0.062551  0.132484  
 V450-A     1.0  0.000000  0.000000  0.000000  0.000000  0.000000  
 G780-A     0.0  1.000000  0.066898  0.161456  0.286823  1.238037  
 G710-A     0.0  1.150032  1.000000  0.016077  0.014674  0.055352  
 G660-A     0.0  0.497488  0.743923  1.000000  0.010329  0.037635  
 G610-A     0.0  0.370277  0.613490  1.218024  1.000000  0.065211  
 G560-A     0.0  0.023802  0.049474  0.132511  0.239216  1.000000  }