Example #1
0
    def testRoundtripWithBeadCalibration(self):
        self.cwd = os.path.dirname(os.path.abspath(__file__))
        self.ex = flow.ImportOp(conditions={
            'Dox': 'float'
        },
                                tubes=[
                                    flow.Tube(file=self.cwd +
                                              '/data/tasbe/rby.fcs',
                                              conditions={'Dox': 1.0})
                                ]).apply()

        op = flow.BeadCalibrationOp(
            units={"PE-Tx-Red-YG-A": "MEPTR"},
            beads_file=self.cwd + '/data/tasbe/beads.fcs',
            beads=flow.BeadCalibrationOp.BEADS[
                "Spherotech RCP-30-5A Lot AA01-AA04, AB01, AB02, AC01, GAA01-R"]
        )
        op.estimate(self.ex)

        ex2 = op.apply(self.ex)

        flow.ExportFCS(path=self.directory, by=['Dox']).export(ex2)

        tube1 = flow.Tube(file=self.directory + '/Dox_1.0.fcs',
                          conditions={"Dox": 1.0})
        ex_rt = flow.ImportOp(conditions={
            'Dox': 'float'
        }, tubes=[tube1]).apply()

        self.assertNotIn('voltage', ex_rt.metadata['PE-Tx-Red-YG-A'])
Example #2
0
 def testChooseChannels(self):
     tube1 = flow.Tube(file = self.cwd + '/data/Plate01/RFP_Well_A3.fcs', conditions = {"Dox" : 10.0})
     
     ex = flow.ImportOp(conditions = {"Dox" : "float"},
                        tubes = [tube1],
                        channels = {'Y2-A' : "Yellow"}).apply()
                        
     self.assertTrue(ex.channels == ["Yellow"])
     with self.assertRaises(RuntimeError):
         flow.ImportOp(conditions = {"Dox" : "float"},
                       tubes = [tube1],
                       channels = {'Y2-B' : "Blue"}).apply()
Example #3
0
 def setUp(self):
     import os
     self.cwd = os.path.dirname(
         os.path.abspath(__file__)) + "/data/Plate01/"
     tube1 = flow.Tube(file=self.cwd + 'RFP_Well_A3.fcs', conditions={})
     import_op = flow.ImportOp(conditions={}, tubes=[tube1])
     self.ex = import_op.apply()
Example #4
0
 def testMetadata(self):
     tube1 = flow.Tube(file = self.cwd + '/data/Plate01/RFP_Well_A3.fcs', conditions = {"Dox" : 10.0})
     tube2 = flow.Tube(file= self.cwd + '/data/Plate01/CFP_Well_A4.fcs', conditions = {"Dox" : 10.0})
     import_op = flow.ImportOp(conditions = {"Dox" : "float"},
                               tubes = [tube1, tube2])
     with self.assertRaises(RuntimeError):
         import_op.apply()
Example #5
0
 def setUp(self):
     self.cwd = os.path.dirname(os.path.abspath(__file__))
     self.ex = flow.ImportOp(conditions = {},
                             tubes = [flow.Tube(file = self.cwd + '/data/tasbe/mkate.fcs',
                                                conditions = {})]).apply()
     
     self.op = flow.HlogTransformOp(channels = ["FSC-A", "Pacific Blue-A"])
Example #6
0
    def setUp(self):
        self.cwd = os.path.dirname(
            os.path.abspath(__file__)) + "/data/Plate01/"
        tube1 = flow.Tube(file=self.cwd + 'RFP_Well_A3.fcs',
                          conditions={"Dox": 10.0})
        tube2 = flow.Tube(file=self.cwd + 'CFP_Well_A4.fcs',
                          conditions={"Dox": 1.0})
        import_op = flow.ImportOp(conditions={"Dox": "float"},
                                  tubes=[tube1, tube2])
        ex = import_op.apply()

        # this works so much better on transformed data
        logicle = flow.LogicleTransformOp()
        logicle.name = "Logicle transformation"
        logicle.channels = ['V2-A', 'Y2-A', 'B1-A']
        logicle.estimate(ex)
        self.ex = logicle.apply(ex)

        self.gate = flow.Range2DOp(name="Range2D",
                                   xchannel="V2-A",
                                   ychannel="Y2-A",
                                   xlow=0.0,
                                   xhigh=0.4,
                                   ylow=0.4,
                                   yhigh=0.8)
