JAL-1683 replace year/version strings with tokens in source
[jalview.git] / src / jalview / datamodel / AlignmentView.java
index ea0fbe0..f73fb74 100644 (file)
@@ -1,27 +1,30 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
  *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
  * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.datamodel;
 
+import jalview.util.MessageManager;
 import jalview.util.ShiftList;
 
 import java.io.PrintStream;
-import java.util.Enumeration;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 
@@ -44,7 +47,19 @@ public class AlignmentView
    * one or more ScGroup objects, which are referenced by each seqCigar's group
    * membership
    */
-  private Vector scGroups;
+  private List<ScGroup> scGroups=null;
+
+  private boolean isNa = false;
+
+  /**
+   * false if the view concerns peptides
+   * 
+   * @return
+   */
+  public boolean isNa()
+  {
+    return isNa;
+  }
 
   /**
    * Group defined over SeqCigars. Unlike AlignmentI associated groups, each
@@ -99,6 +114,7 @@ public class AlignmentView
             (selectedRegionOnly ? selection : null)),
             (selectedRegionOnly && selection != null) ? selection
                     .getStartRes() : 0);
+    isNa = alignment.isNucleotide();
     // walk down SeqCigar array and Alignment Array - optionally restricted by
     // selected region.
     // test group membership for each sequence in each group, store membership
@@ -117,27 +133,24 @@ public class AlignmentView
       selseqs = alignment.getSequencesArray();
     }
 
+    List<List<SequenceI>> seqsets=new ArrayList<List<SequenceI>>();
     // get the alignment's group list and make a copy
-    Vector grps = new Vector();
+    List<SequenceGroup> grps = new ArrayList<SequenceGroup>();
     List<SequenceGroup> gg = alignment.getGroups();
     grps.addAll(gg);
     ScGroup[] sgrps = null;
     boolean addedgps[] = null;
     if (grps != null)
     {
-      SequenceGroup sg;
       if (selection != null && selectedRegionOnly)
       {
         // trim annotation to the region being stored.
         // strip out any groups that do not actually intersect with the
         // visible and selected region
         int ssel = selection.getStartRes(), esel = selection.getEndRes();
-        Vector isg = new Vector();
-        Enumeration en = grps.elements();
-        while (en.hasMoreElements())
+        List<SequenceGroup> isg = new ArrayList<SequenceGroup>();
+        for (SequenceGroup sg : grps)
         {
-          sg = (SequenceGroup) en.nextElement();
-
           if (!(sg.getStartRes() > esel || sg.getEndRes() < ssel))
           {
             // adjust bounds of new group, if necessary.
@@ -152,7 +165,7 @@ public class AlignmentView
             sg.setStartRes(sg.getStartRes() - ssel + 1);
             sg.setEndRes(sg.getEndRes() - ssel + 1);
 
-            isg.addElement(sg);
+            isg.add(sg);
           }
         }
         grps = isg;
@@ -162,13 +175,13 @@ public class AlignmentView
       addedgps = new boolean[grps.size()];
       for (int g = 0; g < sgrps.length; g++)
       {
-        sg = (SequenceGroup) grps.elementAt(g);
+        SequenceGroup sg = grps.get(g);
         sgrps[g] = new ScGroup();
         sgrps[g].sg = new SequenceGroup(sg);
         addedgps[g] = false;
-        grps.setElementAt(sg.getSequences(null), g);
+        seqsets.set(g, sg.getSequences(null));
       }
-      // grps now contains vectors (should be sets) for each group, so we can
+      // seqsets now contains vectors (should be sets) for each group, so we can
       // track when we've done with the group
     }
     int csi = 0;
@@ -182,11 +195,11 @@ public class AlignmentView
           sequences[csi].setGroupMembership(selected);
           selected.addElement(sequences[csi]);
         }
-        if (grps != null)
+        if (seqsets != null)
         {
           for (int sg = 0; sg < sgrps.length; sg++)
           {
-            if (((Vector) grps.elementAt(sg)).contains(selseqs[i]))
+            if ((seqsets.get(sg)).contains(selseqs[i]))
             {
               sequences[csi].setGroupMembership(sgrps[sg]);
               sgrps[sg].sg.deleteSequence(selseqs[i], false);
@@ -195,10 +208,10 @@ public class AlignmentView
               {
                 if (scGroups == null)
                 {
-                  scGroups = new Vector();
+                  scGroups = new ArrayList<ScGroup>();
                 }
                 addedgps[sg] = true;
-                scGroups.addElement(sgrps[sg]);
+                scGroups.add(sgrps[sg]);
               }
             }
           }
@@ -226,8 +239,7 @@ public class AlignmentView
   {
     if (!seqcigararray.isSeqCigarArray())
     {
-      throw new Error(
-              "Implementation Error - can only make an alignment view from a CigarArray of sequences.");
+      throw new Error(MessageManager.getString("error.implementation_error_can_only_make_alignmnet_from_cigararray"));
     }
     // contigs = seqcigararray.applyDeletions();
     contigs = seqcigararray.getDeletedRegions();
@@ -341,7 +353,7 @@ public class AlignmentView
           SequenceGroup[] nsg = new SequenceGroup[nvg];
           for (int g = 0; g < nvg; g++)
           {
-            SequenceGroup sg = ((ScGroup) scGroups.elementAt(g)).sg;
+            SequenceGroup sg = scGroups.get(g).sg;
             if (r)
             {
               if (sg.getStartRes() > gend || sg.getEndRes() < gstart)
@@ -427,7 +439,7 @@ public class AlignmentView
             for (int g = 0; g < nvg; g++)
             {
               if (nsg[g] != null
-                      && sequences[nsq].isMemberOf(scGroups.elementAt(g)))
+                      && sequences[nsq].isMemberOf(scGroups.get(g)))
               {
                 nsg[g].addSequence(aln[nsq], false);
               }
@@ -637,7 +649,7 @@ public class AlignmentView
   {
     if (sequences == null || width <= 0)
     {
-      throw new Error("empty view cannot be updated.");
+      throw new Error(MessageManager.getString("error.empty_view_cannot_be_updated"));
     }
     if (nvismsa == null)
     {
@@ -667,11 +679,7 @@ public class AlignmentView
               j++;
               if (mseq.length != sequences.length)
               {
-                throw new Error(
-                        "Mismatch between number of sequences in block "
-                                + j + " (" + mseq.length
-                                + ") and the original view ("
-                                + 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() }));
               }
               swidth = mseq[0].getLength(); // JBPNote: could ensure padded
               // here.
@@ -824,7 +832,7 @@ public class AlignmentView
               else
               {
                 // place gaps.
-                throw new Error("Padding not yet implemented.");
+                throw new Error(MessageManager.getString("error.padding_not_yet_implemented"));
               }
             }
           }
@@ -837,9 +845,7 @@ public class AlignmentView
     {
       if (nvismsa.length != 1)
       {
-        throw new Error(
-                "Mismatch between visible blocks to update and number of contigs in view (contigs=0,blocks="
-                        + nvismsa.length);
+        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)
       {
@@ -1029,7 +1035,7 @@ public class AlignmentView
               + " groups defined on the view.");
       for (int g = 0; g < view.scGroups.size(); g++)
       {
-        ScGroup sgr = (ScGroup) view.scGroups.elementAt(g);
+        ScGroup sgr = view.scGroups.get(g);
         os.println("Group " + g + ": Name = " + sgr.sg.getName()
                 + " Contains " + sgr.seqs.size() + " Seqs.");
         os.println("This group runs from " + sgr.sg.getStartRes() + " to "