<commit_before>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "    Create tests for various FACS file formats:\n",
    "        1. Windows vs. Mac format testing\n",
    "        2. Tests for various outputs from different flow cytometry machines (ACCURI, CANTO, FACSCAN)\n",
    "\"\"\"\n",
    "import os\n",
    "import re\n",
    "import csv\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import unittest\n",
    "\n",
    "ACCURI_PATTERN = re.compile(r'(Well)_([A-Z]\\d{2})')\n",
    "CANTO_PATTERN = re.compile(r'[\\w\\d_-]+_[A-Z]\\d+_(?P<well>[A-Z]\\d{2})')\n",
    "FACSCAN_PATTERN = re.compile(r'(?P<plate>\\d{2})(?P<well>[A-Z]\\d{2})')\n",
    "ANTIGEN_PATTERN = re.compile(r'(Ag\\d+)')\n",
    "ALPHABET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n",
    "\n",
    "def well_name_position(well_name, columns=12):\n",
    "    '''Convert a well name (A01-K12) or (1-96) to its position (1-96)\n",
    "    '''\n",
    "    match = re.match( r\"^(?P<row>[A-W])?(?P<column>\\d{1,2})$\", well_name.upper())\n",
    "    if match:\n",
    "        # If there is an alphanumeric row position\n",
    "        if match.group(\"row\"):\n",
    "            row = ALPHABET.index(match.group(\"row\"))\n",
    "            column = int(match.group(\"column\"))\n",
    "            return (row * columns) + column\n",
    "        # Otherwise the only position is an absolute one\n",
    "        else:\n",
    "            return int(match.group(\"column\"))\n",
    "    else:\n",
    "        raise ValueError(\"Invalid well_name: %s\" % str(well_name))\n",
    "\n",
    "\n",
    "def match_facs_pattern_pos(line):\n",
    "    \"\"\"Identify line pattern (ACCURI, CANTO, FACSCAN).\n",
    "\n",
    "        Args: \n",
    "            line: a string in the \"Sample\" columns\n",
    "        Returns:\n",
    "            Numerical representation of the well position (i.e. A01 -> 1; H12 -> 96)\n",
    "    \"\"\"\n",
    "    match_accuri = ACCURI_PATTERN.search(line)\n",
    "    match_canto = CANTO_PATTERN.search(line)\n",
    "    match_facscan = FACSCAN_PATTERN.search(line)\n",
    "    # convert well pos -> integer\n",
    "    if match_accuri:\n",
    "        return well_name_position(match_accuri.group(2))\n",
    "    elif match_canto:\n",
    "        return well_name_position(match_canto.group(1))\n",
    "    elif match_facscan:\n",
    "        return well_name_position(match_facscan.group(2))\n",
    "    else:\n",
    "        raise ValueError(\"There is no matching pattern for this file type.\")\n",
    "\n",
    "        \n",
    "def facs_parse_file(data_file, cols=12):\n",
    "    \"\"\" Parsing FLOWJO FACS files.\n",
    "    Args:\n",
    "        data_file: file to Parse\n",
    "    Returns:\n",
    "        plates: {'plate - position': [values,]}\n",
    "    \"\"\"\n",
    "    # get the file name and remove all white spaces\n",
    "    file_name = os.path.basename(data_file.name).split('.')[0].replace(' ', '')\n",
    "    # handle different delimiters and file formats (csv, tsv) on Windows and Mac \n",
    "    sniffer = csv.Sniffer()\n",
    "    dialect = sniffer.sniff(data_file.read().replace('\\r', '\\n'))\n",
    "    data_file.seek(0) # go to the beginning of the file\n",
    "    # data frame manipulations\n",
    "    df = pd.read_csv(data_file, sep=dialect.delimiter)\n",
    "    # keep all of the rows expect Mean and StdDev\n",
    "    df = df.loc[~df['Sample'].isin(['Mean', 'StdDev'])]\n",
    "    # replace a \"*\" with -1\n",
    "    df = df.replace(['*'], [-1])\n",
    "    # get antigens from columns\n",
    "    antigens = df.columns[1:]\n",
    "    # round all values to 4 significant figures\n",
    "    current_indexes = [match_facs_pattern_pos(line) for line in df['Sample'] if line not in ('Mean', 'StdDev')]\n",
    "    full_index = range(1, 97)\n",
    "    # cannot reindex if 1-96 indexes are present\n",
    "    if current_indexes != full_index:\n",
    "        df.index += 1 # index from 1 (not 0)\n",
    "        df.index = current_indexes # reset index as representated by Sample column\n",
    "        df = df.reindex(full_index, fill_value=1) # reindex to add missing values\n",
    "    plates = {\"{} - {}\".format(file_name, antigen): list(df[antigen]) for antigen in antigens}\n",
    "    return plates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      ".\n",
      "----------------------------------------------------------------------\n",
      "Ran 1 test in 0.025s\n",
      "\n",
      "OK\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<unittest.runner.TextTestResult run=1 errors=0 failures=0>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CWD = os.getcwd()\n",
    "expected_output_all = {'accuri - Population 2': [6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 12.0], \n",
    "                       'accuri - Population 3': [7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 14.0], \n",
    "                       'accuri - Population 1': [4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 10.0]}\n",
    "\n",
    "class TestFacs(unittest.TestCase):\n",
    "    \"\"\"\n",
    "        Testing parsing outputs from different flow cytomentry machines (ACCURI, CANTO, FACSCAN)\n",
    "    \"\"\"\n",
    "    \n",
    "    def test_accuri_96(self):\n",
    "        file_name = os.path.join(CWD, 'DATA', 'facs_files_04_2016', 'machine_formats', 'accuri.txt')\n",
    "        with open(file_name, 'r') as data_file:\n",
    "            output = facs_parse_file(data_file)\n",
    "            self.assertEqual(output, expected_output_all)\n",
    "\n",
    "suite = unittest.TestSuite()\n",
    "suite.addTest(TestFacs(\"test_accuri_96\"))\n",
    "runner = unittest.TextTestRunner()\n",
    "runner.run(suite)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"<commit_msg>Adding tests for flow cytometry assay parsing.<commit_after>{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "    Create tests for various FACS file formats:\n",
    "        1. Windows vs. Mac format testing\n",
    "        2. Tests for various outputs from different flow cytometry machines (ACCURI, CANTO, FACSCAN)\n",
    "\"\"\"\n",
    "import os\n",
    "import re\n",
    "import csv\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import unittest\n",
    "\n",
    "ACCURI_PATTERN = re.compile(r'(Well)_([A-Z]\\d{2})')\n",
    "CANTO_PATTERN = re.compile(r'[\\w\\d_-]+_[A-Z]\\d+_(?P<well>[A-Z]\\d{2})')\n",
    "FACSCAN_PATTERN = re.compile(r'(?P<plate>\\d{2})(?P<well>[A-Z]\\d{2})')\n",
    "ANTIGEN_PATTERN = re.compile(r'(Ag\\d+)')\n",
    "ALPHABET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n",
    "\n",
    "def well_name_position(well_name, columns=12):\n",
    "    '''Convert a well name (A01-K12) or (1-96) to its position (1-96)\n",
    "    '''\n",
    "    match = re.match( r\"^(?P<row>[A-W])?(?P<column>\\d{1,2})$\", well_name.upper())\n",
    "    if match:\n",
    "        # If there is an alphanumeric row position\n",
    "        if match.group(\"row\"):\n",
    "            row = ALPHABET.index(match.group(\"row\"))\n",
    "            column = int(match.group(\"column\"))\n",
    "            return (row * columns) + column\n",
    "        # Otherwise the only position is an absolute one\n",
    "        else:\n",
    "            return int(match.group(\"column\"))\n",
    "    else:\n",
    "        raise ValueError(\"Invalid well_name: %s\" % str(well_name))\n",
    "\n",
    "\n",
    "def match_facs_pattern_pos(line):\n",
    "    \"\"\"Identify line pattern (ACCURI, CANTO, FACSCAN).\n",
    "\n",
    "        Args: \n",
    "            line: a string in the \"Sample\" columns\n",
    "        Returns:\n",
    "            Numerical representation of the well position (i.e. A01 -> 1; H12 -> 96)\n",
    "    \"\"\"\n",
    "    match_accuri = ACCURI_PATTERN.search(line)\n",
    "    match_canto = CANTO_PATTERN.search(line)\n",
    "    match_facscan = FACSCAN_PATTERN.search(line)\n",
    "    # convert well pos -> integer\n",
    "    if match_accuri:\n",
    "        return well_name_position(match_accuri.group(2))\n",
    "    elif match_canto:\n",
    "        return well_name_position(match_canto.group(1))\n",
    "    elif match_facscan:\n",
    "        return well_name_position(match_facscan.group(2))\n",
    "    else:\n",
    "        raise ValueError(\"There is no matching pattern for this file type.\")\n",
    "\n",
    "        \n",
    "def facs_parse_file(data_file, cols=12):\n",
    "    \"\"\" Parsing FLOWJO FACS files.\n",
    "    Args:\n",
    "        data_file: file to Parse\n",
    "    Returns:\n",
    "        plates: {'plate - position': [values,]}\n",
    "    \"\"\"\n",
    "    # get the file name and remove all white spaces\n",
    "    file_name = os.path.basename(data_file.name).split('.')[0].replace(' ', '')\n",
    "    # handle different delimiters and file formats (csv, tsv) on Windows and Mac \n",
    "    sniffer = csv.Sniffer()\n",
    "    dialect = sniffer.sniff(data_file.read().replace('\\r', '\\n'))\n",
    "    data_file.seek(0) # go to the beginning of the file\n",
    "    # data frame manipulations\n",
    "    df = pd.read_csv(data_file, sep=dialect.delimiter)\n",
    "    # keep all of the rows expect Mean and StdDev\n",
    "    df = df.loc[~df['Sample'].isin(['Mean', 'StdDev'])]\n",
    "    # replace a \"*\" with -1\n",
    "    df = df.replace(['*'], [-1])\n",
    "    # get antigens from columns\n",
    "    antigens = df.columns[1:]\n",
    "    # round all values to 4 significant figures\n",
    "    current_indexes = [match_facs_pattern_pos(line) for line in df['Sample'] if line not in ('Mean', 'StdDev')]\n",
    "    full_index = range(1, 97)\n",
    "    # cannot reindex if 1-96 indexes are present\n",
    "    if current_indexes != full_index:\n",
    "        df.index += 1 # index from 1 (not 0)\n",
    "        df.index = current_indexes # reset index as representated by Sample column\n",
    "        df = df.reindex(full_index, fill_value=1) # reindex to add missing values\n",
    "    plates = {\"{} - {}\".format(file_name, antigen): list(df[antigen]) for antigen in antigens}\n",
    "    return plates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "...\n",
      "----------------------------------------------------------------------\n",
      "Ran 3 tests in 0.048s\n",
      "\n",
      "OK\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<unittest.runner.TextTestResult run=3 errors=0 failures=0>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CWD = os.getcwd()\n",
    "expected_output_all_accuri = {'accuri - Population 2': [6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 12.0], \n",
    "                              'accuri - Population 3': [7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 14.0], \n",
    "                              'accuri - Population 1': [4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 10.0]}\n",
    "\n",
    "expected_output_all_canto = {'canto - Population 2': [6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 12.0], \n",
    "                             'canto - Population 3': [7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 14.0], \n",
    "                             'canto - Population 1': [4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 10.0]}\n",
    "\n",
    "expected_output_all_facscan = {'facscan - Population 2': [6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 6.25, 12.0], \n",
    "                               'facscan - Population 3': [7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 7.25, 14.0], \n",
    "                               'facscan - Population 1': [4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 4.25, 10.0]}\n",
    "\n",
    "\n",
    "class TestFacs(unittest.TestCase):\n",
    "    \"\"\"\n",
    "        Testing parsing outputs from different flow cytomentry machines (ACCURI, CANTO, FACSCAN)\n",
    "    \"\"\"\n",
    "    \n",
    "    def test_accuri_96(self):\n",
    "        file_name = os.path.join(CWD, 'DATA', 'facs_files_04_2016', 'machine_formats', 'accuri.txt')\n",
    "        with open(file_name, 'r') as data_file:\n",
    "            output = facs_parse_file(data_file)\n",
    "            self.assertEqual(output, expected_output_all_accuri)\n",
    "            \n",
    "            \n",
    "    def test_canto_96(self):\n",
    "        file_name = os.path.join(CWD, 'DATA', 'facs_files_04_2016', 'machine_formats', 'canto.txt')\n",
    "        with open(file_name, 'r') as data_file:\n",
    "            output = facs_parse_file(data_file)\n",
    "            self.assertEqual(output, expected_output_all_canto)\n",
    "            \n",
    "            \n",
    "    def test_facscan_96(self):\n",
    "        file_name = os.path.join(CWD, 'DATA', 'facs_files_04_2016', 'machine_formats', 'facscan.txt')\n",
    "        with open(file_name, 'r') as data_file:\n",
    "            output = facs_parse_file(data_file)\n",
    "            self.assertEqual(output, expected_output_all_facscan)\n",
    "\n",
    "suite = unittest.TestSuite()\n",
    "suite.addTest(TestFacs(\"test_accuri_96\"))\n",
    "suite.addTest(TestFacs(\"test_canto_96\"))\n",
    "suite.addTest(TestFacs(\"test_facscan_96\"))\n",
    "runner = unittest.TextTestRunner()\n",
    "runner.run(suite)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
{'fraction_non_alphanumeric': 0.24811016418700949, 'fraction_numerical': 0.17492416582406473, 'mean_word_length': 2.0338884019865615, 'pattern_counts': {'":': 64, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2880665', 'n_tokens_mistral': 12089, 'n_tokens_neox': 9561, 'n_words': 2126}