JAL-3949 Complete new abstracted logging framework in jalview.log. Updated log calls...
[jalview.git] / src / jalview / io / vamsas / Sequencemapping.java
index b0a3dd4..3c2aa4c 100644 (file)
@@ -1,49 +1,54 @@
 /*
- * 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-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
- * 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.
+ *  
+ * 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.io.vamsas;
 
-import java.util.Vector;
-
+import jalview.bin.Cache;
 import jalview.datamodel.AlignedCodonFrame;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.Mapping;
 import jalview.datamodel.SequenceI;
+import jalview.gui.Desktop;
 import jalview.io.VamsasAppDatastore;
-import uk.ac.vamsas.client.Vobject;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
 import uk.ac.vamsas.objects.core.AlignmentSequence;
 import uk.ac.vamsas.objects.core.DataSet;
-import uk.ac.vamsas.objects.core.Local;
-import uk.ac.vamsas.objects.core.RangeType;
-import uk.ac.vamsas.objects.core.Seg;
 import uk.ac.vamsas.objects.core.Sequence;
 import uk.ac.vamsas.objects.core.SequenceMapping;
 import uk.ac.vamsas.objects.core.SequenceType;
 
 /**
- * binds a vamsas sequence mapping object from the vamsas document to
- * a maplist object associated with a mapping in the Jalview model.
- * We use the maplist object because these are referred to both in
- * the Mapping object associated with a jalview.datamodel.DBRefEntry
- * and in the array of jalview.datamodel.AlCodonFrame objects that
- * Jalview uses to propagate sequence mapping position highlighting
- * across the views.
+ * binds a vamsas sequence mapping object from the vamsas document to a maplist
+ * object associated with a mapping in the Jalview model. We use the maplist
+ * object because these are referred to both in the Mapping object associated
+ * with a jalview.datamodel.DBRefEntry and in the array of
+ * jalview.datamodel.AlCodonFrame objects that Jalview uses to propagate
+ * sequence mapping position highlighting across the views.
+ * 
  * @author JimP
- *
+ * 
  */
 public class Sequencemapping extends Rangetype
 {
@@ -53,10 +58,13 @@ public class Sequencemapping extends Rangetype
     super(datastore, sequenceMapping, jalview.util.MapList.class);
     doJvUpdate();
   }
+
   private SequenceType from;
+
   private DataSet ds;
+
   private Mapping mjvmapping;
