To get cracking, we need some flow cytometry data (i.e., .fcs files). A few FCS data files have been bundled with this python package. To use these files, enter the following in your ipython terminal:
In [1]: import FlowCytometryTools
In [2]: from FlowCytometryTools import test_data_dir, test_data_file
In [3]: datadir = test_data_dir
In [4]: datafile = test_data_file
datadir
will point to a directory containing flow cytometry data while datafile
will point
to a specific FCS file.
To analyze your own data, simply set the ‘datafile’ variable to the path of your .fcs file:
>>> datafile=r'C:\data\my_very_awesome_data.fcs'
Windows Users Windows uses the backslash character (‘’) for paths. However, the backslash character is a special character in python that is used for formatting strings. In order to specify paths correctly, you must precede the path with the character ‘r’.
Good:
>>> datafile=r'C:\data\my_very_awesome_data.fcs'Bad:
>>> datafile='C:\data\my_very_awesome_data.fcs'
Below is a brief description, for more information see FCMeasurement
.
Once datadir
and datafile
have been defined, we can proceed to load the data:
In [5]: from FlowCytometryTools import FCMeasurement
In [6]: sample = FCMeasurement(ID='Test Sample', datafile=datafile)
Want to know which channels were measured? No problem.
In [7]: print(sample.channel_names)
('HDR-T', 'FSC-A', 'FSC-H', 'FSC-W', 'SSC-A', 'SSC-H', 'SSC-W', 'V2-A', 'V2-H', 'V2-W', 'Y2-A', 'Y2-H', 'Y2-W', 'B1-A', 'B1-H', 'B1-W')
In [8]: print(sample.channels)
$PnB $PnG $PnR $PnN $PnE $PnS
Channel Number
1 32 1 262144 HDR-T [0.000000, 0.000000] HDR-T
2 32 1 262144 FSC-A [0.000000, 0.000000] FSC-A
3 32 1 262144 FSC-H [0.000000, 0.000000] FSC-H
4 32 1 262144 FSC-W [0.000000, 0.000000] FSC-W
5 32 1 262144 SSC-A [0.000000, 0.000000] SSC-A
6 32 1 262144 SSC-H [0.000000, 0.000000] SSC-H
7 32 1 262144 SSC-W [0.000000, 0.000000] SSC-W
8 32 1 262144 V2-A [0.000000, 0.000000] V2-A
9 32 1 262144 V2-H [0.000000, 0.000000] V2-H
10 32 1 262144 V2-W [0.000000, 0.000000] V2-W
11 32 1 262144 Y2-A [0.000000, 0.000000] Y2-A
12 32 1 262144 Y2-H [0.000000, 0.000000] Y2-H
13 32 1 262144 Y2-W [0.000000, 0.000000] Y2-W
14 32 1 262144 B1-A [0.000000, 0.000000] B1-A
15 32 1 262144 B1-H [0.000000, 0.000000] B1-H
16 32 1 262144 B1-W [0.000000, 0.000000] B1-W
In addition to the raw data, the FCS files contain “meta” information about the measurements, which may be useful for data analysis. You can access this information using the meta property, which will return to you a python dictionary. The meaning of the fields in meta data is explained in the FCS format specifications (google for the specification).
In [9]: print(type(sample.meta))
<class 'dict'>
In [10]: print(sample.meta.keys())