Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / io / EMBLLikeFlatFile.java
index 64943b2..f6f53a6 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * 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.
+ *  
+ * 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/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.io;
 
 import java.io.IOException;
@@ -12,7 +32,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.TreeMap;
 
-import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.FeatureProperties;
@@ -83,8 +103,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
 
   /**
    * Truncates (if necessary) the exon intervals to match 3 times the length of
-   * the protein; also accepts 3 bases longer (for stop codon not included in
-   * protein)
+   * the protein(including truncation for stop codon included in exon)
    * 
    * @param proteinLength
    * @param exon
@@ -102,11 +121,9 @@ public abstract class EMBLLikeFlatFile extends AlignFile
     int exonLength = MappingUtils.getLength(Arrays.asList(exon));
 
     /*
-     * if exon length matches protein, or is shorter, or longer by the 
-     * length of a stop codon (3 bases), then leave it unchanged
+     * if exon length matches protein, or is shorter, then leave it unchanged
      */
-    if (expectedCdsLength >= exonLength
-            || expectedCdsLength == exonLength - 3)
+    if (expectedCdsLength >= exonLength)
     {
       return exon;
     }
@@ -163,8 +180,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
    * when true, interpret the mol_type 'source' feature attribute
    * and generate an RNA sequence from the DNA record
    */
-  protected boolean produceRna=true;
-    
+  protected boolean produceRna = true;
 
   /*
    * values parsed from the data file
@@ -181,7 +197,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
 
   protected List<DBRefEntry> dbrefs;
 
-  protected boolean sequenceStringIsRNA=false;
+  protected boolean sequenceStringIsRNA = false;
 
   protected String sequenceString;
 
@@ -204,13 +220,14 @@ public abstract class EMBLLikeFlatFile extends AlignFile
      * using TreeMap gives CDS sequences in alphabetical, so readable, order
      */
     cds = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
-    
+
     parse();
   }
 
   /**
-   * process attributes for 'source' until the next FT feature entry
-   * only interested in 'mol_type'
+   * process attributes for 'source' until the next FT feature entry only
+   * interested in 'mol_type'
+   * 
    * @param tokens
    * @return
    * @throws IOException
@@ -239,7 +256,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
       int p = line.indexOf("\\mol_type");
       int qs = line.indexOf("\"", p);
       int qe = line.indexOf("\"", qs + 1);
-      String qualifier=line.substring(qs,qe).toLowerCase(Locale.ROOT);
+      String qualifier = line.substring(qs, qe).toLowerCase(Locale.ROOT);
       if (qualifier.indexOf("rna") > -1)
       {
         sequenceStringIsRNA = true;
@@ -248,12 +265,11 @@ public abstract class EMBLLikeFlatFile extends AlignFile
       {
         sequenceStringIsRNA = false;
       }
-      line=parseFeatureQualifier(sb, false);
+      line = parseFeatureQualifier(sb, false);
     }
     return line;
   }
 
-   
   /**
    * Parses one (GenBank or EMBL format) CDS feature, saves the parsed data, and
    * returns the next line
@@ -291,7 +307,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
       int slashPos = line.indexOf('/');
       if (slashPos == -1)
       {
-        Cache.log.error("Unexpected EMBL line ignored: " + line);
+        Console.error("Unexpected EMBL line ignored: " + line);
         line = nextLine();
         continue;
       }
@@ -321,7 +337,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
           data.codonStart = Integer.parseInt(featureValue.trim());
         } catch (NumberFormatException e)
         {
-          Cache.log.error("Invalid codon_start in XML for " + this.accession
+          Console.error("Invalid codon_start in XML for " + this.accession
                   + ": " + e.getMessage());
         }
       }
@@ -357,7 +373,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
     }
     else
     {
-      Cache.log.error("Ignoring CDS feature with no protein_id for "
+      Console.error("Ignoring CDS feature with no protein_id for "
               + sourceDb + ":" + accession);
     }
 
@@ -382,7 +398,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
   {
     if (this.accession == null || this.sequenceString == null)
     {
-      Cache.log.error("Failed to parse data from EMBL");
+      Console.error("Failed to parse data from EMBL");
       return;
     }
 
@@ -584,7 +600,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
        * workaround until we handle all 'location' formats fully
        * e.g. X53828.1:60..1058 or <123..>289
        */
-      Cache.log.error(String.format(
+      Console.error(String.format(
               "Implementation Notice: EMBLCDS location '%s'not properly supported yet"
                       + " - Making up the CDNA region of (%s:%s)... may be incorrect",
               data.cdsLocation, sourceDb, this.accession));
@@ -594,12 +610,12 @@ public abstract class EMBLLikeFlatFile extends AlignFile
       if (peptideLength * 3 == completeCodonsLength)
       {
         // this might occur for CDS sequences where no features are marked
-        Cache.log.warn("Assuming no stop codon at end of cDNA fragment");
+        Console.warn("Assuming no stop codon at end of cDNA fragment");
         mappedDnaEnd = dna.getEnd();
       }
       else if ((peptideLength + 1) * 3 == completeCodonsLength)
       {
-        Cache.log.warn("Assuming stop codon at end of cDNA fragment");
+        Console.warn("Assuming stop codon at end of cDNA fragment");
         mappedDnaEnd = dna.getEnd() - 3;
       }
 
@@ -673,7 +689,7 @@ public abstract class EMBLLikeFlatFile extends AlignFile
       return MappingUtils.rangeListToArray(ranges);
     } catch (ParseException e)
     {
-      Cache.log.warn(
+      Console.warn(
               String.format("Not parsing inexact CDS location %s in ENA %s",
                       location, accession));
       return new int[] {};
@@ -718,8 +734,8 @@ public abstract class EMBLLikeFlatFile extends AlignFile
       String[] tokens = line.split(WHITESPACE);
       if (tokens.length < 2)
       {
-        Cache.log.error("Ignoring bad EMBL line for " + this.accession
-                + ": " + line);
+        Console.error("Ignoring bad EMBL line for " + this.accession + ": "
+                + line);
         break;
       }
       if (tokens[1].startsWith("/"))
@@ -800,7 +816,8 @@ public abstract class EMBLLikeFlatFile extends AlignFile
   protected String parseFeature(String line) throws IOException
   {
     String[] tokens = line.trim().split(WHITESPACE);
-    if (tokens.length < 2 || (!"CDS".equals(tokens[0]) && (!"source".equals(tokens[0]))))
+    if (tokens.length < 2
+            || (!"CDS".equals(tokens[0]) && (!"source".equals(tokens[0]))))
     {
       return nextLine();
     }