Exemplo n.º 1
0
    def openFiles(self, files):
        ''' Open a collection of files, sort by content type
        
        :Parameters:
        
        files : list
                List of input files
        '''

        coordfile = None
        for filename in files:
            filename = str(filename)
            if not ndimage_file.spider.is_readable(
                    filename) and not ndimage_file.mrc.is_readable(
                        filename) and format.is_readable(filename):
                nameItem = QtGui.QStandardItem(os.path.basename(filename))
                nameItem.setData(filename)
                nameItem.setToolTip(filename)
                countItem = QtGui.QStandardItem(str(len(
                    format.read(filename))))
                countItem.setData(filename)
                countItem.setToolTip(filename)
                self.fileListModel.appendRow([nameItem, countItem])
                self.coordinates_files.append(filename)
                if coordfile is None: coordfile = nameItem  #coordfile=filename
            else:
                self.stack_file = filename
        self.coordinates_files = list(set(self.coordinates_files))
        if coordfile is not None:
            self.ui.fileTableView.selectionModel().setCurrentIndex(
                coordfile.index(), QtGui.QItemSelectionModel.Select
                | QtGui.QItemSelectionModel.Rows)
            #self.openFile(coordfile)
        if self.stack_file != "":
            self.ui.toggleImageDockAction.setEnabled(True)
            self.ui.imageDockWidget.show()
            self.ui.canvas.mpl_connect('pick_event', self.displayImage)
Exemplo n.º 2
0
 def setWorkflow(self, workflow):
     '''
     '''
     
     if not hasattr(workflow, '__iter__'): workflow=[workflow]
     model = self.ui.jobListView.model()
     model.clear()
     mode='w'
     for mod in workflow:
         if self.log_file:
             mod.values.log_file = self.log_file
         mod.values.log_mode = mode
         item = QtGui.QStandardItem(self.job_status_icons[0], mod.name())
         item.setData(mod, QtCore.Qt.UserRole)
         model.appendRow(item)
         if mode != 'a': mode='a'
Exemplo n.º 3
0
    def on_subsetComboBox_currentIndexChanged(self, index):
        ''' Called when the user wants to plot only a subset of the data
        
        :Parameters:
        
        index : int
                New index in the subset combobox
        '''

        if index > 0:
            index = self.ui.subsetComboBox.itemData(index)
            vals = [str(v) for v in numpy.unique(self.data[:, index])]
        else:
            vals = []

        self.subsetListModel.clear()
        for name in vals:
            item = QtGui.QStandardItem(name)
            item.setCheckState(QtCore.Qt.Checked)
            item.setCheckable(True)
            self.subsetListModel.appendRow(item)
