From c0e5cc11664ed7444747859c01f1d36f39ef7fb6 Mon Sep 17 00:00:00 2001 From: Keith Callenberg Date: Mon, 10 May 2021 16:56:36 -0400 Subject: [PATCH 1/3] Slightly more helpful missing key error --- mibidata/mibi_image.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mibidata/mibi_image.py b/mibidata/mibi_image.py index 23919f0..8a4898d 100644 --- a/mibidata/mibi_image.py +++ b/mibidata/mibi_image.py @@ -487,9 +487,26 @@ def channel_inds(self, channels): f'with targets only (no masses were given), available ' \ f'targets are {self._channels}' else: - error_msg = f'Subset of channels, targets or massses not ' \ - f'found matching {channels}, available targets are ' \ - f'{self._channels}' + missing_channels = [] + matches = [] + keys = [channel[1] for channel in self._channels] + + # check for missing channels + # match on case-insensitive substring + for channel in channels: + if channel in keys or len(channel)<3: + continue + missing_channels.append(channel) + matches += [match for match in keys if channel.lower() in \ + match.lower()] + + error_msg = f'Channels, targets or masses not found ' \ + f'matching {missing_channels}. ' + + if len(matches): + error_msg += f'Did you mean {matches}? ' + + error_msg += f'Available targets are {keys}.' raise KeyError(error_msg) def slice_data(self, channels): From 547ac50cd32c1fbd26eb3cee6e2aa4e5fd8e5380 Mon Sep 17 00:00:00 2001 From: Keith Callenberg Date: Tue, 11 May 2021 09:50:59 -0400 Subject: [PATCH 2/3] fix whitespace for pylint --- mibidata/mibi_image.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mibidata/mibi_image.py b/mibidata/mibi_image.py index 8a4898d..7a95efc 100644 --- a/mibidata/mibi_image.py +++ b/mibidata/mibi_image.py @@ -494,9 +494,11 @@ def channel_inds(self, channels): # check for missing channels # match on case-insensitive substring for channel in channels: - if channel in keys or len(channel)<3: + if channel in keys: continue missing_channels.append(channel) + if len(channel) < 3: + continue matches += [match for match in keys if channel.lower() in \ match.lower()] From 0265ce3f49616da90bfa6ffa93107711b99e8d0f Mon Sep 17 00:00:00 2001 From: Keith Callenberg Date: Tue, 11 May 2021 09:55:49 -0400 Subject: [PATCH 3/3] More fixes for pylint --- mibidata/mibi_image.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mibidata/mibi_image.py b/mibidata/mibi_image.py index 7a95efc..b226023 100644 --- a/mibidata/mibi_image.py +++ b/mibidata/mibi_image.py @@ -488,26 +488,26 @@ def channel_inds(self, channels): f'targets are {self._channels}' else: missing_channels = [] - matches = [] + matches = [] keys = [channel[1] for channel in self._channels] - + # check for missing channels # match on case-insensitive substring for channel in channels: - if channel in keys: + if channel in keys: continue missing_channels.append(channel) if len(channel) < 3: continue matches += [match for match in keys if channel.lower() in \ match.lower()] - + error_msg = f'Channels, targets or masses not found ' \ f'matching {missing_channels}. ' - if len(matches): + if matches: error_msg += f'Did you mean {matches}? ' - + error_msg += f'Available targets are {keys}.' raise KeyError(error_msg)