Example #7
0
 def setUp(self):
     self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/Plate01/"
     tube1 = flow.Tube(file = self.cwd + 'RFP_Well_A3.fcs', conditions = {"Dox" : 10.0, "Well" : "A"})
     tube2 = flow.Tube(file= self.cwd + 'CFP_Well_A4.fcs', conditions = {"Dox" : 1.0, "Well" : "B"})
     import_op = flow.ImportOp(conditions = {"Dox" : "float", "Well" : "category"},
                               tubes = [tube1, tube2])
     self.ex = import_op.apply()
Example #8
0
    def testRoundtrip(self):
        flow.ExportFCS(path=self.directory, by=['Dox']).export(self.ex)

        tube1 = flow.Tube(file=self.directory / 'Dox_10.0.fcs',
                          conditions={
                              "Dox": 10.0,
                              "Well": "A"
                          })
        tube2 = flow.Tube(file=self.directory / 'Dox_1.0.fcs',
                          conditions={
                              "Dox": 1.0,
                              "Well": "B"
                          })

        ex_rt = flow.ImportOp(conditions={
            "Dox": "float",
            "Well": "category"
        },
                              tubes=[tube1, tube2]).apply()

        self.assertTrue((self.ex.data == ex_rt.data).all().all())

        for channel in self.ex.channels:
            self.assertEqual(self.ex.metadata[channel]['range'],
                             ex_rt.metadata[channel]['range'])
Example #9
0
 def setUp(self):
     self.cwd = os.path.dirname(os.path.abspath(__file__))
     self.ex = flow.ImportOp(conditions={},
                             tubes=[
                                 flow.Tube(file=self.cwd +
                                           '/data/tasbe/mkate.fcs',
                                           conditions={})
                             ]).apply()
Example #10
0
 def testImport(self):
     tube1 = flow.Tube(file=self.cwd + '/data/Plate01/RFP_Well_A3.fcs',
                       conditions={"Dox": 10.0})
     tube2 = flow.Tube(file=self.cwd + '/data/Plate01/CFP_Well_A4.fcs',
                       conditions={"Dox": 1.0})
     import_op = flow.ImportOp(conditions={"Dox": "float"},
                               tubes=[tube1, tube2])
     import_op.apply()
Example #11
0
 def testCategories(self):
     tube1 = flow.Tube(file=self.cwd + '/data/Plate01/RFP_Well_A3.fcs',
                       conditions={"Dox": "one"})
     tube2 = flow.Tube(file=self.cwd + '/data/Plate01/CFP_Well_A4.fcs',
                       conditions={"Dox": "two"})
     import_op = flow.ImportOp(conditions={"Dox": "category"},
                               tubes=[tube1, tube2])
     import_op.apply()
Example #12
0
    def load_experimental_data(self,
                               keyfile,
                               datadir="",
                               inducer="Inducer Level"):
        """ 
        We detect experimental file by the control column being empty
        """
        #Set indices of keyfile columns
        file_col = 0
        part_col = 1
        control_col = 2
        condition_col = 3
        time_col = 4
        regulation_col = 5

        all_experiments = []  #experiments will be added to this list
        #Keep track of replicates with 2-level dict with default count of 0.
        # Dict[media_conditions][time] = 0
        replicates_dict = defaultdict(lambda: defaultdict(lambda: 0))

        num_rows = keyfile.shape[0]
        for row in range(num_rows):
            if keyfile[row][control_col] == "":
                filename = keyfile[row][file_col]
                experiment_time = keyfile[row][time_col]

                #Parse Media conditions which are numbers. Ignore units like  nM or ul/M
                condition = keyfile[row][condition_col]
                condition = re.search(r'[\d|.]{1,}', condition).group()

                #Check for replicate experiments
                replicates_dict[str(condition)][str(experiment_time)] += 1
                rep = replicates_dict[str(condition)][str(experiment_time)]

                #Set the metadata for the experiment
                #print("Loading replicate: %i" % rep)
                tube = flow.Tube(file=os.path.join(datadir, filename),
                                 conditions={
                                     inducer: float(condition),
                                     'Replicate': int(rep)
                                 })

                all_experiments.append(tube)

        ##Load data
        ### Combine files into single dataframe and import data
        import_op = flow.ImportOp(conditions={
            'Dox': "float",
            'Replicate': "int"
        },
                                  tubes=all_experiments,
                                  coarse=False,
                                  coarse_events=10000)
        cytometry_experiments = import_op.apply()

        print("Successfully loaded %i experimental files." %
              len(all_experiments))
        return cytometry_experiments
