Output groups in annotation file
authoramwaterhouse <Andrew Waterhouse>
Tue, 30 Jan 2007 12:52:50 +0000 (12:52 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 30 Jan 2007 12:52:50 +0000 (12:52 +0000)
src/jalview/appletgui/AlignFrame.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AnnotationExporter.java
src/jalview/gui/AnnotationLabels.java
src/jalview/io/AnnotationFile.java

index 1c2605c..74460f7 100755 (executable)
@@ -673,7 +673,8 @@ public void itemStateChanged(ItemEvent evt)
   public String outputAnnotations(boolean displayTextbox)\r
   {\r
     String annotation = new AnnotationFile().printAnnotations(\r
-      viewport.alignment.getAlignmentAnnotation() );\r
+      viewport.alignment.getAlignmentAnnotation(),\r
+       viewport.alignment.getGroups() );\r
 \r
     if(displayTextbox)\r
     {\r
index 51c7726..3082f74 100755 (executable)
@@ -857,7 +857,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener
   {
     new AnnotationExporter().exportAnnotations(
       alignPanel,
-      viewport.alignment.getAlignmentAnnotation()
+      viewport.alignment.getAlignmentAnnotation(),
+      viewport.alignment.getGroups()
         );
   }
 
index d4975a6..522622d 100755 (executable)
@@ -28,6 +28,7 @@ import jalview.datamodel.AlignmentAnnotation;
 \r
 import java.awt.Color;\r
 import java.awt.FlowLayout;\r
+import java.util.Vector;\r
 import javax.swing.BorderFactory;\r
 \r
 \r
@@ -38,6 +39,7 @@ public class AnnotationExporter
   AlignmentPanel ap;\r
   boolean features = true;\r
   AlignmentAnnotation [] annotations;\r
+  Vector sequenceGroups;\r
 \r
   public AnnotationExporter()\r
   {\r
@@ -66,12 +68,14 @@ public class AnnotationExporter
   }\r
 \r
   public void exportAnnotations(AlignmentPanel ap,\r
-                                AlignmentAnnotation [] annotations)\r
+                                AlignmentAnnotation [] annotations,\r
+                                Vector sequenceGroups)\r
   {\r
     this.ap = ap;\r
     features = false;\r
     GFFFormat.setVisible(false);\r
     this.annotations = annotations;\r
+    this.sequenceGroups = sequenceGroups;\r
     frame.setTitle("Export Annotations");\r
   }\r
 \r
@@ -103,7 +107,9 @@ public class AnnotationExporter
         }\r
         else\r
         {\r
-           text = new AnnotationFile().printAnnotations( annotations );\r
+           text = new AnnotationFile().printAnnotations(\r
+              annotations,\r
+              sequenceGroups );\r
         }\r
 \r
         try\r
@@ -137,7 +143,9 @@ public class AnnotationExporter
     }\r
     else if(!features)\r
     {\r
-      text = new AnnotationFile().printAnnotations( annotations );\r
+      text = new AnnotationFile().printAnnotations(\r
+          annotations,\r
+          sequenceGroups );\r
     }\r
 \r
 \r
index 0ea7998..1176087 100755 (executable)
@@ -200,7 +200,8 @@ public class AnnotationLabels extends JPanel implements MouseListener,
           new AnnotationExporter().exportAnnotations(
               ap,
               new AlignmentAnnotation[]
-              {aa[selectedRow]}
+              {aa[selectedRow]},
+              null
               );
         }
         else if (evt.getActionCommand().equals(COPYCONS_SEQ))
index a7c67cd..80d31fb 100755 (executable)
@@ -24,144 +24,203 @@ import jalview.datamodel.*;
 import java.util.*;\r
 import java.net.URL;\r
 import jalview.schemes.*;\r
