Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / datamodel / AlignmentView.java
index 9ca70f2..6ab71c7 100644 (file)
@@ -74,7 +74,7 @@ public class AlignmentView
 
     ScGroup()
     {
-      seqs = new ArrayList<SeqCigar>();
+      seqs = new ArrayList<>();
     }
 
     /**
@@ -140,18 +140,17 @@ public class AlignmentView
    *          - when set, any groups on the given alignment will be marked on
    *          the view
    */
-  public AlignmentView(AlignmentI alignment,
- HiddenColumns hidden,
-          SequenceGroup selection,
-          boolean hasHiddenColumns, boolean selectedRegionOnly,
-          boolean recordGroups)
+  public AlignmentView(AlignmentI alignment, HiddenColumns hidden,
+          SequenceGroup selection, boolean hasHiddenColumns,
+          boolean selectedRegionOnly, boolean recordGroups)
   {
     // refactored from AlignViewport.getAlignmentView(selectedOnly);
     this(new jalview.datamodel.CigarArray(alignment,
             (hasHiddenColumns ? hidden : null),
             (selectedRegionOnly ? selection : null)),
-            (selectedRegionOnly && selection != null) ? selection
-                    .getStartRes() : 0);
+            (selectedRegionOnly && selection != null)
+                    ? selection.getStartRes()
+                    : 0);
     isNa = alignment.isNucleotide();
     // walk down SeqCigar array and Alignment Array - optionally restricted by
     // selected region.
@@ -161,19 +160,18 @@ public class AlignmentView
     SequenceI[] selseqs;
     if (selection != null && selection.getSize() > 0)
     {
-      List<SequenceI> sel = selection.getSequences(null);
       this.selected = new ScGroup();
-      selseqs = selection
-              .getSequencesInOrder(alignment, selectedRegionOnly);
+      selseqs = selection.getSequencesInOrder(alignment,
+              selectedRegionOnly);
     }
     else
     {
       selseqs = alignment.getSequencesArray();
     }
 
-    List<List<SequenceI>> seqsets = new ArrayList<List<SequenceI>>();
+    List<List<SequenceI>> seqsets = new ArrayList<>();
     // get the alignment's group list and make a copy
-    List<SequenceGroup> grps = new ArrayList<SequenceGroup>();
+    List<SequenceGroup> grps = new ArrayList<>();
     List<SequenceGroup> gg = alignment.getGroups();
     grps.addAll(gg);
     ScGroup[] sgrps = null;
@@ -186,7 +184,7 @@ public class AlignmentView
         // strip out any groups that do not actually intersect with the
         // visible and selected region
         int ssel = selection.getStartRes(), esel = selection.getEndRes();
