From: amwaterhouse Date: Tue, 30 Jan 2007 12:52:50 +0000 (+0000) Subject: Output groups in annotation file X-Git-Tag: Release_2_3~418 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5d455c2d0b8b1ac94d82584e2885654693abb39f;p=jalview.git Output groups in annotation file --- diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 1c2605c..74460f7 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -673,7 +673,8 @@ public void itemStateChanged(ItemEvent evt) public String outputAnnotations(boolean displayTextbox) { String annotation = new AnnotationFile().printAnnotations( - viewport.alignment.getAlignmentAnnotation() ); + viewport.alignment.getAlignmentAnnotation(), + viewport.alignment.getGroups() ); if(displayTextbox) { diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 51c7726..3082f74 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -857,7 +857,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener { new AnnotationExporter().exportAnnotations( alignPanel, - viewport.alignment.getAlignmentAnnotation() + viewport.alignment.getAlignmentAnnotation(), + viewport.alignment.getGroups() ); } diff --git a/src/jalview/gui/AnnotationExporter.java b/src/jalview/gui/AnnotationExporter.java index d4975a6..522622d 100755 --- a/src/jalview/gui/AnnotationExporter.java +++ b/src/jalview/gui/AnnotationExporter.java @@ -28,6 +28,7 @@ import jalview.datamodel.AlignmentAnnotation; import java.awt.Color; import java.awt.FlowLayout; +import java.util.Vector; import javax.swing.BorderFactory; @@ -38,6 +39,7 @@ public class AnnotationExporter AlignmentPanel ap; boolean features = true; AlignmentAnnotation [] annotations; + Vector sequenceGroups; public AnnotationExporter() { @@ -66,12 +68,14 @@ public class AnnotationExporter } public void exportAnnotations(AlignmentPanel ap, - AlignmentAnnotation [] annotations) + AlignmentAnnotation [] annotations, + Vector sequenceGroups) { this.ap = ap; features = false; GFFFormat.setVisible(false); this.annotations = annotations; + this.sequenceGroups = sequenceGroups; frame.setTitle("Export Annotations"); } @@ -103,7 +107,9 @@ public class AnnotationExporter } else { - text = new AnnotationFile().printAnnotations( annotations ); + text = new AnnotationFile().printAnnotations( + annotations, + sequenceGroups ); } try @@ -137,7 +143,9 @@ public class AnnotationExporter } else if(!features) { - text = new AnnotationFile().printAnnotations( annotations ); + text = new AnnotationFile().printAnnotations( + annotations, + sequenceGroups ); } diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 0ea7998..1176087 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -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)) diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index a7c67cd..80d31fb 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -24,144 +24,203 @@ import jalview.datamodel.*; import java.util.*; import java.net.URL; import jalview.schemes.*; +import jalview.analysis.Conservation; public class AnnotationFile { - - public String printAnnotations(AlignmentAnnotation [] annotations) - { - StringBuffer text = new StringBuffer( - "JALVIEW_ANNOTATION\n" - +"# Created: " + StringBuffer text = new StringBuffer( + "JALVIEW_ANNOTATION\n" + +"# Created: " +new java.util.Date()+"\n\n"); - AlignmentAnnotation row; - String comma; - SequenceI seqref = null; - - StringBuffer colours = new StringBuffer(); - StringBuffer graphLine = new StringBuffer(); + public String printAnnotations(AlignmentAnnotation [] annotations, + Vector groups) + { + if(annotations!=null) + { + AlignmentAnnotation row; + String comma; + SequenceI seqref = null; - Hashtable graphGroup = new Hashtable(); + StringBuffer colours = new StringBuffer(); + StringBuffer graphLine = new StringBuffer(); - java.awt.Color color; + Hashtable graphGroup = new Hashtable(); - for(int i=0; i-1) + if (row.graphGroup > -1) { String key = String.valueOf(row.graphGroup); - if(graphGroup.containsKey(key)) + if (graphGroup.containsKey(key)) graphGroup.put(key, graphGroup.get(key) - +"\t"+row.label); + + "\t" + row.label); else graphGroup.put(key, row.label); } - } - - text.append(row.label+"\t"); - if(row.description!=null) - text.append(row.description+"\t"); + } - for(int j=0; j 0 - && !row.annotations[j].displayCharacter.equals(" ")) - { - text.append(comma + row.annotations[j].displayCharacter); - comma = ","; - } - - if (row.annotations[j]!=null) + if (seqref != null && + jalview.util.Comparison.isGap(seqref.getCharAt(j))) + continue; + + if (row.annotations[j] != null) { - color = row.annotations[j].colour; - if (row.annotations[j].value!=0f) - text.append(comma + row.annotations[j].value); + comma = ""; + if (row.annotations[j].secondaryStructure != ' ') + { + text.append(comma + row.annotations[j].secondaryStructure); + comma = ","; + } + if (row.annotations[j].displayCharacter.length() > 0 + && !row.annotations[j].displayCharacter.equals(" ")) + { + text.append(comma + row.annotations[j].displayCharacter); + comma = ","; + } + + if (row.annotations[j] != null) + { + color = row.annotations[j].colour; + if (row.annotations[j].value != 0f) + text.append(comma + row.annotations[j].value); + } } + text.append("|"); } - text.append("|"); + + text.append("\n"); + + if (color != null && color != java.awt.Color.black) + { + colours.append("COLOUR\t" + + row.label + "\t" + + jalview.util.Format.getHexString(color) + "\n"); + } + } text.append("\n"); - if(color!=null && color!=java.awt.Color.black) + text.append(colours.toString()); + text.append(graphLine.toString()); + if (graphGroup.size() > 0) { - colours.append("COLOUR\t" - +row.label+"\t" - +jalview.util.Format.getHexString(color)+"\n"); + text.append("COMBINE\t"); + Enumeration en = graphGroup.elements(); + while (en.hasMoreElements()) + { + text.append(en.nextElement() + "\n"); + } } + } + + if(groups!=null) + { + printGroups(groups); } - text.append("\n"); + return text.toString(); + } - text.append(colours.toString()); - text.append(graphLine.toString()); - if(graphGroup.size()>0) + + public void printGroups(Vector sequenceGroups) + { + SequenceGroup sg; + for (int i = 0; i < sequenceGroups.size(); i++) { - text.append("COMBINE\t"); - Enumeration en = graphGroup.elements(); - while(en.hasMoreElements()) + sg = (SequenceGroup) sequenceGroups.elementAt(i); + text.append("SEQUENCE_GROUP\t" + + sg.getName() + "\t" + + (sg.getStartRes()+1) + "\t" + + (sg.getEndRes()+1) + "\t" + "-1\t"); + for(int s=0; s