JAL-3187 handle no mapping / complement features without NPE
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 21 Feb 2019 14:49:56 +0000 (14:49 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 21 Feb 2019 14:49:56 +0000 (14:49 +0000)
src/jalview/datamodel/MappedFeatures.java
src/jalview/gui/SeqPanel.java
src/jalview/renderer/seqfeatures/FeatureRenderer.java
src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java

index b69a103..25f5ba4 100644 (file)
@@ -69,6 +69,10 @@ public class MappedFeatures
   public List<String> findProteinVariants()
   {
     List<String> vars = new ArrayList<>();
+    if (features.isEmpty())
+    {
+      return vars;
+    }
 
     /*
      * determine canonical codon
index c794e57..55b8559 100644 (file)
@@ -790,12 +790,15 @@ public class SeqPanel extends JPanel
                 : seq.getDatasetSequence();
         MappedFeatures mf = fr2
                 .findComplementFeaturesAtResidue(ds, pos);
-        List<String> pv = mf.findProteinVariants();
-        for (String s : pv)
+        if (mf != null)
         {
-          if (!infos.contains(s))
+          List<String> 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);
+          }
         }
       }
     }
index 39d705b..d580f2c 100644 (file)
@@ -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<SequenceFeature> it = new ReverseListIterator<>(
             mf.features);
     while (it.hasNext())
index 4fc143e..f090190 100644 (file)
@@ -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