JAL-2759 Refactor of hideInsertionsFor after review
authorkiramt <k.mourao@dundee.ac.uk>
Mon, 15 Jan 2018 13:32:35 +0000 (13:32 +0000)
committerkiramt <k.mourao@dundee.ac.uk>
Mon, 15 Jan 2018 13:32:35 +0000 (13:32 +0000)
src/jalview/bin/JalviewLite.java
src/jalview/datamodel/Alignment.java
src/jalview/datamodel/AlignmentI.java
src/jalview/datamodel/HiddenColumns.java
src/jalview/gui/AlignFrame.java
src/jalview/io/AnnotationFile.java
test/jalview/datamodel/HiddenColumnsTest.java

index 6504290..a60496c 100644 (file)
@@ -31,7 +31,6 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentOrder;
 import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
@@ -471,7 +470,7 @@ public class JalviewLite extends Applet
         SequenceI rs = sel.getSequenceAt(0);
         start = rs.findIndex(start);
         end = rs.findIndex(end);
-        List<Integer> cs = new ArrayList<Integer>(csel.getSelected());
+        List<Integer> cs = new ArrayList<>(csel.getSelected());
         csel.clear();
         for (Integer selectedCol : cs)
         {
@@ -921,7 +920,7 @@ public class JalviewLite extends Applet
     setMouseoverListener(currentAlignFrame, listener);
   }
 
-  private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<jalview.javascript.JSFunctionExec>();
+  private Vector<jalview.javascript.JSFunctionExec> javascriptListeners = new Vector<>();
 
   /*
    * (non-Javadoc)
@@ -2165,8 +2164,8 @@ public class JalviewLite extends Applet
           else
           {
             param = st.nextToken();
-            List<SequenceI> tmp = new ArrayList<SequenceI>();
-            List<String> tmp2 = new ArrayList<String>();
+            List<SequenceI> tmp = new ArrayList<>();
+            List<String> tmp2 = new ArrayList<>();
 
             while (st.hasMoreTokens())
             {
@@ -2279,12 +2278,9 @@ public class JalviewLite extends Applet
           JnetAnnotationMaker.add_annotation(predictions,
                   alignFrame.viewport.getAlignment(), 0, false);
           // false == do not add sequence profile from concise output
-          SequenceI repseq = alignFrame.viewport.getAlignment()
-                  .getSequenceAt(0);
-          alignFrame.viewport.getAlignment().setSeqrep(repseq);
-          HiddenColumns cs = new HiddenColumns();
-          cs.hideInsertionsFor(repseq);
-          alignFrame.viewport.getAlignment().setHiddenColumns(cs);
+
+          alignFrame.viewport.getAlignment().setupJPredAlignment();
+
           alignFrame.alignPanel.fontChanged();
           alignFrame.alignPanel.setScrollValues(0, 0);
           result = true;
@@ -2802,9 +2798,9 @@ public class JalviewLite extends Applet
     // callInitCallback();
   }
 
-  private Hashtable<String, long[]> jshashes = new Hashtable<String, long[]>();
+  private Hashtable<String, long[]> jshashes = new Hashtable<>();
 
-  private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<String, Hashtable<String, String[]>>();
+  private Hashtable<String, Hashtable<String, String[]>> jsmessages = new Hashtable<>();
 
   public void setJsMessageSet(String messageclass, String viewId,
           String[] colcommands)
@@ -2812,7 +2808,7 @@ public class JalviewLite extends Applet
     Hashtable<String, String[]> msgset = jsmessages.get(messageclass);
     if (msgset == null)
     {
-      msgset = new Hashtable<String, String[]>();
+      msgset = new Hashtable<>();
       jsmessages.put(messageclass, msgset);
     }
     msgset.put(viewId, colcommands);
index 8c5e4ac..f052c05 100755 (executable)
@@ -1913,4 +1913,14 @@ public class Alignment implements AlignmentI
   {
     hiddenCols = cols;
   }
+
+  @Override
+  public void setupJPredAlignment()
+  {
+    SequenceI repseq = getSequenceAt(0);
+    setSeqrep(repseq);
+    HiddenColumns cs = new HiddenColumns();
+    cs.hideInsertionsFor(repseq.getInsertions());
+    setHiddenColumns(cs);
+  }
 }
index 084b80e..bdc48d0 100755 (executable)
@@ -580,6 +580,17 @@ public interface AlignmentI extends AnnotatedCollectionI
    */
   AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo);
 
+  /**
+   * Set the hidden columns collection on the alignment
+   * 
+   * @param cols
+   */
   public void setHiddenColumns(HiddenColumns cols);
 
+  /**
+   * Set the first sequence as representative and hide its insertions. Typically
+   * used when loading JPred files.
+   */
+  public void setupJPredAlignment();
+
 }
index d1345e3..2b5185f 100644 (file)
@@ -303,14 +303,13 @@ public class HiddenColumns
    * mark the columns corresponding to gap characters as hidden in the column
    * selection
    * 
-   * @param sr
+   * @param insertions
    */
-  public void hideInsertionsFor(SequenceI sr)
+  public void hideInsertionsFor(List<int[]> inserts)
   {
     try
     {
       LOCK.writeLock().lock();
-      List<int[]> inserts = sr.getInsertions();
       for (int[] r : inserts)
       {
         hideColumns(r[0], r[1]);
index fa052f1..0c452c3 100644 (file)
@@ -4627,11 +4627,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
             new JnetAnnotationMaker();
             JnetAnnotationMaker.add_annotation(predictions,
                     viewport.getAlignment(), 0, false);
-            SequenceI repseq = viewport.getAlignment().getSequenceAt(0);
-            viewport.getAlignment().setSeqrep(repseq);
-            HiddenColumns cs = new HiddenColumns();
-            cs.hideInsertionsFor(repseq);
-            viewport.getAlignment().setHiddenColumns(cs);
+            viewport.getAlignment().setupJPredAlignment();
             isAnnotation = true;
           }
           // else if (IdentifyFile.FeaturesFile.equals(format))
index 00476d6..885a298 100755 (executable)
@@ -968,7 +968,7 @@ public class AnnotationFile
             else
             {
               // consider deferring this till after the file has been parsed ?
-              hidden.hideInsertionsFor(sr);
+              hidden.hideInsertionsFor(sr.getInsertions());
             }
           }
           modified = true;
index ba2c1ea..a31d527 100644 (file)
@@ -420,7 +420,7 @@ public class HiddenColumnsTest
             new SequenceI[]
     { new Sequence("refseqGaptest", "KTDVTI----------NFI-----G----L") });
     HiddenColumns cs = new HiddenColumns();
-    cs.hideInsertionsFor(al.getSequenceAt(0));
+    cs.hideInsertionsFor(al.getSequenceAt(0).getInsertions());
     assertEquals("G", ""
             + al.getSequenceAt(0).getCharAt(cs.visibleToAbsoluteColumn(9)));
 
@@ -1139,10 +1139,10 @@ public class HiddenColumnsTest
     SequenceI seq1 = new Sequence("TEST1", "GAL---MFW-KQESPVICY--HRNDT");
     SequenceI seq2 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT");
 
-    h.hideInsertionsFor(seq2);
+    h.hideInsertionsFor(seq2.getInsertions());
     assertTrue(h.equals(h2));
 
-    h.hideInsertionsFor(seq1);
+    h.hideInsertionsFor(seq1.getInsertions());
     h2.hideColumns(3, 5);
     h2.hideColumns(9, 9);
     h2.hideColumns(19, 20);