<commit_before>.. _tutorial:

.. currentmodule:: FlowCytometryTools


.. ipython:: python
    :suppress:

    import numpy as np
    np.set_printoptions(precision=4, suppress=True)

Specifying paths to FCS data
----------------------------

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:

.. ipython:: python

    import os, FlowCytometryTools;
    datadir = os.path.join(FlowCytometryTools.__path__[0], 'tests', 'data', 'Plate01');
    datafile = os.path.join(datadir, 'RFP_Well_A3.fcs');


.. note::

    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'


Working with individual FCS files
---------------------------------

Below is a brief description, for more information see :class:`FCMeasurement`.

Loading the file
++++++++++++++++++++++++++++

Once ``datadir`` and ``datafile`` have been defined, we can proceed to load the data:

.. ipython:: python

	from FlowCytometryTools import FCMeasurement
    sample = FCMeasurement(ID='Test Sample', datafile=datafile)

Channel Information
++++++++++++++++++++++++++++

Want to know which channels were measured? No problem.

.. ipython:: python

    print sample.channel_names

.. ipython:: python

    print sample.channels

Full Meta Data
++++++++++++++++++++++++++++

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).

.. ipython:: python
    
    print type(sample.meta)
    print sample.meta.keys()
    print sample.meta.['$SRC']

Accessing Raw Data
+++++++++++++++++++++++++++

The data is accessible as a `pandas.DataFrame <http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html>`_.

.. ipython:: python
    
    print type(sample.data)
    print sample.data[['Y2-A', 'FSC-A']][:10]


If you do not know how to work with DataFrames, you can get the underlying numpy array using the values property.

.. ipython:: python
    
    print type(sample.data.values)
    print sample.data[['Y2-A', 'FSC-A']][:10].values

Of course, working directly with a pandas DataFrame is very convenient. For example,

.. ipython:: python

    data = sample.data
    print data['Y2-A'].describe()

Want to know how many events are in the data?

.. ipython:: python
<commit_msg>Fix syntax error<commit_after>.. _tutorial:

.. currentmodule:: FlowCytometryTools


.. ipython:: python
    :suppress:

    import numpy as np
    np.set_printoptions(precision=4, suppress=True)

Specifying paths to FCS data
----------------------------

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:

.. ipython:: python

    import os, FlowCytometryTools;
    datadir = os.path.join(FlowCytometryTools.__path__[0], 'tests', 'data', 'Plate01');
    datafile = os.path.join(datadir, 'RFP_Well_A3.fcs');


.. note::

    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'


Working with individual FCS files
---------------------------------

Below is a brief description, for more information see :class:`FCMeasurement`.

Loading the file
++++++++++++++++++++++++++++

Once ``datadir`` and ``datafile`` have been defined, we can proceed to load the data:

.. ipython:: python

	from FlowCytometryTools import FCMeasurement
    sample = FCMeasurement(ID='Test Sample', datafile=datafile)

Channel Information
++++++++++++++++++++++++++++

Want to know which channels were measured? No problem.

.. ipython:: python

    print sample.channel_names

.. ipython:: python

    print sample.channels

Full Meta Data
++++++++++++++++++++++++++++

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).

.. ipython:: python
    
    print type(sample.meta)
    print sample.meta.keys()
    print sample.meta['$SRC']

Accessing Raw Data
+++++++++++++++++++++++++++

The data is accessible as a `pandas.DataFrame <http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html>`_.

.. ipython:: python
    
    print type(sample.data)
    print sample.data[['Y2-A', 'FSC-A']][:10]


If you do not know how to work with DataFrames, you can get the underlying numpy array using the values property.

.. ipython:: python
    
    print type(sample.data.values)
    print sample.data[['Y2-A', 'FSC-A']][:10].values

Of course, working directly with a pandas DataFrame is very convenient. For example,

.. ipython:: python

    data = sample.data
    print data['Y2-A'].describe()

Want to know how many events are in the data?

.. ipython:: python

{'fraction_non_alphanumeric': 0.14586683821164362, 'fraction_numerical': 0.0038597619813444837, 'mean_word_length': 3.487012987012987, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6778878', 'n_tokens_mistral': 1904, 'n_tokens_neox': 1798, 'n_words': 674}