-  
+
   /**
    * create or update a vamsas sequence mapping corresponding to a jalview
    * Mapping between two dataset sequences
@@ -78,31 +86,30 @@ public class Sequencemapping extends Rangetype
     validate();
     doSync();
   }
+
   /**
    * local check that extant mapping context is valid
    */
   public void validate()
   {
-    
+
     SequenceMapping sequenceMapping = (SequenceMapping) vobj;
-    if (sequenceMapping==null)
+    if (sequenceMapping == null)
     {
       return;
     }
     if (from != null && sequenceMapping.getLoc() != from)
     {
-      jalview.bin.Cache.log.warn("Probable IMPLEMENTATION ERROR: " + from
+      Cache.warn("Probable IMPLEMENTATION ERROR: " + from
               + " doesn't match the local mapping sequence.");
     }
     if (ds != null && sequenceMapping.is__stored_in_document()
             && sequenceMapping.getV_parent() != ds)
     {
-      jalview.bin.Cache.log
-              .warn("Probable IMPLEMENTATION ERROR: "
-                      + ds
-                      + " doesn't match the parent of the bound sequence mapping object.");
+      Cache.warn("Probable IMPLEMENTATION ERROR: " + ds
+              + " doesn't match the parent of the bound sequence mapping object.");
     }
-  }    
+  }
 
   public void addToDocument()
   {
@@ -117,18 +124,19 @@ public class Sequencemapping extends Rangetype
   public void conflict()
   {
     conflict(mjvmapping, (SequenceMapping) vobj);
-    
+
   }
 
   public void updateToDoc()
   {
     update(mjvmapping, (SequenceMapping) vobj);
   }
+
   public void updateFromDoc()
   {
     update((SequenceMapping) vobj, (jalview.datamodel.Mapping) jvobj);
   }
-  
+
   private void conflict(Mapping mjvmapping, SequenceMapping sequenceMapping)
   {
     System.err.println("Conflict in update of sequenceMapping "
@@ -146,8 +154,8 @@ public class Sequencemapping extends Rangetype
     SequenceType to = (SequenceType) getjv2vObj(jvto);
     if (to == null)
     {
-      jalview.bin.Cache.log
-              .warn("FIXME NONFATAL - do a second update: Ignoring Forward Reference to seuqence not yet bound to vamsas seuqence object");
+      Cache.warn(
+              "FIXME NONFATAL - do a second update: Ignoring Forward Reference to seuqence not yet bound to vamsas seuqence object");
       return;
     }
     SequenceMapping sequenceMapping = new SequenceMapping();
@@ -177,8 +185,8 @@ public class Sequencemapping extends Rangetype
 
     if (!dnaToProt)
     {
-      jalview.bin.Cache.log
-              .warn("Ignoring Mapping - don't support protein to protein mapping in vamsas document yet.");
+      Cache.warn(
+              "Ignoring Mapping - don't support protein to protein mapping in vamsas document yet.");
       return;
     }
     if (ds == null)
@@ -205,8 +213,8 @@ public class Sequencemapping extends Rangetype
               true);
     }
     ds.addSequenceMapping(sequenceMapping);
-    sequenceMapping.setProvenance(this
-            .dummyProvenance("user defined coding region translation")); // TODO:
+    sequenceMapping.setProvenance(
+            this.dummyProvenance("user defined coding region translation")); // TODO:
     // correctly
     // construct
     // provenance
@@ -217,34 +225,33 @@ public class Sequencemapping extends Rangetype
     // mapping
     bindjvvobj(mjvmapping.getMap(), sequenceMapping);
 
-    jalview.bin.Cache.log.debug("Successfully created mapping "
-            + sequenceMapping.getVorbaId());
+    Cache.debug(
+            "Successfully created mapping " + sequenceMapping.getVorbaId());
   }
 
   // private void update(jalview.util.MapList mjvmapping,
-     //     SequenceMapping sequenceMapping)
+  // SequenceMapping sequenceMapping)
   {
-    jalview.bin.Cache.log
-            .error("Not implemented: Jalview Update Alcodon Mapping:TODO!");
+    Cache.error("Not implemented: Jalview Update Alcodon Mapping:TODO!");
   }
 
   private void update(SequenceMapping sequenceMapping,
           jalview.datamodel.Mapping mjvmapping)
   {
-    jalview.bin.Cache.log
-            .error("Not implemented: Update DBRef Mapping from Jalview");
+    Cache.error("Not implemented: Update DBRef Mapping from Jalview");
   }
+
   private void update(jalview.datamodel.Mapping mjvmapping,
           SequenceMapping sequenceMapping)
   {
-    jalview.bin.Cache.log
-            .error("Not implemented: Jalview Update Sequence DBRef Mapping");
+    Cache.error(
+            "Not implemented: Jalview Update Sequence DBRef Mapping");
   }
 
   /**
-   * bind a SequenceMapping to a live AlCodonFrame element
-   * limitations: Currently, jalview only deals with mappings between dataset
-   * sequences, and even then, only between those that map from DNA to Protein.
+   * bind a SequenceMapping to a live AlCodonFrame element limitations:
+   * Currently, jalview only deals with mappings between dataset sequences, and
+   * even then, only between those that map from DNA to Protein.
    * 
    * @param sequenceMapping
    */
