apply version 2.7 copyright
[jalview.git] / src / jalview / analysis / Dna.java
index ce13665..49c37df 100644 (file)
@@ -1,20 +1,19 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)\r
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
  * \r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
+ * This file is part of Jalview.\r
  * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
  * \r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE.  See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 package jalview.analysis;\r
 \r
@@ -85,7 +84,7 @@ public class Dna
    * @param annotations\r
    * @param aWidth\r
    * @param dataset\r
-   *                destination dataset for translated sequences and mappings\r
+   *          destination dataset for translated sequences and mappings\r
    * @return\r
    */\r
   public static AlignmentI CdnaTranslate(SequenceI[] selection,\r
@@ -100,9 +99,9 @@ public class Dna
    * \r
    * @param selection\r
    * @param seqstring\r
-   * @param product -\r
-   *                array of DbRefEntry objects from which exon map in seqstring\r
-   *                is derived\r
+   * @param product\r
+   *          - array of DbRefEntry objects from which exon map in seqstring is\r
+   *          derived\r
    * @param viscontigs\r
    * @param gapCharacter\r
    * @param annotations\r
@@ -128,7 +127,7 @@ public class Dna
       SequenceI newseq = translateCodingRegion(selection[s], seqstring[s],\r
               viscontigs, codons, gapCharacter,\r
               (product != null) ? product[s] : null); // possibly anonymous\r
-                                                      // product\r
+      // product\r
       if (newseq != null)\r
       {\r
         pepseqs.addElement(newseq);\r
@@ -215,7 +214,7 @@ public class Dna
    * @param viscontigs\r
    * @param gapCharacter\r
    * @param dataset\r
-   *                destination dataset for translated sequences\r
+   *          destination dataset for translated sequences\r
    * @param annotations\r
    * @param aWidth\r
    * @return\r
@@ -364,28 +363,60 @@ public class Dna
   {\r
     // Have a look at all the codon positions for annotation and put the first\r
     // one found into the translated annotation pos.\r
+    int contrib = 0;\r
+    Annotation annot = null;\r
     for (int p = 0; p < 3; p++)\r
     {\r
       if (annotations[is[p]] != null)\r
       {\r
-        return new Annotation(annotations[is[p]]);\r
+        if (annot == null)\r
+        {\r
+          annot = new Annotation(annotations[is[p]]);\r
+          contrib = 1;\r
+        }\r
+        else\r
+        {\r
+          // merge with last\r
+          Annotation cpy = new Annotation(annotations[is[p]]);\r
+          if (annot.colour == null)\r
+          {\r
+            annot.colour = cpy.colour;\r
+          }\r
+          if (annot.description == null || annot.description.length() == 0)\r
+          {\r
+            annot.description = cpy.description;\r
+          }\r
+          if (annot.displayCharacter == null)\r
+          {\r
+            annot.displayCharacter = cpy.displayCharacter;\r
+          }\r
+          if (annot.secondaryStructure == 0)\r
+          {\r
+            annot.secondaryStructure = cpy.secondaryStructure;\r
+          }\r
+          annot.value += cpy.value;\r
+          contrib++;\r
+        }\r
       }\r
     }\r
-    return null;\r
+    if (contrib > 1)\r
+    {\r
+      annot.value /= (float) contrib;\r
+    }\r
+    return annot;\r
   }\r
 \r
   /**\r
    * Translate a na sequence\r
    * \r
    * @param selection\r
-   *                sequence displayed under viscontigs visible columns\r
+   *          sequence displayed under viscontigs visible columns\r
    * @param seqstring\r
-   *                ORF read in some global alignment reference frame\r
+   *          ORF read in some global alignment reference frame\r
    * @param viscontigs\r
-   *                mapping from global reference frame to visible seqstring ORF\r
-   *                read\r
+   *          mapping from global reference frame to visible seqstring ORF read\r
    * @param codons\r
-   *                Definition of global ORF alignment reference frame\r
+   *          Definition of global ORF alignment reference frame\r
    * @param gapCharacter\r
    * @param newSeq\r
    * @return sequence ready to be added to alignment.\r
@@ -517,8 +548,9 @@ public class Dna
         }\r
         if (aspos >= codons.aaWidth)\r
         {\r
-          // update maximum alignment width \r
-          // (we can do this without calling checkCodonFrameWidth because it was already done above)\r
+          // update maximum alignment width\r
+          // (we can do this without calling checkCodonFrameWidth because it was\r
+          // already done above)\r
           codons.setAaWidth(aspos);\r
         }\r
         // ready for next translated reading frame alignment position (if any)\r
@@ -527,8 +559,8 @@ public class Dna
     }\r
     if (resSize > 0)\r
     {\r
-      SequenceI newseq = new Sequence(selection.getName(), protein\r
-              .toString());\r
+      SequenceI newseq = new Sequence(selection.getName(),\r
+              protein.toString());\r
       if (rf != 0)\r
       {\r
         jalview.bin.Cache.log\r
@@ -587,14 +619,13 @@ public class Dna
          * new ranges to exclude untranslated regions. if (skip.size()>0) {\r
          * Vector narange = new Vector(); for (vc=0; vc<scontigs.length; vc++) {\r
          * narange.addElement(new int[] {scontigs[vc]}); } int sint=0,iv[]; vc =\r
-         * 0; while (sint<skip.size()) { skipint = (int[])\r
-         * skip.elementAt(sint); do { iv = (int[]) narange.elementAt(vc); if\r
-         * (iv[0]>=skipint[0] && iv[0]<=skipint[1]) { if (iv[0]==skipint[0]) { //\r
-         * delete beginning of range } else { // truncate range and create new\r
-         * one if necessary iv = (int[]) narange.elementAt(vc+1); if (iv[0]<=skipint[1]) { //\r
-         * truncate range iv[0] = skipint[1]; } else {\r
-         *  } } } else if (iv[0]<skipint[0]) { iv = (int[])\r
-         * narange.elementAt(vc+1); } } while (iv[0]) } }\r
+         * 0; while (sint<skip.size()) { skipint = (int[]) skip.elementAt(sint);\r
+         * do { iv = (int[]) narange.elementAt(vc); if (iv[0]>=skipint[0] &&\r
+         * iv[0]<=skipint[1]) { if (iv[0]==skipint[0]) { // delete beginning of\r
+         * range } else { // truncate range and create new one if necessary iv =\r
+         * (int[]) narange.elementAt(vc+1); if (iv[0]<=skipint[1]) { // truncate\r
+         * range iv[0] = skipint[1]; } else { } } } else if (iv[0]<skipint[0]) {\r
+         * iv = (int[]) narange.elementAt(vc+1); } } while (iv[0]) } }\r
          */\r
         MapList map = new MapList(scontigs, new int[]\r
         { 1, resSize }, 3, 1);\r
@@ -624,7 +655,7 @@ public class Dna
       }\r
     }\r
     // register the mapping somehow\r
-    // \r
+    //\r
     return null;\r
   }\r
 \r
@@ -638,10 +669,10 @@ public class Dna
    * @param pep\r
    * @param map\r
    * @param featureTypes\r
-   *                hash who's keys are the displayed feature type strings\r
+   *          hash who's keys are the displayed feature type strings\r
    * @param featureGroups\r
-   *                hash where keys are feature groups and values are Boolean\r
-   *                objects indicating if they are displayed.\r
+   *          hash where keys are feature groups and values are Boolean objects\r
+   *          indicating if they are displayed.\r
    */\r
   private static void transferCodedFeatures(SequenceI dna, SequenceI pep,\r
           MapList map, Hashtable featureTypes, Hashtable featureGroups)\r
@@ -669,8 +700,7 @@ public class Dna
         fgstate = (featureGroups == null) ? null : ((Boolean) featureGroups\r
                 .get(sf[f].featureGroup));\r
         if ((featureTypes == null || featureTypes.containsKey(sf[f]\r
-                .getType()))\r
-                && (fgstate == null || fgstate.booleanValue()))\r
+                .getType())) && (fgstate == null || fgstate.booleanValue()))\r
         {\r
           if (FeatureProperties.isCodingFeature(null, sf[f].getType()))\r
           {\r