v2
[jalview.git] / src / jalview / datamodel / AlignmentAnnotation.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.datamodel;
19
20 import jalview.analysis.Rna;
21 import jalview.analysis.WUSSParseException;
22
23 import java.util.ArrayList;
24 import java.util.Enumeration;
25 import java.util.Hashtable;
26
27 import fr.orsay.lri.varna.models.rna.RNA;
28
29 /**
30  * DOCUMENT ME!
31  * 
32  * @author $author$
33  * @version $Revision$
34  */
35 public class AlignmentAnnotation
36 {
37   /**
38    * If true, this annotations is calculated every edit, eg consensus, quality
39    * or conservation graphs
40    */
41   public boolean autoCalculated = false;
42
43   public String annotationId;
44   
45   public SequenceI sequenceRef;
46
47   /** DOCUMENT ME!! */
48   public String label;
49
50   /** DOCUMENT ME!! */
51   public String description;
52
53   /** DOCUMENT ME!! */
54   public Annotation[] annotations;
55   
56   
57
58   /**
59    * RNA secondary structure contact positions
60    */
61   public SequenceFeature[] _rnasecstr = null;
62   /**
63    * position of annotation resulting in invalid WUSS parsing or -1
64    */
65   private long invalidrnastruc=-1;
66   /**
67    * Updates the _rnasecstr field Determines the positions that base pair and
68    * the positions of helices based on secondary structure from a Stockholm file
69    * 
70    * @param RNAannot
71    */
72   private void _updateRnaSecStr(CharSequence RNAannot)
73   {
74     try {
75     _rnasecstr = Rna.GetBasePairs(RNAannot);
76     invalidrnastruc=-1;
77     }
78     catch (WUSSParseException px)
79     {
80       invalidrnastruc=px.getProblemPos();
81     }
82     if (invalidrnastruc>-1)
83     {
84       return;
85     }
86     Rna.HelixMap(_rnasecstr);
87     // setRNAStruc(RNAannot);
88     
89     if (_rnasecstr != null && _rnasecstr.length > 0)
90     {
91       // show all the RNA secondary structure annotation symbols.
92       isrna=true;
93       showAllColLabels = true;
94       scaleColLabel = true;
95     }
96     // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup());
97   }
98   public java.util.Hashtable sequenceMapping;
99
100   /** DOCUMENT ME!! */
101   public float graphMin;
102
103   /** DOCUMENT ME!! */
104   public float graphMax;
105
106   /**
107    * Score associated with label and description.
108    */
109   public double score = Double.NaN;
110
111   /**
112    * flag indicating if annotation has a score.
113    */
114   public boolean hasScore = false;
115
116   public GraphLine threshold;
117
118   // Graphical hints and tips
119
120   /** Can this row be edited by the user ? */
121   public boolean editable = false;
122
123   /** Indicates if annotation has a graphical symbol track */
124   public boolean hasIcons; //
125
126   /** Indicates if annotation has a text character label */
127   public boolean hasText;
128
129   /** is the row visible */
130   public boolean visible = true;
131
132   public int graphGroup = -1;
133
134   /** Displayed height of row in pixels */
135   public int height = 0;
136
137   public int graph = 0;
138
139   public int graphHeight = 40;
140
141   public boolean padGaps = false;
142
143   public static final int NO_GRAPH = 0;
144
145   public static final int BAR_GRAPH = 1;
146
147   public static final int LINE_GRAPH = 2;
148
149   public boolean belowAlignment = true;
150
151   public SequenceGroup groupRef = null;
152
153   /**
154    * display every column label, even if there is a row of identical labels
155    */
156   public boolean showAllColLabels = false;
157
158   /**
159    * scale the column label to fit within the alignment column.
160    */
161   public boolean scaleColLabel = false;
162
163   /**
164    * centre the column labels relative to the alignment column
165    */
166   public boolean centreColLabels = false;
167
168   private boolean isrna;
169
170   /*
171    * (non-Javadoc)
172    * 
173    * @see java.lang.Object#finalize()
174    */
175   protected void finalize() throws Throwable
176   {
177     sequenceRef = null;
178     groupRef = null;
179     super.finalize();
180   }
181
182   public static int getGraphValueFromString(String string)
183   {
184     if (string.equalsIgnoreCase("BAR_GRAPH"))
185     {
186       return BAR_GRAPH;
187     }
188     else if (string.equalsIgnoreCase("LINE_GRAPH"))
189     {
190       return LINE_GRAPH;
191     }
192     else
193     {
194       return NO_GRAPH;
195     }
196   }
197
198   /**
199    * Creates a new AlignmentAnnotation object.
200    * 
201    * @param label
202    *          short label shown under sequence labels
203    * @param description
204    *          text displayed on mouseover
205    * @param annotations
206    *          set of positional annotation elements
207    */
208   public AlignmentAnnotation(String label, String description,
209           Annotation[] annotations)
210   {
211     // always editable?
212     editable = true;
213     this.label = label;
214     this.description = description;
215     this.annotations = annotations;
216
217     validateRangeAndDisplay();
218   }
219
220   /**
221    * Checks if annotation labels represent secondary structures
222    * 
223    */
224   void areLabelsSecondaryStructure()
225   {
226     boolean nonSSLabel = false;
227     isrna = false;
228     StringBuffer rnastring = new StringBuffer();
229
230     char firstChar = 0;
231     for (int i = 0; i < annotations.length; i++)
232     {
233       if (annotations[i] == null)
234       {
235         continue;
236       }
237       if (annotations[i].secondaryStructure == 'H'
238               || annotations[i].secondaryStructure == 'E')
239       {
240         hasIcons |= true;
241       }
242       else
243       // Check for RNA secondary structure
244       {
245         if (annotations[i].secondaryStructure == 'S'
246                         || annotations[i].secondaryStructure == 'C')
247         {
248           hasIcons |= true;
249           isrna |= true;
250         }
251       }
252
253       // System.out.println("displaychar " + annotations[i].displayCharacter);
254
255       if (annotations[i].displayCharacter == null
256               || annotations[i].displayCharacter.length() == 0)
257       {
258         rnastring.append('.');
259         continue;
260       }
261       if (annotations[i].displayCharacter.length() == 1)
262       {
263         firstChar = annotations[i].displayCharacter.charAt(0);
264         // check to see if it looks like a sequence or is secondary structure
265         // labelling.
266         if (annotations[i].secondaryStructure != ' '
267                 && !hasIcons
268                 &&
269                 // Uncomment to only catch case where
270                 // displayCharacter==secondary
271                 // Structure
272                 // to correctly redisplay SS annotation imported from Stockholm,
273                 // exported to JalviewXML and read back in again.
274                 // &&
275                 // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure
276                 firstChar != ' '
277                 && firstChar != 'H'
278                 && firstChar != 'E'
279                 && firstChar != 'S'
280                 && firstChar != '-'
281                 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
282         {
283           if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
284                                                                          // parameterise
285                                                                          // to
286                                                                          // gap
287                                                                          // symbol
288                                                                          // number
289           {
290             nonSSLabel = true;
291           }
292         }
293       }
294       else
295       {
296         rnastring.append(annotations[i].displayCharacter.charAt(1));
297       }
298
299       if (annotations[i].displayCharacter.length() > 0)
300       {
301         hasText = true;
302       }
303     }
304
305     if (nonSSLabel)
306     {
307       hasIcons = false;
308       for (int j = 0; j < annotations.length; j++)
309       {
310         if (annotations[j] != null
311                 && annotations[j].secondaryStructure != ' ')
312         {
313           annotations[j].displayCharacter = String
314                   .valueOf(annotations[j].secondaryStructure);
315           annotations[j].secondaryStructure = ' ';
316         }
317
318       }
319     }
320     else
321     {
322       if (isrna)
323       {
324         _updateRnaSecStr(new AnnotCharSequence());
325       }
326     }
327
328     annotationId = this.hashCode() + "";
329   }
330   /**
331    * flyweight access to positions in the alignment annotation row for RNA processing
332    * @author jimp
333    *
334    */
335   private class AnnotCharSequence  implements CharSequence 
336   {
337     int offset=0;
338     int max=0;
339     
340     public AnnotCharSequence() {
341       this(0,annotations.length);
342     }
343     public AnnotCharSequence(int start, int end) {
344       offset=start;
345       max=end;
346     }
347     @Override
348     public CharSequence subSequence(int start, int end)
349     {
350       return new AnnotCharSequence(offset+start, offset+end);
351     }
352     
353     @Override
354     public int length()
355     {
356       return max-offset;
357     }
358     
359     @Override
360     public char charAt(int index)
361     {
362       String dc;
363       return ((index+offset<0) || (index+offset)>=max || annotations[index+offset]==null || (dc=annotations[index+offset].displayCharacter.trim()).length()<1)
364               ? '.' : dc.charAt(0);
365     }
366     public String toString()
367     {
368       char[] string=new char[max-offset];
369       int mx=annotations.length;
370         
371       for (int i=offset;i<mx;i++)
372       {
373         String dc;
374         string[i]=(annotations[i]==null || (dc=annotations[i].displayCharacter.trim()).length()<1 )? '.' : dc.charAt(0);
375       }
376       return new String(string);
377     }
378   };
379   
380   private long _lastrnaannot=-1;
381   public String getRNAStruc(){
382     if (isrna)
383     {
384       String rnastruc = new AnnotCharSequence().toString();
385       if (_lastrnaannot!=rnastruc.hashCode())
386       {
387         // ensure rna structure contacts are up to date
388         _lastrnaannot=rnastruc.hashCode();
389         _updateRnaSecStr(rnastruc);
390       }
391       return rnastruc;
392     }
393     return null;
394   }
395
396 /**
397    * Creates a new AlignmentAnnotation object.
398    * 
399    * @param label
400    *          DOCUMENT ME!
401    * @param description
402    *          DOCUMENT ME!
403    * @param annotations
404    *          DOCUMENT ME!
405    * @param min
406    *          DOCUMENT ME!
407    * @param max
408    *          DOCUMENT ME!
409    * @param winLength
410    *          DOCUMENT ME!
411    */
412   public AlignmentAnnotation(String label, String description,
413           Annotation[] annotations, float min, float max, int graphType)
414   {
415     // graphs are not editable
416     editable = graphType == 0;
417
418     this.label = label;
419     this.description = description;
420     this.annotations = annotations;
421     graph = graphType;
422     graphMin = min;
423     graphMax = max;
424     validateRangeAndDisplay();
425   }
426
427   /**
428    * checks graphMin and graphMax, secondary structure symbols, sets graphType
429    * appropriately, sets null labels to the empty string if appropriate.
430    */
431   public void validateRangeAndDisplay()
432   {
433
434     if (annotations == null)
435     {
436       visible = false; // try to prevent renderer from displaying.
437       return; // this is a non-annotation row annotation - ie a sequence score.
438     }
439
440     int graphType = graph;
441     float min = graphMin;
442     float max = graphMax;
443     boolean drawValues = true;
444
445     if (min == max)
446     {
447       min = 999999999;
448       for (int i = 0; i < annotations.length; i++)
449       {
450         if (annotations[i] == null)
451         {
452           continue;
453         }
454
455         if (drawValues && annotations[i].displayCharacter != null
456                 && annotations[i].displayCharacter.length() > 1)
457         {
458           drawValues = false;
459         }
460
461         if (annotations[i].value > max)
462         {
463           max = annotations[i].value;
464         }
465
466         if (annotations[i].value < min)
467         {
468           min = annotations[i].value;
469         }
470       }
471       // ensure zero is origin for min/max ranges on only one side of zero
472       if (min > 0)
473       {
474         min = 0;
475       }
476       else
477       {
478         if (max < 0)
479         {
480           max = 0;
481         }
482       }
483     }
484
485     graphMin = min;
486     graphMax = max;
487
488     areLabelsSecondaryStructure();
489
490     if (!drawValues && graphType != NO_GRAPH)
491     {
492       for (int i = 0; i < annotations.length; i++)
493       {
494         if (annotations[i] != null)
495         {
496           annotations[i].displayCharacter = "";
497         }
498       }
499     }
500   }
501
502   /**
503    * Copy constructor creates a new independent annotation row with the same
504    * associated sequenceRef
505    * 
506    * @param annotation
507    */
508   public AlignmentAnnotation(AlignmentAnnotation annotation)
509   {
510     this.label = new String(annotation.label);
511     if (annotation.description != null)
512       this.description = new String(annotation.description);
513     this.graphMin = annotation.graphMin;
514     this.graphMax = annotation.graphMax;
515     this.graph = annotation.graph;
516     this.graphHeight = annotation.graphHeight;
517     this.graphGroup = annotation.graphGroup;
518     this.groupRef = annotation.groupRef;
519     this.editable = annotation.editable;
520     this.autoCalculated = annotation.autoCalculated;
521     this.hasIcons = annotation.hasIcons;
522     this.hasText = annotation.hasText;
523     this.height = annotation.height;
524     this.label = annotation.label;
525     this.padGaps = annotation.padGaps;
526     this.visible = annotation.visible;
527     this.centreColLabels=annotation.centreColLabels;
528     this.scaleColLabel=annotation.scaleColLabel;
529     this.showAllColLabels=annotation.showAllColLabels;
530     this.calcId = annotation.calcId;
531     if (this.hasScore = annotation.hasScore)
532     {
533       this.score = annotation.score;
534     }
535     if (annotation.threshold != null)
536     {
537       threshold = new GraphLine(annotation.threshold);
538     }
539     if (annotation.annotations != null)
540     {
541       Annotation[] ann = annotation.annotations;
542       this.annotations = new Annotation[ann.length];
543       for (int i = 0; i < ann.length; i++)
544       {
545         annotations[i] = new Annotation(ann[i]);
546       }
547       ;
548       if (annotation.sequenceRef != null)
549       {
550         this.sequenceRef = annotation.sequenceRef;
551         if (annotation.sequenceMapping != null)
552         {
553           Integer p = null;
554           sequenceMapping = new Hashtable();
555           Enumeration pos = annotation.sequenceMapping.keys();
556           while (pos.hasMoreElements())
557           {
558             // could optimise this!
559             p = (Integer) pos.nextElement();
560             Annotation a = (Annotation) annotation.sequenceMapping.get(p);
561             if (a == null)
562             {
563               continue;
564             }
565             for (int i = 0; i < ann.length; i++)
566             {
567               if (ann[i] == a)
568               {
569                 sequenceMapping.put(p, annotations[i]);
570               }
571             }
572           }
573         }
574         else
575         {
576           this.sequenceMapping = null;
577         }
578       }
579     }
580     // TODO: check if we need to do this: JAL-952
581     //if (this.isrna=annotation.isrna)
582     {
583       // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
584     }
585     validateRangeAndDisplay(); // construct hashcodes, etc.
586   }
587
588   /**
589    * clip the annotation to the columns given by startRes and endRes (inclusive)
590    * and prune any existing sequenceMapping to just those columns.
591    * 
592    * @param startRes
593    * @param endRes
594    */
595   public void restrict(int startRes, int endRes)
596   {
597     if (annotations == null)
598     {
599       // non-positional
600       return;
601     }
602     if (startRes < 0)
603       startRes = 0;
604     if (startRes >= annotations.length)
605       startRes = annotations.length - 1;
606     if (endRes >= annotations.length)
607       endRes = annotations.length - 1;
608     if (annotations == null)
609       return;
610     Annotation[] temp = new Annotation[endRes - startRes + 1];
611     if (startRes < annotations.length)
612     {
613       System.arraycopy(annotations, startRes, temp, 0, endRes - startRes
614               + 1);
615     }
616     if (sequenceRef != null)
617     {
618       // Clip the mapping, if it exists.
619       int spos = sequenceRef.findPosition(startRes);
620       int epos = sequenceRef.findPosition(endRes);
621       if (sequenceMapping != null)
622       {
623         Hashtable newmapping = new Hashtable();
624         Enumeration e = sequenceMapping.keys();
625         while (e.hasMoreElements())
626         {
627           Integer pos = (Integer) e.nextElement();
628           if (pos.intValue() >= spos && pos.intValue() <= epos)
629           {
630             newmapping.put(pos, sequenceMapping.get(pos));
631           }
632         }
633         sequenceMapping.clear();
634         sequenceMapping = newmapping;
635       }
636     }
637     annotations = temp;
638   }
639
640   /**
641    * set the annotation row to be at least length Annotations
642    * 
643    * @param length
644    *          minimum number of columns required in the annotation row
645    * @return false if the annotation row is greater than length
646    */
647   public boolean padAnnotation(int length)
648   {
649     if (annotations == null)
650     {
651       return true; // annotation row is correct - null == not visible and
652       // undefined length
653     }
654     if (annotations.length < length)
655     {
656       Annotation[] na = new Annotation[length];
657       System.arraycopy(annotations, 0, na, 0, annotations.length);
658       annotations = na;
659       return true;
660     }
661     return annotations.length > length;
662
663   }
664
665   /**
666    * DOCUMENT ME!
667    * 
668    * @return DOCUMENT ME!
669    */
670   public String toString()
671   {
672     StringBuffer buffer = new StringBuffer();
673
674     for (int i = 0; i < annotations.length; i++)
675     {
676       if (annotations[i] != null)
677       {
678         if (graph != 0)
679         {
680           buffer.append(annotations[i].value);
681         }
682         else if (hasIcons)
683         {
684           buffer.append(annotations[i].secondaryStructure);
685         }
686         else
687         {
688           buffer.append(annotations[i].displayCharacter);
689         }
690       }
691
692       buffer.append(", ");
693     }
694     // TODO: remove disgusting hack for 'special' treatment of consensus line.
695     if (label.indexOf("Consensus") == 0)
696     {
697       buffer.append("\n");
698
699       for (int i = 0; i < annotations.length; i++)
700       {
701         if (annotations[i] != null)
702         {
703           buffer.append(annotations[i].description);
704         }
705
706         buffer.append(", ");
707       }
708     }
709
710     return buffer.toString();
711   }
712
713   public void setThreshold(GraphLine line)
714   {
715     threshold = line;
716   }
717
718   public GraphLine getThreshold()
719   {
720     return threshold;
721   }
722
723   /**
724    * Attach the annotation to seqRef, starting from startRes position. If
725    * alreadyMapped is true then the indices of the annotation[] array are
726    * sequence positions rather than alignment column positions.
727    * 
728    * @param seqRef
729    * @param startRes
730    * @param alreadyMapped
731    */
732   public void createSequenceMapping(SequenceI seqRef, int startRes,
733           boolean alreadyMapped)
734   {
735
736     if (seqRef == null)
737     {
738       return;
739     }
740     sequenceRef = seqRef;
741     if (annotations == null)
742     {
743       return;
744     }
745     sequenceMapping = new java.util.Hashtable();
746
747     int seqPos;
748
749     for (int i = 0; i < annotations.length; i++)
750     {
751       if (annotations[i] != null)
752       {
753         if (alreadyMapped)
754         {
755           seqPos = seqRef.findPosition(i);
756         }
757         else
758         {
759           seqPos = i + startRes;
760         }
761
762         sequenceMapping.put(new Integer(seqPos), annotations[i]);
763       }
764     }
765
766   }
767
768   public void adjustForAlignment()
769   {
770     if (sequenceRef == null)
771       return;
772
773     if (annotations == null)
774     {
775       return;
776     }
777
778     int a = 0, aSize = sequenceRef.getLength();
779
780     if (aSize == 0)
781     {
782       // Its been deleted
783       return;
784     }
785
786     int position;
787     Annotation[] temp = new Annotation[aSize];
788     Integer index;
789
790     for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
791     {
792       index = new Integer(a);
793       if (sequenceMapping.containsKey(index))
794       {
795         position = sequenceRef.findIndex(a) - 1;
796
797         temp[position] = (Annotation) sequenceMapping.get(index);
798       }
799     }
800
801     annotations = temp;
802   }
803
804   /**
805    * remove any null entries in annotation row and return the number of non-null
806    * annotation elements.
807    * 
808    * @return
809    */
810   public int compactAnnotationArray()
811   {
812     int i = 0, iSize = annotations.length;
813     while (i < iSize)
814     {
815       if (annotations[i] == null)
816       {
817         if (i + 1 < iSize)
818           System.arraycopy(annotations, i + 1, annotations, i, iSize - i
819                   - 1);
820         iSize--;
821       }
822       else
823       {
824         i++;
825       }
826     }
827     Annotation[] ann = annotations;
828     annotations = new Annotation[i];
829     System.arraycopy(ann, 0, annotations, 0, i);
830     ann = null;
831     return iSize;
832   }
833
834   /**
835    * Associate this annotion with the aligned residues of a particular sequence.
836    * sequenceMapping will be updated in the following way: null sequenceI -
837    * existing mapping will be discarded but annotations left in mapped
838    * positions. valid sequenceI not equal to current sequenceRef: mapping is
839    * discarded and rebuilt assuming 1:1 correspondence TODO: overload with
840    * parameter to specify correspondence between current and new sequenceRef
841    * 
842    * @param sequenceI
843    */
844   public void setSequenceRef(SequenceI sequenceI)
845   {
846     if (sequenceI != null)
847     {
848       if (sequenceRef != null)
849       {
850         if (sequenceRef != sequenceI
851                 && !sequenceRef.equals(sequenceI)
852                 && sequenceRef.getDatasetSequence() != sequenceI
853                         .getDatasetSequence())
854         {
855           // if sequenceRef isn't intersecting with sequenceI
856           // throw away old mapping and reconstruct.
857           sequenceRef = null;
858           if (sequenceMapping != null)
859           {
860             sequenceMapping = null;
861             // compactAnnotationArray();
862           }
863           createSequenceMapping(sequenceI, 1, true);
864           adjustForAlignment();
865         }
866         else
867         {
868           // Mapping carried over
869           sequenceRef = sequenceI;
870         }
871       }
872       else
873       {
874         // No mapping exists
875         createSequenceMapping(sequenceI, 1, true);
876         adjustForAlignment();
877       }
878     }
879     else
880     {
881       // throw away the mapping without compacting.
882       sequenceMapping = null;
883       sequenceRef = null;
884     }
885   }
886
887   /**
888    * @return the score
889    */
890   public double getScore()
891   {
892     return score;
893   }
894
895   /**
896    * @param score
897    *          the score to set
898    */
899   public void setScore(double score)
900   {
901     hasScore = true;
902     this.score = score;
903   }
904
905   /**
906    * 
907    * @return true if annotation has an associated score
908    */
909   public boolean hasScore()
910   {
911     return hasScore || !Double.isNaN(score);
912   }
913
914   /**
915    * Score only annotation
916    * 
917    * @param label
918    * @param description
919    * @param score
920    */
921   public AlignmentAnnotation(String label, String description, double score)
922   {
923     this(label, description, null);
924     setScore(score);
925   }
926
927   /**
928    * copy constructor with edit based on the hidden columns marked in colSel
929    * 
930    * @param alignmentAnnotation
931    * @param colSel
932    */
933   public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
934           ColumnSelection colSel)
935   {
936     this(alignmentAnnotation);
937     if (annotations == null)
938     {
939       return;
940     }
941     colSel.makeVisibleAnnotation(this);
942   }
943
944   public void setPadGaps(boolean padgaps, char gapchar)
945   {
946     this.padGaps = padgaps;
947     if (padgaps)
948     {
949       hasText = true;
950       for (int i = 0; i < annotations.length; i++)
951       {
952         if (annotations[i] == null)
953           annotations[i] = new Annotation(String.valueOf(gapchar), null,
954                   ' ', 0f,null);
955         else if (annotations[i].displayCharacter == null
956                 || annotations[i].displayCharacter.equals(" "))
957           annotations[i].displayCharacter = String.valueOf(gapchar);
958       }
959     }
960   }
961
962   /**
963    * format description string for display
964    * 
965    * @param seqname
966    * @return Get the annotation description string optionally prefixed by
967    *         associated sequence name (if any)
968    */
969   public String getDescription(boolean seqname)
970   {
971     if (seqname && this.sequenceRef != null)
972     {
973       int i=description.toLowerCase().indexOf("<html>");
974       if (i>-1)
975       {
976         // move the html tag to before the sequence reference.
977         return "<html>"+sequenceRef.getName()+" : "+description.substring(i+6);
978       }
979       return sequenceRef.getName() + " : " + description;
980     }
981     return description;
982   }
983
984   public boolean isValidStruc()
985   {
986     return invalidrnastruc==-1;
987   }
988   public long getInvalidStrucPos()
989   {
990     return invalidrnastruc;
991   }
992
993   /**
994    * machine readable ID string indicating what generated this annotation
995    */
996   protected String calcId="";
997   public String getCalcId()
998   {
999     return calcId;
1000   }
1001
1002   public void setCalcId(String calcId)
1003   {
1004     this.calcId = calcId;
1005   }
1006   
1007  
1008   
1009 }