+import jalview.analysis.Conservation;\r
 \r
 \r
 public class AnnotationFile\r
 {\r
-\r
-  public String printAnnotations(AlignmentAnnotation [] annotations)\r
-  {\r
-    StringBuffer text = new StringBuffer(\r
-      "JALVIEW_ANNOTATION\n"\r
-      +"# Created: "\r
+  StringBuffer text = new StringBuffer(\r
+        "JALVIEW_ANNOTATION\n"\r
+        +"# Created: "\r
       +new java.util.Date()+"\n\n");\r
 \r
-    AlignmentAnnotation row;\r
-    String comma;\r
-    SequenceI seqref = null;\r
-\r
-    StringBuffer colours = new StringBuffer();\r
-    StringBuffer graphLine = new StringBuffer();\r
+  public String printAnnotations(AlignmentAnnotation [] annotations,\r
+                                Vector groups)\r
+  {\r
+    if(annotations!=null)\r
+    {\r
+      AlignmentAnnotation row;\r
+      String comma;\r
+      SequenceI seqref = null;\r
 \r
-    Hashtable graphGroup = new Hashtable();\r
+      StringBuffer colours = new StringBuffer();\r
+      StringBuffer graphLine = new StringBuffer();\r
 \r
-    java.awt.Color color;\r
+      Hashtable graphGroup = new Hashtable();\r
 \r
-    for(int i=0; i<annotations.length; i++)\r
-    {\r
-      row = annotations[i];\r
+      java.awt.Color color;\r
 \r
-      if(!row.visible)\r
-        continue;\r
+      for (int i = 0; i < annotations.length; i++)\r
+      {\r
+        row = annotations[i];\r
 \r
-      color = null;\r
+        if (!row.visible)\r
+          continue;\r
 \r
-      if( row.sequenceRef == null)\r
-      {\r
-        if(seqref!=null)\r
-          text.append("\nSEQUENCE_REF\tALIGNMENT\n");\r
+        color = null;\r
 \r
-        seqref = null;\r
-      }\r
+        if (row.sequenceRef == null)\r
+        {\r
+          if (seqref != null)\r
+            text.append("\nSEQUENCE_REF\tALIGNMENT\n");\r
 \r
-      else if (seqref == null || seqref != row.sequenceRef)\r
-      {\r
-        seqref = row.sequenceRef;\r
-        text.append("\nSEQUENCE_REF\t" + seqref.getName() + "\n");\r
-      }\r
+          seqref = null;\r
+        }\r
 \r
+        else if (seqref == null || seqref != row.sequenceRef)\r
+        {\r
+          seqref = row.sequenceRef;\r
+          text.append("\nSEQUENCE_REF\t" + seqref.getName() + "\n");\r
+        }\r
 \r
-      if( row.graph == AlignmentAnnotation.NO_GRAPH)\r
-      {\r
+        if (row.graph == AlignmentAnnotation.NO_GRAPH)\r
+        {\r
           text.append("NO_GRAPH\t");\r
-      }\r
-      else\r
-      {\r
-        if( row.graph == AlignmentAnnotation.BAR_GRAPH)\r
-          text.append("BAR_GRAPH\t");\r
-        else if(row.graph == AlignmentAnnotation.LINE_GRAPH)\r
-          text.append("LINE_GRAPH\t");\r
+        }\r
+        else\r
+        {\r
+          if (row.graph == AlignmentAnnotation.BAR_GRAPH)\r
+            text.append("BAR_GRAPH\t");\r
+          else if (row.graph == AlignmentAnnotation.LINE_GRAPH)\r
+            text.append("LINE_GRAPH\t");\r
 \r
-        if(row.getThreshold()!=null)\r
+          if (row.getThreshold() != null)\r
             graphLine.append("GRAPHLINE\t"\r
                              + row.label + "\t"\r
                              + row.getThreshold().value + "\t"\r
                              + row.getThreshold().label + "\t"\r
                              + jalview.util.Format.getHexString(\r
-                                 row.getThreshold().colour)+"\n"\r
+                                 row.getThreshold().colour) + "\n"\r
                 );\r
 \r
-          if(row.graphGroup>-1)\r
+          if (row.graphGroup > -1)\r
           {\r
             String key = String.valueOf(row.graphGroup);\r
-            if(graphGroup.containsKey(key))\r
+            if (graphGroup.containsKey(key))\r
               graphGroup.put(key, graphGroup.get(key)\r
-                             +"\t"+row.label);\r
+                             + "\t" + row.label);\r
             else\r
               graphGroup.put(key, row.label);\r
           }\r
-      }\r
-\r
-      text.append(row.label+"\t");\r
-      if(row.description!=null)\r
-        text.append(row.description+"\t");\r
+        }\r
 \r
-      for(int j=0; j<row.annotations.length; j++)\r
-      {\r
-        if (seqref != null && jalview.util.Comparison.isGap(seqref.getCharAt(j)))\r
-          continue;\r
+        text.append(row.label + "\t");\r
+        if (row.description != null)\r
+          text.append(row.description + "\t");\r
 \r
-        if(row.annotations[j]!=null)\r
+        for (int j = 0; j < row.annotations.length; j++)\r
         {\r
-          comma = "";\r
-          if (row.annotations[j].secondaryStructure!=' ')\r
-          {\r
-            text.append(comma + row.annotations[j].secondaryStructure);\r
-            comma = ",";\r
-          }\r
-          if (row.annotations[j].displayCharacter.length() > 0\r
-                  && !row.annotations[j].displayCharacter.equals(" "))\r
-              {\r
-                text.append(comma + row.annotations[j].displayCharacter);\r
-                comma = ",";\r
-              }\r
-\r
-          if (row.annotations[j]!=null)\r
+          if (seqref != null &&\r
+              jalview.util.Comparison.isGap(seqref.getCharAt(j)))\r
+            continue;\r
+\r
+          if (row.annotations[j] != null)\r
           {\r
-            color = row.annotations[j].colour;\r
-            if (row.annotations[j].value!=0f)\r
-              text.append(comma + row.annotations[j].value);\r
+            comma = "";\r
+            if (row.annotations[j].secondaryStructure != ' ')\r
+            {\r
+              text.append(comma + row.annotations[j].secondaryStructure);\r
+              comma = ",";\r
+            }\r
+            if (row.annotations[j].displayCharacter.length() > 0\r
+                && !row.annotations[j].displayCharacter.equals(" "))\r
+            {\r
+              text.append(comma + row.annotations[j].displayCharacter);\r
+              comma = ",";\r
+            }\r
+\r
+            if (row.annotations[j] != null)\r
+            {\r
+              color = row.annotations[j].colour;\r
+              if (row.annotations[j].value != 0f)\r
+                text.append(comma + row.annotations[j].value);\r
+            }\r
           }\r
+          text.append("|");\r
         }\r
-        text.append("|");\r
+\r
+        text.append("\n");\r
+\r
+        if (color != null && color != java.awt.Color.black)\r
+        {\r
+          colours.append("COLOUR\t"\r
+                         + row.label + "\t"\r
+                         + jalview.util.Format.getHexString(color) + "\n");\r
+        }\r
+\r
       }\r
 \r
       text.append("\n");\r
 \r
-      if(color!=null && color!=java.awt.Color.black)\r
+      text.append(colours.toString());\r
+      text.append(graphLine.toString());\r
+      if (graphGroup.size() > 0)\r
       {\r
-        colours.append("COLOUR\t"\r
-                       +row.label+"\t"\r
-                       +jalview.util.Format.getHexString(color)+"\n");\r
+        text.append("COMBINE\t");\r
+        Enumeration en = graphGroup.elements();\r
+        while (en.hasMoreElements())\r
+        {\r
+          text.append(en.nextElement() + "\n");\r
+        }\r
       }\r
+    }\r
+\r
 \r
+    if(groups!=null)\r
+    {\r
+      printGroups(groups);\r
     }\r
 \r
-    text.append("\n");\r
+    return text.toString();\r
+  }\r
 \r
-    text.append(colours.toString());\r
-    text.append(graphLine.toString());\r
-    if(graphGroup.size()>0)\r
+\r
+  public void printGroups(Vector sequenceGroups)\r
+  {\r
+    SequenceGroup sg;\r
+    for (int i = 0; i < sequenceGroups.size(); i++)\r
     {\r
-      text.append("COMBINE\t");\r
-      Enumeration en = graphGroup.elements();\r
-      while(en.hasMoreElements())\r
+      sg = (SequenceGroup) sequenceGroups.elementAt(i);\r
+      text.append("SEQUENCE_GROUP\t"\r
+                  + sg.getName() + "\t"\r
+                  + (sg.getStartRes()+1) + "\t"\r
+                  + (sg.getEndRes()+1)  + "\t" + "-1\t");\r
+      for(int s=0; s<sg.getSize(); s++)\r
       {\r
-        text.append(en.nextElement()+"\n");\r
+        text.append(sg.getSequenceAt(s).getName()+"\t");\r
       }\r
-    }\r
 \r
-    return text.toString();\r
+      text.append("\nPROPERTIES\t"+sg.getName()+"\t");\r
+\r
+      if(sg.getDescription()!=null)\r
+        text.append("description="+sg.getDescription()+"\t");\r
+      if(sg.cs!=null)\r
+      {\r
+        text.append("colour="+ColourSchemeProperty.getColourName(sg.cs)+"\t");\r
+        if(sg.cs.getThreshold()!=0)\r
+          text.append("pidThreshold="+sg.cs.getThreshold());\r
+        if(sg.cs.conservationApplied())\r
+          text.append("consThreshold="+sg.cs.getConservationInc()+"\t");\r
+      }\r
+      text.append("outlineColour="+\r
+                  jalview.util.Format.getHexString(sg.getOutlineColour())+"\t");\r
+\r
+      text.append("displayBoxes=" + sg.getDisplayBoxes() + "\t");\r
+      text.append("displayText=" + sg.getDisplayText() + "\t");\r
+      text.append("colourText=" + sg.getColourText() + "\t");\r
+\r
+      if (sg.textColour != java.awt.Color.black)\r
+        text.append("textCol1=" +\r
+                    jalview.util.Format.getHexString(sg.textColour) + "\t");\r
+      if (sg.textColour2 != java.awt.Color.white)\r
+        text.append("textCol2=" +\r
+                    jalview.util.Format.getHexString(sg.textColour2) + "\t");\r
+      if(sg.thresholdTextColour!=0)\r
+      text.append("textColThreshold="+sg.thresholdTextColour);\r
+\r
+      text.append("\n\n");\r
+\r
+    }\r
   }\r
 \r
 \r
@@ -529,7 +588,6 @@ public class AnnotationFile
       sg.setEndRes(   refSeq.findIndex( sg.getEndRes() +1) -1 );\r
     }\r
 \r
-\r
     al.addGroup(sg);\r
     annotationsHash.put(sg.getName(), sg);\r
   }\r
