Example #1
0
    def getListOfExperiments(self):
        settings = ConfigSettings(SECTION_REGISTRY)
        settings.read(self.oBatchSettings.settingsFilename)

        settings.set_section(SECTION_NAME_GENERAL)
        settings.set2('pathin', self.oBatchSettings.baseInDir)
        settings.set2('pathout', self.oBatchSettings.baseOutDir)

        imagecontainer = ImageContainer()
        imagecontainer.import_from_settings(settings)

        if self.oBatchSettings.plates is None:
            plates = imagecontainer.plates
        else:
            plates = self.oBatchSettings.plates

        lstExperiments = []
        for plate in plates:
            meta_data = imagecontainer.get_meta_data(plate)
            positions = meta_data.positions

            if self.oBatchSettings.omit_processed_positions:
                finished_pos = [os.path.splitext(x)[0].split('__')[0] for x in
                                os.listdir(os.path.join(self.oBatchSettings.baseOutDir,
                                                        plate, 'log', '_finished'))]
                positions = filter(lambda x: x not in finished_pos, positions)

            lstExperiments.extend([(x,y) for x,y in zip([plate for i in positions],
                                                        positions) ])

        return lstExperiments
Example #2
0
        else:
            parser.error("Only SGE supported at the moment (environment variable '%s')." % ENV_INDEX_SGE)


    # if no position list was specified via the program options get it from the settings file
    if  position_list is None:
        if settings.get(SECTION_NAME_GENERAL, 'constrain_positions'):
            position_list = settings.get(SECTION_NAME_GENERAL, 'positions') or None


    # construct a dummy string containing all plates and positions known to imagecontainer
    if position_list is None:
        positions = []
        for plate_id in imagecontainer.plates:
            imagecontainer.set_plate(plate_id)
            meta_data = imagecontainer.get_meta_data()
            positions += ['%s___%s' % (plate_id, pos) for pos in meta_data.positions]
    else:
        positions = position_list.split(',')


    if index is not None and (index < 0 or index >= len(positions)):
        parser.error("Cluster index %s does not match number of positions %d." % (index, len(positions)))

    # batch size was specified
    if batch_size is not None:
        if index is None:
            parser.error("Batch size requires a cluster index.")
        # select slice of positions according to index and batch size
        positions = positions[(index*batch_size) : ((index+1)*batch_size)]
    # index alone was specified
Example #3
0
    def _load_image_container(self, plate_infos, scan_plates=None, show_dlg=True):

        self._clear_browser()
        imagecontainer = ImageContainer()
        self._imagecontainer = imagecontainer

        if scan_plates is None:
            scan_plates = dict((info[0], False) for info in plate_infos)

        def load(dlg):
            iter = imagecontainer.iter_import_from_settings(self._settings, scan_plates)
            for idx, info in enumerate(iter):
                dlg.targetSetValue.emit(idx + 1)

            if len(imagecontainer.plates) > 0:
                plate = imagecontainer.plates[0]
                imagecontainer.set_plate(plate)

        self.dlg = waitingProgressDialog('Please wait until the input structure is scanned\n'
                                    'or the structure data loaded...', self, load, (0, len(scan_plates)))
        self.dlg.exec_(passDialog=True)

        if len(imagecontainer.plates) > 0:
            imagecontainer.check_dimensions()
            channels = imagecontainer.channels

            # do not report value changes to the main window
            self._settings.set_notify_change(False)

            self.set_image_crop_size()

            problems = []
            for prefix in ['primary', 'secondary', 'tertiary']:
                trait = self._settings.get_trait(SECTION_NAME_OBJECTDETECTION,
                                                 '%s_channelid' % prefix)
                if trait.set_list_data(channels) is None:
                    problems.append(prefix)
                self._tabs[1].get_widget('%s_channelid' % prefix).update()

            # report problems about a mismatch between channel IDs found in the data and specified by the user
            if len(problems) > 0:
                critical(self, "Selected channel IDs not valid",
                         "The selected channel IDs for %s are not valid.\nValid IDs are %s." %
                         (", ".join(["'%s Channel'" % s.capitalize() for s in problems]),
                          ", ".join(["'%s'" % s for s in channels])))
                # a mismatch between settings and data will cause changed settings
                self.settings_changed(True)

            trait = self._settings.get_trait(SECTION_NAME_TRACKING,
                                             'tracking_duration_unit')

            # allow time-base tracking durations only if time-stamp
            # information is present
            meta_data = imagecontainer.get_meta_data()
            if meta_data.has_timestamp_info:
                result = trait.set_list_data(TRACKING_DURATION_UNITS_TIMELAPSE)
            else:
                result = trait.set_list_data(TRACKING_DURATION_UNITS_DEFAULT)
            if result is None:
                critical(self, "Could not set tracking duration units",
                         "The tracking duration units selected to match the load data. Please check your settings.")
                # a mismatch between settings and data will cause changed settings
                self.settings_changed(True)

            # activate change notification again
            self._settings.set_notify_change(True)


            self.set_modules_active(state=True)
            if show_dlg:
                information(self, "Plate(s) successfully loaded",
                            "%d plates loaded successfully." % len(imagecontainer.plates))
        else:
            critical(self, "No valid image data found",
                     "The naming schema provided might not fit your image data"
                     "or the coordinate file is not correct.\n\nPlease modify "
                     "the values and scan the structure again.")
