Working with the fcs parser

ATTENTION The parser returns the data exactly as recorded in the file. This means that no transformations or compensation have been applied to this data. It is up to you to transform the data from this point for doing analysis and visualization.


In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
import fcsparser

path = fcsparser.test_sample_path # path to a test data file that is included with the package

Unpack meta only


In [3]:
meta = fcsparser.parse(path, meta_data_only=True)
print type(meta)
print meta.keys()


<type 'dict'>
[u'SAMPLE ID', u'$P7N', u'$ETIM', u'$P7E', u'$P7G', u'P8DISPLAY', u'SampleID', u'$P7B', u'FSC ASF', u'CYTNUM', u'$ENDDATA', u'P2DISPLAY', u'EXPORT USER NAME', u'$P7V', u'$ENDSTEXT', u'$P7R', u'LASER2NAME', u'CREATOR', u'LASER1DELAY', u'$P3V', u'$P11R', u'P4DISPLAY', u'$P11N', u'P2MS', u'THRESHOLD', u'$P11E', u'$SYS', u'$P11B', u'$P6B', u'$INST', u'$P6G', u'$P6E', u'APPLY COMPENSATION', u'$PAR', u'EXPORT TIME', u'$P6N', u'$P6R', u'$P6V', u'P9MS', u'$ENDANALYSIS', u'LASER4DELAY', u'$CYT', u'$BTIM', u'$P3E', u'$OP', u'$P1N', u'P1DISPLAY', u'$P1B', u'$P1G', u'$P1E', u'P7BS', u'$P1R', u'P3MS', u'P9BS', u'$P1V', u'PLATE NAME', u'$P9B', u'$P9G', u'$P9E', u'SPILL', u'$FIL', u'$P9R', u'$P9V', u'$DATE', u'WELL ID', u'P10BS', u'P6MS', u'LASER1ASF', u'P1BS', u'P2BS', u'LASER2ASF', u'$P8B', u'$P8E', u'P6BS', u'$P8V', u'$P10R', u'$P8N', u'P5BS', u'LASER4NAME', u'LASER4ASF', u'$P10N', u'$P10B', u'$P10E', u'$P10G', u'$P3R', u'P11MS', u'$SRC', u'$P3B', u'P4MS', u'$P3G', u'$BYTEORD', u'$P3N', u'P5DISPLAY', u'$TOT', u'P8MS', u'P11BS', u'EXPERIMENT NAME', u'$P2V', u'$P9N', u'WINDOW EXTENSION', u'$P2R', u'$BEGINSTEXT', u'LASER3DELAY', u'$P2G', u'$P2E', u'$P2B', u'$P2N', u'LASER3NAME', u'P7MS', u'$P5V', u'$P8G', '__header__', u'P7DISPLAY', u'$BEGINDATA', u'$DATATYPE', u'$TIMESTEP', u'P10MS', u'$P5R', u'$P5G', u'P10DISPLAY', u'$P5E', u'$P5B', u'$P5N', u'$BEGINANALYSIS', u'LASER1NAME', u'P5MS', u'$P10V', u'P8BS', u'GUID', u'P9DISPLAY', u'$P11G', u'$P8R', u'LASER3ASF', u'AUTOBS', u'P1MS', u'$MODE', u'$P4E', u'$P4G', u'P3BS', u'$P4B', u'$P4N', u'PLATE ID', u'$NEXTDATA', u'$P4V', u'$P4R', u'P4BS', u'TUBE NAME', u'LASER2DELAY']

Unpack meta and reformat


In [4]:
meta = fcsparser.parse(path, meta_data_only=True, reformat_meta=True)
meta['_channels_']


Out[4]:
$PnN $PnB $PnG $PnE $PnR $PnV
Channel Number
1 FSC-A 32 1.0 [0, 0] 262144 611
2 FSC-H 32 1.0 [0, 0] 262144 611
3 FSC-W 32 1.0 [0, 0] 262144 611
4 SSC-A 32 1.0 [0, 0] 262144 210
5 SSC-H 32 1.0 [0, 0] 262144 210
6 SSC-W 32 1.0 [0, 0] 262144 210
7 FITC-A 32 1.0 [0, 0] 262144 580
8 PerCP-Cy5-5-A 32 1.0 [0, 0] 262144 580
9 AmCyan-A 32 1.0 [0, 0] 262144 550
10 PE-TxRed YG-A 32 1.0 [0, 0] 262144 500
11 Time 32 0.01 [0, 0] 262144 None

Unpack meta and data


In [5]:
meta, data = fcsparser.parse(path, meta_data_only=False, reformat_meta=True)

In [6]:
print type(meta)
print type(data)


