merge
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 8 Oct 2015 10:09:41 +0000 (11:09 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 8 Oct 2015 10:09:41 +0000 (11:09 +0100)
src/jalview/datamodel/AlignmentAnnotation.java
src/jalview/gui/AlignFrame.java
src/jalview/io/JSONFile.java
src/jalview/json/binding/biojson/v1/AlignmentAnnotationPojo.java
src/jalview/json/binding/biojson/v1/AnnotationDisplaySettingPojo.java [new file with mode: 0644]
src/jalview/json/binding/biojson/v1/AnnotationPojo.java
src/jalview/schemes/UserColourScheme.java
test/jalview/io/JSONFileTest.java

index bb45b67..9bd1f2e 100755 (executable)
@@ -957,6 +957,12 @@ public class AlignmentAnnotation
 
   }
 
+  /**
+   * When positional annotation and a sequence reference is present, clears and
+   * resizes the annotations array to the current alignment width, and adds
+   * annotation according to aligned positions of the sequenceRef given by
+   * sequenceMapping.
+   */
   public void adjustForAlignment()
   {
     if (sequenceRef == null)
@@ -980,18 +986,20 @@ public class AlignmentAnnotation
     int position;
     Annotation[] temp = new Annotation[aSize];
     Integer index;
-
-    for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
+    if (sequenceMapping != null)
     {
-      index = new Integer(a);
-      if (sequenceMapping.containsKey(index))
+      for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
       {
-        position = sequenceRef.findIndex(a) - 1;
+        index = new Integer(a);
+        Annotation annot = sequenceMapping.get(index);
+        if (annot != null)
+        {
+          position = sequenceRef.findIndex(a) - 1;
 
-        temp[position] = sequenceMapping.get(index);
+          temp[position] = annot;
+        }
       }
     }
-
     annotations = temp;
   }
 
