From: gmungoc Date: Thu, 21 Feb 2019 14:49:56 +0000 (+0000) Subject: JAL-3187 handle no mapping / complement features without NPE X-Git-Tag: Release_2_11_1_0~57 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=825ef108d5bfcf9b3e3eb9422b27658c80ab0854;p=jalview.git JAL-3187 handle no mapping / complement features without NPE --- diff --git a/src/jalview/datamodel/MappedFeatures.java b/src/jalview/datamodel/MappedFeatures.java index b69a103..25f5ba4 100644 --- a/src/jalview/datamodel/MappedFeatures.java +++ b/src/jalview/datamodel/MappedFeatures.java @@ -69,6 +69,10 @@ public class MappedFeatures public List findProteinVariants() { List vars = new ArrayList<>(); + if (features.isEmpty()) + { + return vars; + } /* * determine canonical codon diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index c794e57..55b8559 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -790,12 +790,15 @@ public class SeqPanel extends JPanel : seq.getDatasetSequence(); MappedFeatures mf = fr2 .findComplementFeaturesAtResidue(ds, pos); - List pv = mf.findProteinVariants(); - for (String s : pv) + if (mf != null) { - if (!infos.contains(s)) + List pv = mf.findProteinVariants(); + for (String s : pv) { - infos.addAll(pv); + if (!infos.contains(s)) + { + infos.addAll(pv); + } } } } @@ -933,7 +936,10 @@ public class SeqPanel extends JPanel FeatureRendererModel fr2 = af.getFeatureRenderer(); MappedFeatures mf = fr2.findComplementFeaturesAtResidue(sequence, pos); - seqARep.appendFeatures(tooltipText, pos, mf.features, fr2); + if (mf != null) + { + seqARep.appendFeatures(tooltipText, pos, mf.features, fr2); + } } } } diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java index 39d705b..d580f2c 100644 --- a/src/jalview/renderer/seqfeatures/FeatureRenderer.java +++ b/src/jalview/renderer/seqfeatures/FeatureRenderer.java @@ -457,13 +457,16 @@ public class FeatureRenderer extends FeatureRendererModel int column = seq.findIndex(pos); MappedFeatures mf = fr2 .findComplementFeaturesAtResidue(seq, pos); - for (SequenceFeature sf : mf.features) + if (mf != null) { - FeatureColourI fc = fr2.getFeatureStyle(sf.getType()); - Color featureColour = fr2.getColor(sf, fc); - renderFeature(g, seq, column - 1, column - 1, featureColour, - start, end, y1, colourOnly); - drawnColour = featureColour; + for (SequenceFeature sf : mf.features) + { + FeatureColourI fc = fr2.getFeatureStyle(sf.getType()); + Color featureColour = fr2.getColor(sf, fc); + renderFeature(g, seq, column - 1, column - 1, featureColour, + start, end, y1, colourOnly); + drawnColour = featureColour; + } } } return drawnColour; @@ -563,7 +566,10 @@ public class FeatureRenderer extends FeatureRendererModel FeatureRendererModel fr2 = af.getFeatureRenderer(); MappedFeatures mf = fr2.findComplementFeaturesAtResidue( seq, seq.findPosition(column - 1)); - + if (mf == null) + { + return null; + } ReverseListIterator it = new ReverseListIterator<>( mf.features); while (it.hasNext()) diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 4fc143e..f090190 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -1156,10 +1156,11 @@ public abstract class FeatureRendererModel } /** - * Answers a (possibly empty) list of features in this alignment at a position - * (or range) which is mappable from the given sequence residue position in a - * mapped alignment. Features are returned in render order of feature type (on - * top last), with order within feature type undefined. + * Answers a bean containing a mapping, and a list of features in this + * alignment at a position (or range) which is mappable from the given + * sequence residue position in a mapped alignment. Features are returned in + * render order of feature type (on top last), with order within feature type + * undefined. If no features or mapping are found, answers null. * * @param sequence * @param pos @@ -1220,6 +1221,10 @@ public abstract class FeatureRendererModel break; } } + if (found.isEmpty()) + { + return null; + } /* * sort by renderorder, inefficiently