@@ -556,13 +614,29 @@ public class AnnotationFile
         else if(key.equalsIgnoreCase("colour"))\r
           sg.cs = ColourSchemeProperty.getColour(al, value);\r
         else if (key.equalsIgnoreCase("pidThreshold"))\r
-          sg.cs.setThreshold(Integer.parseInt(value), false);//\r
+        {\r
+          sg.cs.setThreshold(Integer.parseInt(value), true);\r
+\r
+        }\r
+        else if (key.equalsIgnoreCase("consThreshold"))\r
+        {\r
+          sg.cs.setConservationInc(Integer.parseInt(value));\r
+          Conservation c = new Conservation("Group",\r
+                    ResidueProperties.propHash, 3,\r
+                    sg.getSequences(null),\r
+                    sg.getStartRes(),\r
+                    sg.getEndRes() + 1);\r
+\r
+            c.calculate();\r
+            c.verdict(false, 25);\r
+\r
+            sg.cs.setConservation(c);\r
+\r
+        }\r
         else if (key.equalsIgnoreCase("outlineColour"))\r
          {\r
            sg.setOutlineColour(new UserColourScheme(value).findColour('A'));\r
          }\r
-\r
-         //Boolean.valueOf(string).booleanValue();\r
         else if (key.equalsIgnoreCase("displayBoxes"))\r
          sg.setDisplayBoxes( Boolean.valueOf(value).booleanValue() );\r
         else if (key.equalsIgnoreCase("displayText"))\r
@@ -580,6 +654,7 @@ public class AnnotationFile
         else if (key.equalsIgnoreCase("textColThreshold"))\r
          sg.thresholdTextColour = Integer.parseInt(value);\r
 \r
+       sg.recalcConservation();\r
       }\r
     }\r
   }\r