Jalview 2.6 source licence
[jalview.git] / src / jalview / analysis / AAFrequency.java
index fc8cb4c..11e7a3d 100755 (executable)
@@ -1,20 +1,19 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
+ * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
- * This program 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 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
  * 
- * This program 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.
+ * 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.
  * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ * 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/>.
  */
 package jalview.analysis;
 
@@ -194,9 +193,9 @@ public class AAFrequency
           boolean includeAllConsSymbols)
   {
     completeConsensus(consensus, hconsensus, iStart, width,
-            ignoreGapsInConsensusCalculation, includeAllConsSymbols,
-            null); //new char[]
-            // { 'A', 'C', 'G', 'T', 'U' });
+            ignoreGapsInConsensusCalculation, includeAllConsSymbols, null); // new
+                                                                            // char[]
+    // { 'A', 'C', 'G', 'T', 'U' });
   }
 
   public static void completeConsensus(AlignmentAnnotation consensus,
@@ -205,8 +204,18 @@ public class AAFrequency
           boolean includeAllConsSymbols, char[] alphabet)
   {
     float tval, value;
+    if (consensus==null || consensus.annotations==null || consensus.annotations.length<width)
+    {
+      // called with a bad alignment annotation row - wait for it to be initialised properly
+      return;
+    }
     for (int i = iStart; i < width; i++)
     {
+      if (i>=hconsensus.length) {
+        // happens if sequences calculated over were shorter than alignment width
+        consensus.annotations[i]=null;
+        continue;
+      }
       value = 0;
       if (ignoreGapsInConsensusCalculation)
       {
@@ -230,7 +239,7 @@ public class AAFrequency
       if (profile != null && includeAllConsSymbols)
       {
         mouseOver = "";
-        if (alphabet!=null)
+        if (alphabet != null)
         {
           for (int c = 0; c < alphabet.length; c++)
           {