Example #4
0
    def _load_image_container(self, plate_infos=None, scan_plates=None,
                              show_dialog=True):
        self._clear_browser()

        if plate_infos is None:
            plate_infos = list(ImageContainer.iter_check_plates(self._settings))

        imagecontainer = ImageContainer()
        self._imagecontainer = imagecontainer

        if scan_plates is None:
            scan_plates = dict((info[0], False) for info in plate_infos)

        def load(emitter, icontainer, settings, splates):
            iter_ = icontainer.iter_import_from_settings(settings, scan_plates=splates)
            for idx, info in enumerate(iter_):
                emitter.setValue.emit(idx)

            emitter.setLabelText.emit("checking dimensions...")
            emitter.setRange.emit(0, 0)
            QtCore.QCoreApplication.processEvents()

            if len(icontainer.plates) > 0:
                icontainer.set_plate(icontainer.plates[0])
                icontainer.check_dimensions()


        label = ('Please wait until the input structure is scanned\n'
                 'or the structure data loaded...')
        self._dlg = ProgressDialog(label, None, 0, len(scan_plates), self)
        emitter = ProgressObject()
        emitter.setRange.connect(self._dlg.setRange)
        emitter.setValue.connect(self._dlg.setValue)
        emitter.setLabelText.connect(self._dlg.setLabelText)

        try:
            func = lambda: load(emitter, imagecontainer,
                                self._settings, scan_plates)
            self._dlg.exec_(func, (emitter, ))
        except ImportError as e:
            # structure file from versions older than 1.3 contain pdk which is
            # removed
            if 'pdk' in str(e):
                QMessageBox.critical(self, "Error",
                                     ("Your structure file format is outdated.\n"
                                      "You have to rescan the plate(s)"))
            else:
                QMessageBox.critical(self, "Error", traceback.format_exc())
            return
        except Exception as e:
            QMessageBox.critical(self, "Error", str(e))


        try: # I hate lookup tables!
            self._tab_lookup['Cluster'][1].set_imagecontainer(imagecontainer)
        except KeyError:
            pass

        if len(imagecontainer.plates) > 0:
            channels = imagecontainer.channels

            # do not report value changes to the main window
            self._settings.set_notify_change(False)

            self.set_image_crop_size()

            problems = []
            for prefix in ['primary', 'secondary', 'tertiary']:
                trait = self._settings.get_trait(SECTION_NAME_OBJECTDETECTION,
                                                 '%s_channelid' % prefix)
                if trait.set_list_data(channels) is None:
                    problems.append(prefix)
                self._tabs[1].get_widget('%s_channelid' % prefix).update()

            # report problems about a mismatch between channel IDs found in the data
            # and specified by the user
            if len(problems) > 0:
                # a mismatch between settings and data will cause changed settings
                self.settings_changed(True)

            trait = self._settings.get_trait(SECTION_NAME_EVENT_SELECTION,
                                             'duration_unit')

            # allow time-base tracking durations only if time-stamp
            # information is present
            meta_data = imagecontainer.get_meta_data()
            if meta_data.has_timestamp_info:
                result = trait.set_list_data(TimeConverter.units)
            else:
                result = trait.set_list_data([TimeConverter.FRAMES])
            if result is None:
                QMessageBox.critical(self, "Could not set tracking duration units",
                                     ("The tracking duration units selected to match the "
                                      "load data. Please check your settings."))
                # a mismatch between settings and data will cause changed settings
                self.settings_changed(True)

            # activate change notification again
            self._settings.set_notify_change(True)


            self.set_modules_active(state=True)
            if show_dialog:
                QMessageBox.information(
                    self, "Information",
                    "%d plate(s) successfully loaded." % len(imagecontainer.plates))
        else:
            QMessageBox.critical(self, "Error",
                                 ("No images found\n"
                                  "Verifiy your nameing scheme and rescan the data."))
