def activated(self): # add an import plugin plugin = ImportPlugin() wi = WorkflowItem(task=self) wi.operation = plugin.get_operation() self.model.workflow.append(wi) self.model.selected = wi # if we're debugging, add a few data bits if self.debug: from cytoflow import Tube wi.operation.conditions["Dox"] = "log" tube1 = Tube(file="../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs", conditions={"Dox": 0.1}) tube2 = Tube(file="../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs", conditions={"Dox": 1.0}) wi.operation.tubes.append(tube1) wi.operation.tubes.append(tube2) self.add_operation( 'edu.mit.synbio.cytoflowgui.op_plugins.threshold') self.model.selected.operation.channel = "Y2-A" self.model.selected.operation.threshold = 2000 self.model.selected.operation.name = "T"
def update_import_op(self, op): trait_to_dtype = {"Str" : "category", "Float" : "float", "LogFloat" : "log", "Bool" : "bool", "Int" : "int"} op.conditions.clear() for trait_name, trait in self.tube_traits.items(): if not trait.condition: continue trait_type = trait.__class__.__name__ op.conditions[trait_name] = trait_to_dtype[trait_type] for tube in self.tubes: op_tube = CytoflowTube(source = tube.Source, tube = tube.Tube, file = tube._file) if "Row" in tube.trait_names(): op_tube.row = tube.Row if "Col" in tube.trait_names(): op_tube.col = tube.Col op_tube.conditions = tube.trait_get(condition = True) # AFAICT this is going to cause the op to reload THE ENTIRE # SET each time a tube is added. >.> # TODO - FIX THIS. need a general strategy for only updating # if there's a "pause" in the action. op.tubes.append(op_tube)
def activated(self): # add the import op self.add_operation(ImportPlugin().id) self.model.selected = self.model.workflow[0] # if we're debugging, add a few data bits if self.model.debug: from cytoflow import Tube import_op = self.model.workflow[0].operation import_op.conditions = {"Dox": "float", "Well": "category"} # import_op.conditions["Dox"] = "float" # import_op.conditions["Well"] = "category" tube1 = Tube(file="../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs", conditions={ "Dox": 0.0, "Well": 'A' }) tube2 = Tube(file="../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs", conditions={ "Dox": 10.0, "Well": 'A' }) tube3 = Tube(file="../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs", conditions={ "Dox": 0.0, "Well": 'B' }) tube4 = Tube(file="../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs", conditions={ "Dox": 10.0, "Well": 'B' }) import_op.tubes = [tube1, tube2, tube3, tube4] # self.add_operation(ChannelStatisticPlugin().id) # stat_op = self.model.workflow[1].operation # stat_op.name = "Test" # stat_op.channel = "Y2-A" # stat_op.statistic_name = "Geom.Mean" # stat_op.by = ["Dox", "Well"] # self.model.selected = self.model.workflow[1] self.model.modified = False
def activated(self): # if we're coming back from the TASBE task, re-load the saved # workflow if self.model.backup_workflow: self.model.workflow = self.model.backup_workflow self.model.backup_workflow = [] return # else, set up a new workflow # add the import op if not self.model.workflow: self.add_operation(ImportPlugin().id) self.model.selected = self.model.workflow[0] # if we're debugging, add a few data bits if self.model.debug: from cytoflow import Tube import_op = self.model.workflow[0].operation import_op.conditions = {"Dox" : "float", "Well" : "category"} tube1 = Tube(file = "../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs", conditions = {"Dox" : 0.0, "Well" : 'A'}) tube2 = Tube(file = "../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs", conditions = {"Dox" : 10.0, "Well" : 'A'}) tube3 = Tube(file = "../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs", conditions = {"Dox" : 0.0, "Well" : 'B'}) tube4 = Tube(file = "../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs", conditions = {"Dox" : 10.0, "Well" : 'B'}) import_op.tubes = [tube1, tube2, tube3, tube4] # from cytoflowgui.op_plugins import ChannelStatisticPlugin # self.add_operation(ChannelStatisticPlugin().id) # stat_op = self.model.workflow[1].operation # stat_op.name = "Test" # stat_op.channel = "Y2-A" # stat_op.statistic_name = "Geom.Mean" # stat_op.by = ["Dox", "Well"] # self.model.selected = self.model.workflow[1] self.model.modified = False
def setUp(self): super().setUp() plugin = ImportPlugin() op = plugin.get_operation() from cytoflow import Tube self.cwd = os.path.dirname(os.path.abspath(__file__)) tube = Tube(file=self.cwd + "/../../cytoflow/tests/data/tasbe/rby.fcs") op.tubes = [tube] wi = WorkflowItem(operation=op, status="waiting", view_error="Not yet plotted") self.workflow.workflow.append(wi) op.do_estimate = True self.workflow.wi_waitfor(wi, 'status', 'valid') self.assertTrue( self.workflow.remote_eval("self.workflow[0].result is not None")) plugin = ThresholdPlugin() op = plugin.get_operation() op.name = "Morpho" op.channel = "FSC-A" op.threshold = 100000 wi = WorkflowItem(operation=op, status='waiting') self.workflow.workflow.append(wi) self.workflow.selected = wi self.workflow.wi_waitfor(wi, 'status', 'valid')
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 apply(self, experiment): if self.blank_file != self._blank_exp_file: self._blank_exp = ImportOp(tubes=[Tube( file=self.blank_file)]).apply() self._blank_exp_file = self.blank_file self._blank_exp_channels = self._blank_exp.channels self.changed = (Changed.PREV_RESULT, None) return out_dir = Path(self.output_directory) for path in self.input_files: in_file_path = Path(path) out_file_path = out_dir / in_file_path.name if out_file_path.exists(): raise util.CytoflowOpError( None, "File {} already exists".format(out_file_path)) tubes = [ Tube(file=path, conditions={'filename': Path(path).stem}) for path in self.input_files ] for tube in tubes: self.status = "Converting " + Path(tube.file).stem experiment = ImportOp(tubes=[tube], conditions={ 'filename': 'category' }).apply() experiment = self._af_op.apply(experiment) experiment = self._bleedthrough_op.apply(experiment) experiment = self._bead_calibration_op.apply(experiment) if self.do_color_translation: experiment = self._color_translation_op.apply(experiment) ExportFCS(path=self.output_directory, by=['filename'], _include_by=False).export(experiment) self.input_files = [] self.status = "Done converting!"
def update_import_op(self, op): trait_to_dtype = { "Str": "category", "Float": "float", "LogFloat": "log", "Bool": "bool", "Int": "int" } op.conditions.clear() for trait_name, trait in self.tube_traits.items(): if not trait.condition: continue trait_type = trait.__class__.__name__ op.conditions[trait_name] = trait_to_dtype[trait_type] for tube in self.tubes: op_tube = CytoflowTube(source=tube.Source, tube=tube.Tube, file=tube._file) if "Row" in tube.trait_names(): op_tube.row = tube.Row if "Col" in tube.trait_names(): op_tube.col = tube.Col op_tube.conditions = tube.trait_get(condition=True) # AFAICT this is going to cause the op to reload THE ENTIRE # SET each time a tube is added. >.> # TODO - FIX THIS. need a general strategy for only updating # if there's a "pause" in the action. op.tubes.append(op_tube)
def setUp(self): from cytoflow import Tube self.cwd = os.path.dirname(os.path.abspath(__file__)) + "/data/Plate01/" tube1 = Tube(file = self.cwd + "CFP_Well_A4.fcs", conditions = {"Dox" : 0.0, "Well" : 'Aa'}) tube2 = Tube(file = self.cwd + "RFP_Well_A3.fcs", conditions = {"Dox" : 10.0, "Well" : 'Aa'}) tube3 = Tube(file = self.cwd + "YFP_Well_A7.fcs", conditions = {"Dox" : 100.0, "Well" : 'Aa'}) tube4 = Tube(file = self.cwd + "CFP_Well_B4.fcs", conditions = {"Dox" : 0.0, "Well" : 'Bb'}) tube5 = Tube(file = self.cwd + "RFP_Well_A6.fcs", conditions = {"Dox" : 10.0, "Well" : 'Bb'}) tube6 = Tube(file = self.cwd + "YFP_Well_C7.fcs", conditions = {"Dox" : 100.0, "Well" : 'Bb'}) tube7 = Tube(file = self.cwd + "CFP_Well_B4.fcs", conditions = {"Dox" : 0.0, "Well" : 'Cc'}) tube8 = Tube(file = self.cwd + "RFP_Well_A6.fcs", conditions = {"Dox" : 10.0, "Well" : 'Cc'}) tube9 = Tube(file = self.cwd + "YFP_Well_C7.fcs", conditions = {"Dox" : 100.0, "Well" : 'Cc'}) self.ex = flow.ImportOp(conditions = {"Dox" : "float", "Well" : "category"}, tubes = [tube1, tube2, tube3, tube4, tube5, tube6, tube7, tube8, tube9]).apply()
def setUp(self): WorkflowTest.setUp(self) plugin = ImportPlugin() op = plugin.get_operation() from cytoflow import Tube self.cwd = os.path.dirname(os.path.abspath(__file__)) tube = Tube(file = self.cwd + "/../../cytoflow/tests/data/tasbe/rby.fcs") op.tubes = [tube] wi = WorkflowItem(operation = op, view_error = "Not yet plotted") self.workflow.workflow.append(wi) self.assertTrue(wait_for(wi, 'status', lambda v: v == 'valid', 5)) self.assertTrue(self.workflow.remote_eval("self.workflow[0].result is not None"))
def setUp(self): WorkflowTest.setUp(self) plugin = ImportPlugin() op = plugin.get_operation() from cytoflow import Tube op.conditions = {"Dox" : "float", "Well" : "category"} self.cwd = os.path.dirname(os.path.abspath(__file__)) tube1 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs", conditions = {"Dox" : 0.0, "Well" : 'A'}) tube2 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs", conditions = {"Dox" : 10.0, "Well" : 'A'}) tube3 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/YFP_Well_A7.fcs", conditions = {"Dox" : 100.0, "Well" : 'A'}) tube4 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs", conditions = {"Dox" : 0.0, "Well" : 'B'}) tube5 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs", conditions = {"Dox" : 10.0, "Well" : 'B'}) tube6 = Tube(file = self.cwd + "/../../cytoflow/tests/data/Plate01/YFP_Well_C7.fcs", conditions = {"Dox" : 100.0, "Well" : 'B'}) op.tubes = [tube1, tube2, tube3, tube4, tube5, tube6] wi = WorkflowItem(operation = op, view_error = "Not yet plotted") self.workflow.workflow.append(wi) self.assertTrue(wait_for(wi, 'status', lambda v: v == 'valid', 5)) self.assertTrue(self.workflow.remote_eval("self.workflow[0].result is not None"))
def setUp(self): super().setUp() import_plugin = ImportPlugin() import_op = import_plugin.get_operation() from cytoflow import Tube import_op.conditions = { "Dox": "float", "IP": "float", "Well": "category" } self.cwd = os.path.dirname(os.path.abspath(__file__)) tube1 = Tube(file=self.cwd + "/../../cytoflow/tests/data/Plate01/CFP_Well_A4.fcs", conditions={ "Dox": 1.0, "IP": 1.0, "Well": 'A' }) tube2 = Tube(file=self.cwd + "/../../cytoflow/tests/data/Plate01/RFP_Well_A3.fcs", conditions={ "Dox": 1.0, "IP": 10.0, "Well": 'B' }) tube3 = Tube(file=self.cwd + "/../../cytoflow/tests/data/Plate01/YFP_Well_A7.fcs", conditions={ "Dox": 10.0, "IP": 1.0, "Well": 'A' }) tube4 = Tube(file=self.cwd + "/../../cytoflow/tests/data/Plate01/CFP_Well_B4.fcs", conditions={ "Dox": 10.0, "IP": 10.0, "Well": 'B' }) tube5 = Tube(file=self.cwd + "/../../cytoflow/tests/data/Plate01/RFP_Well_A6.fcs", conditions={ "Dox": 100.0, "IP": 1.0, "Well": 'A' }) tube6 = Tube(file=self.cwd + "/../../cytoflow/tests/data/Plate01/YFP_Well_C7.fcs", conditions={ "Dox": 100.0, "IP": 100.0, "Well": 'B' }) import_op.tubes = [tube1, tube2, tube3, tube4, tube5, tube6] wi = WorkflowItem(operation=import_op, status="waiting", view_error="Not yet plotted") self.workflow.workflow.append(wi) import_op.do_estimate = True self.workflow.wi_waitfor(wi, 'status', 'valid') self.assertTrue( self.workflow.remote_eval("self.workflow[0].result is not None")) stats_plugin = ChannelStatisticPlugin() stats_op_1 = stats_plugin.get_operation() stats_op_1.name = "MeanByDoxIP" stats_op_1.channel = "Y2-A" stats_op_1.statistic_name = "Geom.Mean" stats_op_1.by = ['Dox', 'IP'] stats_op_1.subset_list.append( CategorySubset(name="Well", values=['A', 'B'])) stats_op_1.subset_list.append( RangeSubset(name="Dox", values=[1.0, 10.0, 100.0])) stats_op_1.subset_list.append( RangeSubset(name="IP", values=[1.0, 10.0])) stats_wi_1 = WorkflowItem(operation=stats_op_1, status="waiting", view_error="Not yet plotted") self.workflow.workflow.append(stats_wi_1) self.workflow.wi_waitfor(stats_wi_1, 'status', 'valid') stats_op_2 = stats_plugin.get_operation() stats_op_2.name = "SDByDoxIP" stats_op_2.channel = "Y2-A" stats_op_2.statistic_name = "Geom.SD" stats_op_2.by = ['Dox', 'IP'] stats_op_2.subset_list.append( CategorySubset(name="Well", values=['A', 'B'])) stats_op_2.subset_list.append( RangeSubset(name="Dox", values=[1.0, 10.0, 100.0])) stats_op_2.subset_list.append( RangeSubset(name="IP", values=[1.0, 10.0])) stats_wi_2 = WorkflowItem(operation=stats_op_2, status="waiting", view_error="Not yet plotted") self.workflow.workflow.append(stats_wi_2) self.workflow.selected = stats_wi_2 self.workflow.wi_waitfor(stats_wi_2, 'status', 'valid')
def _load_tube(data, version): return Tube(**data)
def setUp(self, thin=100): """Run once per test at the beginning""" from cytoflow import Tube self.cwd = os.path.dirname( os.path.abspath(__file__)) + "/data/Plate01/" tube1 = Tube(file=self.cwd + "CFP_Well_A4.fcs", conditions={ "Dox": 0.0, "Well": 'A' }) tube2 = Tube(file=self.cwd + "RFP_Well_A3.fcs", conditions={ "Dox": 10.0, "Well": 'A' }) tube3 = Tube(file=self.cwd + "YFP_Well_A7.fcs", conditions={ "Dox": 100.0, "Well": 'A' }) tube4 = Tube(file=self.cwd + "CFP_Well_B4.fcs", conditions={ "Dox": 0.0, "Well": 'B' }) tube5 = Tube(file=self.cwd + "RFP_Well_A6.fcs", conditions={ "Dox": 10.0, "Well": 'B' }) tube6 = Tube(file=self.cwd + "YFP_Well_C7.fcs", conditions={ "Dox": 100.0, "Well": 'B' }) tube7 = Tube(file=self.cwd + "CFP_Well_B4.fcs", conditions={ "Dox": 0.0, "Well": 'C' }) tube8 = Tube(file=self.cwd + "RFP_Well_A6.fcs", conditions={ "Dox": 10.0, "Well": 'C' }) tube9 = Tube(file=self.cwd + "YFP_Well_C7.fcs", conditions={ "Dox": 100.0, "Well": 'C' }) self.ex = flow.ImportOp(conditions={ "Dox": "float", "Well": "category" }, tubes=[ tube1, tube2, tube3, tube4, tube5, tube6, tube7, tube8, tube9 ]).apply() if thin > 1: # thin the dataset 100-fold from 90k to 900 rows for thin=100 self.ex.add_condition("bucket", "int", np.arange(self.ex.data.shape[0]) % thin) self.ex = self.ex.query("bucket == 0")
def apply(self, experiment): if self.blank_file != self._blank_exp_file: self._blank_exp = ImportOp(tubes=[Tube( file=self.blank_file)]).apply() self._blank_exp_file = self.blank_file self._blank_exp_channels = self._blank_exp.channels self.changed = (Changed.PREV_RESULT, None) return out_dir = Path(self.output_directory) for path in self.input_files: in_file_path = Path(path) out_file_path = out_dir / in_file_path.name if out_file_path.exists(): raise util.CytoflowOpError( None, "File {} already exists".format(out_file_path)) tubes = [ Tube(file=path, conditions={'filename': Path(path).stem}) for path in self.input_files ] for tube in tubes: self.status = "Converting " + Path(tube.file).stem experiment = ImportOp(tubes=[tube], conditions={ 'filename': 'category' }).apply() experiment = self._af_op.apply(experiment) experiment = self._bleedthrough_op.apply(experiment) experiment = self._bead_calibration_op.apply(experiment) if self.do_color_translation: experiment = self._color_translation_op.apply(experiment) tube_meta = fcsparser.parse( tube.file, channel_naming=experiment.metadata["name_metadata"], meta_data_only=True, reformat_meta=False) del tube_meta['__header__'] tube_meta = { k: v for (k, v) in tube_meta.items() if not k.startswith("flowCore_") } tube_meta = { k: v for (k, v) in tube_meta.items() if not (k.startswith("$P") and k[2].isdigit()) } drop_kws = [ "$BEGINANALYSIS", "$ENDANALYSIS", "$BEGINSTEXT", "$ENDSTEXT", "$BEGINDATA", "$ENDDATA", "$BYTEORD", "$DATATYPE", "$MODE", "$NEXTDATA", "$TOT", "$PAR" ] tube_meta = { k: v for (k, v) in tube_meta.items() if not k in drop_kws } ExportFCS(path=self.output_directory, by=['filename'], _include_by=False, keywords=tube_meta).export(experiment) self.input_files = [] self.status = "Done converting!"