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
File: browser.py Project: jni/cecog
def load_image_container_from_settings(settings):
    imagecontainer = ImageContainer()
    infos = imagecontainer.iter_check_plates(settings)
    scan_plates = dict((info[0], False) for info in infos)
    import_iter = imagecontainer.iter_import_from_settings(settings, scan_plates)
    for idx, info in enumerate(import_iter):
        pass

    if len(imagecontainer.plates) > 0:
        plate = imagecontainer.plates[0]
        imagecontainer.set_plate(plate)
    return imagecontainer
Example #3
0
def load_image_container_from_settings(settings):
    imagecontainer = ImageContainer()
    infos = imagecontainer.iter_check_plates(settings)
    scan_plates = dict((info[0], False) for info in infos)
    import_iter = imagecontainer.iter_import_from_settings(
        settings, scan_plates)
    for idx, info in enumerate(import_iter):
        pass

    if len(imagecontainer.plates) > 0:
        plate = imagecontainer.plates[0]
        imagecontainer.set_plate(plate)
    return imagecontainer
Example #4
0
    else:
        path_input = settings.get2('pathin')
    if path_output is not None:
        settings.set2('pathout', path_output)
        logger.info('Overwrite output path by %s' % path_output)
    else:
        path_output = settings.get2('pathout')


    if multiple_plates is None:
        multiple_plates = settings.get(SECTION_NAME_GENERAL, 'has_multiple_plates')
    else:
        logger.info('Overwrite has_multiple_plates by %s' % multiple_plates)


    imagecontainer = ImageContainer()
    imagecontainer.import_from_settings(settings)

    # FIXME: Could be more generally specified. SGE is setting the job item index via an environment variable
    if index is None:
        pass
    elif index.isdigit():
        index = int(index)
    else:
        if index == ENV_INDEX_SGE:
            logger.info("Using SGE job item index: environment variable '%s'" % index)

            if index not in os.environ:
                parser.error("SGE environment variable '%s' not defined.")
            index = int(os.environ[index])
            # decrement index (index is in range of 1..n for SGE)
Example #5
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 #6
0
    def _on_load_input(self):
        txt = "Error scanning image structure"
        path_in = self._settings.get(SECTION_NAME_GENERAL, 'pathin')
        if path_in == '':
            critical(self, txt, "Image path must be defined.")
        elif not os.path.isdir(path_in) and \
             not os.path.isdir(os.path.join(self.environ.package_dir, path_in)):
            critical(self, txt, "Image path '%s' not found." % path_in)
        else:
            try:
                infos = list(ImageContainer.iter_check_plates(self._settings))
            except:
                exception(self, txt)
            else:
                found_any = numpy.any([not info[3] is None for info in infos])
                cancel = False
                if found_any:
                    found_plates = [info[0] for info in infos
                                    if not info[3] is None]
                    missing_plates = [info[0] for info in infos
                                      if info[3] is None]
                    has_missing = len(missing_plates) > 0
                    txt = '%s plates were already scanned.\nDo you want ' \
                          'to rescan the file structure(s)? ' \
                          'This can take several minutes.' % \
                          ('Some' if has_missing else 'All')
                    title = 'Rescan input structure?'

                    box = QMessageBox(QMessageBox.Question, title, title,
                                      QMessageBox.Cancel, self, Qt.Sheet)
                    box.setWindowModality(Qt.WindowModal)
                    box.setInformativeText(txt)
                    box.setDetailedText('Plates with scanned structure: \n%s\n'
                                        '\nPlates without scanned structure: '
                                        '\n%s' %
                                        ('\n'.join(found_plates),
                                         '\n'.join(missing_plates)))
                    if not has_missing:
                        btn1 = QtGui.QPushButton('No', box)
                        box.addButton(btn1, QMessageBox.NoRole)
                        box.setDefaultButton(btn1)
                    elif len(found_plates) > 0:
                        btn1 = QtGui.QPushButton('Rescan missing', box)
                        box.addButton(btn1, QMessageBox.YesRole)
                        box.setDefaultButton(btn1)
                    else:
                        btn1 = None

                    btn2 = QtGui.QPushButton('Rescan all', box)
                    box.addButton(btn2, QMessageBox.YesRole)

                    if box.exec_() == QMessageBox.Cancel:
                        cancel = True
                    else:
                        btn = box.clickedButton()
                        if btn == btn1:
                            if has_missing:
                                scan_plates = dict([(info[0], info[0] in missing_plates) for info in infos])
                            else:
                                scan_plates = dict((info[0], False) for info in infos)
                        else:
                            scan_plates = dict((info[0], True) for info in infos)
                else:
                    has_multiple = self._settings.get(SECTION_NAME_GENERAL,
                                                      "has_multiple_plates")
                    if not question(self, "No structure data found",
                                    "Are you sure to scan %s?\n\nThis can take "
                                    "several minutes depending on the number of"
                                    " images." %
                                    ("%d plates" % len(infos) if has_multiple
                                     else "one plate")):
                        cancel = True
                    scan_plates = dict((info[0], True) for info in infos)
                if not cancel:
                    self._load_image_container(infos, scan_plates)
