From 1dcd8de9d8655acad313fe9755148c362998f197 Mon Sep 17 00:00:00 2001 From: Lubomir Chorbadjiev Date: Wed, 27 Mar 2019 11:30:09 +0200 Subject: [PATCH] handling of whitespace in guide table added... --- scgv/models/loader.py | 9 ++++++++- scgv/models/model.py | 8 +++++--- scgv/qtviews/heatmap.py | 7 +++---- scgv/views/track.py | 7 ++----- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/scgv/models/loader.py b/scgv/models/loader.py index 2968b5a..a9c4eb6 100644 --- a/scgv/models/loader.py +++ b/scgv/models/loader.py @@ -37,7 +37,7 @@ def load(self): self.ratio_df = self.data.get('ratio', None) self.clone_df = self.data.get('clone', None) self.tree_df = self.data.get('tree', None) - self.guide_df = self.data.get('guide', None) + self.guide_df = self._guide_clenup(self.data.get('guide', None)) self.featuremat_df = self.data.get('featuremat', None) self.features_df = self.data.get('features', None) self.genome = self.data.get('genome', 'hg19') @@ -46,6 +46,13 @@ def load(self): assert self.seg_df is not None assert self.genome is not None + def _guide_clenup(self, guide_df): + if guide_df is None: + return None + for column in guide_df.select_dtypes(include=[object]).columns: + guide_df[column] = guide_df[column].str.strip() + return guide_df + @classmethod def _organize_filenames(cls, namelist): print(namelist) diff --git a/scgv/models/model.py b/scgv/models/model.py index f326898..fc6972e 100644 --- a/scgv/models/model.py +++ b/scgv/models/model.py @@ -274,8 +274,6 @@ def make_sectors_legend(self): return None sectors, sector_mapping = self.make_sector(self.ordering) - print(sector_mapping) - pathology_mapping = {} for sector_key, sector_value in sector_mapping.items(): sector_df = self.data.guide_df[ @@ -290,7 +288,11 @@ def make_sectors_legend(self): .format( sector_key, sector_df[self.PATHOLOGY_COLUMN].unique())) - pathology_mapping[str(pathology).strip()] = sector_value + + pathology = str(pathology).strip() + assert pathology not in pathology_mapping + + pathology_mapping[pathology] = sector_value return sectors, pathology_mapping diff --git a/scgv/qtviews/heatmap.py b/scgv/qtviews/heatmap.py index dcc854a..3c3cd92 100644 --- a/scgv/qtviews/heatmap.py +++ b/scgv/qtviews/heatmap.py @@ -139,10 +139,9 @@ def show(self): vmin = min(self.mapping.values()) self.legend.clear() - print(self.mapping) - for key, value in self.mapping.items(): - color = self.cmap.colors[int(value) - vmin] + index = int(value) - vmin + color = self.cmap.colors[index] self.legend.add_entry( text=str(key), color=color) @@ -257,7 +256,7 @@ def set_model(self, model): self.legend.set_model(model) self.model = model - self.tracks = self.model.tracks + self.tracks = self.model.tracks self.selected_track = None if not self.tracks: return diff --git a/scgv/views/track.py b/scgv/views/track.py index 282d653..ad6e226 100644 --- a/scgv/views/track.py +++ b/scgv/views/track.py @@ -13,16 +13,13 @@ def select_colormap(self, track_mapping): assert size <= 20 if size > 12: - print("select_colormap: tab20") cmap = plt.get_cmap('tab20') elif size > 7: - print("select_colormap: Paired") cmap = plt.get_cmap('Paired') else: - print("select_colormap: tab10") cmap = plt.get_cmap('tab10') - - return ListedColormap(cmap.colors[:size]) + colors = cmap.colors[:size] + return ListedColormap(colors) def __init__(self, model, track_name, track, mapping): super(TrackViewer, self).__init__(model)