def __init__(self, settings, tstep, timeunit): self.constrain_graph = settings('ErrorCorrection', 'constrain_graph') self.hmm_constrain = dict() self.classifier_dirs = dict() self.regionnames = COrderedDict() # settings that depend whether if the channel is checked for # error correction or not for channel in CHANNEL_PREFIX: rname = self._regionname(settings, channel) if settings('ErrorCorrection', channel) and bool(rname): self.regionnames[channel] = rname self.hmm_constrain[channel] = self._hmm_constrain( \ settings('ErrorCorrection', '%s_graph' %channel)) _setting = '%s_classification_envpath' % channel self.classifier_dirs[channel] = \ settings('Classification', _setting) self.mapping_dir = settings('General', 'plate_layout') if settings('ErrorCorrection', 'groupby_sirna'): self.sortby = PlateMapping.SIRNA elif settings('ErrorCorrection', 'groupby_genesymbol'): self.sortby = PlateMapping.GENE else: self.sortby = PlateMapping.FILE # timelapse in minutes self.overwrite_timelapse = \ settings('ErrorCorrection', 'overwrite_time_lapse') self.timeunit = timeunit if self.overwrite_timelapse: self.timelapse = settings('ErrorCorrection', 'timelapse') else: self.timelapse = tstep self.sorting = settings('ErrorCorrection', 'enable_sorting') if self.sorting: try: self.sorting_sequence = \ eval('('+settings('ErrorCorrection', 'sorting_sequence')+',)') except SyntaxError: raise SyntaxError( ("Error Correction: invalid Label sequence - " "use a comma separated list of integers")) else: self.sorting_sequence = None self.tmax = settings('ErrorCorrection', 'max_time') self.ignore_tracking_branches = \ settings('ErrorCorrection', 'ignore_tracking_branches') self.write_gallery = settings('ErrorCorrection', 'compose_galleries') self.n_galleries = \ settings('ErrorCorrection', 'compose_galleries_sample') self.resampling_factor = settings('ErrorCorrection', 'resampling_factor') self.size_gallery_image = settings('ErrorCorrection', 'size_gallery_image')
def _channel_regions(self, pchannel, chid): """Return a dict that contains the processing channel an the region used for feature extraction.""" regions = COrderedDict() if chid is None: for prefix in (CH_PRIMARY + CH_OTHER): if self._settings.get("Classification", "merge_%s" % prefix): regions[prefix.title()] = \ self._settings.get("Classification", "%s_%s_region" %(CH_VIRTUAL[0], prefix)) else: regions[pchannel.title()] = self._settings.get( \ 'Classification', "%s_classification_regionname" %pchannel) return regions
def _channel_regions(self, p_channel): """Return a dict of of channel region pairs according to the classifier""" regions = COrderedDict() if self.CHANNELS[p_channel.lower()].is_virtual(): for prefix, channel in self.CHANNELS.iteritems(): if channel.is_virtual(): continue if self.settings.get("Classification", "merge_%s" %prefix): regions[prefix.title()] = \ self.settings.get("Classification", "%s_%s_region" %(self.MERGED_CHANNEL.lower(), prefix)) else: regions[p_channel] = self.settings.get("Classification", self._resolve_name(p_channel, 'classification_regionname')) return regions
def __init__(self, *args, **kw): super(MergedChannel, self).__init__(*args, **kw) # defines channels an regions to concatenate self._merge_regions = COrderedDict() self._channels = None
class MergedChannel(ChannelCore): """Virtual or PseudoChannel which is meant to concatenate features of other channels. It cannot perform an segmentation or other operation on images. """ NAME = 'Merged' PREFIX = NAME.lower() _rank = 4 _is_virtual = True def __init__(self, *args, **kw): super(MergedChannel, self).__init__(*args, **kw) # defines channels an regions to concatenate self._merge_regions = COrderedDict() self._channels = None @property def merge_regions(self): return self._merge_regions @merge_regions.setter def merge_regions(self, regions): """Set channels and regions to concatenate.""" reginfo = MetaPluginManager().region_info reginfo.names[self.NAME.lower()] = [regions.values()] self._merge_regions.update(regions) @merge_regions.deleter def merged_regions(self): del self._merge_regions def apply_segmentation(self, channels, master="Primary"): self._channels = channels self._new_container(master) def apply_features(self, *args, **kw): """Concatenate features of images objects of different channels""" holder = ObjectHolder("-".join(self._merge_regions.values())) for cname, region_name in self._merge_regions.iteritems(): channel = self._channels[cname] holder0 = channel.get_region(region_name) pfx = "%s_%s" %(cname, region_name) feature_names = ["_".join((pfx, f)) for f in holder0.feature_names] holder.cat_samples(holder0, feature_names) removed = holder.remove_incomplete() if len(removed) > 0: self.logger.info("Found incomplete samples in merged channel") self.logger.info("removed samples: %s" %",".join([str(r) for r in removed])) self._regions[self.regkey] = holder self.lstFeatureNames = holder.feature_names def _new_container(self, master): # not sure if it makes a difference to have a master # perhaps a method to get an rgb image # find the region of the primary channel # it does not feel a great piece of code ... available_regions = self._channels[master].containers.keys() if 'primary' in available_regions: default_region = 'primary' elif 'primary' in [x[:len('primary')] for x in available_regions]: default_region = filter(lambda x: x[:len('primary')]=='primary', available_regions)[0] else: default_region = available_regions[0] mcnt = self._channels[master].containers[default_region] self.containers[self.regkey] = mcnt @property def regkey(self): return self._merge_regions.values() def meta_images(self, alpha=1.0): """Return a list of image, hexcolor, alpha-value tripples, which is used for ccore.makeRGBImage method. """ images = list() ccolors = dict([(c.strChannelId, False) for c in self._channels.values()]) for channel in self._channels.values(): ccolor = channel.strChannelId if ccolor is not None and not ccolors[channel.strChannelId]: ccolors[channel.strChannelId] = True images.append((channel.meta_image.image, Colors.channel_hexcolor(ccolor), alpha)) return images def sub_channels(self): for schannel, region in self._merge_regions.iteritems(): yield self._channels[schannel], region # most of the following functions are just dummy implementations to stay # combatible to processing channels that do actually perform segmentation def purge(self, *args, **kw): self._channels = None def normalize_image(self, *args, **kw): pass def apply_zselection(self, *args, **kw): pass def apply_registration(self, *args, **kw): pass def apply_binning(self, *args, **kw): pass
class MergedChannel(ChannelCore): """Virtual or PseudoChannel which is meant to concatenate features of other channels. It cannot perform an segmentation or other operation on images. """ NAME = 'Merged' PREFIX = NAME.lower() _rank = 4 _is_virtual = True def __init__(self, *args, **kw): super(MergedChannel, self).__init__(*args, **kw) # defines channels an regions to concatenate self._merge_regions = COrderedDict() self._channels = None @property def merge_regions(self): return self._merge_regions @merge_regions.setter def merge_regions(self, regions): """Set channels and regions to concatenate.""" reginfo = MetaPluginManager().region_info reginfo.names[self.NAME.lower()] = [regions.values()] self._merge_regions.update(regions) @merge_regions.deleter def merged_regions(self): del self._merge_regions def apply_segmentation(self, channels, master="Primary"): self._channels = channels self._new_container(master) def apply_features(self, *args, **kw): """Concatenate features of images objects of different channels""" holder = ObjectHolder("-".join(self._merge_regions.values())) for cname, region_name in self._merge_regions.iteritems(): channel = self._channels[cname] holder0 = channel.get_region(region_name) pfx = "%s_%s" % (cname, region_name) feature_names = ["_".join((pfx, f)) for f in holder0.feature_names] holder.cat_samples(holder0, feature_names) removed = holder.remove_incomplete() if len(removed) > 0: self.logger.info("Found incomplete samples in merged channel") self.logger.info("removed samples: %s" % ",".join([str(r) for r in removed])) self._regions[self.regkey] = holder self.lstFeatureNames = holder.feature_names def _new_container(self, master): # not sure if it makes a difference to have a master # perhaps a method to get an rgb image # find the region of the primary channel # it does not feel a great piece of code ... available_regions = self._channels[master].containers.keys() if 'primary' in available_regions: default_region = 'primary' elif 'primary' in [x[:len('primary')] for x in available_regions]: default_region = filter(lambda x: x[:len('primary')] == 'primary', available_regions)[0] else: default_region = available_regions[0] mcnt = self._channels[master].containers[default_region] self.containers[self.regkey] = mcnt @property def regkey(self): return self._merge_regions.values() def meta_images(self, alpha=1.0): """Return a list of image, hexcolor, alpha-value tripples, which is used for ccore.makeRGBImage method. """ images = list() ccolors = dict([(c.strChannelId, False) for c in self._channels.values()]) for channel in self._channels.values(): ccolor = channel.strChannelId if ccolor is not None and not ccolors[channel.strChannelId]: ccolors[channel.strChannelId] = True images.append((channel.meta_image.image, Colors.channel_hexcolor(ccolor), alpha)) return images def sub_channels(self): for schannel, region in self._merge_regions.iteritems(): yield self._channels[schannel], region # most of the following functions are just dummy implementations to stay # combatible to processing channels that do actually perform segmentation def purge(self, *args, **kw): self._channels = None def normalize_image(self, *args, **kw): pass def apply_zselection(self, *args, **kw): pass def apply_registration(self, *args, **kw): pass def apply_binning(self, *args, **kw): pass
def __init__(self, settings, tstep, timeunit): if settings('ErrorCorrection', 'hmm_baumwelch'): self.hmm_algorithm = self.HMM_BAUMWELCH else: self.hmm_algorithm = self.HMM_SMOOTHING self.constrain_graph = settings('ErrorCorrection', 'constrain_graph') self.hmm_constrain = dict() self.classifier_dirs = dict() self.regionnames = COrderedDict() # settings that depend whether if the channel is checked for # error correction or not for channel in CHANNEL_PREFIX: rname = self._regionname(settings, channel) if settings('ErrorCorrection', channel) and bool(rname): self.regionnames[channel] = rname self.hmm_constrain[channel] = self._hmm_constrain( \ settings('ErrorCorrection', '%s_graph' %channel)) _setting = '%s_classification_envpath' % channel self.classifier_dirs[channel] = \ settings('Classification', _setting) self.position_labels = settings('ErrorCorrection', 'position_labels') self.mapping_dir = settings('ErrorCorrection', 'mappingfile_path') if settings('ErrorCorrection', 'groupby_oligoid'): self.sortby = PlateMapping.OLIGO elif settings('ErrorCorrection', 'groupby_genesymbol'): self.sortby = PlateMapping.GENE else: self.sortby = PlateMapping.POSITION # special case, sort by position if no mappings file is provided if not self.position_labels: self.sortby = PlateMapping.POSITION # timelapse in minutes self.overwrite_timelapse = \ settings('ErrorCorrection', 'overwrite_time_lapse') self.timeunit = timeunit if self.overwrite_timelapse: self.timelapse = settings('ErrorCorrection', 'timelapse') else: self.timelapse = tstep self.sorting = settings('ErrorCorrection', 'enable_sorting') if self.sorting: try: self.sorting_sequence = \ eval('('+settings('ErrorCorrection', 'sorting_sequence')+',)') except SyntaxError: raise SyntaxError( ("Error Correction: invalid Label sequence - " "use a comma separated list of integers")) else: self.sorting_sequence = None self.tmax = settings('ErrorCorrection', 'max_time') self.ignore_tracking_branches = \ settings('ErrorCorrection', 'ignore_tracking_branches') self.write_gallery = settings('ErrorCorrection', 'compose_galleries') self.n_galleries = \ settings('ErrorCorrection', 'compose_galleries_sample') if settings('EventSelection', 'supervised_event_selection'): self.eventselection = self.EVENTSELECTION_SUPERVISED else: self.eventselection = self.EVENTSELECTION_UNSUPERVISED self.nclusters = settings('EventSelection', 'num_clusters') self.resampling_factor = settings('ErrorCorrection', 'resampling_factor') self.size_gallery_image = settings('ErrorCorrection', 'size_gallery_image')