コード例 #1
0
    def _on_add_tubes(self):
        """
        Handle "Add tubes..." button.  Add tubes to the experiment.
        """

        file_dialog = FileDialog()
        file_dialog.wildcard = "Flow cytometry files (*.fcs *.lmd)|*.fcs *.lmd|"
        file_dialog.action = 'open files'
        file_dialog.open()

        if file_dialog.return_code != PyfaceOK:
            return

        for path in file_dialog.paths:
            try:
                metadata, _ = parse_tube(path, metadata_only=True)
            except Exception as e:
                raise RuntimeError("FCS reader threw an error on tube {0}: {1}"\
                                   .format(path, e.value))

            # if we're the first tube loaded, create a dummy experiment
            # and setup default metadata columns
            if not self.model.dummy_experiment:
                self.model.dummy_experiment = \
                    ImportOp(tubes = [CytoflowTube(file = path)]).apply(metadata_only = True)

            # check the next tube against the dummy experiment
            try:
                check_tube(path, self.model.dummy_experiment)
            except util.CytoflowError as e:
                error(None, e.__str__(), "Error importing tube")
                return

            metadata['CF_File'] = Path(path).stem
            tube = Tube(file=path,
                        parent=self.model,
                        metadata=sanitize_metadata(metadata))

            self.model.tubes.append(tube)

            for trait in self.model.tube_traits:
                if trait.type != 'metadata' and trait.name:
                    tube.on_trait_change(self._try_multiedit, trait.name)
コード例 #2
0
 def _on_add_tubes(self):
     """
     Handle "Add tubes..." button.  Add tubes to the experiment.
     """
     
     file_dialog = FileDialog()
     file_dialog.wildcard = "Flow cytometry files (*.fcs)|*.fcs|"
     file_dialog.action = 'open files'
     file_dialog.open()
     
     if file_dialog.return_code != PyfaceOK:
         return
     
     for path in file_dialog.paths:
         try:
             tube_meta = fcsparser.parse(path, 
                                         meta_data_only = True, 
                                         reformat_meta = True)
             #tube_channels = tube_meta["_channels_"].set_index("$PnN")
         except Exception as e:
             raise RuntimeError("FCS reader threw an error on tube {0}: {1}"\
                                .format(path, e.value))
             
             
         # if we're the first tube loaded, create a dummy experiment
         if not self.model.dummy_experiment:
             self.model.dummy_experiment = ImportOp(tubes = [CytoflowTube(file = path)],
                                                    coarse_events = 1).apply()
                                                    
         # check the next tube against the dummy experiment
         try:
             check_tube(path, self.model.dummy_experiment)
         except util.CytoflowError as e:
             error(None, e.__str__(), "Error importing tube")
             return
             
         tube = Tube()
         
         for trait_name, trait in self.model.tube_traits.items():
             tube.add_trait(trait_name, trait)
             
             # this magic makes sure the trait is actually defined
             # in tube.__dict__, so it shows up in trait_names etc.
             tube.trait_set(**{trait_name : trait.default_value})
             if trait.condition:
                 tube.on_trait_change(self._try_multiedit, trait_name)
         
         tube.trait_set(file = path, parent = self.model)
         
         if '$SRC' in tube_meta:    
             self._add_metadata("$SRC", "$SRC", Str(condition = False))
             tube.trait_set(**{"$SRC" : tube_meta['$SRC']})
             
         if 'TUBE NAME' in tube_meta:
             self._add_metadata("TUBE NAME", "TUBE NAME", Str(condition = False))
             tube.trait_set(**{"TUBE NAME" : tube_meta['TUBE NAME']})
             
         if '$SMNO' in tube_meta:
             self._add_metadata("$SMNO", "$SMNO", Str(condition = False))
             tube.trait_set(**{"$SMNO" : tube_meta['$SMNO']})
             
         if 'WELL ID' in tube_meta:
             self._add_metadata("Row", "Row", Str(condition = False))
             self._add_metadata("Col", "Col", Int(condition = False))
             
             pos = tube_meta['WELL ID']
             row = pos[0]
             col = int(pos[1:3])
             
             tube.trait_set(**{"Row" : row, "Col" : col})
             
         
         self.model.tubes.append(tube)
コード例 #3
0
ファイル: import_dialog.py プロジェクト: gjvargas/cytoflow
    def _on_add_tubes(self):
        """
        Handle "Add tubes..." button.  Add tubes to the experiment.
        """

        # TODO - adding a set of files, then a condition, then another
        # set doesn't work.

        file_dialog = FileDialog()
        file_dialog.wildcard = "Flow cytometry files (*.fcs)|*.fcs|"
        file_dialog.action = "open files"
        file_dialog.open()

        if file_dialog.return_code != PyfaceOK:
            return

        for path in file_dialog.paths:
            try:
                tube_meta = fcsparser.parse(path, meta_data_only=True, reformat_meta=True)
                # tube_channels = tube_meta["_channels_"].set_index("$PnN")
            except Exception as e:
                raise RuntimeError("FCS reader threw an error on tube {0}: {1}".format(path, e.value))

            # if we're the first tube loaded, create a dummy experiment
            if not self.model.dummy_experiment:
                self.model.dummy_experiment = ImportOp(tubes=[CytoflowTube(file=path)], coarse_events=1).apply()

            # check the next tube against the dummy experiment
            try:
                check_tube(path, self.model.dummy_experiment)
            except util.CytoflowError as e:
                error(None, e.__str__(), "Error importing tube")
                return

            tube = Tube()

            for trait_name, trait in self.model.tube_traits.items():
                # TODO - do we still need to check for transient?
                tube.add_trait(trait_name, trait)

                # this magic makes sure the trait is actually defined
                # in tube.__dict__, so it shows up in trait_names etc.
                tube.trait_set(**{trait_name: trait.default_value})
                if trait.condition:
                    tube.on_trait_change(self._try_multiedit, trait_name)

            tube.trait_set(file=path, parent=self.model)

            if "$SRC" in tube_meta:
                self._add_metadata("$SRC", "$SRC", Str(condition=False))
                tube.trait_set(**{"$SRC": tube_meta["$SRC"]})

            if "TUBE NAME" in tube_meta:
                self._add_metadata("TUBE NAME", "TUBE NAME", Str(condition=False))
                tube.trait_set(**{"TUBE NAME": tube_meta["TUBE NAME"]})

            if "$SMNO" in tube_meta:
                self._add_metadata("$SMNO", "$SMNO", Str(condition=False))
                tube.trait_set(**{"$SMNO": tube_meta["SMNO"]})

            self.model.tubes.append(tube)
            self.btn_add_cond.setEnabled(True)