### Install FCSParser using pip or conda Source: https://github.com/eyurtsev/fcsparser/blob/master/README.rst Instructions for installing the fcsparser package using either pip or conda. This is the first step to using the library. ```bash pip install fcsparser ``` ```bash conda install -c conda-forge fcsparser ``` -------------------------------- ### Parse FCS file metadata and data in Python Source: https://github.com/eyurtsev/fcsparser/blob/master/README.rst A basic example of how to use the fcsparser library to read an FCS file. It demonstrates importing the library, specifying a file path, and parsing the metadata and data. ```python import fcsparser path = fcsparser.test_sample_path meta, data = fcsparser.parse(path, reformat_meta=True) ``` -------------------------------- ### GET /fcsparser/parse Source: https://context7.com/eyurtsev/fcsparser/llms.txt Parses an FCS file from a given path, allowing configuration of data types and text encoding. ```APIDOC ## GET /fcsparser/parse ### Description Parses an FCS file from a specified file path. Returns metadata and a pandas DataFrame or numpy array. ### Method GET ### Endpoint fcsparser.parse(path, dtype='float32', encoding='utf-8') ### Parameters #### Path Parameters - **path** (string) - Required - The file system path to the .fcs file. #### Query Parameters - **dtype** (string) - Optional - Data type for the output array (e.g., 'float32', 'float64', or None). - **encoding** (string) - Optional - Text encoding for the file (e.g., 'utf-8', 'latin-1'). ### Request Example fcsparser.parse('sample.fcs', dtype='float32', encoding='utf-8') ### Response #### Success Response (200) - **meta** (dict) - Metadata extracted from the FCS file. - **data** (DataFrame) - The parsed event data. #### Response Example (meta, data) = fcsparser.parse('sample.fcs') ``` -------------------------------- ### Plotting Raw FCS Data in Python Source: https://github.com/eyurtsev/fcsparser/blob/master/doc/fcsparser_example.ipynb This Python code snippet uses matplotlib to create a scatter plot of raw FCS data. It visualizes two channels, 'FITC-A' and 'AmCyan-A', without any applied transformations. Ensure matplotlib and pandas are installed for this to function. ```python import matplotlib.pyplot as plt # Assuming 'data' is a pandas DataFrame loaded from an FCS file # Example data structure: # data = {'FITC-A': [10, 20, 30, 40, 50], 'AmCyan-A': [15, 25, 35, 45, 55]} plt.scatter(data['FITC-A'], data['AmCyan-A'], alpha=0.8, color='gray') plt.xlabel('FITC-A') plt.ylabel('AmCyan-A') plt.title('Raw FCS Data Scatter Plot') plt.show() ``` -------------------------------- ### Initialize and Load FCS Data Source: https://github.com/eyurtsev/fcsparser/blob/master/doc/fcsparser_example.ipynb Demonstrates how to import the fcsparser library, locate a test sample file, and parse the metadata from an FCS file. ```python import fcsparser path = fcsparser.test_sample_path meta = fcsparser.parse(path, meta_data_only=True) print(type(meta)) print(meta.keys()) ``` -------------------------------- ### Configure Channel Naming Source: https://context7.com/eyurtsev/fcsparser/llms.txt Demonstrates how to control channel naming conventions using the channel_naming parameter, choosing between descriptive names ($PnS) or unique identifiers ($PnN). ```python import fcsparser path = 'sample.fcs' # Using descriptive names meta1, data1 = fcsparser.parse(path, channel_naming='$PnS') # Using short unique names meta2, data2 = fcsparser.parse(path, channel_naming='$PnN') ``` -------------------------------- ### Unpack Meta and Data from FCS File - Python Source: https://github.com/eyurtsev/fcsparser/blob/master/doc/fcsparser_example.ipynb This snippet demonstrates how to load both metadata and data from an FCS file using the fcsparser library. It specifies `meta_data_only=False` to retrieve all data and `reformat_meta=True` for cleaner metadata. The output shows the types of the returned meta (dictionary) and data (pandas DataFrame). ```python meta, data = fcsparser.parse(path, meta_data_only=False, reformat_meta=True) ``` ```python print type(meta) print type(data) ``` ```python data ``` -------------------------------- ### Basic Metadata Parsing Source: https://github.com/eyurtsev/fcsparser/blob/master/doc/fcsparser_example.ipynb This snippet demonstrates how to parse FCS files to extract only the metadata. The parser returns data exactly as recorded, without any transformations or compensations. ```APIDOC ## Basic Metadata Parsing ### Description Parses an FCS file to retrieve only its metadata. The data is returned in its raw format as stored in the file, requiring further processing for analysis and visualization. ### Method `fcsparser.parse() ### Endpoint N/A (Python library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fcsparser path = fcsparser.test_sample_path # path to a test data file meta = fcsparser.parse(path, meta_data_only=True) print type(meta) print meta.keys() ``` ### Response #### Success Response (200) - **type** (dict) - The type of the metadata object. - **keys** (list) - A list of keys representing the metadata fields available in the FCS file. #### Response Example ``` [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'$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', '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'] ``` ``` -------------------------------- ### POST /fcsparser/FCSParser Source: https://context7.com/eyurtsev/fcsparser/llms.txt Provides a class-based interface for advanced FCS parsing, including raw data access and byte-stream parsing. ```APIDOC ## POST /fcsparser/FCSParser ### Description Instantiates an FCSParser object for granular control over parsing, or uses from_data to parse from a bytes-like object. ### Method POST ### Endpoint FCSParser(path, read_data=True, channel_naming='$PnS') or FCSParser.from_data(bytes) ### Parameters #### Request Body - **path** (string) - Required - File path for the parser instance. - **read_data** (bool) - Optional - Whether to read the data segment immediately. - **channel_naming** (string) - Optional - Naming convention for channels. ### Request Example from fcsparser.api import FCSParser parser = FCSParser.from_data(fcs_bytes) ### Response #### Success Response (200) - **parser** (object) - An instance of the FCSParser class containing annotation, data, and analysis attributes. #### Response Example parser.dataframe ``` -------------------------------- ### Parse FCS File for Metadata and Data Source: https://context7.com/eyurtsev/fcsparser/llms.txt Basic usage of the parse function to extract metadata as a dictionary and experimental data as a pandas DataFrame. ```python import fcsparser path = 'sample.fcs' meta, data = fcsparser.parse(path) print(f"Number of events: {meta['$TOT']}") print(f"Data shape: {data.shape}") ``` -------------------------------- ### Parse FCS files with custom data types Source: https://context7.com/eyurtsev/fcsparser/llms.txt Demonstrates how to parse FCS files while specifying the numpy data type for the output array. This allows for memory optimization or precision adjustment. ```python import fcsparser path = 'sample.fcs' # Default behavior - convert to float32 meta, data = fcsparser.parse(path, dtype='float32') # Keep original data types meta, data = fcsparser.parse(path, dtype=None) # Use float64 for higher precision meta, data = fcsparser.parse(path, dtype='float64') ``` -------------------------------- ### Reformat FCS Metadata Source: https://github.com/eyurtsev/fcsparser/blob/master/doc/fcsparser_example.ipynb Shows how to parse an FCS file with the reformat_meta option enabled to structure the metadata into a more readable format, specifically accessing channel information. ```python meta = fcsparser.parse(path, meta_data_only=True, reformat_meta=True) print(meta['_channels_']) ``` -------------------------------- ### Reformatted Metadata Parsing Source: https://github.com/eyurtsev/fcsparser/blob/master/doc/fcsparser_example.ipynb This snippet shows how to parse FCS files with metadata reformatting enabled. This provides a more structured and readable representation of channel information. ```APIDOC ## Reformatted Metadata Parsing ### Description Parses an FCS file and reformats the metadata for improved readability, particularly for channel-related information. ### Method `fcsparser.parse() ### Endpoint N/A (Python library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import fcsparser path = fcsparser.test_sample_path # path to a test data file meta = fcsparser.parse(path, meta_data_only=True, reformat_meta=True) print meta['_channels_'] ``` ### Response #### Success Response (200) - **meta['_channels_']** (DataFrame) - A pandas DataFrame containing reformatted channel information, including channel names, bit depth, gain, range, and scaling factor. #### Response Example ``` $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 ``` ``` -------------------------------- ### Specify text encoding for FCS files Source: https://context7.com/eyurtsev/fcsparser/llms.txt Shows how to handle FCS files that use non-UTF-8 character encodings by passing an encoding parameter to the parse function. ```python import fcsparser path = 'sample.fcs' # Default UTF-8 encoding meta, data = fcsparser.parse(path, encoding='utf-8') # For files with different encodings meta, data = fcsparser.parse(path, encoding='latin-1') ``` -------------------------------- ### Access Multiple Data Sets Source: https://context7.com/eyurtsev/fcsparser/llms.txt Handles FCS files containing multiple data sets by specifying the index of the desired data set using the data_set parameter. ```python import fcsparser path = 'multi_dataset.fcs' meta0, data0 = fcsparser.parse(path, data_set=0) meta1, data1 = fcsparser.parse(path, data_set=1) ``` -------------------------------- ### Advanced parsing with FCSParser class Source: https://context7.com/eyurtsev/fcsparser/llms.txt Utilizes the FCSParser class for lower-level access to FCS components, including raw metadata, channel naming strategies, and direct DataFrame conversion. ```python from fcsparser.api import FCSParser path = 'sample.fcs' parser = FCSParser(path, read_data=True, channel_naming='$PnS') annotation = parser.annotation data = parser.data channel_names = parser.get_channel_names() df = parser.dataframe parser.reformat_meta() ``` -------------------------------- ### Parse FCS File with Reformatted Metadata Source: https://context7.com/eyurtsev/fcsparser/llms.txt Parses an FCS file with the reformat_meta option enabled to organize channel information into a dedicated pandas DataFrame. ```python import fcsparser path = 'sample.fcs' meta, data = fcsparser.parse(path, reformat_meta=True) channels_df = meta['_channels_'] print(channels_df) ``` -------------------------------- ### Analyze and visualize FCS data Source: https://context7.com/eyurtsev/fcsparser/llms.txt Provides a workflow for parsing, filtering, and visualizing flow cytometry data using pandas and matplotlib. ```python import fcsparser import matplotlib.pyplot as plt path = fcsparser.test_sample_path meta, data = fcsparser.parse(path, reformat_meta=True) filtered = data[data['FSC-A'] > 0] plt.scatter(data['FITC-A'], data['AmCyan-A'], alpha=0.3, s=1, c='gray') plt.savefig('scatter_plot.png') ``` -------------------------------- ### Extract Metadata Only Source: https://context7.com/eyurtsev/fcsparser/llms.txt Retrieves only the metadata segment of an FCS file without loading the full experimental data, which is efficient for large files. ```python import fcsparser path = 'sample.fcs' meta = fcsparser.parse(path, meta_data_only=True) print(f"Date: {meta.get('$DATE')}") print(f"Total events: {meta.get('$TOT')}") ``` -------------------------------- ### Parse FCS data from bytes Source: https://context7.com/eyurtsev/fcsparser/llms.txt Enables parsing of FCS data directly from a bytes-like object, which is useful for processing streams or data retrieved from databases. ```python from fcsparser.api import FCSParser with open('sample.fcs', 'rb') as f: fcs_bytes = f.read() parser = FCSParser.from_data(fcs_bytes) df = parser.dataframe ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.