Exemplo n.º 4
0
    def on_loadImagesPushButton_clicked(self):
        ''' Load the current batch of images into the list
        '''

        if len(self.files) == 0: return
        self.imageListModel.clear()
        index, start = self.imageSubset(self.ui.pageSpinBox.value() - 1,
                                        self.ui.imageCountSpinBox.value())
        if len(index) == 0:
            self.ui.pageSpinBox.blockSignals(True)
            self.ui.pageSpinBox.setValue(0)
            self.ui.pageSpinBox.blockSignals(False)
            self.ui.imageCountSpinBox.blockSignals(True)
            self.ui.imageCountSpinBox.setValue(1)
            self.ui.imageCountSpinBox.blockSignals(False)
            index, start = self.imageSubset(0, 1)
        bin_factor = self.ui.decimateSpinBox.value()
        nstd = self.ui.clampDoubleSpinBox.value()
        img = None
        self.loaded_images = []
        self.base_level = None
        zoom = self.ui.imageZoomDoubleSpinBox.value()
        masks = {}

        template = self.get_template()

        progressDialog = QtGui.QProgressDialog('Opening...', "Cancel", 0,
                                               len(index), self)
        progressDialog.setWindowModality(QtCore.Qt.WindowModal)
        progressDialog.show()

        self.ui.imageListView.setModel(None)

        if not drawing.is_available():
            _logger.info("No PIL loaded")
            self.advanced_settings.mark_image = False
        if not plotting.is_available():
            _logger.info("No matplotlib loaded")
            self.advanced_settings.mark_image = False

        current_powerspec = self.advanced_settings.current_powerspec
        if current_powerspec:
            if self.advanced_settings.invert:
                _logger.info("Cannot invert a power spectra")
        else:
            if self.advanced_settings.center_mask > 0:
                _logger.info("Cannot mask micrograph")

        added_items = []
        for i, (imgname, img, pixel_size) in enumerate(
                iter_images(self.files, index, template)):
            selimg = None
            progressDialog.setValue(i + 1)
            if hasattr(img, 'ndim'):
                if current_powerspec and self.advanced_settings.center_mask > 0 and img.shape not in masks:
                    masks[img.shape] = ndimage_utility.model_disk(
                        self.advanced_settings.center_mask, img.shape) * -1 + 1
                if self.advanced_settings.invert and not current_powerspec:
                    if img.max() != img.min(): ndimage_utility.invert(img, img)
                img = ndimage_utility.replace_outlier(img,
                                                      nstd,
                                                      nstd,
                                                      replace='mean')
                if self.advanced_settings.gaussian_high_pass > 0.0:
                    img = ndimage_filter.filter_gaussian_highpass(
                        img,
                        pixel_size / self.advanced_settings.gaussian_high_pass)
                if self.advanced_settings.gaussian_low_pass > 0.0:
                    img = ndimage_filter.filter_gaussian_lowpass(
                        img,
                        pixel_size / self.advanced_settings.gaussian_low_pass)
                if current_powerspec and self.advanced_settings.center_mask > 0:
                    #img[numpy.logical_not(masks[img.shape])] = numpy.mean(img[masks[img.shape]])
                    img *= masks[img.shape]
                if bin_factor > 1.0:
                    img = ndimage_interpolate.interpolate(
                        img, bin_factor,
                        self.advanced_settings.downsample_type)
                pixel_size *= bin_factor
                img = self.display_powerspectra_1D(img, imgname, pixel_size)
                img = self.display_resolution(img, imgname, pixel_size)
                img = self.box_particles(img, imgname)
                if self.advanced_settings.mark_image:
                    imgm = self.imageMarker(img)
                    selimg = qimage_utility.numpy_to_qimage(imgm)
                qimg = qimage_utility.numpy_to_qimage(img)
                if img.ndim == 2:
                    if self.base_level is not None:
                        qimg.setColorTable(self.color_level)
                    else:
                        self.base_level = qimg.colorTable()
                        self.color_level = qimage_utility.adjust_level(
                            qimage_utility.change_contrast, self.base_level,
                            self.ui.contrastSlider.value())
                        qimg.setColorTable(self.color_level)
                else:
                    if self.base_level is None: self.base_level = []
                    self.base_level.append(qimg.colorTable())
                    self.color_level = qimage_utility.adjust_level(
                        qimage_utility.change_contrast, self.base_level[-1],
                        self.ui.contrastSlider.value())
                    qimg.setColorTable(self.color_level)

            else:
                qimg = img.convertToFormat(QtGui.QImage.Format_Indexed8)
                if self.base_level is None: self.base_level = []
                self.base_level.append(qimg.colorTable())
                self.color_level = qimage_utility.adjust_level(
                    qimage_utility.change_contrast, self.base_level[-1],
                    self.ui.contrastSlider.value())
                qimg.setColorTable(self.color_level)
            self.loaded_images.append(qimg)
            pix = QtGui.QPixmap.fromImage(qimg)
            icon = QtGui.QIcon()
            icon.addPixmap(pix, QtGui.QIcon.Normal)
            if selimg is not None:
                pix = QtGui.QPixmap.fromImage(selimg)
            icon.addPixmap(pix, QtGui.QIcon.Selected)
            if self.advanced_settings.show_label:
                item = QtGui.QStandardItem(
                    icon,
                    "%s/%d" % (os.path.basename(imgname[0]), imgname[1] + 1))
            else:
                item = QtGui.QStandardItem(icon, "")
            if hasattr(start, '__iter__'):
                item.setData(start[i], QtCore.Qt.UserRole)
            else:
                item.setData(i + start, QtCore.Qt.UserRole)

            self.addToolTipImage(imgname, item, pixel_size)
            self.imageListModel.appendRow(item)
            added_items.append(item)

        self.ui.imageListView.setModel(self.imageListModel)
        progressDialog.hide()
        for item in added_items:
            self.notify_added_item(item)

        self.imagesize = img.shape[0] if hasattr(img, 'shape') else img.width()
        n = max(5, int(self.imagesize * zoom))
        self.ui.imageListView.setIconSize(QtCore.QSize(n, n))

        batch_count = numpy.ceil(
            float(self.imageTotal()) / self.ui.imageCountSpinBox.value())
        self.ui.pageSpinBox.setSuffix(" of %d" % batch_count)
        self.ui.pageSpinBox.setMaximum(batch_count)
        self.ui.actionForward.setEnabled(
            self.ui.pageSpinBox.value() < batch_count)
        self.ui.actionBackward.setEnabled(self.ui.pageSpinBox.value() > 0)
