def calc_foci_in_dirlist(dir_path, dir_list, nuclei_name=u'3DAPI.TIF', foci_name=u'3FITС.TIF', outfile = u'result.txt',\ sensitivity = 8., min_cell_size = 1500, peak_min_val_perc = 60, foci_min_val_perc = 90,\ foci_radius = 10, foci_min_level_on_bg = 40, foci_rescale_min = None, foci_rescale_max = None,\ nuclei_color = 0.66, foci_color = 0.33): '''Calculates foci from dir''' dirs_with_images = dir_list pre_image_dirs = [image_dir for image_dir in dirs_with_images if \ (os.path.isfile(os.path.join(image_dir,nuclei_name)) and os.path.isfile(os.path.join(image_dir, foci_name)))] image_dirs = [ pic_an.image_dir(image_dir, nuclei_name, foci_name) for image_dir in pre_image_dirs ] path1, name2 = os.path.split(dir_path) name1 = os.path.split(path1)[1] print name1, name2, path1 name = name1 + '_' + name2 absoutfile = os.path.join(dir_path, outfile) print name cell_set = pic_an.cell_set(name=name, cells=[]) remained = len(image_dirs) print "We have", remained, 'images to load for', name print "Image loading have started for", name for image_dir in image_dirs: image_dir.load_separate_images(sensitivity, min_cell_size) remained -= 1 if remained == 0: print "Image loading have finished for", name else: print remained, 'images remained to load for', name cell_set.extend(image_dir) if len(cell_set.cells) == 0: print "There are no cells in the images from ", dir_path return print "We have", len(cell_set.cells), "cells to analyze for", name cell_set.rescale_nuclei() cell_set.rescale_foci((foci_rescale_min, foci_rescale_max)) cell_set.calculate_foci(peak_min_val_perc, foci_min_val_perc, foci_radius, foci_min_level_on_bg) cell_set.calculate_foci_parameters() cell_set.write_parameters(absoutfile) for image_dir in image_dirs: image_dir.write_all_pic_files(nuclei_color, foci_color)
def getScaleFromSelected(self): self.cell_set = pic_an.cell_set(name=self.workDir, cells=[]) tasksize=len(self.getCheckedPaths()) self.parent.pbar.show() pbarvalue=0 self.parent.pbar.setValue(pbarvalue) pbarstep = (100 - 10 )/ tasksize if len(self.folderWidgets) != 0: for i in xrange(0,len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState() == QtCore.Qt.Checked : self.imageDirs[i].detect_cells(self.parent.settings.sensitivity, self.parent.settings.min_cell_size, load_foci=True) self.cell_set.extend(self.imageDirs[i]) pbarvalue+=pbarstep self.parent.pbar.setValue(pbarvalue) (self.parent.settings.foci_rescale_min, self.parent.settings.foci_rescale_max) = self.cell_set.get_foci_rescale_values() print 'Foci rescale values changed to:\nmin: ' + str(self.parent.settings.foci_rescale_min) \ + '\nmax: '+ str(self.parent.settings.foci_rescale_max) self.parent.pbar.setValue(100)
def getScaleFromSelected(self): self.cell_set = pic_an.cell_set(name=self.workDir, cells=[]) tasksize = len(self.getCheckedPaths()) self.parent.pbar.show() pbarvalue = 0 self.parent.pbar.setValue(pbarvalue) pbarstep = (100 - 10) / tasksize if len(self.folderWidgets) != 0: for i in xrange(0, len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState( ) == QtCore.Qt.Checked: self.imageDirs[i].detect_cells( self.parent.settings.sensitivity, self.parent.settings.min_cell_size, load_foci=True) self.cell_set.extend(self.imageDirs[i]) pbarvalue += pbarstep self.parent.pbar.setValue(pbarvalue) (self.parent.settings.foci_rescale_min, self.parent.settings.foci_rescale_max ) = self.cell_set.get_foci_rescale_values() print 'Foci rescale values changed to:\nmin: ' + str(self.parent.settings.foci_rescale_min) \ + '\nmax: '+ str(self.parent.settings.foci_rescale_max) self.parent.pbar.setValue(100)
def runCalc(self): dir_path = self.fileMenuArea.getWorkDir() dirs_with_images = self.fileMenuArea.getCheckedPaths() if len(dirs_with_images) == 0 : return else: if (self.oldDirsWithImages == dirs_with_images) & self.lastCalc & (not(self.settingsChanged)): print "No changes in selection" else: pre_image_dirs = [image_dir for image_dir in dirs_with_images if \ (os.path.isfile(os.path.join(image_dir,self.nuclei_name)) and os.path.isfile(os.path.join(image_dir, self.foci_name)))] image_dirs = [pic_an.image_dir(image_dir, self.nuclei_name, self.foci_name) for image_dir in pre_image_dirs] name = unicode(QtCore.QDir(dir_path).dirName()) absoutfile = os.path.join(dir_path,unicode(self.outfile)) print absoutfile cell_set = pic_an.cell_set(name=name, cells=[]) remained = len(image_dirs) if remained != 0: pbarval = 0 self.pbar.show() self.pbar.setValue(pbarval) pbarstep = (100 - 10 )/ remained print "We have", remained, 'images to load for', name print "Image loading have started for", name for image_dir in image_dirs: image_dir.load_separate_images(self.sensitivity, self.min_cell_size) pbarval +=pbarstep self.pbar.setValue(pbarval) remained -= 1 if remained == 0: print "Image loading have finished for", name else: print remained, 'images remained to load for', name cell_set.extend(image_dir) if len(cell_set.cells) == 0: print "There are no cells in the images from ", dir_path return print "We have", len(cell_set.cells), "cells to analyze for", name cell_set.rescale_nuclei() cell_set.rescale_foci((self.foci_rescale_min, self.foci_rescale_max)) self.oldFoci_rescale_min, self.oldFoci_rescale_max = cell_set.get_foci_rescale_values() cell_set.calculate_foci(self.peak_min_val_perc, self.foci_min_val_perc, self.foci_radius, self.foci_min_level_on_bg) cell_set.calculate_foci_parameters() cell_set.write_parameters(absoutfile) params = cell_set.get_parameters() self.statusArea.hide() self.statusArea.setItem(0,0,QtGui.QTableWidgetItem(str(params[0]))) for i in xrange(1,13): self.statusArea.setItem((i+1)%2,(i+1)//2,QtGui.QTableWidgetItem(str(params[i]))) #self.update() for image_dir in image_dirs: image_dir.write_all_pic_files(self.nuclei_color, self.foci_color) self.statusArea.show() self.pbar.setValue(100) self.updateImages() self.fileMenuArea.updateWorkDir() self.fileMenuArea.setCheckedFromPaths(dirs_with_images) self.oldDirsWithImages = dirs_with_images self.lastCalc=True self.settingsChanged=False else: print "no images is dataset"
def getScale(self): dir_path = self.fileMenuArea.getWorkDir() dirs_with_images = self.fileMenuArea.getCheckedPaths() if len(dirs_with_images) == 0 : return else: if (self.oldDirsWithImages == dirs_with_images) & (not(self.settingsChanged)): print "No changes in selection, setting values from previous calc" self.foci_rescale_min = self.oldFoci_rescale_min self.foci_rescale_max = self.oldFoci_rescale_max print "Foci rescale min max", self.foci_rescale_min, self.foci_rescale_max else: ### move to folderMenu widget? pre_image_dirs = [image_dir for image_dir in dirs_with_images if \ (os.path.isfile(os.path.join(image_dir,self.nuclei_name)) and os.path.isfile(os.path.join(image_dir, self.foci_name)))] image_dirs = [pic_an.image_dir(image_dir, self.nuclei_name, self.foci_name) for image_dir in pre_image_dirs] ######################### name = unicode(QtCore.QDir(dir_path).dirName()) cell_set = pic_an.cell_set(name=name, cells=[]) remained = len(image_dirs) if remained != 0: pbarval = 0 self.pbar.show() self.pbar.setValue(pbarval) pbarstep = (100 - 10 )/ remained print "We have", remained, 'images to load for', name print "Image loading have started for", name for image_dir in image_dirs: image_dir.load_separate_images(self.sensitivity, self.min_cell_size) pbarval +=pbarstep self.pbar.setValue(pbarval) remained -= 1 if remained == 0: print "Image loading have finished for", name else: print remained, 'images remained to load for', name cell_set.extend(image_dir) if len(cell_set.cells) == 0: print "There are no cells in the images from ", dir_path return print "We have", len(cell_set.cells), "cells to analyze for", name cell_set.rescale_foci((None, None)) self.foci_rescale_min, self.foci_rescale_max = cell_set.get_foci_rescale_values() self.oldFoci_rescale_min, self.oldFoci_rescale_max = self.foci_rescale_min, self.foci_rescale_max print "Foci rescale min max", self.foci_rescale_min, self.foci_rescale_max self.pbar.setValue(100) self.oldDirsWithImages = dirs_with_images self.lastCalc=False self.settingsChanged=False else: print "no images is dataset"
def openWorkDir(self, workdir=None): if not (workdir): workdir = QtGui.QFileDialog.getExistingDirectory( directory=self.workDir) if workdir != "": self.parent.workDir = unicode(workdir) if workdir != "": self.workDir = unicode(workdir) for i in reversed(range(self.folderLayout.count())): self.folderLayout.itemAt(i).widget().setParent(None) self.selectedImage = "" self.selectedImageDir = "" self.checkedPaths = [] self.nameList = [] folderIterator = QtCore.QDirIterator( self.workDir, QtCore.QDir.Dirs | QtCore.QDir.NoDotAndDotDot) while folderIterator.hasNext(): imageQDir = QtCore.QDir(folderIterator.next()) imageList = imageQDir.entryList( ["*.TIF", "*.tif", "*.jpg", "*.JPG", "*.BMP", "*.bmp"]) for name in imageList: if not (name in self.nameList): self.nameList.append(unicode(name)) [ self.parent.nuclNameComboBox.removeItem(0) for i in xrange(self.parent.nuclNameComboBox.count()) ] self.parent.nuclNameComboBox.addItems(self.nameList) if self.parent.settings.nuclei_name in self.nameList: #print self.parent.nuclNameComboBox.itemText(1) self.parent.nuclNameComboBox.setCurrentIndex( self.parent.nuclNameComboBox.findText( self.parent.settings.nuclei_name)) else: self.parent.nuclNameComboBox.setCurrentIndex(0) self.parent.settings.nuclei_name = self.nameList[0] [ self.parent.fociNameComboBox.removeItem(1) for i in xrange(1, self.parent.fociNameComboBox.count()) ] self.parent.fociNameComboBox.addItems(self.nameList) if self.parent.settings.foci_name in self.nameList: self.parent.fociNameComboBox.setCurrentIndex( self.parent.fociNameComboBox.findText( self.parent.settings.foci_name)) else: self.parent.fociNameComboBox.setCurrentIndex(0) self.parent.settings.foci_name = '--None--' self.checkAllBox = QtGui.QCheckBox('Check/Uncheck All', self) self.checkAllBox.setChecked(True) self.checkAllBox.stateChanged.connect(lambda: (self.checkAll( ) if self.checkAllBox.isChecked() else self.unCheckAll())) self.folderLayout.addWidget(self.checkAllBox) self.folderWidgets = [] self.imageDirs = [] self.cell_set = pic_an.cell_set(name=self.workDir, cells=[]) i = 0 folderIterator = QtCore.QDirIterator( self.workDir, QtCore.QDir.Dirs | QtCore.QDir.NoDotAndDotDot) while folderIterator.hasNext(): imageQDir = QtCore.QDir(folderIterator.next()) nucleiPath = imageQDir.absolutePath() + QtCore.QDir.separator( ) + self.parent.settings.nuclei_name fociPath = imageQDir.absolutePath() + QtCore.QDir.separator( ) + self.parent.settings.foci_name if ((self.parent.settings.foci_name == '--None--') & (QtCore.QFile(nucleiPath).exists())): self.imageDirs.append( pic_an.image_dir( unicode(imageQDir.absolutePath()), unicode(self.parent.settings.nuclei_name))) self.folderWidgets.append(imageFolderWidget(imageQDir)) self.folderLayout.addWidget(self.folderWidgets[-1]) self.folderWidgets[-1].signal_hideall.connect( self.hideAllImageLabels) ############ self.folderWidgets[-1].signal_show_image.connect( lambda key=i: self.updateImage(key)) self.folderWidgets[-1].signal_show_all_images.connect( lambda key=i: self.updateImages(key)) ############ i += 1 elif ((QtCore.QFile(fociPath).exists()) & (QtCore.QFile(nucleiPath).exists())): self.imageDirs.append( pic_an.image_dir( unicode(imageQDir.absolutePath()), unicode(self.parent.settings.nuclei_name), unicode(self.parent.settings.foci_name))) self.folderWidgets.append(imageFolderWidget(imageQDir)) self.folderLayout.addWidget(self.folderWidgets[-1]) self.folderWidgets[-1].signal_hideall.connect( self.hideAllImageLabels) ############ self.folderWidgets[-1].signal_show_image.connect( lambda key=i: self.updateImage(key)) self.folderWidgets[-1].signal_show_all_images.connect( lambda key=i: self.updateImages(key)) ############ i += 1 print str(len(self.imageDirs)) + ' dirs found in working directory' try: self.updateImages(0) except IndexError: self.signal_update_images.emit()
def calculateSelected(self): self.parent.outfileButton.setEnabled(False) self.parent.singleCellOutputBox.setEnabled(False) name = QtCore.QDir(self.workDir).dirName() self.cell_set = pic_an.cell_set(name=name, cells=[]) tasksize = len(self.getCheckedPaths()) print("We have %d images to load for %s" % (tasksize, name)) self.parent.pbar.show() pbarvalue = 0 self.parent.pbar.setValue(pbarvalue) pbarstep = (100 - 10) / tasksize # Calculation if len(self.folderWidgets) != 0: if self.parent.settings.foci_name == '--None--': for i in xrange(0, len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState( ) == QtCore.Qt.Checked: self.imageDirs[i].detect_cells( self.parent.settings.sensitivity, self.parent.settings.min_cell_size, load_foci=False) self.cell_set.extend(self.imageDirs[i]) tasksize -= 1 if tasksize == 0: print("Image loading has finished for %s" % name) else: print('%d images remained to load for %s' % (tasksize, name)) pbarvalue += pbarstep self.parent.pbar.setValue(pbarvalue) for i in xrange(0, len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState( ) == QtCore.Qt.Checked: self.imageDirs[i].write_all_pic_files( self.parent.settings.nuclei_color, self.parent.settings.foci_color) self.updateParamsTable() self.updateAllImageLabels() self.refreshImages() self.parent.pbar.setValue(100) self.parent.outfileButton.setEnabled(True) self.parent.singleCellOutputBox.setEnabled(True) else: for i in xrange(0, len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState( ) == QtCore.Qt.Checked: self.imageDirs[i].detect_cells( self.parent.settings.sensitivity, self.parent.settings.min_cell_size, load_foci=True) self.cell_set.extend(self.imageDirs[i]) tasksize -= 1 if tasksize == 0: print("Image loading has finished for %s" % name) else: print('%d images remained to load for %s' % (tasksize, name)) pbarvalue += pbarstep self.parent.pbar.setValue(pbarvalue) if len(self.cell_set.cells) == 0: print("No cells were detected in %s" % name) return print("We have %d cells to analyze for %s" % (len(self.cell_set.cells), name)) self.cell_set.calculate_foci( self.parent.settings.foci_lookup_sensivity, self.parent.settings.foci_area_fill_percent, self.parent.settings.min_foci_radius, self.parent.settings.max_foci_radius, self.parent.settings.allowed_foci_overlap, self.parent.settings.return_circles, self.parent.settings.normalize_intensity, (self.parent.settings.foci_rescale_min, self.parent.settings.foci_rescale_max)) # Retrieving results # self.cell_set.calculate_foci_parameters() self.updateParamsTable() self.parent.outfileButton.setEnabled(True) self.parent.singleCellOutputBox.setEnabled(True) for i in xrange(0, len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState( ) == QtCore.Qt.Checked: self.imageDirs[i].write_all_pic_files( self.parent.settings.nuclei_color, self.parent.settings.foci_color) #self.folderWidgets[i]=imageFolderWidget(imageDirPath) # Table update self.refreshImages() self.updateAllImageLabels() self.parent.pbar.setValue(100) print("Foci calculation has finished for %s" % name)
def runCalc(self): dir_path = self.fileMenuArea.getWorkDir() dirs_with_images = self.fileMenuArea.getCheckedPaths() if len(dirs_with_images) == 0: return else: if (self.oldDirsWithImages == dirs_with_images) & self.lastCalc & ( not (self.settingsChanged)): print "No changes in selection" else: pre_image_dirs = [image_dir for image_dir in dirs_with_images if \ (os.path.isfile(os.path.join(image_dir,self.nuclei_name)) and os.path.isfile(os.path.join(image_dir, self.foci_name)))] image_dirs = [ pic_an.image_dir(image_dir, self.nuclei_name, self.foci_name) for image_dir in pre_image_dirs ] name = unicode(QtCore.QDir(dir_path).dirName()) absoutfile = os.path.join(dir_path, unicode(self.outfile)) print absoutfile cell_set = pic_an.cell_set(name=name, cells=[]) remained = len(image_dirs) if remained != 0: pbarval = 0 self.pbar.show() self.pbar.setValue(pbarval) pbarstep = (100 - 10) / remained print "We have", remained, 'images to load for', name print "Image loading have started for", name for image_dir in image_dirs: image_dir.load_separate_images(self.sensitivity, self.min_cell_size) pbarval += pbarstep self.pbar.setValue(pbarval) remained -= 1 if remained == 0: print "Image loading have finished for", name else: print remained, 'images remained to load for', name cell_set.extend(image_dir) if len(cell_set.cells) == 0: print "There are no cells in the images from ", dir_path return print "We have", len( cell_set.cells), "cells to analyze for", name cell_set.rescale_nuclei() cell_set.rescale_foci( (self.foci_rescale_min, self.foci_rescale_max)) self.oldFoci_rescale_min, self.oldFoci_rescale_max = cell_set.get_foci_rescale_values( ) cell_set.calculate_foci(self.peak_min_val_perc, self.foci_min_val_perc, self.foci_radius, self.foci_min_level_on_bg) cell_set.calculate_foci_parameters() cell_set.write_parameters(absoutfile) params = cell_set.get_parameters() self.statusArea.hide() self.statusArea.setItem( 0, 0, QtGui.QTableWidgetItem(str(params[0]))) for i in xrange(1, 13): self.statusArea.setItem( (i + 1) % 2, (i + 1) // 2, QtGui.QTableWidgetItem(str(params[i]))) #self.update() for image_dir in image_dirs: image_dir.write_all_pic_files(self.nuclei_color, self.foci_color) self.statusArea.show() self.pbar.setValue(100) self.updateImages() self.fileMenuArea.updateWorkDir() self.fileMenuArea.setCheckedFromPaths(dirs_with_images) self.oldDirsWithImages = dirs_with_images self.lastCalc = True self.settingsChanged = False else: print "no images is dataset"
def getScale(self): dir_path = self.fileMenuArea.getWorkDir() dirs_with_images = self.fileMenuArea.getCheckedPaths() if len(dirs_with_images) == 0: return else: if (self.oldDirsWithImages == dirs_with_images) & (not (self.settingsChanged)): print "No changes in selection, setting values from previous calc" self.foci_rescale_min = self.oldFoci_rescale_min self.foci_rescale_max = self.oldFoci_rescale_max print "Foci rescale min max", self.foci_rescale_min, self.foci_rescale_max else: ### move to folderMenu widget? pre_image_dirs = [image_dir for image_dir in dirs_with_images if \ (os.path.isfile(os.path.join(image_dir,self.nuclei_name)) and os.path.isfile(os.path.join(image_dir, self.foci_name)))] image_dirs = [ pic_an.image_dir(image_dir, self.nuclei_name, self.foci_name) for image_dir in pre_image_dirs ] ######################### name = unicode(QtCore.QDir(dir_path).dirName()) cell_set = pic_an.cell_set(name=name, cells=[]) remained = len(image_dirs) if remained != 0: pbarval = 0 self.pbar.show() self.pbar.setValue(pbarval) pbarstep = (100 - 10) / remained print "We have", remained, 'images to load for', name print "Image loading have started for", name for image_dir in image_dirs: image_dir.load_separate_images(self.sensitivity, self.min_cell_size) pbarval += pbarstep self.pbar.setValue(pbarval) remained -= 1 if remained == 0: print "Image loading have finished for", name else: print remained, 'images remained to load for', name cell_set.extend(image_dir) if len(cell_set.cells) == 0: print "There are no cells in the images from ", dir_path return print "We have", len( cell_set.cells), "cells to analyze for", name cell_set.rescale_foci((None, None)) self.foci_rescale_min, self.foci_rescale_max = cell_set.get_foci_rescale_values( ) self.oldFoci_rescale_min, self.oldFoci_rescale_max = self.foci_rescale_min, self.foci_rescale_max print "Foci rescale min max", self.foci_rescale_min, self.foci_rescale_max self.pbar.setValue(100) self.oldDirsWithImages = dirs_with_images self.lastCalc = False self.settingsChanged = False else: print "no images is dataset"
def openWorkDir(self,workdir=None): if not(workdir): workdir=QtGui.QFileDialog.getExistingDirectory(directory=self.workDir) if workdir != "": self.parent.workDir=unicode(workdir) if workdir != "": self.workDir=unicode(workdir) for i in reversed(range(self.folderLayout.count())): self.folderLayout.itemAt(i).widget().setParent(None) self.selectedImage="" self.selectedImageDir="" self.checkedPaths=[] self.nameList=[] folderIterator=QtCore.QDirIterator(self.workDir,QtCore.QDir.Dirs|QtCore.QDir.NoDotAndDotDot) while folderIterator.hasNext(): imageQDir=QtCore.QDir(folderIterator.next()) imageList= imageQDir.entryList(["*.TIF", "*.tif", "*.jpg", "*.JPG", "*.BMP", "*.bmp"]) for name in imageList: if not(name in self.nameList): self.nameList.append(unicode(name)) [self.parent.nuclNameComboBox.removeItem(0) for i in xrange(self.parent.nuclNameComboBox.count())] self.parent.nuclNameComboBox.addItems(self.nameList) if self.parent.settings.nuclei_name in self.nameList: #print self.parent.nuclNameComboBox.itemText(1) self.parent.nuclNameComboBox.setCurrentIndex(self.parent.nuclNameComboBox.findText(self.parent.settings.nuclei_name)) else: self.parent.nuclNameComboBox.setCurrentIndex(0) self.parent.settings.nuclei_name=self.nameList[0] [self.parent.fociNameComboBox.removeItem(1) for i in xrange(1,self.parent.fociNameComboBox.count())] self.parent.fociNameComboBox.addItems(self.nameList) if self.parent.settings.foci_name in self.nameList: self.parent.fociNameComboBox.setCurrentIndex(self.parent.fociNameComboBox.findText(self.parent.settings.foci_name)) else: self.parent.fociNameComboBox.setCurrentIndex(0) self.parent.settings.foci_name='--None--' self.checkAllBox = QtGui.QCheckBox('Check/Uncheck All', self) self.checkAllBox.setChecked(True) self.checkAllBox.stateChanged.connect(lambda: (self.checkAll() if self.checkAllBox.isChecked() else self.unCheckAll())) self.folderLayout.addWidget(self.checkAllBox) self.folderWidgets=[] self.imageDirs=[] self.cell_set = pic_an.cell_set(name=self.workDir, cells=[]) i=0 folderIterator=QtCore.QDirIterator(self.workDir,QtCore.QDir.Dirs|QtCore.QDir.NoDotAndDotDot) while folderIterator.hasNext(): imageQDir=QtCore.QDir(folderIterator.next()) nucleiPath=imageQDir.absolutePath() + QtCore.QDir.separator() + self.parent.settings.nuclei_name fociPath=imageQDir.absolutePath() + QtCore.QDir.separator() + self.parent.settings.foci_name if ((self.parent.settings.foci_name == '--None--')&(QtCore.QFile(nucleiPath).exists())): self.imageDirs.append(pic_an.image_dir(unicode(imageQDir.absolutePath()), unicode(self.parent.settings.nuclei_name))) self.folderWidgets.append(imageFolderWidget(imageQDir)) self.folderLayout.addWidget(self.folderWidgets[-1]) self.folderWidgets[-1].signal_hideall.connect(self.hideAllImageLabels) ############ self.folderWidgets[-1].signal_show_image.connect(lambda key=i: self.updateImage(key)) self.folderWidgets[-1].signal_show_all_images.connect(lambda key=i: self.updateImages(key)) ############ i+=1 elif ((QtCore.QFile(fociPath).exists())&(QtCore.QFile(nucleiPath).exists())): self.imageDirs.append(pic_an.image_dir(unicode(imageQDir.absolutePath()), unicode(self.parent.settings.nuclei_name), unicode(self.parent.settings.foci_name))) self.folderWidgets.append(imageFolderWidget(imageQDir)) self.folderLayout.addWidget(self.folderWidgets[-1]) self.folderWidgets[-1].signal_hideall.connect(self.hideAllImageLabels) ############ self.folderWidgets[-1].signal_show_image.connect(lambda key=i: self.updateImage(key)) self.folderWidgets[-1].signal_show_all_images.connect(lambda key=i: self.updateImages(key)) ############ i+=1 print str(len(self.imageDirs)) + ' dirs found in working directory' try: self.updateImages(0) except IndexError: self.signal_update_images.emit()
def calculateSelected(self): self.parent.outfileButton.setEnabled(False) self.parent.singleCellOutputBox.setEnabled(False) name=QtCore.QDir(self.workDir).dirName() self.cell_set = pic_an.cell_set(name=name, cells=[]) tasksize=len(self.getCheckedPaths()) print("We have %d images to load for %s" % (tasksize, name)) self.parent.pbar.show() pbarvalue=0 self.parent.pbar.setValue(pbarvalue) pbarstep = (100 - 10 )/ tasksize # Calculation if len(self.folderWidgets) != 0: if self.parent.settings.foci_name == '--None--': for i in xrange(0,len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState() == QtCore.Qt.Checked : self.imageDirs[i].detect_cells(self.parent.settings.sensitivity, self.parent.settings.min_cell_size, load_foci=False) self.cell_set.extend(self.imageDirs[i]) tasksize -= 1 if tasksize == 0: print("Image loading has finished for %s" % name) else: print('%d images remained to load for %s' % (tasksize, name)) pbarvalue+=pbarstep self.parent.pbar.setValue(pbarvalue) for i in xrange(0,len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState() == QtCore.Qt.Checked : self.imageDirs[i].write_all_pic_files(self.parent.settings.nuclei_color, self.parent.settings.foci_color) self.updateParamsTable() self.updateAllImageLabels() self.refreshImages() self.parent.pbar.setValue(100) self.parent.outfileButton.setEnabled(True) self.parent.singleCellOutputBox.setEnabled(True) else: for i in xrange(0,len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState() == QtCore.Qt.Checked : self.imageDirs[i].detect_cells(self.parent.settings.sensitivity, self.parent.settings.min_cell_size, load_foci=True) self.cell_set.extend(self.imageDirs[i]) tasksize -= 1 if tasksize == 0: print("Image loading has finished for %s" % name) else: print('%d images remained to load for %s' % (tasksize, name)) pbarvalue+=pbarstep self.parent.pbar.setValue(pbarvalue) if len(self.cell_set.cells) == 0: print("No cells were detected in %s" % name) return print("We have %d cells to analyze for %s" % (len(self.cell_set.cells), name)) self.cell_set.calculate_foci(self.parent.settings.foci_lookup_sensivity, self.parent.settings.foci_area_fill_percent, self.parent.settings.min_foci_radius, self.parent.settings.max_foci_radius, self.parent.settings.allowed_foci_overlap, self.parent.settings.return_circles, self.parent.settings.normalize_intensity, (self.parent.settings.foci_rescale_min, self.parent.settings.foci_rescale_max)) # Retrieving results # self.cell_set.calculate_foci_parameters() self.updateParamsTable() self.parent.outfileButton.setEnabled(True) self.parent.singleCellOutputBox.setEnabled(True) for i in xrange(0,len(self.folderWidgets)): if self.folderWidgets[i].checked.checkState() == QtCore.Qt.Checked : self.imageDirs[i].write_all_pic_files(self.parent.settings.nuclei_color, self.parent.settings.foci_color) #self.folderWidgets[i]=imageFolderWidget(imageDirPath) # Table update self.refreshImages() self.updateAllImageLabels() self.parent.pbar.setValue(100) print("Foci calculation has finished for %s" % name)