Example #13
0
    def setUp(self):

        from cytoflow import Tube
             
        self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/tasbe/"
     
        tube = Tube(file = self.cwd + "rby.fcs")
        
        self.ex = flow.ImportOp(tubes = [tube])
 def setUp(self):
     import os
     self.cwd = os.path.dirname(os.path.abspath(__file__))
     self.ex = flow.ImportOp(conditions = {},
                             tubes = [flow.Tube(file = self.cwd + '/data/tasbe/rby.fcs',
                                                conditions = {})]).apply()        
     
     self.op = flow.BleedthroughPiecewiseOp(
                              controls = {"FITC-A" : self.cwd + '/data/tasbe/eyfp.fcs',
                                          "PE-Tx-Red-YG-A" : self.cwd + '/data/tasbe/mkate.fcs'})
    def createExperiment(self, fcsfile, condition):
        """
        Data processing for an individual FCS file, allowing for data transformations to be applied at this time.

        Reads the data through the CytoFlow API,
        Converts the data into a numPy dataset, applies transformations as requested through the Flow Utils API,
        and then converts it back into a pandas Dataframe, adding it to the SQL database file in the process.
        This step can be optimized in the future to reduce memory and increase the speed of transformations.

        Parameters
        ----------
        fcsfile : str
            Name of the FCS file to process
        condition : int
            Value of a classificiation column for future potential machine learning implementations.

        """
        tube1 = flow.Tube(file=os.path.join(self.file_loc, fcsfile),
                          conditions={'NN': condition})
        import_op = flow.ImportOp(conditions={'NN': 'float'}, tubes=[tube1])

        exp = import_op.apply()
        allDat = exp.data

        def convertToDF(nparr, columns):
            data = pd.DataFrame(columns=columns)
            for i in range(len(nparr)):
                data.loc[i] = list(nparr[i])
            return data

        def hyperlog(df):
            nparr = df.values
            mod_events = fu.transforms.hyperlog(nparr,
                                                np.arange(0, len(df.columns)))
            mod_pd = convertToDF(mod_events, df.columns)
            return mod_pd

        def logicle(df):
            nparr = df.values
            mod_events = fu.transforms.logicle(nparr,
                                               np.arange(0, len(df.columns)))
            mod_pd = convertToDF(mod_events, df.columns)
            return mod_pd

        if (self.transformation == "hyperlog"):
            allDat = hyperlog(allDat)
        elif (self.transformation == "logicle"):
            allDat = logicle(allDat)

        #Export to SQLDB
        try:
            allDat.to_sql(fcsfile, self.conn)
        except Error as e:
            print(e)
        return allDat
Example #16
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("fcs_file", help="FCS file to analyze")
    args = parser.parse_args()

    op = flow.ImportOp(tubes=[flow.Tube(file=args.fcs_file, conditions={})])
    ex = op.apply()
    for c in ex.channels:
        m = ex.metadata[c]
        if "voltage" in m:
            print "{0}\t{1}".format(c, m["voltage"])
    def setUp(self):
        import os
        self.cwd = os.path.dirname(os.path.abspath(__file__))
        self.ex = flow.ImportOp(conditions = {},
                                tubes = [flow.Tube(file = self.cwd + '/data/tasbe/blank.fcs',
                                                   conditions = {})]).apply()

        self.op = flow.AutofluorescenceOp(
                    blank_file = self.cwd + '/data/tasbe/blank.fcs',
                    channels = ["Pacific Blue-A", "FITC-A", "PE-Tx-Red-YG-A"])
        self.op.estimate(self.ex)
Example #18
0
    def setUp(self):
        self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/Plate01/"
        tube1 = flow.Tube(file = self.cwd + 'RFP_Well_A3.fcs', conditions = {"Dox" : 10.0})
        tube2 = flow.Tube(file= self.cwd + 'CFP_Well_A4.fcs', conditions = {"Dox" : 1.0})
        import_op = flow.ImportOp(conditions = {"Dox" : "float"},
                                  tubes = [tube1, tube2])
        self.ex = import_op.apply()

        self.gate = flow.ThresholdOp(name = "Threshold",
                                     channel = "Y2-A",
                                     threshold = 500)
 def testApply(self):
     
     ex = flow.ImportOp(tubes = [flow.Tube(file = self.cwd + '/data/tasbe/blank.fcs')]).apply()
     ex2 = self.op.apply(ex)
     
     import numpy as np
     self.assertAlmostEqual(np.median(ex2["FITC-A"]), 0.0)
     self.assertAlmostEqual(np.median(ex2["Pacific Blue-A"]), 0.0)
     self.assertAlmostEqual(np.median(ex2["PE-Tx-Red-YG-A"]), 0.0)
     
     with self.assertRaises(ValueError):
         self.assertFalse((self.ex.data == ex2.data).all().all())