@@ -274,15 +281,15 @@ public class Sequencemapping extends Rangetype
     }
     if (sdloc == null || sdmap == null)
     {
-      jalview.bin.Cache.log.info("Ignoring non sequence-sequence mapping");
+      Cache.info("Ignoring non sequence-sequence mapping");
       return;
     }
-    mobj = this.getvObj2jv((Vobject) sdloc);
+    mobj = this.getvObj2jv(sdloc);
     if (mobj instanceof SequenceI)
     {
       from = (SequenceI) mobj;
     }
-    mobj = this.getvObj2jv((Vobject) sdmap);
+    mobj = this.getvObj2jv(sdmap);
     if (mobj instanceof SequenceI)
     {
       to = (SequenceI) mobj;
@@ -290,8 +297,8 @@ public class Sequencemapping extends Rangetype
     if (from == null || to == null)
     {
 
-      jalview.bin.Cache.log
-              .error("Probable Vamsas implementation error : unbound dataset sequences involved in a mapping are being parsed!");
+      Cache.error(
+              "Probable Vamsas implementation error : unbound dataset sequences involved in a mapping are being parsed!");
       return;
     }
 
@@ -319,19 +326,17 @@ public class Sequencemapping extends Rangetype
     }
     // create mapping storage object and make each dataset alignment reference
     // it.
-    jalview.datamodel.AlignmentI dsLoc = (jalview.datamodel.AlignmentI) getvObj2jv(sdloc
-            .getV_parent());
-    jalview.datamodel.AlignmentI dsMap = (jalview.datamodel.AlignmentI) getvObj2jv(sdmap
-            .getV_parent());
-    AlignedCodonFrame afc = new AlignedCodonFrame(0);
+    AlignmentI dsLoc = (AlignmentI) getvObj2jv(sdloc.getV_parent());
+    AlignmentI dsMap = (AlignmentI) getvObj2jv(sdmap.getV_parent());
+    AlignedCodonFrame acf = new AlignedCodonFrame();
 
     if (dsLoc != null && dsLoc != dsMap)
     {
-      dsLoc.addCodonFrame(afc);
+      dsLoc.addCodonFrame(acf);
     }
     if (dsMap != null)
     {
-      dsMap.addCodonFrame(afc);
+      dsMap.addCodonFrame(acf);
     }
     // create and add the new mapping to (each) dataset's codonFrame
 
@@ -341,25 +346,26 @@ public class Sequencemapping extends Rangetype
       if (!sense)
       {
         mapping = this.parsemapType(sequenceMapping, 1, 3); // invert sense
-        mapping = new jalview.util.MapList(mapping.getToRanges(), mapping
-                .getFromRanges(), mapping.getToRatio(), mapping
-                .getFromRatio());
-        afc.addMap(to, from, mapping);
+        mapping = new jalview.util.MapList(mapping.getToRanges(),
+                mapping.getFromRanges(), mapping.getToRatio(),
+                mapping.getFromRatio());
+        acf.addMap(to, from, mapping);
       }
       else
       {
         mapping = this.parsemapType(sequenceMapping, 3, 1); // correct sense
-        afc.addMap(from, to, mapping);
+        acf.addMap(from, to, mapping);
       }
-    } else {
+    }
+    else
+    {
       mapping = this.parsemapType(sequenceMapping, 1, 1); // correct sense
-      afc.addMap(from, to, mapping);
+      acf.addMap(from, to, mapping);
     }
     bindjvvobj(mapping, sequenceMapping);
     jalview.structure.StructureSelectionManager
-            .getStructureSelectionManager().addMappings(
-                    new AlignedCodonFrame[]
-                    { afc });
+            .getStructureSelectionManager(Desktop.instance)
+            .registerMapping(acf);
     // Try to link up any conjugate database references in the two sequences
     // matchConjugateDBRefs(from, to, mapping);
     // Try to propagate any dbrefs across this mapping.