Exemplo n.º 5
0
    def __init__(self, parent=None, helpDialog=None):
        "Initialize ReferenceUI widget"

        QtGui.QWidget.__init__(self, parent)

        # Build window
        _logger.info("\rBuilding main window ...")
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.task = None
        self.lastpath = str(QtCore.QDir.currentPath())
        self.helpDialog = helpDialog
        self.ui.referenceTabWidget.currentChanged.connect(
            lambda x: self.captureScreen.emit(x + 1))

        self.emdbCannedModel = QtGui.QStandardItemModel(self)
        canned = [
            ('Ribosome-40S', '1346',
             ':/references/reference/1346/emdb_1346_pix32.png',
             """The eukaryotic translation initiation factors eIF1 and eIF1A induce an open conformation of the 40S ribosome.
Passmore LA, Schmeing TM, Maag D, Applefield DJ, Acker MG, Algire MA, Lorsch JR, Ramakrishnan V
MOLECULAR CELL (2007) 26, pp. 41-50"""),
            ('Ribosome-60S', '1705',
             ':/references/reference/1705/emdb_1705_pix32.png',
             """Mechanism of eIF6-mediated inhibition of ribosomal subunit joining.
Gartmann M, Blau M, Armache JP, Mielke T, Topf M, Beckmann R
J.BIOL.CHEM. (2010) 285, pp. 14848-14851"""),
            ('Ribosome-80S', '2275',
             ':/references/reference/2275/emdb_2275_pix32.png',
             """Ribosome structures to near-atomic resolution from thirty thousand cryo-EM particles.
Bai XC, Fernandez IS, McMullan G, Scheres SH
ELIFE (2013) 2, pp. e00461-e00461"""),
            ('ATP synthase', '5335',
             ':/references/reference/5335/emd_5335_pix32.png',
             """Subnanometre-resolution structure of the intact Thermus thermophilus H+-driven ATP synthase.
Lau WC, Rubinstein JL
NATURE (2012) 481, pp. 214-218"""),
            ('Ribosome-70S', '5360',
             ':/references/reference/5360/emdb_5360_pix32.png',
             """Structural characterization of mRNA-tRNA translocation intermediates.
Agirrezabala X, Liao HY, Schreiner E, Fu J, Ortiz-Meoz RF, Schulten K, Green R, Frank J
PROC.NAT.ACAD.SCI.USA (2012) 109, pp. 6094-6099"""),
            ('Ribosome-30S', '5503',
             ':/references/reference/5503/emdb_5503_pix512.png',
             """Dissecting the in vivo assembly of the 30S ribosomal subunit reveals the role of RimM and general features of the assembly process.
Guo Q, Goto S, Chen Y, Feng B, Xu Y, Muto A, Himeno H, Deng H, Lei J, Gao N
NUCLEIC ACIDS RES. (2013) 41, pp. 2609-2620"""),
            ('Ribosome-50S', '5787',
             ':/references/reference/5787/emdb_5787_pix32.png',
             """Functional domains of the 50S subunit mature late in the assembly process.
Jomaa A, Jain N, Davis JH, Williamson JR, Britton RA, Ortega J
NUCLEIC ACIDS RES. (2013)"""),
        ]
        for entry in canned:
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(entry[2]), QtGui.QIcon.Normal,
                           QtGui.QIcon.Off)
            item = QtGui.QStandardItem(icon, entry[0])
            item.setData(entry[1], QtCore.Qt.UserRole)
            item.setData(entry[3], QtCore.Qt.UserRole + 1)
            self.emdbCannedModel.appendRow(item)
        self.ui.emdbCannedListView.setModel(self.emdbCannedModel)
        self.taskFinished.connect(self.onDownloadFromEMDBComplete)
        self.ui.referenceLineEdit.editingFinished.connect(
            self.onReferenceEditChanged)
        self.ui.referenceTabWidget.setCurrentIndex(0)
        self.ui.referenceTabWidget.setCurrentIndex(1)