Example #5
0
        else:
            parser.error("Only SGE supported at the moment (environment variable '%s')." % ENV_INDEX_SGE)


    # if no position list was specified via the program options get it from the settings file
    if  position_list is None:
        if settings.get(SECTION_NAME_GENERAL, 'constrain_positions'):
            position_list = settings.get(SECTION_NAME_GENERAL, 'positions') or None


    # construct a dummy string containing all plates and positions known to imagecontainer
    if position_list is None:
        positions = []
        for plate_id in imagecontainer.plates:
            imagecontainer.set_plate(plate_id)
            meta_data = imagecontainer.get_meta_data()
            positions += ['%s___%s' % (plate_id, pos) for pos in meta_data.positions]
#     else:
#         positions = position_list.split(',')


    if index is not None and (index < 0 or index >= len(positions)):
        parser.error("Cluster index %s does not match number of positions %d." % (index, len(positions)))

    # batch size was specified
    if batch_size is not None:
        if index is None:
            parser.error("Batch size requires a cluster index.")
        # select slice of positions according to index and batch size
        positions = positions[(index*batch_size) : ((index+1)*batch_size)]
    # index alone was specified
Example #6
0
    settings = ConfigSettings()
    settings.read(settingsfile)

    imagecontainer = ImageContainer()
    imagecontainer.import_from_settings(settings)

    if settings('General', 'constrain_positions'):
        positions = settings('General', 'positions').split(POSSEP)
        if not settings('General', 'has_multiple_plates'):
            plate = os.path.split(settings("General", "pathin"))[1]
            positions = ['%s%s%s' % (plate, PLATESEP, p) for p in positions]
    else:
        positions = list()
        for plate in imagecontainer.plates:
            imagecontainer.set_plate(plate)
            meta_data = imagecontainer.get_meta_data()
            positions += \
              ['%s%s%s' % (plate, PLATESEP, pos) for pos in meta_data.positions]

    n_positions = len(positions)

    if index is not None and (index < 0 or index >= len(positions)):
        raise RuntimeError(
            "Cluster index %s does not match number of positions %d."
            %(index, len(positions)))

    # batch size was specified
    if batch_size is not None:
        if index is None:
            raise RuntimeError("Batch size requires a cluster index.")
        # select slice of positions according to index and batch size
Example #7
0
            parser.error(
                "Only SGE supported at the moment (environment variable '%s')."
                % ENV_INDEX_SGE)

    # if no position list was specified via the program options get it from the settings file
    if position_list is None:
        if settings.get(SECTION_NAME_GENERAL, 'constrain_positions'):
            position_list = settings.get(SECTION_NAME_GENERAL,
                                         'positions') or None

    # construct a dummy string containing all plates and positions known to imagecontainer
    if position_list is None:
        positions = []
        for plate_id in imagecontainer.plates:
            imagecontainer.set_plate(plate_id)
            meta_data = imagecontainer.get_meta_data()
            positions += [
                '%s___%s' % (plate_id, pos) for pos in meta_data.positions
            ]
#     else:
#         positions = position_list.split(',')

    if index is not None and (index < 0 or index >= len(positions)):
        parser.error(
            "Cluster index %s does not match number of positions %d." %
            (index, len(positions)))

    # batch size was specified
    if batch_size is not None:
        if index is None:
            parser.error("Batch size requires a cluster index.")