Example #20
0
 def setUp(self):
     import os
     self.cwd = os.path.dirname(os.path.abspath(__file__))
     self.ex = flow.ImportOp(conditions = {},
                             tubes = [flow.Tube(file = self.cwd + '/data/tasbe/rby.fcs',
                                                conditions = {})]).apply()        
     
     self.op = flow.BeadCalibrationOp(
                 units = {"PE-Tx-Red-YG-A" : "MEPTR"},
                 beads_file = self.cwd + '/data/tasbe/beads.fcs',
                 beads = flow.BeadCalibrationOp.BEADS["Spherotech RCP-30-5A Lot AA01-AA04, AB01, AB02, AC01, GAA01-R"])
     self.op.estimate(self.ex)
Example #21
0
    def setUp(self):
        self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/Plate01/"
        tube1 = flow.Tube(file = self.cwd + 'RFP_Well_A3.fcs', conditions = {"Dox" : 10.0})
        tube2 = flow.Tube(file= self.cwd + 'CFP_Well_A4.fcs', conditions = {"Dox" : 1.0})
        import_op = flow.ImportOp(conditions = {"Dox" : "float"},
                                  tubes = [tube1, tube2])
        self.ex = import_op.apply()

        self.op = flow.FlowPeaksOp(name = "FP",
                                   channels = ["V2-A", "Y2-A"],
                                   scale = {"V2-A" : "logicle",
                                            "Y2-A" : "logicle"},
                                   h0 = 0.5)
Example #22
0
 def setUp(self):
     import os
     self.cwd = os.path.dirname(os.path.abspath(__file__))
     self.ex = flow.ImportOp(conditions = {'Dox' : 'int'},
                             tubes = [flow.Tube(file = self.cwd + '/data/tasbe/rby.fcs',
                                                conditions = {'Dox' : 10})]).apply()        
     
     self.op = flow.BleedthroughLinearOp(
                     controls = {"FITC-A" : self.cwd + '/data/tasbe/eyfp.fcs',
                                 "PE-Tx-Red-YG-A" : self.cwd + '/data/tasbe/mkate.fcs',
                                 "Pacific Blue-A" : self.cwd + '/data/tasbe/ebfp.fcs'})
         
     self.op.estimate(self.ex)
Example #23
0
    def setUp(self):
        self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/Plate01/"
        tube1 = flow.Tube(file = self.cwd + 'RFP_Well_A3.fcs', conditions = {"Dox" : 10.0})
        tube2 = flow.Tube(file= self.cwd + 'CFP_Well_A4.fcs', conditions = {"Dox" : 1.0})
        import_op = flow.ImportOp(conditions = {"Dox" : "float"},
                                  tubes = [tube1, tube2])
        self.ex = import_op.apply()

        self.gate = flow.Range2DOp(name = "Range2D",
                                   xchannel = "V2-A",
                                   ychannel = "Y2-A",
                                   xlow = -200, xhigh = 800,
                                   ylow = 800, yhigh = 30000)
Example #24
0
    def testRoundtrip(self):
        flow.ExportFCS(path=self.directory, by=['Dox']).export(self.ex)

        tube1 = flow.Tube(file=self.directory + '/Dox_10.0.fcs',
                          conditions={"Dox": 10.0})
        tube2 = flow.Tube(file=self.directory + '/Dox_1.0.fcs',
                          conditions={"Dox": 1.0})

        ex_rt = flow.ImportOp(conditions={
            "Dox": "float"
        },
                              tubes=[tube1, tube2]).apply()

        self.assertTrue((self.ex.data == ex_rt.data).all().all())
Example #25
0
    def setUp(self):
        self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/Plate01/"

        tube1 = flow.Tube(file = self.cwd + 'RFP_Well_A3.fcs', conditions = {"Dox" : 10.0})
        tube2 = flow.Tube(file= self.cwd + 'CFP_Well_A4.fcs', conditions = {"Dox" : 1.0})
        import_op = flow.ImportOp(conditions = {"Dox" : "float"},
                                  tubes = [tube1, tube2])
        self.ex = import_op.apply()
        
        self.gate = flow.GaussianMixtureOp(name = "Gauss",
                                           channels = ["Y2-A"],
                                           sigma = 0.5,
                                           num_components = 2,
                                           scale = {"Y2-A" : "logicle"},
                                           posteriors = True)