@@ -1028,11 +1036,11 @@ public class AlignmentAnnotation
   }
 
   /**
-   * Associate this annotion with the aligned residues of a particular sequence.
-   * sequenceMapping will be updated in the following way: null sequenceI -
-   * existing mapping will be discarded but annotations left in mapped
-   * positions. valid sequenceI not equal to current sequenceRef: mapping is
-   * discarded and rebuilt assuming 1:1 correspondence TODO: overload with
+   * Associate this annotation with the aligned residues of a particular
+   * sequence. sequenceMapping will be updated in the following way: null
+   * sequenceI - existing mapping will be discarded but annotations left in
+   * mapped positions. valid sequenceI not equal to current sequenceRef: mapping
+   * is discarded and rebuilt assuming 1:1 correspondence TODO: overload with
    * parameter to specify correspondence between current and new sequenceRef
    * 
    * @param sequenceI
index 7908b0c..5c29b9b 100644 (file)
@@ -3516,6 +3516,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
         cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
                 cs, "Background"));
       }
+      if (cs instanceof TCoffeeColourScheme)
+      {
+        tcoffeeColour.setEnabled(true);
+        tcoffeeColour.setSelected(true);
+      }
     }
 
     viewport.setGlobalColourScheme(cs);
index aece7a6..5cd09a1 100644 (file)
@@ -39,12 +39,14 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.json.binding.biojson.v1.AlignmentAnnotationPojo;
 import jalview.json.binding.biojson.v1.AlignmentPojo;
+import jalview.json.binding.biojson.v1.AnnotationDisplaySettingPojo;
 import jalview.json.binding.biojson.v1.AnnotationPojo;
 import jalview.json.binding.biojson.v1.ColourSchemeMapper;
 import jalview.json.binding.biojson.v1.SequenceFeaturesPojo;
 import jalview.json.binding.biojson.v1.SequenceGrpPojo;
 import jalview.json.binding.biojson.v1.SequencePojo;
 import jalview.schemes.ColourSchemeProperty;
+import jalview.schemes.UserColourScheme;
 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
 
 import java.awt.Color;
@@ -90,6 +92,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
 
   private ArrayList<SequenceI> hiddenSequences;
 
+  private final static String TCOFFEE_SCORE = "TCoffeeScore";
+
   public JSONFile()
   {
     super();
@@ -211,7 +215,10 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
       }
       else
       {
-        if (globalColourScheme.equalsIgnoreCase("RNA Helices"))
+        // These color schemes require annotation, disable them if annotations
+        // are not exported
+        if (globalColourScheme.equalsIgnoreCase("RNA Helices")
+                || globalColourScheme.equalsIgnoreCase("T-COFFEE SCORES"))
         {
           jsonAlignmentPojo.setGlobalColorScheme("None");
         }
@@ -367,6 +374,26 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
       AlignmentAnnotationPojo alignAnnotPojo = new AlignmentAnnotationPojo();
       alignAnnotPojo.setDescription(annot.description);
       alignAnnotPojo.setLabel(annot.label);
+      if (!Double.isNaN(annot.score))
+      {
+        alignAnnotPojo.setScore(annot.score);
+      }
+      alignAnnotPojo.setCalcId(annot.getCalcId());
+      alignAnnotPojo.setGraphType(annot.graph);
+
+      AnnotationDisplaySettingPojo annotSetting = new AnnotationDisplaySettingPojo();
+      annotSetting.setBelowAlignment(annot.belowAlignment);
+      annotSetting.setCentreColLabels(annot.centreColLabels);
+      annotSetting.setScaleColLabel(annot.scaleColLabel);
+      annotSetting.setShowAllColLabels(annot.showAllColLabels);
+      annotSetting.setVisible(annot.visible);
+      annotSetting.setHasIcon(annot.hasIcons);
+      alignAnnotPojo.setAnnotationSettings(annotSetting);
+      SequenceI refSeq = annot.sequenceRef;
+      if (refSeq != null)
+      {
+        alignAnnotPojo.setSequenceRef(String.valueOf(refSeq.hashCode()));
+      }
       for (Annotation annotation : annot.annotations)
       {
         AnnotationPojo annotationPojo = new AnnotationPojo();
@@ -376,12 +403,28 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
           annotationPojo.setValue(annotation.value);
           annotationPojo
                   .setSecondaryStructure(annotation.secondaryStructure);
-          annotationPojo.setDisplayCharacter(annotation.displayCharacter);
+          String displayChar = annotation.displayCharacter == null ? null
+                  : annotation.displayCharacter;
+          // System.out.println("--------------------->[" + displayChar + "]");
+          annotationPojo.setDisplayCharacter(displayChar);
+          if (annotation.colour != null)
+          {
+            annotationPojo.setColour(jalview.util.Format
+                    .getHexString(annotation.colour));
+          }
           alignAnnotPojo.getAnnotations().add(annotationPojo);
         }
         else
         {
-          alignAnnotPojo.getAnnotations().add(annotationPojo);
+          if (annot.getCalcId() != null
+                  && annot.getCalcId().equalsIgnoreCase(TCOFFEE_SCORE))
+          {
+            // do nothing
+          }
+          else
+          {
+            alignAnnotPojo.getAnnotations().add(annotationPojo);
+          }
         }
       }
       jsonAnnotations.add(alignAnnotPojo);
@@ -515,6 +558,12 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
                     : annot.get("displayCharacter").toString();
 
             annotations[count] = new Annotation(displayChar, desc, ss, val);
+            if (annot.get("colour") != null)
+            {
+              Color color = UserColourScheme.getColourFromString(annot.get(
+                      "colour").toString());
+              annotations[count].colour = color;
+            }
           }
           ++count;
         }
@@ -522,7 +571,65 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         AlignmentAnnotation alignAnnot = new AlignmentAnnotation(alAnnot
                 .get("label").toString(), alAnnot.get("description")
                 .toString(), annotations);
+        alignAnnot.graph = (alAnnot.get("graphType") == null) ? 0 : Integer
+                .valueOf(alAnnot.get("graphType")
+                        .toString());
+
+        JSONObject diplaySettings = (JSONObject) alAnnot
+                .get("annotationSettings");
+        if (diplaySettings != null)
+        {
+
+          alignAnnot.scaleColLabel = (diplaySettings.get("scaleColLabel") == null) ? false
+                  : Boolean.valueOf(diplaySettings.get("scaleColLabel")
+                          .toString());
+          alignAnnot.showAllColLabels = (diplaySettings
+                  .get("showAllColLabels") == null) ? true : Boolean
+                  .valueOf(diplaySettings.get("showAllColLabels")
+                          .toString());
+          alignAnnot.centreColLabels = (diplaySettings
+                  .get("centreColLabels") == null) ? true
+                  : Boolean.valueOf(diplaySettings.get("centreColLabels")
+                          .toString());
+          alignAnnot.belowAlignment = (diplaySettings.get("belowAlignment") == null) ? false
+                  : Boolean.valueOf(diplaySettings.get("belowAlignment")
+                          .toString());
+          alignAnnot.visible = (diplaySettings.get("visible") == null) ? true
+                  : Boolean.valueOf(diplaySettings.get("visible")
+                          .toString());
+          alignAnnot.hasIcons = (diplaySettings.get("hasIcon") == null) ? true
+                  : Boolean.valueOf(diplaySettings.get("hasIcon")
+                          .toString());
+
+        }
+        if (alAnnot.get("score") != null)
+        {
+          alignAnnot.score = Double
+                  .valueOf(alAnnot.get("score").toString());
+        }
+
+        String calcId = (alAnnot.get("calcId") == null) ? "" : alAnnot.get(
+                "calcId").toString();
+        alignAnnot.setCalcId(calcId);
+        String seqHash = (alAnnot.get("sequenceRef") != null) ? alAnnot
+                .get("sequenceRef").toString() : null;
+
+        Sequence sequence = (seqHash != null) ? seqMap.get(seqHash) : null;
+        if (sequence != null)
+        {
+          alignAnnot.sequenceRef = sequence;
+          sequence.addAlignmentAnnotation(alignAnnot);
+          if (alignAnnot.label.equalsIgnoreCase("T-COFFEE"))
+          {
+            alignAnnot.createSequenceMapping(sequence, sequence.getStart(),
+                    false);
+            sequence.addAlignmentAnnotation(alignAnnot);
+            alignAnnot.adjustForAlignment();
+          }
+        }
+        alignAnnot.validateRangeAndDisplay();
         this.annotations.add(alignAnnot);
+
       }
     } catch (Exception e)
     {
@@ -639,10 +746,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
     {
       if (annot != null && !annot.autoCalculated)
       {
-        if (!annot.visible)
-        {
-          continue;
-        }
         annotations.add(annot);
       }
     }
index 5e43f6d..a9e57a9 100644 (file)
@@ -30,17 +30,41 @@ public class AlignmentAnnotationPojo
 
   @Attributes(
     required = false,
-    description = "Label for the Alignment Annotation")
+    description = "Label for the alignment annotation")
   private String label;
 
   @Attributes(
     required = false,
-    description = "Description for the Alignment Annotation")
+    description = "Description for the alignment annotation")
   private String description;
 
   @Attributes(required = false)
   private List<AnnotationPojo> annotations = new ArrayList<AnnotationPojo>();
 
+  @Attributes(
+    required = false,
+    enums = { "0", "1", "2" },
+    description = "Determines the rendering for the annotation<br><ul><li>0 - No graph</li><li>1 - Bar Graph</li><li>2 - Line graph</li></ul>")
+  private int graphType;
+
+  @Attributes(
+    required = false,
+    description = "Reference to the sequence in the alignment<br> if per-sequence annotation")
+  private String sequenceRef;
+
+  @Attributes(
+    required = false,
+    description = "Stores display settings for an annotation")
+  private AnnotationDisplaySettingPojo annotationSettings;
+
+  @Attributes(required = false, description = "Score of the annotation")
+  private double score;
+
+  @Attributes(
+    required = false,
+    description = "The annotation generation source")
+  private String calcId;
+
   public String getLabel()
   {
     return label;
@@ -71,4 +95,55 @@ public class AlignmentAnnotationPojo
     this.annotations = annotations;
   }
 
+  public String getSequenceRef()
+  {
+    return sequenceRef;
+  }
+
+  public void setSequenceRef(String sequenceRef)
+  {
+    this.sequenceRef = sequenceRef;
+  }
+
+  public int getGraphType()
+  {
+    return graphType;
+  }
+
+  public void setGraphType(int graphType)
+  {
+    this.graphType = graphType;
+  }
+
+  public AnnotationDisplaySettingPojo getAnnotationSettings()
+  {
+    return annotationSettings;
+  }
+
+  public void setAnnotationSettings(
+          AnnotationDisplaySettingPojo annotationSettings)
+  {
+    this.annotationSettings = annotationSettings;
+  }
+
+  public double getScore()
+  {
+    return score;
+  }
+
+  public void setScore(double score)
+  {
+    this.score = score;
+  }
+
+  public String getCalcId()
+  {
+    return calcId;
+  }
+
+  public void setCalcId(String calcId)
+  {
+    this.calcId = calcId;
+  }
+
 }
diff --git a/src/jalview/json/binding/biojson/v1/AnnotationDisplaySettingPojo.java b/src/jalview/json/binding/biojson/v1/AnnotationDisplaySettingPojo.java
new file mode 100644 (file)
index 0000000..be50b79
--- /dev/null
@@ -0,0 +1,98 @@
+package jalview.json.binding.biojson.v1;
+
+import com.github.reinert.jjschema.Attributes;
+
+public class AnnotationDisplaySettingPojo
+{
+
+  @Attributes(
+    required = false,
+    description = "Indicates if column label is scaled to fit within the <br>alignment column")
+  private boolean scaleColLabel;
+
+  @Attributes(
+    required = false,
+    description = "Indicates if every column label is displayed.")
+  private boolean showAllColLabels;
+
+  @Attributes(
+    required = false,
+    description = "Indicates if column labels is centred relative to the <br>alignment column")
+  private boolean centreColLabels;
+
+  @Attributes(
+    required = false,
+    description = "Indicates if the Annotation is shown below the alignment")
+  private boolean belowAlignment;
+
+  @Attributes(
+    required = false,
+    description = "Indicates if the annotation row is visible")
+  private boolean visible;
+
+  @Attributes(
+    required = false,
+    description = "Indicates if annotation has a graphical symbol track")
+  private boolean hasIcon;
+
+  public boolean isScaleColLabel()
+  {
+    return scaleColLabel;
+  }
+
+  public void setScaleColLabel(boolean scaleColLabel)
+  {
+    this.scaleColLabel = scaleColLabel;
+  }
+
+  public boolean isShowAllColLabels()
+  {
+    return showAllColLabels;
+  }
+
+  public void setShowAllColLabels(boolean showAllColLabels)
+  {
+    this.showAllColLabels = showAllColLabels;
+  }
+
+  public boolean isCentreColLabels()
+  {
+    return centreColLabels;
+  }
+
+  public void setCentreColLabels(boolean centreColLabels)
+  {
+    this.centreColLabels = centreColLabels;
+  }
+
+  public boolean isBelowAlignment()
+  {
+    return belowAlignment;
+  }
+
+  public void setBelowAlignment(boolean belowAlignment)
+  {
+    this.belowAlignment = belowAlignment;
+  }
+
+  public boolean isVisible()
+  {
+    return visible;
+  }
+
+  public void setVisible(boolean visible)
+  {
+    this.visible = visible;
+  }
+
+  public boolean isHasIcon()
+  {
+    return hasIcon;
+  }
+
+  public void setHasIcon(boolean hasIcon)
+  {
+    this.hasIcon = hasIcon;
+  }
+
+}
index 407ade4..d49c1d5 100644 (file)
@@ -43,6 +43,11 @@ public class AnnotationPojo
   @Attributes(required = false, description = "Value of the annotation")
   private float value;
 
+  @Attributes(
+    required = false,
+    description = "Colour of the annotation position in hex string.")
+  private String colour;
+
   public String getDisplayCharacter()
   {
     return displayCharacter;
@@ -83,4 +88,14 @@ public class AnnotationPojo
     this.value = value;
   }
 
+  public String getColour()
+  {
+    return colour;
+  }
+
+  public void setColour(String colour)
+  {
+    this.colour = colour;
+  }
+
 }
index 92989fb..7aff05a 100755 (executable)
@@ -99,7 +99,7 @@ public class UserColourScheme extends ResidueColourScheme
     return schemeName;
   }
 
-  public Color getColourFromString(String colour)
+  public static Color getColourFromString(String colour)
   {
     colour = colour.trim();
 
index 4c2757f..d327134 100644 (file)
@@ -324,9 +324,6 @@ public class JSONFileTest
             "Colourscheme is null, parsing failed!");
     Assert.assertEquals(testJsonFile.getGlobalColourScheme(), "Zappo",
             "Zappo colour scheme expected!");
-    // Assert.assertTrue(
-    // testJsonFile.getGlobalColourScheme() instanceof ZappoColourScheme,
-    // "Zappo colour scheme expected!");
   }
 
   @Test(groups = { "Functional" })