Example #7
0
                            help='Run applicaton in debug mode')
    args, _ = parser.parse_known_args()

    freeze_support()
    app = QtGui.QApplication(sys.argv)
    app.setWindowIcon(QtGui.QIcon(':cecog_analyzer_icon'))
    app.setApplicationName(cecog.APPNAME)

    splash = QtGui.QSplashScreen(QtGui.QPixmap(':cecog_splash'))
    splash.show()

    is_app = hasattr(sys, 'frozen')
    if is_app:
        redirect = (sys.frozen == "windows_exe")
    else:
        redirect = False

    main = CecogAnalyzer(cecog.APPNAME, cecog.VERSION, redirect,  args.debug)
    main._read_settings(join(main.environ.user_config_dir, args.configfile))

    try:
        if (args.load and os.path.isfile(args.configfile)) or is_app:
            infos = list(ImageContainer.iter_check_plates(main._settings))
            main._load_image_container(infos, show_dlg=False)
    except Exception, e:
        msg = "Could not load images\n%s" %e.message
        QMessageBox.critical(None, "Error", msg)
    main.show()
    splash.finish(main)
    sys.exit(app.exec_())
Example #8
0
    else:
        path_input = settings.get2('pathin')
    if path_output is not None:
        settings.set2('pathout', path_output)
        logger.info('Overwrite output path by %s' % path_output)
    else:
        path_output = settings.get2('pathout')


    if multiple_plates is None:
        multiple_plates = settings.get(SECTION_NAME_GENERAL, 'has_multiple_plates')
    else:
        logger.info('Overwrite has_multiple_plates by %s' % multiple_plates)


    imagecontainer = ImageContainer()
    imagecontainer.import_from_settings(settings)

    # FIXME: Could be more generally specified. SGE is setting the job item index via an environment variable
    if index is None:
        pass
    elif index.isdigit():
        index = int(index)
    else:
        if index == ENV_INDEX_SGE:
            logger.info("Using SGE job item index: environment variable '%s'" % index)

            if index not in os.environ:
                parser.error("SGE environment variable '%s' not defined.")
            index = int(os.environ[index])
            # decrement index (index is in range of 1..n for SGE)
Example #9
0
    else:
        path_input = settings.get2('pathin')
    if path_output is not None:
        settings.set2('pathout', path_output)
        logger.info('Overwrite output path by %s' % path_output)
    else:
        path_output = settings.get2('pathout')


    if multiple_plates is None:
        multiple_plates = settings.get(SECTION_NAME_GENERAL, 'has_multiple_plates')
    else:
        logger.info('Overwrite has_multiple_plates by %s' % multiple_plates)


    imagecontainer = ImageContainer()
    if position_list is not None:
        positions = position_list.split(',')
        plates = set(np.array([el.split('___') for el in positions])[:,0])
    else:
        plates=None
    
    imagecontainer.import_from_settings(settings, plates_restriction=plates)

    # FIXME: Could be more generally specified. SGE is setting the job item index via an environment variable
    if index is None:
        pass
    elif index.isdigit():
        index = int(index)
    else:
        if index == ENV_INDEX_SGE:
Example #10
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 #11
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 #12
0
    logger.setLevel(logging.ERROR)

    print "*"*(len(version) + 53)
    print "*** CellCognition - Batch Script - Version %s ***" %version
    print "*"*(len(version) + 53)
    print "SGE job item index: environment variable '%s'" %str(index)
    print 'cmd: %s' %" ".join(sys.argv)

    environ = CecogEnvironment(version, redirect=False, debug=False)
    settingsfile = os.path.abspath(args.settings)

    # read the settings data from file
    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]
Example #13
0
        logger.info('Overwrite input path by %s' % path_input)
    else:
        path_input = settings.get2('pathin')
    if path_output is not None:
        settings.set2('pathout', path_output)
        logger.info('Overwrite output path by %s' % path_output)
    else:
        path_output = settings.get2('pathout')

    if multiple_plates is None:
        multiple_plates = settings.get(SECTION_NAME_GENERAL,
                                       'has_multiple_plates')
    else:
        logger.info('Overwrite has_multiple_plates by %s' % multiple_plates)

    imagecontainer = ImageContainer()
    if position_list is not None:
        positions = position_list.split(',')
        plates = set(np.array([el.split('___') for el in positions])[:, 0])
    else:
        plates = None

    imagecontainer.import_from_settings(settings, plates_restriction=plates)

    # FIXME: Could be more generally specified. SGE is setting the job item index via an environment variable
    if index is None:
        pass
    elif index.isdigit():
        index = int(index)
    else:
        if index == ENV_INDEX_SGE: