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 != ' ' && !hasIcons &&
383 // Uncomment to only catch case where
384 // displayCharacter==secondary
386 // to correctly redisplay SS annotation imported from Stockholm,
387 // exported to JalviewXML and read back in again.
389 // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure
390 firstChar != ' ' && firstChar != '$' && firstChar != 0xCE
391 && firstChar != '(' && firstChar != '[' && firstChar != '>'
392 && firstChar != '{' && firstChar != 'A' && firstChar != 'B'
393 && firstChar != 'C' && firstChar != 'D' && firstChar != 'E'
394 && firstChar != 'F' && firstChar != 'G' && firstChar != 'H'
395 && firstChar != 'I' && firstChar != 'J' && firstChar != 'K'
396 && firstChar != 'L' && firstChar != 'M' && firstChar != 'N'
397 && firstChar != 'O' && firstChar != 'P' && firstChar != 'Q'
398 && firstChar != 'R' && firstChar != 'S' && firstChar != 'T'
399 && firstChar != 'U' && firstChar != 'V' && firstChar != 'W'
400 && firstChar != 'X' && firstChar != 'Y' && firstChar != 'Z'
402 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
404 if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
417 rnastring.append(annotations[i].displayCharacter.charAt(1));
420 if (annotations[i].displayCharacter.length() > 0)
429 for (int j = 0; j < annotations.length; j++)
431 if (annotations[j] != null
432 && annotations[j].secondaryStructure != ' ')
434 annotations[j].displayCharacter = String
435 .valueOf(annotations[j].secondaryStructure);
436 annotations[j].secondaryStructure = ' ';
445 _updateRnaSecStr(new AnnotCharSequence());
451 * flyweight access to positions in the alignment annotation row for RNA
457 private class AnnotCharSequence implements CharSequence
463 public AnnotCharSequence()
465 this(0, annotations.length);
468 AnnotCharSequence(int start, int end)
475 public CharSequence subSequence(int start, int end)
477 return new AnnotCharSequence(offset + start, offset + end);
487 public char charAt(int index)
489 return ((index + offset < 0) || (index + offset) >= max
490 || annotations[index + offset] == null
491 || (annotations[index + offset].secondaryStructure <= ' ')
493 : annotations[index + offset].displayCharacter == null
495 + offset].displayCharacter
498 + offset].secondaryStructure
500 + offset].displayCharacter
505 public String toString()
507 char[] string = new char[max - offset];
508 int mx = annotations.length;
510 for (int i = offset; i < mx; i++)
512 string[i] = (annotations[i] == null
513 || (annotations[i].secondaryStructure <= 32))
515 : (annotations[i].displayCharacter == null
516 || annotations[i].displayCharacter
518 ? annotations[i].secondaryStructure
519 : annotations[i].displayCharacter
522 return new String(string);
526 private long _lastrnaannot = -1;
528 public String getRNAStruc()
532 String rnastruc = new AnnotCharSequence().toString();
533 if (_lastrnaannot != rnastruc.hashCode())
535 // ensure rna structure contacts are up to date
536 _lastrnaannot = rnastruc.hashCode();
537 _updateRnaSecStr(rnastruc);
545 * Creates a new AlignmentAnnotation object.
560 public AlignmentAnnotation(String label, String description,
561 Annotation[] annotations, float min, float max, int graphType)
564 // graphs are not editable
565 editable = graphType == 0;
568 this.description = description;
569 this.annotations = annotations;
573 validateRangeAndDisplay();
577 * checks graphMin and graphMax, secondary structure symbols, sets graphType
578 * appropriately, sets null labels to the empty string if appropriate.
580 public void validateRangeAndDisplay()
583 if (annotations == null)
585 visible = false; // try to prevent renderer from displaying.
586 invalidrnastruc = -1;
587 return; // this is a non-annotation row annotation - ie a sequence score.
590 int graphType = graph;
591 float min = graphMin;
592 float max = graphMax;
593 boolean drawValues = true;
598 for (int i = 0; i < annotations.length; i++)
600 if (annotations[i] == null)
605 if (drawValues && annotations[i].displayCharacter != null
606 && annotations[i].displayCharacter.length() > 1)
611 if (annotations[i].value > max)
613 max = annotations[i].value;
616 if (annotations[i].value < min)
618 min = annotations[i].value;
620 if (_linecolour == null && annotations[i].colour != null)
622 _linecolour = annotations[i].colour;
625 // ensure zero is origin for min/max ranges on only one side of zero
642 areLabelsSecondaryStructure();
644 if (!drawValues && graphType != NO_GRAPH)
646 for (int i = 0; i < annotations.length; i++)
648 if (annotations[i] != null)
650 annotations[i].displayCharacter = "";
657 * Copy constructor creates a new independent annotation row with the same
658 * associated sequenceRef
662 public AlignmentAnnotation(AlignmentAnnotation annotation)
665 this.label = new String(annotation.label);
666 if (annotation.description != null)
668 this.description = new String(annotation.description);
670 this.graphMin = annotation.graphMin;
671 this.graphMax = annotation.graphMax;
672 this.graph = annotation.graph;
673 this.graphHeight = annotation.graphHeight;
674 this.graphGroup = annotation.graphGroup;
675 this.groupRef = annotation.groupRef;
676 this.editable = annotation.editable;
677 this.autoCalculated = annotation.autoCalculated;
678 this.hasIcons = annotation.hasIcons;
679 this.hasText = annotation.hasText;
680 this.height = annotation.height;
681 this.label = annotation.label;
682 this.padGaps = annotation.padGaps;
683 this.visible = annotation.visible;
684 this.centreColLabels = annotation.centreColLabels;
685 this.scaleColLabel = annotation.scaleColLabel;
686 this.showAllColLabels = annotation.showAllColLabels;
687 this.calcId = annotation.calcId;
688 if (annotation.properties != null)
690 properties = new HashMap<>();
691 for (Map.Entry<String, String> val : annotation.properties.entrySet())
693 properties.put(val.getKey(), val.getValue());
696 if (this.hasScore = annotation.hasScore)
698 this.score = annotation.score;
700 if (annotation.threshold != null)
702 threshold = new GraphLine(annotation.threshold);
704 Annotation[] ann = annotation.annotations;
705 if (annotation.annotations != null)
707 this.annotations = new Annotation[ann.length];
708 for (int i = 0; i < ann.length; i++)
712 annotations[i] = new Annotation(ann[i]);
713 if (_linecolour != null)
715 _linecolour = annotations[i].colour;
720 if (annotation.sequenceRef != null)
722 this.sequenceRef = annotation.sequenceRef;
723 if (annotation.sequenceMapping != null)
726 sequenceMapping = new HashMap<>();
727 Iterator<Integer> pos = annotation.sequenceMapping.keySet()
729 while (pos.hasNext())
731 // could optimise this!
733 Annotation a = annotation.sequenceMapping.get(p);
740 for (int i = 0; i < ann.length; i++)
744 sequenceMapping.put(p, annotations[i]);
752 this.sequenceMapping = null;
755 // TODO: check if we need to do this: JAL-952
756 // if (this.isrna=annotation.isrna)
758 // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
760 validateRangeAndDisplay(); // construct hashcodes, etc.
764 * clip the annotation to the columns given by startRes and endRes (inclusive)
765 * and prune any existing sequenceMapping to just those columns.
770 public void restrict(int startRes, int endRes)
772 if (annotations == null)
781 if (startRes >= annotations.length)
783 startRes = annotations.length - 1;
785 if (endRes >= annotations.length)
787 endRes = annotations.length - 1;
789 if (annotations == null)
793 Annotation[] temp = new Annotation[endRes - startRes + 1];
794 if (startRes < annotations.length)
796 System.arraycopy(annotations, startRes, temp, 0,
797 endRes - startRes + 1);
799 if (sequenceRef != null)
801 // Clip the mapping, if it exists.
802 int spos = sequenceRef.findPosition(startRes);
803 int epos = sequenceRef.findPosition(endRes);
804 if (sequenceMapping != null)
806 Map<Integer, Annotation> newmapping = new HashMap<>();
807 Iterator<Integer> e = sequenceMapping.keySet().iterator();
810 Integer pos = e.next();
811 if (pos.intValue() >= spos && pos.intValue() <= epos)
813 newmapping.put(pos, sequenceMapping.get(pos));
816 sequenceMapping.clear();
817 sequenceMapping = newmapping;
824 * set the annotation row to be at least length Annotations
827 * minimum number of columns required in the annotation row
828 * @return false if the annotation row is greater than length
830 public boolean padAnnotation(int length)
832 if (annotations == null)
834 return true; // annotation row is correct - null == not visible and
837 if (annotations.length < length)
839 Annotation[] na = new Annotation[length];
840 System.arraycopy(annotations, 0, na, 0, annotations.length);
844 return annotations.length > length;
851 * @return DOCUMENT ME!
854 public String toString()
856 if (annotations == null)
860 StringBuilder buffer = new StringBuilder(256);
862 for (int i = 0; i < annotations.length; i++)
864 if (annotations[i] != null)
868 buffer.append(annotations[i].value);
872 buffer.append(annotations[i].secondaryStructure);
876 buffer.append(annotations[i].displayCharacter);
882 // TODO: remove disgusting hack for 'special' treatment of consensus line.
883 if (label.indexOf("Consensus") == 0)
887 for (int i = 0; i < annotations.length; i++)
889 if (annotations[i] != null)
891 buffer.append(annotations[i].description);
898 return buffer.toString();
901 public void setThreshold(GraphLine line)
906 public GraphLine getThreshold()
912 * Attach the annotation to seqRef, starting from startRes position. If
913 * alreadyMapped is true then the indices of the annotation[] array are
914 * sequence positions rather than alignment column positions.
918 * @param alreadyMapped
920 public void createSequenceMapping(SequenceI seqRef, int startRes,
921 boolean alreadyMapped)
928 sequenceRef = seqRef;
929 if (annotations == null)
933 sequenceMapping = new HashMap<>();
937 for (int i = 0; i < annotations.length; i++)
939 if (annotations[i] != null)
943 seqPos = seqRef.findPosition(i);
947 seqPos = i + startRes;
950 sequenceMapping.put(new Integer(seqPos), annotations[i]);
957 * When positional annotation and a sequence reference is present, clears and
958 * resizes the annotations array to the current alignment width, and adds
959 * annotation according to aligned positions of the sequenceRef given by
962 public void adjustForAlignment()
964 if (sequenceRef == null)
969 if (annotations == null)
974 int a = 0, aSize = sequenceRef.getLength();
983 Annotation[] temp = new Annotation[aSize];
985 if (sequenceMapping != null)
987 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
989 index = new Integer(a);
990 Annotation annot = sequenceMapping.get(index);
993 position = sequenceRef.findIndex(a) - 1;
995 temp[position] = annot;
1003 * remove any null entries in annotation row and return the number of non-null
1004 * annotation elements.
1008 public int compactAnnotationArray()
1010 int i = 0, iSize = annotations.length;
1013 if (annotations[i] == null)
1017 System.arraycopy(annotations, i + 1, annotations, i,
1027 Annotation[] ann = annotations;
1028 annotations = new Annotation[i];
1029 System.arraycopy(ann, 0, annotations, 0, i);
1035 * Associate this annotation with the aligned residues of a particular
1036 * sequence. sequenceMapping will be updated in the following way: null
1037 * sequenceI - existing mapping will be discarded but annotations left in
1038 * mapped positions. valid sequenceI not equal to current sequenceRef: mapping
1039 * is discarded and rebuilt assuming 1:1 correspondence TODO: overload with
1040 * parameter to specify correspondence between current and new sequenceRef
1044 public void setSequenceRef(SequenceI sequenceI)
1046 if (sequenceI != null)
1048 if (sequenceRef != null)
1050 boolean rIsDs = sequenceRef.getDatasetSequence() == null,
1051 tIsDs = sequenceI.getDatasetSequence() == null;
1052 if (sequenceRef != sequenceI
1054 && sequenceRef != sequenceI.getDatasetSequence())
1056 && sequenceRef.getDatasetSequence() != sequenceI)
1057 && (!rIsDs && !tIsDs
1058 && sequenceRef.getDatasetSequence() != sequenceI
1059 .getDatasetSequence())
1060 && !sequenceRef.equals(sequenceI))
1062 // if sequenceRef isn't intersecting with sequenceI
1063 // throw away old mapping and reconstruct.
1065 if (sequenceMapping != null)
1067 sequenceMapping = null;
1068 // compactAnnotationArray();
1070 createSequenceMapping(sequenceI, 1, true);
1071 adjustForAlignment();
1075 // Mapping carried over
1076 sequenceRef = sequenceI;
1081 // No mapping exists
1082 createSequenceMapping(sequenceI, 1, true);
1083 adjustForAlignment();
1088 // throw away the mapping without compacting.
1089 sequenceMapping = null;
1097 public double getScore()
1106 public void setScore(double score)
1114 * @return true if annotation has an associated score
1116 public boolean hasScore()
1118 return hasScore || !Double.isNaN(score);
1122 * Score only annotation
1125 * @param description
1128 public AlignmentAnnotation(String label, String description, double score)
1130 this(label, description, null);
1135 * copy constructor with edit based on the hidden columns marked in colSel
1137 * @param alignmentAnnotation
1140 public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
1141 HiddenColumns hidden)
1143 this(alignmentAnnotation);
1144 if (annotations == null)
1148 hidden.makeVisibleAnnotation(this);
1151 public void setPadGaps(boolean padgaps, char gapchar)
1153 this.padGaps = padgaps;
1157 for (int i = 0; i < annotations.length; i++)
1159 if (annotations[i] == null)
1161 annotations[i] = new Annotation(String.valueOf(gapchar), null,
1164 else if (annotations[i].displayCharacter == null
1165 || annotations[i].displayCharacter.equals(" "))
1167 annotations[i].displayCharacter = String.valueOf(gapchar);
1174 * format description string for display
1177 * @return Get the annotation description string optionally prefixed by
1178 * associated sequence name (if any)
1180 public String getDescription(boolean seqname)
1182 if (seqname && this.sequenceRef != null)
1184 int i = description.toLowerCase().indexOf("<html>");
1187 // move the html tag to before the sequence reference.
1188 return "<html>" + sequenceRef.getName() + " : "
1189 + description.substring(i + 6);
1191 return sequenceRef.getName() + " : " + description;
1196 public boolean isValidStruc()
1198 return invalidrnastruc == -1;
1201 public long getInvalidStrucPos()
1203 return invalidrnastruc;
1207 * machine readable ID string indicating what generated this annotation
1209 protected String calcId = "";
1212 * properties associated with the calcId
1214 protected Map<String, String> properties = new HashMap<>();
1217 * base colour for line graphs. If null, will be set automatically by
1218 * searching the alignment annotation
1220 public java.awt.Color _linecolour;
1222 public String getCalcId()
1227 public void setCalcId(String calcId)
1229 this.calcId = calcId;
1232 public boolean isRNA()
1238 * transfer annotation to the given sequence using the given mapping from the
1239 * current positions or an existing sequence mapping
1243 * map involving sq as To or From
1245 public void liftOver(SequenceI sq, Mapping sp2sq)
1247 if (sp2sq.getMappedWidth() != sp2sq.getWidth())
1249 // TODO: employ getWord/MappedWord to transfer annotation between cDNA and
1250 // Protein reference frames
1252 "liftOver currently not implemented for transfer of annotation between different types of seqeunce");
1254 boolean mapIsTo = (sp2sq != null)
1255 ? (sp2sq.getTo() == sq
1256 || sp2sq.getTo() == sq.getDatasetSequence())
1259 // TODO build a better annotation element map and get rid of annotations[]
1260 Map<Integer, Annotation> mapForsq = new HashMap<>();
1261 if (sequenceMapping != null)
1265 for (Entry<Integer, Annotation> ie : sequenceMapping.entrySet())
1267 Integer mpos = Integer
1268 .valueOf(mapIsTo ? sp2sq.getMappedPosition(ie.getKey())
1269 : sp2sq.getPosition(ie.getKey()));
1270 if (mpos >= sq.getStart() && mpos <= sq.getEnd())
1272 mapForsq.put(mpos, ie.getValue());
1275 sequenceMapping = mapForsq;
1277 adjustForAlignment();
1287 * like liftOver but more general.
1289 * Takes an array of int pairs that will be used to update the internal
1290 * sequenceMapping and so shuffle the annotated positions
1293 * - new sequence reference for the annotation row - if null,
1294 * sequenceRef is left unchanged
1296 * array of ints containing corresponding positions
1298 * - column for current coordinate system (-1 for index+1)
1300 * - column for destination coordinate system (-1 for index+1)
1302 * - offset added to index when referencing either coordinate system
1303 * @note no checks are made as to whether from and/or to are sensible
1304 * @note caller should add the remapped annotation to newref if they have not
1307 public void remap(SequenceI newref, HashMap<Integer, int[]> mapping,
1308 int from, int to, int idxoffset)
1310 if (mapping != null)
1312 Map<Integer, Annotation> old = sequenceMapping;
1313 Map<Integer, Annotation> remap = new HashMap<>();
1315 for (int mp[] : mapping.values())
1321 Annotation ann = null;
1324 ann = sequenceMapping.get(Integer.valueOf(idxoffset + index));
1328 if (mp != null && mp.length > from)
1330 ann = sequenceMapping.get(Integer.valueOf(mp[from]));
1337 remap.put(Integer.valueOf(idxoffset + index), ann);
1341 if (to > -1 && to < mp.length)
1343 remap.put(Integer.valueOf(mp[to]), ann);
1348 sequenceMapping = remap;
1352 sequenceRef = newref;
1354 adjustForAlignment();
1358 public String getProperty(String property)
1360 if (properties == null)
1364 return properties.get(property);
1367 public void setProperty(String property, String value)
1369 if (properties == null)
1371 properties = new HashMap<>();
1373 properties.put(property, value);
1376 public boolean hasProperties()
1378 return properties != null && properties.size() > 0;
1381 public Collection<String> getProperties()
1383 if (properties == null)
1385 return Collections.emptyList();
1387 return properties.keySet();
1391 * Returns the Annotation for the given sequence position (base 1) if any,
1397 public Annotation getAnnotationForPosition(int position)
1399 return sequenceMapping == null ? null : sequenceMapping.get(position);
1404 * Set the id to "ann" followed by a counter that increments so as to be
1405 * unique for the lifetime of the JVM
1407 protected final void setAnnotationId()
1409 this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
1413 * Returns the match for the last unmatched opening RNA helix pair symbol
1414 * preceding the given column, or '(' if nothing found to match.
1419 public String getDefaultRnaHelixSymbol(int column)
1421 String result = "(";
1422 if (annotations == null)
1428 * for each preceding column, if it contains an open bracket,
1429 * count whether it is still unmatched at column, if so return its pair
1430 * (likely faster than the fancy alternative using stacks)
1432 for (int col = column - 1; col >= 0; col--)
1434 Annotation annotation = annotations[col];
1435 if (annotation == null)
1439 String displayed = annotation.displayCharacter;
1440 if (displayed == null || displayed.length() != 1)
1444 char symbol = displayed.charAt(0);
1445 if (!Rna.isOpeningParenthesis(symbol))
1451 * found an opening bracket symbol
1452 * count (closing-opening) symbols of this type that follow it,
1453 * up to and excluding the target column; if the count is less
1454 * than 1, the opening bracket is unmatched, so return its match
1456 String closer = String
1457 .valueOf(Rna.getMatchingClosingParenthesis(symbol));
1458 String opener = String.valueOf(symbol);
1460 for (int j = col + 1; j < column; j++)
1462 if (annotations[j] != null)
1464 String s = annotations[j].displayCharacter;
1465 if (closer.equals(s))
1469 else if (opener.equals(s))
1483 protected static synchronized long nextId()
1490 * @return true for rows that have a range of values in their annotation set
1492 public boolean isQuantitative()
1494 return graphMin < graphMax;