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 HiddenMarkovModel hmm;
56 private static long counter = 0;
59 * If true, this annotations is calculated every edit, eg consensus, quality
60 * or conservation graphs
62 public boolean autoCalculated = false;
65 * unique ID for this annotation, used to match up the same annotation row
66 * shown in multiple views and alignments
68 public String annotationId;
71 * the sequence this annotation is associated with (or null)
73 public SequenceI sequenceRef;
75 /** label shown in dropdown menus and in the annotation label area */
78 /** longer description text shown as a tooltip */
79 public String description;
81 /** Array of annotations placed in the current coordinate system */
82 public Annotation[] annotations;
84 public List<SimpleBP> bps = null;
87 * RNA secondary structure contact positions
89 public SequenceFeature[] _rnasecstr = null;
92 * position of annotation resulting in invalid WUSS parsing or -1. -2 means
93 * there was no RNA structure in this annotation
95 private long invalidrnastruc = -2;
98 * Updates the _rnasecstr field Determines the positions that base pair and
99 * the positions of helices based on secondary structure from a Stockholm file
103 private void _updateRnaSecStr(CharSequence RNAannot)
107 bps = Rna.getModeleBP(RNAannot);
108 _rnasecstr = Rna.getBasePairs(bps);
109 invalidrnastruc = -1;
110 } catch (WUSSParseException px)
112 // DEBUG System.out.println(px);
113 invalidrnastruc = px.getProblemPos();
115 if (invalidrnastruc > -1)
119 Rna.HelixMap(_rnasecstr);
120 // setRNAStruc(RNAannot);
122 if (_rnasecstr != null && _rnasecstr.length > 0)
124 // show all the RNA secondary structure annotation symbols.
126 showAllColLabels = true;
127 scaleColLabel = true;
130 // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup());
134 private void _markRnaHelices()
137 // Figure out number of helices
138 // Length of rnasecstr is the number of pairs of positions that base pair
139 // with each other in the secondary structure
140 for (int x = 0; x < _rnasecstr.length; x++)
144 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
145 * this.annotation._rnasecstr[x].getBegin());
147 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
151 val = Integer.valueOf(_rnasecstr[x].getFeatureGroup());
156 } catch (NumberFormatException q)
161 annotations[_rnasecstr[x].getBegin()].value = val;
162 annotations[_rnasecstr[x].getEnd()].value = val;
164 // annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val;
165 // annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val;
171 * map of positions in the associated annotation
173 private Map<Integer, Annotation> sequenceMapping;
176 * lower range for quantitative data
178 public float graphMin;
181 * Upper range for quantitative data
183 public float graphMax;
186 * Score associated with label and description.
188 public double score = Double.NaN;
191 * flag indicating if annotation has a score.
193 public boolean hasScore = false;
195 public GraphLine threshold;
197 // Graphical hints and tips
199 /** Can this row be edited by the user ? */
200 public boolean editable = false;
202 /** Indicates if annotation has a graphical symbol track */
203 public boolean hasIcons; //
205 /** Indicates if annotation has a text character label */
206 public boolean hasText;
208 /** is the row visible */
209 public boolean visible = true;
211 public int graphGroup = -1;
213 /** Displayed height of row in pixels */
214 public int height = 0;
216 public int graph = 0;
218 public int graphHeight = 40;
220 public boolean padGaps = false;
222 public static final int NO_GRAPH = 0;
224 public static final int BAR_GRAPH = 1;
226 public static final int LINE_GRAPH = 2;
228 public boolean belowAlignment = true;
230 public SequenceGroup groupRef = null;
233 * display every column label, even if there is a row of identical labels
235 public boolean showAllColLabels = false;
238 * scale the column label to fit within the alignment column.
240 public boolean scaleColLabel = false;
243 * centre the column labels relative to the alignment column
245 public boolean centreColLabels = false;
247 private boolean isrna;
252 * @see java.lang.Object#finalize()
255 protected void finalize() throws Throwable
262 public static int getGraphValueFromString(String string)
264 if (string.equalsIgnoreCase("BAR_GRAPH"))
268 else if (string.equalsIgnoreCase("LINE_GRAPH"))
278 // JBPNote: what does this do ?
279 public void ConcenStru(CharSequence RNAannot) throws WUSSParseException
281 bps = Rna.getModeleBP(RNAannot);
285 * Creates a new AlignmentAnnotation object.
288 * short label shown under sequence labels
290 * text displayed on mouseover
292 * set of positional annotation elements
294 public AlignmentAnnotation(String label, String description,
295 Annotation[] annotations)
301 this.description = description;
302 this.annotations = annotations;
304 validateRangeAndDisplay();
308 * Checks if annotation labels represent secondary structures
311 void areLabelsSecondaryStructure()
313 boolean nonSSLabel = false;
315 StringBuffer rnastring = new StringBuffer();
318 for (int i = 0; i < annotations.length; i++)
320 if (annotations[i] == null)
324 if (annotations[i].secondaryStructure == 'H'
325 || annotations[i].secondaryStructure == 'E')
330 // Check for RNA secondary structure
332 // System.out.println(annotations[i].secondaryStructure);
333 // TODO: 2.8.2 should this ss symbol validation check be a function in
334 // RNA/ResidueProperties ?
335 if (annotations[i].secondaryStructure == '('
336 || annotations[i].secondaryStructure == '['
337 || annotations[i].secondaryStructure == '<'
338 || annotations[i].secondaryStructure == '{'
339 || annotations[i].secondaryStructure == 'A'
340 || annotations[i].secondaryStructure == 'B'
341 || annotations[i].secondaryStructure == 'C'
342 || annotations[i].secondaryStructure == 'D'
343 || annotations[i].secondaryStructure == 'E'
344 || annotations[i].secondaryStructure == 'F'
345 || annotations[i].secondaryStructure == 'G'
346 || annotations[i].secondaryStructure == 'H'
347 || annotations[i].secondaryStructure == 'I'
348 || annotations[i].secondaryStructure == 'J'
349 || annotations[i].secondaryStructure == 'K'
350 || annotations[i].secondaryStructure == 'L'
351 || annotations[i].secondaryStructure == 'M'
352 || annotations[i].secondaryStructure == 'N'
353 || annotations[i].secondaryStructure == 'O'
354 || annotations[i].secondaryStructure == 'P'
355 || annotations[i].secondaryStructure == 'Q'
356 || annotations[i].secondaryStructure == 'R'
357 || annotations[i].secondaryStructure == 'S'
358 || annotations[i].secondaryStructure == 'T'
359 || annotations[i].secondaryStructure == 'U'
360 || annotations[i].secondaryStructure == 'V'
361 || annotations[i].secondaryStructure == 'W'
362 || annotations[i].secondaryStructure == 'X'
363 || annotations[i].secondaryStructure == 'Y'
364 || annotations[i].secondaryStructure == 'Z')
371 // System.out.println("displaychar " + annotations[i].displayCharacter);
373 if (annotations[i].displayCharacter == null
374 || annotations[i].displayCharacter.length() == 0)
376 rnastring.append('.');
379 if (annotations[i].displayCharacter.length() == 1)
381 firstChar = annotations[i].displayCharacter.charAt(0);
382 // check to see if it looks like a sequence or is secondary structure
384 if (annotations[i].secondaryStructure != ' '
387 // Uncomment to only catch case where
388 // displayCharacter==secondary
390 // to correctly redisplay SS annotation imported from Stockholm,
391 // exported to JalviewXML and read back in again.
393 // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure
428 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
430 if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
443 rnastring.append(annotations[i].displayCharacter.charAt(1));
446 if (annotations[i].displayCharacter.length() > 0)
455 for (int j = 0; j < annotations.length; j++)
457 if (annotations[j] != null
458 && annotations[j].secondaryStructure != ' ')
460 annotations[j].displayCharacter = String
461 .valueOf(annotations[j].secondaryStructure);
462 annotations[j].secondaryStructure = ' ';
471 _updateRnaSecStr(new AnnotCharSequence());
477 * flyweight access to positions in the alignment annotation row for RNA
483 private class AnnotCharSequence implements CharSequence
489 public AnnotCharSequence()
491 this(0, annotations.length);
494 AnnotCharSequence(int start, int end)
501 public CharSequence subSequence(int start, int end)
503 return new AnnotCharSequence(offset + start, offset + end);
513 public char charAt(int index)
515 return ((index + offset < 0) || (index + offset) >= max
516 || annotations[index + offset] == null
517 || (annotations[index + offset].secondaryStructure <= ' ') ? ' '
518 : annotations[index + offset].displayCharacter == null
519 || annotations[index + offset].displayCharacter
520 .length() == 0 ? annotations[index + offset].secondaryStructure
521 : annotations[index + offset].displayCharacter
526 public String toString()
528 char[] string = new char[max - offset];
529 int mx = annotations.length;
531 for (int i = offset; i < mx; i++)
533 string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
534 : (annotations[i].displayCharacter == null
535 || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
536 : annotations[i].displayCharacter.charAt(0));
538 return new String(string);
542 private long _lastrnaannot = -1;
544 public String getRNAStruc()
548 String rnastruc = new AnnotCharSequence().toString();
549 if (_lastrnaannot != rnastruc.hashCode())
551 // ensure rna structure contacts are up to date
552 _lastrnaannot = rnastruc.hashCode();
553 _updateRnaSecStr(rnastruc);
561 * Creates a new AlignmentAnnotation object.
576 public AlignmentAnnotation(String label, String description,
577 Annotation[] annotations, float min, float max, int graphType)
580 // graphs are not editable
581 editable = graphType == 0;
584 this.description = description;
585 this.annotations = annotations;
589 validateRangeAndDisplay();
593 * checks graphMin and graphMax, secondary structure symbols, sets graphType
594 * appropriately, sets null labels to the empty string if appropriate.
596 public void validateRangeAndDisplay()
599 if (annotations == null)
601 visible = false; // try to prevent renderer from displaying.
602 invalidrnastruc = -1;
603 return; // this is a non-annotation row annotation - ie a sequence score.
606 int graphType = graph;
607 float min = graphMin;
608 float max = graphMax;
609 boolean drawValues = true;
614 for (int i = 0; i < annotations.length; i++)
616 if (annotations[i] == null)
621 if (drawValues && annotations[i].displayCharacter != null
622 && annotations[i].displayCharacter.length() > 1)
627 if (annotations[i].value > max)
629 max = annotations[i].value;
632 if (annotations[i].value < min)
634 min = annotations[i].value;
636 if (_linecolour == null && annotations[i].colour != null)
638 _linecolour = annotations[i].colour;
641 // ensure zero is origin for min/max ranges on only one side of zero
658 areLabelsSecondaryStructure();
660 if (!drawValues && graphType != NO_GRAPH)
662 for (int i = 0; i < annotations.length; i++)
664 if (annotations[i] != null)
666 annotations[i].displayCharacter = "";
673 * Copy constructor creates a new independent annotation row with the same
674 * associated sequenceRef
678 public AlignmentAnnotation(AlignmentAnnotation annotation)
681 this.label = new String(annotation.label);
682 if (annotation.description != null)
684 this.description = new String(annotation.description);
686 this.graphMin = annotation.graphMin;
687 this.graphMax = annotation.graphMax;
688 this.graph = annotation.graph;
689 this.graphHeight = annotation.graphHeight;
690 this.graphGroup = annotation.graphGroup;
691 this.groupRef = annotation.groupRef;
692 this.editable = annotation.editable;
693 this.autoCalculated = annotation.autoCalculated;
694 this.hasIcons = annotation.hasIcons;
695 this.hasText = annotation.hasText;
696 this.height = annotation.height;
697 this.label = annotation.label;
698 this.padGaps = annotation.padGaps;
699 this.visible = annotation.visible;
700 this.centreColLabels = annotation.centreColLabels;
701 this.scaleColLabel = annotation.scaleColLabel;
702 this.showAllColLabels = annotation.showAllColLabels;
703 this.calcId = annotation.calcId;
704 if (annotation.properties != null)
706 properties = new HashMap<>();
707 for (Map.Entry<String, String> val : annotation.properties.entrySet())
709 properties.put(val.getKey(), val.getValue());
712 if (this.hasScore = annotation.hasScore)
714 this.score = annotation.score;
716 if (annotation.threshold != null)
718 threshold = new GraphLine(annotation.threshold);
720 Annotation[] ann = annotation.annotations;
721 if (annotation.annotations != null)
723 this.annotations = new Annotation[ann.length];
724 for (int i = 0; i < ann.length; i++)
728 annotations[i] = new Annotation(ann[i]);
729 if (_linecolour != null)
731 _linecolour = annotations[i].colour;
736 if (annotation.sequenceRef != null)
738 this.sequenceRef = annotation.sequenceRef;
739 if (annotation.sequenceMapping != null)
742 sequenceMapping = new HashMap<>();
743 Iterator<Integer> pos = annotation.sequenceMapping.keySet()
745 while (pos.hasNext())
747 // could optimise this!
749 Annotation a = annotation.sequenceMapping.get(p);
756 for (int i = 0; i < ann.length; i++)
760 sequenceMapping.put(p, annotations[i]);
768 this.sequenceMapping = null;
771 // TODO: check if we need to do this: JAL-952
772 // if (this.isrna=annotation.isrna)
774 // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
776 validateRangeAndDisplay(); // construct hashcodes, etc.
780 * clip the annotation to the columns given by startRes and endRes (inclusive)
781 * and prune any existing sequenceMapping to just those columns.
786 public void restrict(int startRes, int endRes)
788 if (annotations == null)
797 if (startRes >= annotations.length)
799 startRes = annotations.length - 1;
801 if (endRes >= annotations.length)
803 endRes = annotations.length - 1;
805 if (annotations == null)
809 Annotation[] temp = new Annotation[endRes - startRes + 1];
810 if (startRes < annotations.length)
812 System.arraycopy(annotations, startRes, temp, 0, endRes - startRes
815 if (sequenceRef != null)
817 // Clip the mapping, if it exists.
818 int spos = sequenceRef.findPosition(startRes);
819 int epos = sequenceRef.findPosition(endRes);
820 if (sequenceMapping != null)
822 Map<Integer, Annotation> newmapping = new HashMap<>();
823 Iterator<Integer> e = sequenceMapping.keySet().iterator();
826 Integer pos = e.next();
827 if (pos.intValue() >= spos && pos.intValue() <= epos)
829 newmapping.put(pos, sequenceMapping.get(pos));
832 sequenceMapping.clear();
833 sequenceMapping = newmapping;
840 * set the annotation row to be at least length Annotations
843 * minimum number of columns required in the annotation row
844 * @return false if the annotation row is greater than length
846 public boolean padAnnotation(int length)
848 if (annotations == null)
850 return true; // annotation row is correct - null == not visible and
853 if (annotations.length < length)
855 Annotation[] na = new Annotation[length];
856 System.arraycopy(annotations, 0, na, 0, annotations.length);
860 return annotations.length > length;
867 * @return DOCUMENT ME!
870 public String toString()
872 if (annotations == null)
876 StringBuilder buffer = new StringBuilder(256);
878 for (int i = 0; i < annotations.length; i++)
880 if (annotations[i] != null)
884 buffer.append(annotations[i].value);
888 buffer.append(annotations[i].secondaryStructure);
892 buffer.append(annotations[i].displayCharacter);
898 // TODO: remove disgusting hack for 'special' treatment of consensus line.
899 if (label.indexOf("Consensus") == 0)
903 for (int i = 0; i < annotations.length; i++)
905 if (annotations[i] != null)
907 buffer.append(annotations[i].description);
914 return buffer.toString();
917 public void setThreshold(GraphLine line)
922 public GraphLine getThreshold()
928 * Attach the annotation to seqRef, starting from startRes position. If
929 * alreadyMapped is true then the indices of the annotation[] array are
930 * sequence positions rather than alignment column positions.
934 * @param alreadyMapped
936 public void createSequenceMapping(SequenceI seqRef, int startRes,
937 boolean alreadyMapped)
944 sequenceRef = seqRef;
945 if (annotations == null)
949 sequenceMapping = new HashMap<>();
953 for (int i = 0; i < annotations.length; i++)
955 if (annotations[i] != null)
959 seqPos = seqRef.findPosition(i);
963 seqPos = i + startRes;
966 sequenceMapping.put(new Integer(seqPos), annotations[i]);
973 * When positional annotation and a sequence reference is present, clears and
974 * resizes the annotations array to the current alignment width, and adds
975 * annotation according to aligned positions of the sequenceRef given by
978 public void adjustForAlignment()
980 if (sequenceRef == null)
985 if (annotations == null)
990 int a = 0, aSize = sequenceRef.getLength();
999 Annotation[] temp = new Annotation[aSize];
1001 if (sequenceMapping != null)
1003 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
1005 index = new Integer(a);
1006 Annotation annot = sequenceMapping.get(index);
1009 position = sequenceRef.findIndex(a) - 1;
1011 temp[position] = annot;
1019 * remove any null entries in annotation row and return the number of non-null
1020 * annotation elements.
1024 public int compactAnnotationArray()
1026 int i = 0, iSize = annotations.length;
1029 if (annotations[i] == null)
1033 System.arraycopy(annotations, i + 1, annotations, i, iSize - i
1043 Annotation[] ann = annotations;
1044 annotations = new Annotation[i];
1045 System.arraycopy(ann, 0, annotations, 0, i);
1051 * Associate this annotation with the aligned residues of a particular
1052 * sequence. sequenceMapping will be updated in the following way: null
1053 * sequenceI - existing mapping will be discarded but annotations left in
1054 * mapped positions. valid sequenceI not equal to current sequenceRef: mapping
1055 * is discarded and rebuilt assuming 1:1 correspondence TODO: overload with
1056 * parameter to specify correspondence between current and new sequenceRef
1060 public void setSequenceRef(SequenceI sequenceI)
1062 if (sequenceI != null)
1064 if (sequenceRef != null)
1066 boolean rIsDs = sequenceRef.getDatasetSequence() == null, tIsDs = sequenceI
1067 .getDatasetSequence() == null;
1068 if (sequenceRef != sequenceI
1069 && (rIsDs && !tIsDs && sequenceRef != sequenceI
1070 .getDatasetSequence())
1071 && (!rIsDs && tIsDs && sequenceRef.getDatasetSequence() != sequenceI)
1072 && (!rIsDs && !tIsDs && sequenceRef.getDatasetSequence() != sequenceI
1073 .getDatasetSequence())
1074 && !sequenceRef.equals(sequenceI))
1076 // if sequenceRef isn't intersecting with sequenceI
1077 // throw away old mapping and reconstruct.
1079 if (sequenceMapping != null)
1081 sequenceMapping = null;
1082 // compactAnnotationArray();
1084 createSequenceMapping(sequenceI, 1, true);
1085 adjustForAlignment();
1089 // Mapping carried over
1090 sequenceRef = sequenceI;
1095 // No mapping exists
1096 createSequenceMapping(sequenceI, 1, true);
1097 adjustForAlignment();
1102 // throw away the mapping without compacting.
1103 sequenceMapping = null;
1111 public double getScore()
1120 public void setScore(double score)
1128 * @return true if annotation has an associated score
1130 public boolean hasScore()
1132 return hasScore || !Double.isNaN(score);
1136 * Score only annotation
1139 * @param description
1142 public AlignmentAnnotation(String label, String description, double score)
1144 this(label, description, null);
1149 * copy constructor with edit based on the hidden columns marked in colSel
1151 * @param alignmentAnnotation
1154 public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
1155 HiddenColumns hidden)
1157 this(alignmentAnnotation);
1158 if (annotations == null)
1162 hidden.makeVisibleAnnotation(this);
1165 public void setPadGaps(boolean padgaps, char gapchar)
1167 this.padGaps = padgaps;
1171 for (int i = 0; i < annotations.length; i++)
1173 if (annotations[i] == null)
1175 annotations[i] = new Annotation(String.valueOf(gapchar), null,
1178 else if (annotations[i].displayCharacter == null
1179 || annotations[i].displayCharacter.equals(" "))
1181 annotations[i].displayCharacter = String.valueOf(gapchar);
1188 * format description string for display
1191 * @return Get the annotation description string optionally prefixed by
1192 * associated sequence name (if any)
1194 public String getDescription(boolean seqname)
1196 if (seqname && this.sequenceRef != null)
1198 int i = description.toLowerCase().indexOf("<html>");
1201 // move the html tag to before the sequence reference.
1202 return "<html>" + sequenceRef.getName() + " : "
1203 + description.substring(i + 6);
1205 return sequenceRef.getName() + " : " + description;
1210 public boolean isValidStruc()
1212 return invalidrnastruc == -1;
1215 public long getInvalidStrucPos()
1217 return invalidrnastruc;
1221 * machine readable ID string indicating what generated this annotation
1223 protected String calcId = "";
1226 * properties associated with the calcId
1228 protected Map<String, String> properties = new HashMap<>();
1231 * base colour for line graphs. If null, will be set automatically by
1232 * searching the alignment annotation
1234 public java.awt.Color _linecolour;
1236 public String getCalcId()
1241 public void setCalcId(String calcId)
1243 this.calcId = calcId;
1246 public boolean isRNA()
1252 * transfer annotation to the given sequence using the given mapping from the
1253 * current positions or an existing sequence mapping
1257 * map involving sq as To or From
1259 public void liftOver(SequenceI sq, Mapping sp2sq)
1261 if (sp2sq.getMappedWidth() != sp2sq.getWidth())
1263 // TODO: employ getWord/MappedWord to transfer annotation between cDNA and
1264 // Protein reference frames
1266 "liftOver currently not implemented for transfer of annotation between different types of seqeunce");
1268 boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == sq || sp2sq
1269 .getTo() == sq.getDatasetSequence()) : false;
1271 // TODO build a better annotation element map and get rid of annotations[]
1272 Map<Integer, Annotation> mapForsq = new HashMap<>();
1273 if (sequenceMapping != null)
1277 for (Entry<Integer, Annotation> ie : sequenceMapping.entrySet())
1279 Integer mpos = Integer.valueOf(mapIsTo ? sp2sq
1280 .getMappedPosition(ie.getKey()) : sp2sq.getPosition(ie
1282 if (mpos >= sq.getStart() && mpos <= sq.getEnd())
1284 mapForsq.put(mpos, ie.getValue());
1287 sequenceMapping = mapForsq;
1289 adjustForAlignment();
1299 * like liftOver but more general.
1301 * Takes an array of int pairs that will be used to update the internal
1302 * sequenceMapping and so shuffle the annotated positions
1305 * - new sequence reference for the annotation row - if null,
1306 * sequenceRef is left unchanged
1308 * array of ints containing corresponding positions
1310 * - column for current coordinate system (-1 for index+1)
1312 * - column for destination coordinate system (-1 for index+1)
1314 * - offset added to index when referencing either coordinate system
1315 * @note no checks are made as to whether from and/or to are sensible
1316 * @note caller should add the remapped annotation to newref if they have not
1319 public void remap(SequenceI newref, HashMap<Integer, int[]> mapping,
1320 int from, int to, int idxoffset)
1322 if (mapping != null)
1324 Map<Integer, Annotation> old = sequenceMapping;
1325 Map<Integer, Annotation> remap = new HashMap<>();
1327 for (int mp[] : mapping.values())
1333 Annotation ann = null;
1336 ann = sequenceMapping.get(Integer.valueOf(idxoffset + index));
1340 if (mp != null && mp.length > from)
1342 ann = sequenceMapping.get(Integer.valueOf(mp[from]));
1349 remap.put(Integer.valueOf(idxoffset + index), ann);
1353 if (to > -1 && to < mp.length)
1355 remap.put(Integer.valueOf(mp[to]), ann);
1360 sequenceMapping = remap;
1364 sequenceRef = newref;
1366 adjustForAlignment();
1370 public String getProperty(String property)
1372 if (properties == null)
1376 return properties.get(property);
1379 public void setProperty(String property, String value)
1381 if (properties == null)
1383 properties = new HashMap<>();
1385 properties.put(property, value);
1388 public boolean hasProperties()
1390 return properties != null && properties.size() > 0;
1393 public Collection<String> getProperties()
1395 if (properties == null)
1397 return Collections.emptyList();
1399 return properties.keySet();
1403 * Returns the Annotation for the given sequence position (base 1) if any,
1409 public Annotation getAnnotationForPosition(int position)
1411 return sequenceMapping == null ? null : sequenceMapping.get(position);
1416 * Set the id to "ann" followed by a counter that increments so as to be
1417 * unique for the lifetime of the JVM
1419 protected final void setAnnotationId()
1421 this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
1425 * Returns the match for the last unmatched opening RNA helix pair symbol
1426 * preceding the given column, or '(' if nothing found to match.
1431 public String getDefaultRnaHelixSymbol(int column)
1433 String result = "(";
1434 if (annotations == null)
1440 * for each preceding column, if it contains an open bracket,
1441 * count whether it is still unmatched at column, if so return its pair
1442 * (likely faster than the fancy alternative using stacks)
1444 for (int col = column - 1; col >= 0; col--)
1446 Annotation annotation = annotations[col];
1447 if (annotation == null)
1451 String displayed = annotation.displayCharacter;
1452 if (displayed == null || displayed.length() != 1)
1456 char symbol = displayed.charAt(0);
1457 if (!Rna.isOpeningParenthesis(symbol))
1463 * found an opening bracket symbol
1464 * count (closing-opening) symbols of this type that follow it,
1465 * up to and excluding the target column; if the count is less
1466 * than 1, the opening bracket is unmatched, so return its match
1468 String closer = String.valueOf(Rna
1469 .getMatchingClosingParenthesis(symbol));
1470 String opener = String.valueOf(symbol);
1472 for (int j = col + 1; j < column; j++)
1474 if (annotations[j] != null)
1476 String s = annotations[j].displayCharacter;
1477 if (closer.equals(s))
1481 else if (opener.equals(s))
1495 protected static synchronized long nextId()
1502 * @return true for rows that have a range of values in their annotation set
1504 public boolean isQuantitative()
1506 return graphMin < graphMax;
1509 public void setHMM(HiddenMarkovModel markov)
1514 public HiddenMarkovModel getHMM()