2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import jalview.analysis.Rna;
24 import jalview.analysis.SecStrConsensus.SimpleBP;
25 import jalview.analysis.WUSSParseException;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.Iterator;
31 import java.util.List;
33 import java.util.Map.Entry;
41 public class AlignmentAnnotation
43 private static final String ANNOTATION_ID_PREFIX = "ann";
46 * Identifers for different types of profile data
48 public static final int SEQUENCE_PROFILE = 0;
50 public static final int STRUCTURE_PROFILE = 1;
52 public static final int CDNA_PROFILE = 2;
54 private static long counter = 0;
57 * If true, this annotations is calculated every edit, eg consensus, quality
58 * or conservation graphs
60 public boolean autoCalculated = false;
63 * unique ID for this annotation, used to match up the same annotation row
64 * shown in multiple views and alignments
66 public String annotationId;
69 * the sequence this annotation is associated with (or null)
71 public SequenceI sequenceRef;
73 /** label shown in dropdown menus and in the annotation label area */
76 /** longer description text shown as a tooltip */
77 public String description;
79 /** Array of annotations placed in the current coordinate system */
80 public Annotation[] annotations;
82 public List<SimpleBP> bps = null;
85 * RNA secondary structure contact positions
87 public SequenceFeature[] _rnasecstr = null;
90 * position of annotation resulting in invalid WUSS parsing or -1. -2 means
91 * there was no RNA structure in this annotation
93 private long invalidrnastruc = -2;
96 * Updates the _rnasecstr field Determines the positions that base pair and
97 * the positions of helices based on secondary structure from a Stockholm file
101 private void _updateRnaSecStr(CharSequence RNAannot)
105 bps = Rna.getModeleBP(RNAannot);
106 _rnasecstr = Rna.getBasePairs(bps);
107 invalidrnastruc = -1;
108 } catch (WUSSParseException px)
110 // DEBUG System.out.println(px);
111 invalidrnastruc = px.getProblemPos();
113 if (invalidrnastruc > -1)
117 Rna.HelixMap(_rnasecstr);
118 // setRNAStruc(RNAannot);
120 if (_rnasecstr != null && _rnasecstr.length > 0)
122 // show all the RNA secondary structure annotation symbols.
124 showAllColLabels = true;
125 scaleColLabel = true;
128 // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup());
132 private void _markRnaHelices()
135 // Figure out number of helices
136 // Length of rnasecstr is the number of pairs of positions that base pair
137 // with each other in the secondary structure
138 for (int x = 0; x < _rnasecstr.length; x++)
142 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
143 * this.annotation._rnasecstr[x].getBegin());
145 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
149 val = Integer.valueOf(_rnasecstr[x].getFeatureGroup());
154 } catch (NumberFormatException q)
159 annotations[_rnasecstr[x].getBegin()].value = val;
160 annotations[_rnasecstr[x].getEnd()].value = val;
162 // annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val;
163 // annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val;
169 * map of positions in the associated annotation
171 private Map<Integer, Annotation> sequenceMapping;
174 * lower range for quantitative data
176 public float graphMin;
179 * Upper range for quantitative data
181 public float graphMax;
184 * Score associated with label and description.
186 public double score = Double.NaN;
189 * flag indicating if annotation has a score.
191 public boolean hasScore = false;
193 public GraphLine threshold;
195 // Graphical hints and tips
197 /** Can this row be edited by the user ? */
198 public boolean editable = false;
200 /** Indicates if annotation has a graphical symbol track */
201 public boolean hasIcons; //
203 /** Indicates if annotation has a text character label */
204 public boolean hasText;
206 /** is the row visible */
207 public boolean visible = true;
209 public int graphGroup = -1;
211 /** Displayed height of row in pixels */
212 public int height = 0;
214 public int graph = 0;
216 public int graphHeight = 40;
218 public boolean padGaps = false;
220 public static final int NO_GRAPH = 0;
222 public static final int BAR_GRAPH = 1;
224 public static final int LINE_GRAPH = 2;
226 public boolean belowAlignment = true;
228 public SequenceGroup groupRef = null;
231 * display every column label, even if there is a row of identical labels
233 public boolean showAllColLabels = false;
236 * scale the column label to fit within the alignment column.
238 public boolean scaleColLabel = false;
241 * centre the column labels relative to the alignment column
243 public boolean centreColLabels = false;
245 private boolean isrna;
250 * @see java.lang.Object#finalize()
253 protected void finalize() throws Throwable
260 public static int getGraphValueFromString(String string)
262 if (string.equalsIgnoreCase("BAR_GRAPH"))
266 else if (string.equalsIgnoreCase("LINE_GRAPH"))
276 // JBPNote: what does this do ?
277 public void ConcenStru(CharSequence RNAannot) throws WUSSParseException
279 bps = Rna.getModeleBP(RNAannot);
283 * Creates a new AlignmentAnnotation object.
286 * short label shown under sequence labels
288 * text displayed on mouseover
290 * set of positional annotation elements
292 public AlignmentAnnotation(String label, String description,
293 Annotation[] annotations)
299 this.description = description;
300 this.annotations = annotations;
302 validateRangeAndDisplay();
306 * Checks if annotation labels represent secondary structures
309 void areLabelsSecondaryStructure()
311 boolean nonSSLabel = false;
313 StringBuffer rnastring = new StringBuffer();
316 for (int i = 0; i < annotations.length; i++)
318 if (annotations[i] == null)
322 if (annotations[i].secondaryStructure == 'H'
323 || annotations[i].secondaryStructure == 'E')
328 // Check for RNA secondary structure
330 // System.out.println(annotations[i].secondaryStructure);
331 // TODO: 2.8.2 should this ss symbol validation check be a function in
332 // RNA/ResidueProperties ?
333 if (annotations[i].secondaryStructure == '('
334 || annotations[i].secondaryStructure == '['
335 || annotations[i].secondaryStructure == '<'
336 || annotations[i].secondaryStructure == '{'
337 || annotations[i].secondaryStructure == 'A'
338 || annotations[i].secondaryStructure == 'B'
339 || annotations[i].secondaryStructure == 'C'
340 || annotations[i].secondaryStructure == 'D'
341 || annotations[i].secondaryStructure == 'E'
342 || annotations[i].secondaryStructure == 'F'
343 || annotations[i].secondaryStructure == 'G'
344 || annotations[i].secondaryStructure == 'H'
345 || annotations[i].secondaryStructure == 'I'
346 || annotations[i].secondaryStructure == 'J'
347 || annotations[i].secondaryStructure == 'K'
348 || annotations[i].secondaryStructure == 'L'
349 || annotations[i].secondaryStructure == 'M'
350 || annotations[i].secondaryStructure == 'N'
351 || annotations[i].secondaryStructure == 'O'
352 || annotations[i].secondaryStructure == 'P'
353 || annotations[i].secondaryStructure == 'Q'
354 || annotations[i].secondaryStructure == 'R'
355 || annotations[i].secondaryStructure == 'S'
356 || annotations[i].secondaryStructure == 'T'
357 || annotations[i].secondaryStructure == 'U'
358 || annotations[i].secondaryStructure == 'V'
359 || annotations[i].secondaryStructure == 'W'
360 || annotations[i].secondaryStructure == 'X'
361 || annotations[i].secondaryStructure == 'Y'
362 || annotations[i].secondaryStructure == 'Z')
369 // System.out.println("displaychar " + annotations[i].displayCharacter);
371 if (annotations[i].displayCharacter == null
372 || annotations[i].displayCharacter.length() == 0)
374 rnastring.append('.');
377 if (annotations[i].displayCharacter.length() == 1)
379 firstChar = annotations[i].displayCharacter.charAt(0);
380 // check to see if it looks like a sequence or is secondary structure
382 if (annotations[i].secondaryStructure != ' '
385 // Uncomment to only catch case where
386 // displayCharacter==secondary
388 // to correctly redisplay SS annotation imported from Stockholm,
389 // exported to JalviewXML and read back in again.
391 // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure
426 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
428 if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
441 rnastring.append(annotations[i].displayCharacter.charAt(1));
444 if (annotations[i].displayCharacter.length() > 0)
453 for (int j = 0; j < annotations.length; j++)
455 if (annotations[j] != null
456 && annotations[j].secondaryStructure != ' ')
458 annotations[j].displayCharacter = String
459 .valueOf(annotations[j].secondaryStructure);
460 annotations[j].secondaryStructure = ' ';
469 _updateRnaSecStr(new AnnotCharSequence());
475 * flyweight access to positions in the alignment annotation row for RNA
481 private class AnnotCharSequence implements CharSequence
487 public AnnotCharSequence()
489 this(0, annotations.length);
492 AnnotCharSequence(int start, int end)
499 public CharSequence subSequence(int start, int end)
501 return new AnnotCharSequence(offset + start, offset + end);
511 public char charAt(int index)
513 return ((index + offset < 0) || (index + offset) >= max
514 || annotations[index + offset] == null
515 || (annotations[index + offset].secondaryStructure <= ' ') ? ' '
516 : annotations[index + offset].displayCharacter == null
517 || annotations[index + offset].displayCharacter
518 .length() == 0 ? annotations[index + offset].secondaryStructure
519 : annotations[index + offset].displayCharacter
524 public String toString()
526 char[] string = new char[max - offset];
527 int mx = annotations.length;
529 for (int i = offset; i < mx; i++)
531 string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
532 : (annotations[i].displayCharacter == null
533 || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
534 : annotations[i].displayCharacter.charAt(0));
536 return new String(string);
540 private long _lastrnaannot = -1;
542 public String getRNAStruc()
546 String rnastruc = new AnnotCharSequence().toString();
547 if (_lastrnaannot != rnastruc.hashCode())
549 // ensure rna structure contacts are up to date
550 _lastrnaannot = rnastruc.hashCode();
551 _updateRnaSecStr(rnastruc);
559 * Creates a new AlignmentAnnotation object.
574 public AlignmentAnnotation(String label, String description,
575 Annotation[] annotations, float min, float max, int graphType)
578 // graphs are not editable
579 editable = graphType == 0;
582 this.description = description;
583 this.annotations = annotations;
587 validateRangeAndDisplay();
591 * checks graphMin and graphMax, secondary structure symbols, sets graphType
592 * appropriately, sets null labels to the empty string if appropriate.
594 public void validateRangeAndDisplay()
597 if (annotations == null)
599 visible = false; // try to prevent renderer from displaying.
600 invalidrnastruc = -1;
601 return; // this is a non-annotation row annotation - ie a sequence score.
604 int graphType = graph;
605 float min = graphMin;
606 float max = graphMax;
607 boolean drawValues = true;
612 for (int i = 0; i < annotations.length; i++)
614 if (annotations[i] == null)
619 if (drawValues && annotations[i].displayCharacter != null
620 && annotations[i].displayCharacter.length() > 1)
625 if (annotations[i].value > max)
627 max = annotations[i].value;
630 if (annotations[i].value < min)
632 min = annotations[i].value;
634 if (_linecolour == null && annotations[i].colour != null)
636 _linecolour = annotations[i].colour;
639 // ensure zero is origin for min/max ranges on only one side of zero
656 areLabelsSecondaryStructure();
658 if (!drawValues && graphType != NO_GRAPH)
660 for (int i = 0; i < annotations.length; i++)
662 if (annotations[i] != null)
664 annotations[i].displayCharacter = "";
671 * Copy constructor creates a new independent annotation row with the same
672 * associated sequenceRef
676 public AlignmentAnnotation(AlignmentAnnotation annotation)
679 this.label = new String(annotation.label);
680 if (annotation.description != null)
682 this.description = new String(annotation.description);
684 this.graphMin = annotation.graphMin;
685 this.graphMax = annotation.graphMax;
686 this.graph = annotation.graph;
687 this.graphHeight = annotation.graphHeight;
688 this.graphGroup = annotation.graphGroup;
689 this.groupRef = annotation.groupRef;
690 this.editable = annotation.editable;
691 this.autoCalculated = annotation.autoCalculated;
692 this.hasIcons = annotation.hasIcons;
693 this.hasText = annotation.hasText;
694 this.height = annotation.height;
695 this.label = annotation.label;
696 this.padGaps = annotation.padGaps;
697 this.visible = annotation.visible;
698 this.centreColLabels = annotation.centreColLabels;
699 this.scaleColLabel = annotation.scaleColLabel;
700 this.showAllColLabels = annotation.showAllColLabels;
701 this.calcId = annotation.calcId;
702 if (annotation.properties != null)
704 properties = new HashMap<String, String>();
705 for (Map.Entry<String, String> val : annotation.properties.entrySet())
707 properties.put(val.getKey(), val.getValue());
710 if (this.hasScore = annotation.hasScore)
712 this.score = annotation.score;
714 if (annotation.threshold != null)
716 threshold = new GraphLine(annotation.threshold);
718 Annotation[] ann = annotation.annotations;
719 if (annotation.annotations != null)
721 this.annotations = new Annotation[ann.length];
722 for (int i = 0; i < ann.length; i++)
726 annotations[i] = new Annotation(ann[i]);
727 if (_linecolour != null)
729 _linecolour = annotations[i].colour;
734 if (annotation.sequenceRef != null)
736 this.sequenceRef = annotation.sequenceRef;
737 if (annotation.sequenceMapping != null)
740 sequenceMapping = new HashMap<Integer, Annotation>();
741 Iterator<Integer> pos = annotation.sequenceMapping.keySet()
743 while (pos.hasNext())
745 // could optimise this!
747 Annotation a = annotation.sequenceMapping.get(p);
754 for (int i = 0; i < ann.length; i++)
758 sequenceMapping.put(p, annotations[i]);
766 this.sequenceMapping = null;
769 // TODO: check if we need to do this: JAL-952
770 // if (this.isrna=annotation.isrna)
772 // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
774 validateRangeAndDisplay(); // construct hashcodes, etc.
778 * clip the annotation to the columns given by startRes and endRes (inclusive)
779 * and prune any existing sequenceMapping to just those columns.
784 public void restrict(int startRes, int endRes)
786 if (annotations == null)
795 if (startRes >= annotations.length)
797 startRes = annotations.length - 1;
799 if (endRes >= annotations.length)
801 endRes = annotations.length - 1;
803 if (annotations == null)
807 Annotation[] temp = new Annotation[endRes - startRes + 1];
808 if (startRes < annotations.length)
810 System.arraycopy(annotations, startRes, temp, 0, endRes - startRes
813 if (sequenceRef != null)
815 // Clip the mapping, if it exists.
816 int spos = sequenceRef.findPosition(startRes);
817 int epos = sequenceRef.findPosition(endRes);
818 if (sequenceMapping != null)
820 Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
821 Iterator<Integer> e = sequenceMapping.keySet().iterator();
824 Integer pos = e.next();
825 if (pos.intValue() >= spos && pos.intValue() <= epos)
827 newmapping.put(pos, sequenceMapping.get(pos));
830 sequenceMapping.clear();
831 sequenceMapping = newmapping;
838 * set the annotation row to be at least length Annotations
841 * minimum number of columns required in the annotation row
842 * @return false if the annotation row is greater than length
844 public boolean padAnnotation(int length)
846 if (annotations == null)
848 return true; // annotation row is correct - null == not visible and
851 if (annotations.length < length)
853 Annotation[] na = new Annotation[length];
854 System.arraycopy(annotations, 0, na, 0, annotations.length);
858 return annotations.length > length;
865 * @return DOCUMENT ME!
868 public String toString()
870 if (annotations == null)
874 StringBuilder buffer = new StringBuilder(256);
876 for (int i = 0; i < annotations.length; i++)
878 if (annotations[i] != null)
882 buffer.append(annotations[i].value);
886 buffer.append(annotations[i].secondaryStructure);
890 buffer.append(annotations[i].displayCharacter);
896 // TODO: remove disgusting hack for 'special' treatment of consensus line.
897 if (label.indexOf("Consensus") == 0)
901 for (int i = 0; i < annotations.length; i++)
903 if (annotations[i] != null)
905 buffer.append(annotations[i].description);
912 return buffer.toString();
915 public void setThreshold(GraphLine line)
920 public GraphLine getThreshold()
926 * Attach the annotation to seqRef, starting from startRes position. If
927 * alreadyMapped is true then the indices of the annotation[] array are
928 * sequence positions rather than alignment column positions.
932 * @param alreadyMapped
934 public void createSequenceMapping(SequenceI seqRef, int startRes,
935 boolean alreadyMapped)
942 sequenceRef = seqRef;
943 if (annotations == null)
947 sequenceMapping = new HashMap<Integer, Annotation>();
951 for (int i = 0; i < annotations.length; i++)
953 if (annotations[i] != null)
957 seqPos = seqRef.findPosition(i);
961 seqPos = i + startRes;
964 sequenceMapping.put(new Integer(seqPos), annotations[i]);
971 * When positional annotation and a sequence reference is present, clears and
972 * resizes the annotations array to the current alignment width, and adds
973 * annotation according to aligned positions of the sequenceRef given by
976 public void adjustForAlignment()
978 if (sequenceRef == null)
983 if (annotations == null)
988 int a = 0, aSize = sequenceRef.getLength();
997 Annotation[] temp = new Annotation[aSize];
999 if (sequenceMapping != null)
1001 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
1003 index = new Integer(a);
1004 Annotation annot = sequenceMapping.get(index);
1007 position = sequenceRef.findIndex(a) - 1;
1009 temp[position] = annot;
1017 * remove any null entries in annotation row and return the number of non-null
1018 * annotation elements.
1022 public int compactAnnotationArray()
1024 int i = 0, iSize = annotations.length;
1027 if (annotations[i] == null)
1031 System.arraycopy(annotations, i + 1, annotations, i, iSize - i
1041 Annotation[] ann = annotations;
1042 annotations = new Annotation[i];
1043 System.arraycopy(ann, 0, annotations, 0, i);
1049 * Associate this annotation with the aligned residues of a particular
1050 * sequence. sequenceMapping will be updated in the following way: null
1051 * sequenceI - existing mapping will be discarded but annotations left in
1052 * mapped positions. valid sequenceI not equal to current sequenceRef: mapping
1053 * is discarded and rebuilt assuming 1:1 correspondence TODO: overload with
1054 * parameter to specify correspondence between current and new sequenceRef
1058 public void setSequenceRef(SequenceI sequenceI)
1060 if (sequenceI != null)
1062 if (sequenceRef != null)
1064 boolean rIsDs = sequenceRef.getDatasetSequence() == null, tIsDs = sequenceI
1065 .getDatasetSequence() == null;
1066 if (sequenceRef != sequenceI
1067 && (rIsDs && !tIsDs && sequenceRef != sequenceI
1068 .getDatasetSequence())
1069 && (!rIsDs && tIsDs && sequenceRef.getDatasetSequence() != sequenceI)
1070 && (!rIsDs && !tIsDs && sequenceRef.getDatasetSequence() != sequenceI
1071 .getDatasetSequence())
1072 && !sequenceRef.equals(sequenceI))
1074 // if sequenceRef isn't intersecting with sequenceI
1075 // throw away old mapping and reconstruct.
1077 if (sequenceMapping != null)
1079 sequenceMapping = null;
1080 // compactAnnotationArray();
1082 createSequenceMapping(sequenceI, 1, true);
1083 adjustForAlignment();
1087 // Mapping carried over
1088 sequenceRef = sequenceI;
1093 // No mapping exists
1094 createSequenceMapping(sequenceI, 1, true);
1095 adjustForAlignment();
1100 // throw away the mapping without compacting.
1101 sequenceMapping = null;
1109 public double getScore()
1118 public void setScore(double score)
1126 * @return true if annotation has an associated score
1128 public boolean hasScore()
1130 return hasScore || !Double.isNaN(score);
1134 * Score only annotation
1137 * @param description
1140 public AlignmentAnnotation(String label, String description, double score)
1142 this(label, description, null);
1147 * copy constructor with edit based on the hidden columns marked in colSel
1149 * @param alignmentAnnotation
1152 public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
1153 HiddenColumns hidden)
1155 this(alignmentAnnotation);
1156 if (annotations == null)
1160 hidden.makeVisibleAnnotation(this);
1163 public void setPadGaps(boolean padgaps, char gapchar)
1165 this.padGaps = padgaps;
1169 for (int i = 0; i < annotations.length; i++)
1171 if (annotations[i] == null)
1173 annotations[i] = new Annotation(String.valueOf(gapchar), null,
1176 else if (annotations[i].displayCharacter == null
1177 || annotations[i].displayCharacter.equals(" "))
1179 annotations[i].displayCharacter = String.valueOf(gapchar);
1186 * format description string for display
1189 * @return Get the annotation description string optionally prefixed by
1190 * associated sequence name (if any)
1192 public String getDescription(boolean seqname)
1194 if (seqname && this.sequenceRef != null)
1196 int i = description.toLowerCase().indexOf("<html>");
1199 // move the html tag to before the sequence reference.
1200 return "<html>" + sequenceRef.getName() + " : "
1201 + description.substring(i + 6);
1203 return sequenceRef.getName() + " : " + description;
1208 public boolean isValidStruc()
1210 return invalidrnastruc == -1;
1213 public long getInvalidStrucPos()
1215 return invalidrnastruc;
1219 * machine readable ID string indicating what generated this annotation
1221 protected String calcId = "";
1224 * properties associated with the calcId
1226 protected Map<String, String> properties = new HashMap<String, String>();
1229 * base colour for line graphs. If null, will be set automatically by
1230 * searching the alignment annotation
1232 public java.awt.Color _linecolour;
1234 public String getCalcId()
1239 public void setCalcId(String calcId)
1241 this.calcId = calcId;
1244 public boolean isRNA()
1250 * transfer annotation to the given sequence using the given mapping from the
1251 * current positions or an existing sequence mapping
1255 * map involving sq as To or From
1257 public void liftOver(SequenceI sq, Mapping sp2sq)
1259 if (sp2sq.getMappedWidth() != sp2sq.getWidth())
1261 // TODO: employ getWord/MappedWord to transfer annotation between cDNA and
1262 // Protein reference frames
1264 "liftOver currently not implemented for transfer of annotation between different types of seqeunce");
1266 boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == sq || sp2sq
1267 .getTo() == sq.getDatasetSequence()) : false;
1269 // TODO build a better annotation element map and get rid of annotations[]
1270 Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
1271 if (sequenceMapping != null)
1275 for (Entry<Integer, Annotation> ie : sequenceMapping.entrySet())
1277 Integer mpos = Integer.valueOf(mapIsTo ? sp2sq
1278 .getMappedPosition(ie.getKey()) : sp2sq.getPosition(ie
1280 if (mpos >= sq.getStart() && mpos <= sq.getEnd())
1282 mapForsq.put(mpos, ie.getValue());
1285 sequenceMapping = mapForsq;
1287 adjustForAlignment();
1297 * like liftOver but more general.
1299 * Takes an array of int pairs that will be used to update the internal
1300 * sequenceMapping and so shuffle the annotated positions
1303 * - new sequence reference for the annotation row - if null,
1304 * sequenceRef is left unchanged
1306 * array of ints containing corresponding positions
1308 * - column for current coordinate system (-1 for index+1)
1310 * - column for destination coordinate system (-1 for index+1)
1312 * - offset added to index when referencing either coordinate system
1313 * @note no checks are made as to whether from and/or to are sensible
1314 * @note caller should add the remapped annotation to newref if they have not
1317 public void remap(SequenceI newref, HashMap<Integer, int[]> mapping,
1318 int from, int to, int idxoffset)
1320 if (mapping != null)
1322 Map<Integer, Annotation> old = sequenceMapping;
1323 Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
1325 for (int mp[] : mapping.values())
1331 Annotation ann = null;
1334 ann = sequenceMapping.get(Integer.valueOf(idxoffset + index));
1338 if (mp != null && mp.length > from)
1340 ann = sequenceMapping.get(Integer.valueOf(mp[from]));
1347 remap.put(Integer.valueOf(idxoffset + index), ann);
1351 if (to > -1 && to < mp.length)
1353 remap.put(Integer.valueOf(mp[to]), ann);
1358 sequenceMapping = remap;
1362 sequenceRef = newref;
1364 adjustForAlignment();
1368 public String getProperty(String property)
1370 if (properties == null)
1374 return properties.get(property);
1377 public void setProperty(String property, String value)
1379 if (properties == null)
1381 properties = new HashMap<String, String>();
1383 properties.put(property, value);
1386 public boolean hasProperties()
1388 return properties != null && properties.size() > 0;
1391 public Collection<String> getProperties()
1393 if (properties == null)
1395 return Collections.emptyList();
1397 return properties.keySet();
1401 * Returns the Annotation for the given sequence position (base 1) if any,
1407 public Annotation getAnnotationForPosition(int position)
1409 return sequenceMapping == null ? null : sequenceMapping.get(position);
1414 * Set the id to "ann" followed by a counter that increments so as to be
1415 * unique for the lifetime of the JVM
1417 protected final void setAnnotationId()
1419 this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
1423 * Returns the match for the last unmatched opening RNA helix pair symbol
1424 * preceding the given column, or '(' if nothing found to match.
1429 public String getDefaultRnaHelixSymbol(int column)
1431 String result = "(";
1432 if (annotations == null)
1438 * for each preceding column, if it contains an open bracket,
1439 * count whether it is still unmatched at column, if so return its pair
1440 * (likely faster than the fancy alternative using stacks)
1442 for (int col = column - 1; col >= 0; col--)
1444 Annotation annotation = annotations[col];
1445 if (annotation == null)
1449 String displayed = annotation.displayCharacter;
1450 if (displayed == null || displayed.length() != 1)
1454 char symbol = displayed.charAt(0);
1455 if (!Rna.isOpeningParenthesis(symbol))
1461 * found an opening bracket symbol
1462 * count (closing-opening) symbols of this type that follow it,
1463 * up to and excluding the target column; if the count is less
1464 * than 1, the opening bracket is unmatched, so return its match
1466 String closer = String.valueOf(Rna
1467 .getMatchingClosingParenthesis(symbol));
1468 String opener = String.valueOf(symbol);
1470 for (int j = col + 1; j < column; j++)
1472 if (annotations[j] != null)
1474 String s = annotations[j].displayCharacter;
1475 if (closer.equals(s))
1479 else if (opener.equals(s))
1493 protected static synchronized long nextId()