-        List<SequenceGroup> isg = new ArrayList<SequenceGroup>();
+        List<SequenceGroup> isg = new ArrayList<>();
         for (SequenceGroup sg : grps)
         {
           if (!(sg.getStartRes() > esel || sg.getEndRes() < ssel))
@@ -246,7 +244,7 @@ public class AlignmentView
               {
                 if (scGroups == null)
                 {
-                  scGroups = new ArrayList<ScGroup>();
+                  scGroups = new ArrayList<>();
                 }
                 addedgps[sg] = true;
                 scGroups.add(sgrps[sg]);
@@ -335,9 +333,9 @@ public class AlignmentView
   {
     HiddenColumns hidden = new HiddenColumns();
 
-    return new Object[] {
-        SeqCigar.createAlignmentSequences(sequences, gapCharacter, hidden,
-                contigs), hidden };
+    return new Object[] { SeqCigar.createAlignmentSequences(sequences,
+            gapCharacter, hidden, contigs),
+        hidden };
   }
 
   /**
@@ -370,8 +368,8 @@ public class AlignmentView
    *          - true if vcal is alignment of the visible regions of the view
    *          (e.g. as returned from getVisibleAlignment)
    */
-  private void addPrunedGroupsInOrder(AlignmentI vcal, int gstart,
-          int gend, boolean viscontigs)
+  private void addPrunedGroupsInOrder(AlignmentI vcal, int gstart, int gend,
+          boolean viscontigs)
   {
     boolean r = false;
     if (gstart > -1 && gstart <= gend)
@@ -441,8 +439,8 @@ public class AlignmentView
               for (int h = 0; h < contigs.length; h += 3)
               {
                 {
-                  prune.addShift(p + contigs[h + 1], contigs[h + 2]
-                          - contigs[h + 1]);
+                  prune.addShift(p + contigs[h + 1],
+                          contigs[h + 2] - contigs[h + 1]);
                 }
                 p = contigs[h + 1] + contigs[h + 2];
               }
@@ -652,8 +650,8 @@ public class AlignmentView
           SequenceI mseq[] = new SequenceI[sequences.length];
           for (int s = 0; s < mseq.length; s++)
           {
-            mseq[s] = sequences[s].getSeq(gapCharacter).getSubSequence(
-                    start, contigs[contig + 1]);
+            mseq[s] = sequences[s].getSeq(gapCharacter)
+                    .getSubSequence(start, contigs[contig + 1]);
           }
           smsa[j] = mseq;
           j++;
@@ -699,9 +697,8 @@ public class AlignmentView
   {
     if (sequences == null || width <= 0)
     {
-      throw new Error(
-              MessageManager
-                      .getString("error.empty_view_cannot_be_updated"));
+      throw new Error(MessageManager
+              .getString("error.empty_view_cannot_be_updated"));
     }
     if (nvismsa == null)
     {
@@ -732,17 +729,13 @@ public class AlignmentView
               j++;
               if (mseq.length != sequences.length)
               {
-                throw new Error(
-                        MessageManager
-                                .formatMessage(
-                                        "error.mismatch_between_number_of_sequences_in_block",
-                                        new String[] {
-                                            Integer.valueOf(j).toString(),
-                                            Integer.valueOf(mseq.length)
-                                                    .toString(),
-                                            Integer.valueOf(
-                                                    sequences.length)
-                                                    .toString() }));
+                throw new Error(MessageManager.formatMessage(
+                        "error.mismatch_between_number_of_sequences_in_block",
+                        new String[]
+                        { Integer.valueOf(j).toString(),
+                            Integer.valueOf(mseq.length).toString(),
+                            Integer.valueOf(sequences.length)
+                                    .toString() }));
               }
               swidth = mseq[0].getLength(); // JBPNote: could ensure padded
               // here.
@@ -754,9 +747,9 @@ public class AlignmentView
                 }
                 else
                 {
-                  alignment[s].setSequence(alignment[s]
-                          .getSequenceAsString()
-                          + mseq[s].getSequenceAsString());
+                  alignment[s]
+                          .setSequence(alignment[s].getSequenceAsString()
+                                  + mseq[s].getSequenceAsString());
                   if (mseq[s].getStart() <= mseq[s].getEnd())
                   {
                     alignment[s].setEnd(mseq[s].getEnd());
@@ -788,9 +781,9 @@ public class AlignmentView
                   }
                   else
                   {
-                    alignment[s].setSequence(alignment[s]
-                            .getSequenceAsString()
-                            + oseq.getSequenceAsString());
+                    alignment[s]
+                            .setSequence(alignment[s].getSequenceAsString()
+                                    + oseq.getSequenceAsString());
                     if (oseq.getEnd() >= oseq.getStart())
                     {
                       alignment[s].setEnd(oseq.getEnd());
@@ -825,8 +818,7 @@ public class AlignmentView
             }
           }
           // mark hidden segment as hidden in the new alignment
-          hidden.hideColumns(nwidth, nwidth + contigs[contig + 2]
-                  - 1);
+          hidden.hideColumns(nwidth, nwidth + contigs[contig + 2] - 1);
           nwidth += contigs[contig + 2];
         }
         // Do final segment - if it exists
@@ -881,9 +873,9 @@ public class AlignmentView
                   }
                   else
                   {
-                    alignment[s].setSequence(alignment[s]
-                            .getSequenceAsString()
-                            + oseq.getSequenceAsString());
+                    alignment[s]
+                            .setSequence(alignment[s].getSequenceAsString()
+                                    + oseq.getSequenceAsString());
                     if (oseq.getEnd() >= oseq.getStart())
                     {
                       alignment[s].setEnd(oseq.getEnd());
@@ -895,9 +887,8 @@ public class AlignmentView
               else
               {
                 // place gaps.
-                throw new Error(
-                        MessageManager
-                                .getString("error.padding_not_yet_implemented"));
+                throw new Error(MessageManager
+                        .getString("error.padding_not_yet_implemented"));
               }
             }
           }
@@ -909,12 +900,10 @@ public class AlignmentView
     {
       if (nvismsa.length != 1)
       {
-        throw new Error(
-                MessageManager
-                        .formatMessage(
-                                "error.mismatch_between_visible_blocks_to_update_and_number_of_contigs_in_view",
-                                new String[] { Integer.valueOf(
-                                        nvismsa.length).toString() }));
+        throw new Error(MessageManager.formatMessage(
+                "error.mismatch_between_visible_blocks_to_update_and_number_of_contigs_in_view",
+                new String[]
+                { Integer.valueOf(nvismsa.length).toString() }));
       }
       if (nvismsa[0] != null)
       {
@@ -1139,12 +1128,12 @@ public class AlignmentView
   public static void testSelectionViews(AlignmentI alignment,
           HiddenColumns hidden, SequenceGroup selection)
   {
-    System.out.println("Testing standard view creation:\n");
+    jalview.bin.Console.outPrintln("Testing standard view creation:\n");
     AlignmentView view = null;
     try
     {
-      System.out
-              .println("View with no hidden columns, no limit to selection, no groups to be collected:");
+      jalview.bin.Console.outPrintln(
+              "View with no hidden columns, no limit to selection, no groups to be collected:");
       view = new AlignmentView(alignment, hidden, selection, false, false,
               false);
       summariseAlignmentView(view, System.out);
@@ -1152,99 +1141,99 @@ public class AlignmentView
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err
-              .println("Failed to generate alignment with selection but no groups marked.");
+      jalview.bin.Console.errPrintln(
+              "Failed to generate alignment with selection but no groups marked.");
     }
     try
     {
-      System.out
-              .println("View with no hidden columns, no limit to selection, and all groups to be collected:");
+      jalview.bin.Console.outPrintln(
+              "View with no hidden columns, no limit to selection, and all groups to be collected:");
       view = new AlignmentView(alignment, hidden, selection, false, false,
               true);
       summariseAlignmentView(view, System.out);
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err
-              .println("Failed to generate alignment with selection marked but no groups marked.");
+      jalview.bin.Console.errPrintln(
+              "Failed to generate alignment with selection marked but no groups marked.");
     }
     try
     {
-      System.out
-              .println("View with no hidden columns, limited to selection and no groups to be collected:");
+      jalview.bin.Console.outPrintln(
+              "View with no hidden columns, limited to selection and no groups to be collected:");
       view = new AlignmentView(alignment, hidden, selection, false, true,
               false);
       summariseAlignmentView(view, System.out);
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err
-              .println("Failed to generate alignment with selection restricted but no groups marked.");
+      jalview.bin.Console.errPrintln(
+              "Failed to generate alignment with selection restricted but no groups marked.");
     }
     try
     {
-      System.out
-              .println("View with no hidden columns, limited to selection, and all groups to be collected:");
+      jalview.bin.Console.outPrintln(
+              "View with no hidden columns, limited to selection, and all groups to be collected:");
       view = new AlignmentView(alignment, hidden, selection, false, true,
               true);
       summariseAlignmentView(view, System.out);
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err
-              .println("Failed to generate alignment with selection restricted and groups marked.");
+      jalview.bin.Console.errPrintln(
+              "Failed to generate alignment with selection restricted and groups marked.");
     }
     try
     {
-      System.out
-              .println("View *with* hidden columns, no limit to selection, no groups to be collected:");
+      jalview.bin.Console.outPrintln(
+              "View *with* hidden columns, no limit to selection, no groups to be collected:");
       view = new AlignmentView(alignment, hidden, selection, true, false,
               false);
       summariseAlignmentView(view, System.out);
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err
-              .println("Failed to generate alignment with selection but no groups marked.");
+      jalview.bin.Console.errPrintln(
+              "Failed to generate alignment with selection but no groups marked.");
     }
     try
     {
-      System.out
-              .println("View *with* hidden columns, no limit to selection, and all groups to be collected:");
+      jalview.bin.Console.outPrintln(
+              "View *with* hidden columns, no limit to selection, and all groups to be collected:");
       view = new AlignmentView(alignment, hidden, selection, true, false,
               true);
       summariseAlignmentView(view, System.out);
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err
-              .println("Failed to generate alignment with selection marked but no groups marked.");
+      jalview.bin.Console.errPrintln(
+              "Failed to generate alignment with selection marked but no groups marked.");
     }
     try
     {
-      System.out
-              .println("View *with* hidden columns, limited to selection and no groups to be collected:");
+      jalview.bin.Console.outPrintln(
+              "View *with* hidden columns, limited to selection and no groups to be collected:");
       view = new AlignmentView(alignment, hidden, selection, true, true,
               false);
       summariseAlignmentView(view, System.out);
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err
-              .println("Failed to generate alignment with selection restricted but no groups marked.");
+      jalview.bin.Console.errPrintln(
+              "Failed to generate alignment with selection restricted but no groups marked.");
     }
     try
     {
-      System.out
-              .println("View *with* hidden columns, limited to selection, and all groups to be collected:");
+      jalview.bin.Console.outPrintln(
+              "View *with* hidden columns, limited to selection, and all groups to be collected:");
       view = new AlignmentView(alignment, hidden, selection, true, true,
               true);
       summariseAlignmentView(view, System.out);
     } catch (Exception e)
     {
       e.printStackTrace();
-      System.err
-              .println("Failed to generate alignment with selection restricted and groups marked.");
+      jalview.bin.Console.errPrintln(
+              "Failed to generate alignment with selection restricted and groups marked.");
     }
 
   }