<type 'dict'>
<class 'pandas.core.frame.DataFrame'>

In [7]:
data


Out[7]:
FSC-A FSC-H FSC-W SSC-A SSC-H SSC-W FITC-A PerCP-Cy5-5-A AmCyan-A PE-TxRed YG-A Time
0 -28531.250000 10 0.000 700.149963 1656 27708.351562 98.799995 54.149998 164.220001 120.360001 0.200000
1 -49414.878906 8 0.000 1275.849976 2278 36705.050781 155.800003 13.300000 161.840012 94.860001 0.400000
2 -58684.320312 14 0.000 -512.049988 472 0.000000 22.799999 8.550000 172.550003 85.680000 0.500000
3 -3857.839844 432 0.000 276.449982 1339 13530.564453 -49.399998 34.200001 157.080002 89.759995 0.700000
4 22825.830078 4606 262143.000 -505.399994 472 0.000000 90.250000 9.500000 330.820007 76.500000 0.700000
5 17345.339844 3708 262143.000 -341.049988 586 0.000000 63.649998 30.400000 241.570007 76.500000 1.100000
6 -66212.421875 5 0.000 1134.299927 2062 36051.152344 180.500000 -3.800000 216.580017 76.500000 1.300000
7 -59752.527344 1 0.000 -436.049988 554 0.000000 -11.400000 -7.600000 151.130005 68.339996 1.300000
8 -17016.660156 11 0.000 -209.000000 749 0.000000 -91.199997 0.950000 252.280014 44.879997 1.500000
9 28728.789062 5717 262143.000 -453.149994 558 0.000000 76.949997 23.750000 133.279999 56.099998 1.600000
10 17430.000000 3568 262143.000 -468.350006 475 0.000000 66.500000 -19.000000 99.960007 59.160000 1.700000
11 24527.330078 4681 262143.000 -76.949997 931 0.000000 189.050003 3.800000 320.110016 75.479996 2.000000
12 -42823.847656 2 0.000 -410.399994 548 0.000000 19.000000 5.700000 199.920013 26.520000 2.300000
13 -61499.679688 4 0.000 -91.199997 882 0.000000 12.349999 23.750000 127.330009 23.459999 3.000000
14 -61684.769531 4 0.000 -240.349991 774 0.000000 98.799995 -14.250000 51.170002 -17.340000 3.000000
15 -62284.859375 9 0.000 94.049995 1139 5411.466309 30.400000 49.399998 173.740005 -21.420000 3.100000
16 -57402.800781 4 0.000 -438.899994 463 0.000000 131.099991 -39.899998 139.230011 28.559999 3.100000
17 44351.050781 8240 262143.000 103.549995 1179 5755.939453 -50.349998 -26.600000 60.690002 10.200000 3.400000
18 52054.277344 9440 262143.000 314.449982 1179 17479.044922 -178.599991 -14.250000 59.500004 -6.120000 3.500000
19 54260.417969 9800 262143.000 -29.449999 950 0.000000 208.050003 -38.950001 153.510010 24.480000 3.500000
20 33469.750000 6408 262143.000 -299.250000 606 0.000000 -34.200001 -13.300000 57.120003 -23.459999 3.600000
21 15418.080078 3030 262143.000 -190.949997 804 0.000000 47.500000 -41.799999 58.310001 -31.619999 3.700000
22 -29567.089844 12 0.000 1451.599976 2406 39539.507812 228.949997 -16.150000 160.650009 12.240000 3.800000
23 5559.339844 1384 262143.000 -434.149994 418 0.000000 -104.500000 -3.800000 95.200005 -6.120000 3.900000
24 5126.909668 1428 235292.125 -134.899994 854 0.000000 24.699999 18.049999 133.279999 12.240000 3.900000
25 34302.238281 23089 97363.750 1101.049927 1726 41806.730469 50.349998 -38.000000 114.240005 45.899998 4.100000
26 -52817.878906 9 0.000 334.399994 1279 17134.666016 -133.949997 0.950000 -48.790001 13.260000 4.200000
27 -47389.679688 8 0.000 -144.399994 710 0.000000 33.250000 -4.750000 17.850000 -8.160000 4.200000
28 -42845.429688 5 0.000 1240.699951 2238 36331.777344 20.900000 18.049999 120.190002 24.480000 4.200000
29 -19319.080078 8 0.000 296.399994 1266 15343.499023 -69.349998 -15.200000 33.320000 17.340000 4.200000
... ... ... ... ... ... ... ... ... ... ... ...
14915 -22298.779297 12 0.000 901.549988 870 67912.625000 -165.300003 23.750000 16.660000 18.360001 1001.000000
14916 -26106.820312 10 0.000 981.349976 984 65359.507812 42.750000 19.000000 -1.190000 7.140000 1001.000000
14917 -19690.919922 15 0.000 2438.649902 2301 69456.484375 2530.800049 -2.850000 29.750002 -1.020000 1001.000000
14918 34640.878906 7101 262143.000 1294.849976 1279 66348.156250 184.300003 320.149994 1087.660034 3080.399902 1001.000000
14919 37935.148438 7260 262143.000 481.649994 450 70145.367188 68.400002 -1.900000 21.420002 -24.480000 1001.099976
14920 -47467.699219 13 0.000 1153.299927 1139 66358.789062 94.049995 -8.550000 -23.800001 37.739998 1001.599976
14921 -42225.417969 13 0.000 1374.650024 1303 69139.734375 -46.549999 -19.000000 52.360001 19.379999 1001.599976
14922 -39570.250000 8 0.000 2337.000000 2214 69176.890625 2817.699951 26.600000 222.530014 10.200000 1001.599976
14923 -55350.207031 0 262143.000 591.849976 566 68529.109375 48.450001 59.849998 -1.190000 20.400000 1001.799988
14924 -35747.269531 9 0.000 2230.599854 2115 69118.007812 3297.449951 -6.650000 64.260002 -22.439999 1001.799988
14925 -25881.888672 4 0.000 1066.849976 991 70552.054688 104.500000 -3.800000 -32.130001 42.840000 1001.900024
14926 -12305.580078 5 0.000 724.849976 686 69247.476562 96.900002 -13.300000 24.990002 -13.260000 1001.900024
14927 -3449.479980 13 0.000 1695.750000 1527 72778.437500 -63.649998 7.600000 10.710001 18.360001 1002.000000
14928 37962.539062 6384 262143.000 1679.599976 1627 67654.742188 -92.150002 8.550000 35.700001 -6.120000 1002.099976
14929 56014.207031 10781 262143.000 2150.800049 2027 69538.648438 377.149994 474.049988 1669.570068 4133.040039 1002.099976
14930 68764.671875 11966 262143.000 3408.599854 3240 68946.304688 1238.799927 28.500000 121.380005 -1.020000 1002.200012
14931 42695.199219 7835 262143.000 1944.650024 1389 91752.765625 1368.000000 17.100000 217.770004 -8.160000 1002.200012
14932 28975.298828 5532 262143.000 707.750000 646 71800.468750 -0.950000 -8.550000 32.130001 32.639999 1002.200012
14933 31328.349609 5532 262143.000 1510.500000 1498 66082.859375 53.200001 7.600000 34.510002 14.280000 1002.200012
14934 -27985.939453 9 0.000 859.750000 759 74235.281250 187.149994 9.500000 29.750002 41.820000 1002.299988
14935 -41983.058594 12 0.000 2090.000000 1938 70676.085938 455.049988 407.549988 1264.970093 4071.839844 1002.400024
14936 -40131.328125 5 0.000 589.000000 558 69176.890625 28.500000 -6.650000 10.710001 16.320000 1002.400024
14937 -44740.320312 8 0.000 442.699982 418 69408.570312 -111.150002 13.300000 45.220001 27.539999 1002.400024
14938 -43414.808594 0 262143.000 496.850006 475 68550.664062 -64.599998 5.700000 -35.700001 32.639999 1002.500000
14939 -52364.699219 5 0.000 1444.000000 1335 70886.882812 55.099998 -5.700000 -23.800001 -27.539999 1002.599976
14940 -28177.669922 4 0.000 1650.150024 1551 69725.484375 157.699997 398.049988 1391.110107 2730.540039 1002.700012
14941 -19354.769531 7 0.000 1086.799927 1073 66378.867188 56.049999 -12.349999 -15.470001 -14.280000 1002.700012
14942 12428.419922 2658 262143.000 496.850006 496 65648.312500 -24.699999 -9.500000 10.710001 -7.140000 1002.700012
14943 21995.000000 4392 262143.000 558.599976 514 71222.585938 67.449997 -12.349999 14.280001 -5.100000 1002.700012
14944 68924.859375 12210 262143.000 690.649963 564 80252.546875 32.299999 -37.049999 10.710001 -5.100000 1002.900024

14945 rows × 11 columns

Untransformed data

The plot below is a plot of the raw data as recorded in the file. Specifically, no compensation or transformation has been applied to this data.

To better visualize this data you might want to take a look at either hlog or logicle transformations.


In [8]:
scatter(data['FITC-A'], data['AmCyan-A'], alpha=0.8, color='gray')


Out[8]:
<matplotlib.collections.PathCollection at 0x7fb3c34d7f50>