Example #26
0
 def setUp(self):
     import os
     self.cwd = os.path.dirname(os.path.abspath(__file__))
     self.ex = flow.ImportOp(conditions = {'Dox' : 'int'},
                             tubes = [flow.Tube(file = self.cwd + '/data/tasbe/mkate.fcs',
                                                conditions = {'Dox' : 3})]).apply()        
     
     self.op = flow.ColorTranslationOp(
                     controls = {("PE-Tx-Red-YG-A", "FITC-A") :
                                 self.cwd + '/data/tasbe/rby.fcs',
                                 ("Pacific Blue-A", "FITC-A") :
                                 self.cwd + '/data/tasbe/rby.fcs'},
                     mixture_model = True)
         
     self.op.estimate(self.ex)
Example #27
0
    def setUp(self):
        self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/Plate01/"
        tube1 = flow.Tube(file = self.cwd + 'RFP_Well_A3.fcs', conditions = {"Dox" : 10.0})
        tube2 = flow.Tube(file= self.cwd + 'CFP_Well_A4.fcs', conditions = {"Dox" : 1.0})
        import_op = flow.ImportOp(conditions = {"Dox" : "float"},
                                  tubes = [tube1, tube2])
        self.ex = import_op.apply()

        self.op = flow.PCAOp(name = "PCA",
                             channels = ["V2-A", "V2-H", "Y2-A", "Y2-H"],
                             scale = {"V2-A" : "log",
                                      "V2-H" : "log",
                                      "Y2-A" : "log",
                                      "Y2-H" : "log"},
                             num_components = 2)
Example #28
0
    def setUp(self):
        self.cwd = os.path.dirname(
            os.path.abspath(__file__)) + "/data/Plate01/"
        tube1 = flow.Tube(file=self.cwd + 'RFP_Well_A3.fcs',
                          conditions={"Dox": 10.0})
        tube2 = flow.Tube(file=self.cwd + 'CFP_Well_A4.fcs',
                          conditions={"Dox": 1.0})
        import_op = flow.ImportOp(conditions={"Dox": "float"},
                                  tubes=[tube1, tube2])
        self.ex = import_op.apply()

        self.gate = flow.DensityGateOp(name="D",
                                       xchannel="V2-A",
                                       ychannel="Y2-A",
                                       xscale="logicle",
                                       yscale="logicle",
                                       keep=0.8)
Example #29
0
    def setUp(self):
        self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/Plate01/"

        tube1 = flow.Tube(file = self.cwd + 'RFP_Well_A3.fcs', conditions = {"Dox" : 10.0})
        tube2 = flow.Tube(file= self.cwd + 'CFP_Well_A4.fcs', conditions = {"Dox" : 1.0})
        import_op = flow.ImportOp(conditions = {"Dox" : "float"},
                                  tubes = [tube1, tube2])
        self.ex = import_op.apply()
        
        self.ex = flow.ThresholdOp(name = "T",
                                   channel = "Y2-A",
                                   threshold = 500).apply(self.ex)
                                   
        self.ex = flow.ChannelStatisticOp(name = "ByDox",
                                          by = ['Dox', 'T'],
                                          channel = "Y2-A",
                                          function = len).apply(self.ex)
Example #30
0
    def testManufacturers(self):
        files = [
            'Accuri - C6.fcs', 'Applied Biosystems - Attune.fcs',
            'BD - FACS Aria II.fcs', 'Beckman Coulter - Cyan.fcs',
            'Beckman Coulter - Cytomics FC500.LMD',
            'Beckman Coulter - Gallios.LMD',
            'Beckman Coulter - MoFlo Astrios - linear settings.fcs',
            'Beckman Coulter - MoFlo Astrios - log settings.fcs',
            'Beckman Coulter - MoFlo XDP.fcs', 'Cytek DxP10.fcs',
            'Cytek xP5.fcs', 'iCyt - Eclipse.lmd', 'Millipore - Guava.fcs',
            'Miltenyi Biotec - MACSQuant Analyzer.fcs', 'Partec - PAS.FCS',
            'Stratedigm - S1400.fcs',
            'System II listmode with extra info in bits D10-D15.LMD'
        ]

        for file in files:
            path = self.cwd + '/data/instruments/' + file
            import_op = flow.ImportOp(tubes=[flow.Tube(file=path)])
            import_op.apply()