@@ -371,45 +377,51 @@ public class Sequencemapping extends Rangetype
    * associated with conjugate DBRefEntry under given mapping
    * 
    * @param from
-   *                sequence corresponding to from reference for sequence
-   *                mapping
+   *          sequence corresponding to from reference for sequence mapping
    * @param to
-   *                sequence correspondeing to to reference for sequence mapping
+   *          sequence correspondeing to to reference for sequence mapping
    * @param smap
-   *                maplist parsed in same sense as from and to
+   *          maplist parsed in same sense as from and to
    */
   private void matchConjugateDBRefs(SequenceI from, SequenceI to,
           jalview.util.MapList smap)
   {
-    if (from.getDBRef() == null && to.getDBRef() == null)
+    if (from.getDBRefs() == null && to.getDBRefs() == null)
     {
-      if (jalview.bin.Cache.log.isDebugEnabled())
+      if (Cache.isDebugEnabled())
       {
-        jalview.bin.Cache.log.debug("Not matching conjugate refs for "
+        Cache.debug("Not matching conjugate refs for "
                 + from.getName() + " and " + to.getName());
       }
       return;
     }
-    if (jalview.bin.Cache.log.isDebugEnabled())
+    if (Cache.isDebugEnabled())
     {
-      jalview.bin.Cache.log.debug("Matching conjugate refs for "
+      Cache.debug("Matching conjugate refs for "
               + from.getName() + " and " + to.getName());
     }
-    jalview.datamodel.DBRefEntry[] fdb = from.getDBRef();
-    jalview.datamodel.DBRefEntry[] tdb = new jalview.datamodel.DBRefEntry[to
-            .getDBRef().length];
-    int tdblen = to.getDBRef().length;
-    System.arraycopy(to.getDBRef(), 0, tdb, 0, tdblen);
+    List<DBRefEntry> fdb = from.getDBRefs();
+    List<DBRefEntry> tdb = new ArrayList<DBRefEntry>(to.getDBRefs());
+    int tdblen = to.getDBRefs().size();
+//    
+//    
+//    YOWSER
+//    
+//    System.arraycopy(to.getDBRefs(), 0, tdb, 0, tdblen);
+//    
+//    
+//    
+//    
     Vector matched = new Vector();
     jalview.util.MapList smapI = smap.getInverse();
-    for (int f = 0; f < fdb.length; f++)
+    for (int f = 0, fn = fdb.size(); f < fn; f++)
     {
-      jalview.datamodel.DBRefEntry fe = fdb[f];
+      jalview.datamodel.DBRefEntry fe = fdb.get(f);
       jalview.datamodel.Mapping fmp = fe.getMap();
-      boolean fmpnnl = fmp != null;
+      boolean fmpnnl = (fmp != null);
       // if (fmpnnl && fmp.getTo()!=null)
       // {
-      // jalview.bin.Cache.log.debug("Not overwriting existing To reference in
+      // Cache.debug("Not overwriting existing To reference in
       // "+fe);
       // continue;
       // }
@@ -421,7 +433,7 @@ public class Sequencemapping extends Rangetype
               : false;
       for (int t = 0; t < tdblen; t++)
       {
-        jalview.datamodel.DBRefEntry te = tdb[t];
+        jalview.datamodel.DBRefEntry te = tdb.get(t);
         if (te != null)
         {
           if (fe.getSource().equals(te.getSource())
@@ -437,8 +449,9 @@ public class Sequencemapping extends Rangetype
             boolean smaptolocal2tm = (tmpnnl) ? smap.equals(tmp.getMap())
                     : false;
             // smap to maps from te.map to te.local
-            boolean smaptotemap2local = (tmpnnl) ? smapI.equals(fmp
-                    .getMap()) : false;
+            boolean smaptotemap2local = (tmpnnl)
+                    ? smapI.equals(fmp.getMap())
+                    : false;
             if (smapfromlocal2fe && smaptotemap2local)
             {
               // smap implies mapping from to to from