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
99 * @param rnaAnnotation
101 private void _updateRnaSecStr(CharSequence rnaAnnotation)
105 _rnasecstr = Rna.getHelixMap(rnaAnnotation);
106 invalidrnastruc = -1;
107 } catch (WUSSParseException px)
109 // DEBUG System.out.println(px);
110 invalidrnastruc = px.getProblemPos();
112 if (invalidrnastruc > -1)
117 if (_rnasecstr != null && _rnasecstr.length > 0)
119 // show all the RNA secondary structure annotation symbols.
121 showAllColLabels = true;
122 scaleColLabel = true;
125 // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup());
129 private void _markRnaHelices()
132 // Figure out number of helices
133 // Length of rnasecstr is the number of pairs of positions that base pair
134 // with each other in the secondary structure
135 for (int x = 0; x < _rnasecstr.length; x++)
139 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
140 * this.annotation._rnasecstr[x].getBegin());
142 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
146 val = Integer.valueOf(_rnasecstr[x].getFeatureGroup());
151 } catch (NumberFormatException q)
156 annotations[_rnasecstr[x].getBegin()].value = val;
157 annotations[_rnasecstr[x].getEnd()].value = val;
159 // annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val;
160 // annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val;
166 * map of positions in the associated annotation
168 private Map<Integer, Annotation> sequenceMapping;
171 * lower range for quantitative data
173 public float graphMin;
176 * Upper range for quantitative data
178 public float graphMax;
181 * Score associated with label and description.
183 public double score = Double.NaN;
186 * flag indicating if annotation has a score.
188 public boolean hasScore = false;
190 public GraphLine threshold;
192 // Graphical hints and tips
194 /** Can this row be edited by the user ? */
195 public boolean editable = false;
197 /** Indicates if annotation has a graphical symbol track */
198 public boolean hasIcons; //
200 /** Indicates if annotation has a text character label */
201 public boolean hasText;
203 /** is the row visible */
204 public boolean visible = true;
206 public int graphGroup = -1;
208 /** Displayed height of row in pixels */
209 public int height = 0;
211 public int graph = 0;
213 public int graphHeight = 40;
215 public boolean padGaps = false;
217 public static final int NO_GRAPH = 0;
219 public static final int BAR_GRAPH = 1;
221 public static final int LINE_GRAPH = 2;
223 public boolean belowAlignment = true;
225 public SequenceGroup groupRef = null;
228 * display every column label, even if there is a row of identical labels
230 public boolean showAllColLabels = false;
233 * scale the column label to fit within the alignment column.
235 public boolean scaleColLabel = false;
238 * centre the column labels relative to the alignment column
240 public boolean centreColLabels = false;
242 private boolean isrna;
247 * @see java.lang.Object#finalize()
250 protected void finalize() throws Throwable
257 public static int getGraphValueFromString(String string)
259 if (string.equalsIgnoreCase("BAR_GRAPH"))
263 else if (string.equalsIgnoreCase("LINE_GRAPH"))
274 * Creates a new AlignmentAnnotation object.
277 * short label shown under sequence labels
279 * text displayed on mouseover
281 * set of positional annotation elements
283 public AlignmentAnnotation(String label, String description,
284 Annotation[] annotations)
290 this.description = description;
291 this.annotations = annotations;
293 validateRangeAndDisplay();
297 * Checks if annotation labels represent secondary structures
300 void areLabelsSecondaryStructure()
302 boolean nonSSLabel = false;
304 StringBuffer rnastring = new StringBuffer();
307 for (int i = 0; i < annotations.length; i++)
309 if (annotations[i] == null)
313 if (annotations[i].secondaryStructure == 'H'
314 || annotations[i].secondaryStructure == 'E')
319 // Check for RNA secondary structure
321 // System.out.println(annotations[i].secondaryStructure);
322 // TODO: 2.8.2 should this ss symbol validation check be a function in
323 // RNA/ResidueProperties ?
324 if (annotations[i].secondaryStructure == '('
325 || annotations[i].secondaryStructure == '['
326 || annotations[i].secondaryStructure == '<'
327 || annotations[i].secondaryStructure == '{'
328 || annotations[i].secondaryStructure == 'A'
329 || annotations[i].secondaryStructure == 'B'
330 || annotations[i].secondaryStructure == 'C'
331 || annotations[i].secondaryStructure == 'D'
332 || annotations[i].secondaryStructure == 'E'
333 || annotations[i].secondaryStructure == 'F'
334 || annotations[i].secondaryStructure == 'G'
335 || annotations[i].secondaryStructure == 'H'
336 || annotations[i].secondaryStructure == 'I'
337 || annotations[i].secondaryStructure == 'J'
338 || annotations[i].secondaryStructure == 'K'
339 || annotations[i].secondaryStructure == 'L'
340 || annotations[i].secondaryStructure == 'M'
341 || annotations[i].secondaryStructure == 'N'
342 || annotations[i].secondaryStructure == 'O'
343 || annotations[i].secondaryStructure == 'P'
344 || annotations[i].secondaryStructure == 'Q'
345 || annotations[i].secondaryStructure == 'R'
346 || annotations[i].secondaryStructure == 'S'
347 || annotations[i].secondaryStructure == 'T'
348 || annotations[i].secondaryStructure == 'U'
349 || annotations[i].secondaryStructure == 'V'
350 || annotations[i].secondaryStructure == 'W'
351 || annotations[i].secondaryStructure == 'X'
352 || annotations[i].secondaryStructure == 'Y'
353 || annotations[i].secondaryStructure == 'Z')
360 // System.out.println("displaychar " + annotations[i].displayCharacter);
362 if (annotations[i].displayCharacter == null
363 || annotations[i].displayCharacter.length() == 0)
365 rnastring.append('.');
368 if (annotations[i].displayCharacter.length() == 1)
370 firstChar = annotations[i].displayCharacter.charAt(0);
371 // check to see if it looks like a sequence or is secondary structure
373 if (annotations[i].secondaryStructure != ' ' && !hasIcons &&
374 // Uncomment to only catch case where
375 // displayCharacter==secondary
377 // to correctly redisplay SS annotation imported from Stockholm,
378 // exported to JalviewXML and read back in again.
380 // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure
381 firstChar != ' ' && firstChar != '$' && firstChar != 0xCE
382 && firstChar != '(' && firstChar != '[' && firstChar != '>'
383 && firstChar != '{' && firstChar != 'A' && firstChar != 'B'
384 && firstChar != 'C' && firstChar != 'D' && firstChar != 'E'
385 && firstChar != 'F' && firstChar != 'G' && firstChar != 'H'
386 && firstChar != 'I' && firstChar != 'J' && firstChar != 'K'
387 && firstChar != 'L' && firstChar != 'M' && firstChar != 'N'
388 && firstChar != 'O' && firstChar != 'P' && firstChar != 'Q'
389 && firstChar != 'R' && firstChar != 'S' && firstChar != 'T'
390 && firstChar != 'U' && firstChar != 'V' && firstChar != 'W'
391 && firstChar != 'X' && firstChar != 'Y' && firstChar != 'Z'
393 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
395 if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
408 rnastring.append(annotations[i].displayCharacter.charAt(1));
411 if (annotations[i].displayCharacter.length() > 0)
420 for (int j = 0; j < annotations.length; j++)
422 if (annotations[j] != null
423 && annotations[j].secondaryStructure != ' ')
425 annotations[j].displayCharacter = String
426 .valueOf(annotations[j].secondaryStructure);
427 annotations[j].secondaryStructure = ' ';
436 _updateRnaSecStr(new AnnotCharSequence());
442 * flyweight access to positions in the alignment annotation row for RNA
448 private class AnnotCharSequence implements CharSequence
454 public AnnotCharSequence()
456 this(0, annotations.length);
459 AnnotCharSequence(int start, int end)
466 public CharSequence subSequence(int start, int end)
468 return new AnnotCharSequence(offset + start, offset + end);
478 public char charAt(int index)
480 return ((index + offset < 0) || (index + offset) >= max
481 || annotations[index + offset] == null
482 || (annotations[index + offset].secondaryStructure <= ' ')
484 : annotations[index + offset].displayCharacter == null
486 + offset].displayCharacter
489 + offset].secondaryStructure
491 + offset].displayCharacter
496 public String toString()
498 char[] string = new char[max - offset];
499 int mx = annotations.length;
501 for (int i = offset; i < mx; i++)
503 string[i] = (annotations[i] == null
504 || (annotations[i].secondaryStructure <= 32))
506 : (annotations[i].displayCharacter == null
507 || annotations[i].displayCharacter
509 ? annotations[i].secondaryStructure
510 : annotations[i].displayCharacter
513 return new String(string);
517 private long _lastrnaannot = -1;
519 public String getRNAStruc()
523 String rnastruc = new AnnotCharSequence().toString();
524 if (_lastrnaannot != rnastruc.hashCode())
526 // ensure rna structure contacts are up to date
527 _lastrnaannot = rnastruc.hashCode();
528 _updateRnaSecStr(rnastruc);
536 * Creates a new AlignmentAnnotation object.
551 public AlignmentAnnotation(String label, String description,
552 Annotation[] annotations, float min, float max, int graphType)
555 // graphs are not editable
556 editable = graphType == 0;
559 this.description = description;
560 this.annotations = annotations;
564 validateRangeAndDisplay();
568 * checks graphMin and graphMax, secondary structure symbols, sets graphType
569 * appropriately, sets null labels to the empty string if appropriate.
571 public void validateRangeAndDisplay()
574 if (annotations == null)
576 visible = false; // try to prevent renderer from displaying.
577 invalidrnastruc = -1;
578 return; // this is a non-annotation row annotation - ie a sequence score.
581 int graphType = graph;
582 float min = graphMin;
583 float max = graphMax;
584 boolean drawValues = true;
589 for (int i = 0; i < annotations.length; i++)
591 if (annotations[i] == null)
596 if (drawValues && annotations[i].displayCharacter != null
597 && annotations[i].displayCharacter.length() > 1)
602 if (annotations[i].value > max)
604 max = annotations[i].value;
607 if (annotations[i].value < min)
609 min = annotations[i].value;
611 if (_linecolour == null && annotations[i].colour != null)
613 _linecolour = annotations[i].colour;
616 // ensure zero is origin for min/max ranges on only one side of zero
633 areLabelsSecondaryStructure();
635 if (!drawValues && graphType != NO_GRAPH)
637 for (int i = 0; i < annotations.length; i++)
639 if (annotations[i] != null)
641 annotations[i].displayCharacter = "";
648 * Copy constructor creates a new independent annotation row with the same
649 * associated sequenceRef
653 public AlignmentAnnotation(AlignmentAnnotation annotation)
656 this.label = new String(annotation.label);
657 if (annotation.description != null)
659 this.description = new String(annotation.description);
661 this.graphMin = annotation.graphMin;
662 this.graphMax = annotation.graphMax;
663 this.graph = annotation.graph;
664 this.graphHeight = annotation.graphHeight;
665 this.graphGroup = annotation.graphGroup;
666 this.groupRef = annotation.groupRef;
667 this.editable = annotation.editable;
668 this.autoCalculated = annotation.autoCalculated;
669 this.hasIcons = annotation.hasIcons;
670 this.hasText = annotation.hasText;
671 this.height = annotation.height;
672 this.label = annotation.label;
673 this.padGaps = annotation.padGaps;
674 this.visible = annotation.visible;
675 this.centreColLabels = annotation.centreColLabels;
676 this.scaleColLabel = annotation.scaleColLabel;
677 this.showAllColLabels = annotation.showAllColLabels;
678 this.calcId = annotation.calcId;
679 if (annotation.properties != null)
681 properties = new HashMap<String, String>();
682 for (Map.Entry<String, String> val : annotation.properties.entrySet())
684 properties.put(val.getKey(), val.getValue());
687 if (this.hasScore = annotation.hasScore)
689 this.score = annotation.score;
691 if (annotation.threshold != null)
693 threshold = new GraphLine(annotation.threshold);
695 Annotation[] ann = annotation.annotations;
696 if (annotation.annotations != null)
698 this.annotations = new Annotation[ann.length];
699 for (int i = 0; i < ann.length; i++)
703 annotations[i] = new Annotation(ann[i]);
704 if (_linecolour != null)
706 _linecolour = annotations[i].colour;
711 if (annotation.sequenceRef != null)
713 this.sequenceRef = annotation.sequenceRef;
714 if (annotation.sequenceMapping != null)
717 sequenceMapping = new HashMap<Integer, Annotation>();
718 Iterator<Integer> pos = annotation.sequenceMapping.keySet()
720 while (pos.hasNext())
722 // could optimise this!
724 Annotation a = annotation.sequenceMapping.get(p);
731 for (int i = 0; i < ann.length; i++)
735 sequenceMapping.put(p, annotations[i]);
743 this.sequenceMapping = null;
746 // TODO: check if we need to do this: JAL-952
747 // if (this.isrna=annotation.isrna)
749 // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
751 validateRangeAndDisplay(); // construct hashcodes, etc.
755 * clip the annotation to the columns given by startRes and endRes (inclusive)
756 * and prune any existing sequenceMapping to just those columns.
761 public void restrict(int startRes, int endRes)
763 if (annotations == null)
772 if (startRes >= annotations.length)
774 startRes = annotations.length - 1;
776 if (endRes >= annotations.length)
778 endRes = annotations.length - 1;
780 if (annotations == null)
784 Annotation[] temp = new Annotation[endRes - startRes + 1];
785 if (startRes < annotations.length)
787 System.arraycopy(annotations, startRes, temp, 0,
788 endRes - startRes + 1);
790 if (sequenceRef != null)
792 // Clip the mapping, if it exists.
793 int spos = sequenceRef.findPosition(startRes);
794 int epos = sequenceRef.findPosition(endRes);
795 if (sequenceMapping != null)
797 Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
798 Iterator<Integer> e = sequenceMapping.keySet().iterator();
801 Integer pos = e.next();
802 if (pos.intValue() >= spos && pos.intValue() <= epos)
804 newmapping.put(pos, sequenceMapping.get(pos));
807 sequenceMapping.clear();
808 sequenceMapping = newmapping;
815 * set the annotation row to be at least length Annotations
818 * minimum number of columns required in the annotation row
819 * @return false if the annotation row is greater than length
821 public boolean padAnnotation(int length)
823 if (annotations == null)
825 return true; // annotation row is correct - null == not visible and
828 if (annotations.length < length)
830 Annotation[] na = new Annotation[length];
831 System.arraycopy(annotations, 0, na, 0, annotations.length);
835 return annotations.length > length;
842 * @return DOCUMENT ME!
845 public String toString()
847 if (annotations == null)
851 StringBuilder buffer = new StringBuilder(256);
853 for (int i = 0; i < annotations.length; i++)
855 if (annotations[i] != null)
859 buffer.append(annotations[i].value);
863 buffer.append(annotations[i].secondaryStructure);
867 buffer.append(annotations[i].displayCharacter);
873 // TODO: remove disgusting hack for 'special' treatment of consensus line.
874 if (label.indexOf("Consensus") == 0)
878 for (int i = 0; i < annotations.length; i++)
880 if (annotations[i] != null)
882 buffer.append(annotations[i].description);
889 return buffer.toString();
892 public void setThreshold(GraphLine line)
897 public GraphLine getThreshold()
903 * Attach the annotation to seqRef, starting from startRes position. If
904 * alreadyMapped is true then the indices of the annotation[] array are
905 * sequence positions rather than alignment column positions.
909 * @param alreadyMapped
911 public void createSequenceMapping(SequenceI seqRef, int startRes,
912 boolean alreadyMapped)
919 sequenceRef = seqRef;
920 if (annotations == null)
924 sequenceMapping = new HashMap<Integer, Annotation>();
928 for (int i = 0; i < annotations.length; i++)
930 if (annotations[i] != null)
934 seqPos = seqRef.findPosition(i);
938 seqPos = i + startRes;
941 sequenceMapping.put(new Integer(seqPos), annotations[i]);
948 * When positional annotation and a sequence reference is present, clears and
949 * resizes the annotations array to the current alignment width, and adds
950 * annotation according to aligned positions of the sequenceRef given by
953 public void adjustForAlignment()
955 if (sequenceRef == null)
960 if (annotations == null)
965 int a = 0, aSize = sequenceRef.getLength();
974 Annotation[] temp = new Annotation[aSize];
976 if (sequenceMapping != null)
978 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
980 index = new Integer(a);
981 Annotation annot = sequenceMapping.get(index);
984 position = sequenceRef.findIndex(a) - 1;
986 temp[position] = annot;
994 * remove any null entries in annotation row and return the number of non-null
995 * annotation elements.
999 public int compactAnnotationArray()
1001 int i = 0, iSize = annotations.length;
1004 if (annotations[i] == null)
1008 System.arraycopy(annotations, i + 1, annotations, i,
1018 Annotation[] ann = annotations;
1019 annotations = new Annotation[i];
1020 System.arraycopy(ann, 0, annotations, 0, i);
1026 * Associate this annotation with the aligned residues of a particular
1027 * sequence. sequenceMapping will be updated in the following way: null
1028 * sequenceI - existing mapping will be discarded but annotations left in
1029 * mapped positions. valid sequenceI not equal to current sequenceRef: mapping
1030 * is discarded and rebuilt assuming 1:1 correspondence TODO: overload with
1031 * parameter to specify correspondence between current and new sequenceRef
1035 public void setSequenceRef(SequenceI sequenceI)
1037 if (sequenceI != null)
1039 if (sequenceRef != null)
1041 boolean rIsDs = sequenceRef.getDatasetSequence() == null,
1042 tIsDs = sequenceI.getDatasetSequence() == null;
1043 if (sequenceRef != sequenceI
1045 && sequenceRef != sequenceI.getDatasetSequence())
1047 && sequenceRef.getDatasetSequence() != sequenceI)
1048 && (!rIsDs && !tIsDs
1049 && sequenceRef.getDatasetSequence() != sequenceI
1050 .getDatasetSequence())
1051 && !sequenceRef.equals(sequenceI))
1053 // if sequenceRef isn't intersecting with sequenceI
1054 // throw away old mapping and reconstruct.
1056 if (sequenceMapping != null)
1058 sequenceMapping = null;
1059 // compactAnnotationArray();
1061 createSequenceMapping(sequenceI, 1, true);
1062 adjustForAlignment();
1066 // Mapping carried over
1067 sequenceRef = sequenceI;
1072 // No mapping exists
1073 createSequenceMapping(sequenceI, 1, true);
1074 adjustForAlignment();
1079 // throw away the mapping without compacting.
1080 sequenceMapping = null;
1088 public double getScore()
1097 public void setScore(double score)
1105 * @return true if annotation has an associated score
1107 public boolean hasScore()
1109 return hasScore || !Double.isNaN(score);
1113 * Score only annotation
1116 * @param description
1119 public AlignmentAnnotation(String label, String description, double score)
1121 this(label, description, null);
1126 * copy constructor with edit based on the hidden columns marked in colSel
1128 * @param alignmentAnnotation
1131 public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
1132 HiddenColumns hidden)
1134 this(alignmentAnnotation);
1135 if (annotations == null)
1139 hidden.makeVisibleAnnotation(this);
1142 public void setPadGaps(boolean padgaps, char gapchar)
1144 this.padGaps = padgaps;
1148 for (int i = 0; i < annotations.length; i++)
1150 if (annotations[i] == null)
1152 annotations[i] = new Annotation(String.valueOf(gapchar), null,
1155 else if (annotations[i].displayCharacter == null
1156 || annotations[i].displayCharacter.equals(" "))
1158 annotations[i].displayCharacter = String.valueOf(gapchar);
1165 * format description string for display
1168 * @return Get the annotation description string optionally prefixed by
1169 * associated sequence name (if any)
1171 public String getDescription(boolean seqname)
1173 if (seqname && this.sequenceRef != null)
1175 int i = description.toLowerCase().indexOf("<html>");
1178 // move the html tag to before the sequence reference.
1179 return "<html>" + sequenceRef.getName() + " : "
1180 + description.substring(i + 6);
1182 return sequenceRef.getName() + " : " + description;
1187 public boolean isValidStruc()
1189 return invalidrnastruc == -1;
1192 public long getInvalidStrucPos()
1194 return invalidrnastruc;
1198 * machine readable ID string indicating what generated this annotation
1200 protected String calcId = "";
1203 * properties associated with the calcId
1205 protected Map<String, String> properties = new HashMap<String, String>();
1208 * base colour for line graphs. If null, will be set automatically by
1209 * searching the alignment annotation
1211 public java.awt.Color _linecolour;
1213 public String getCalcId()
1218 public void setCalcId(String calcId)
1220 this.calcId = calcId;
1223 public boolean isRNA()
1229 * transfer annotation to the given sequence using the given mapping from the
1230 * current positions or an existing sequence mapping
1234 * map involving sq as To or From
1236 public void liftOver(SequenceI sq, Mapping sp2sq)
1238 if (sp2sq.getMappedWidth() != sp2sq.getWidth())
1240 // TODO: employ getWord/MappedWord to transfer annotation between cDNA and
1241 // Protein reference frames
1243 "liftOver currently not implemented for transfer of annotation between different types of seqeunce");
1245 boolean mapIsTo = (sp2sq != null)
1246 ? (sp2sq.getTo() == sq
1247 || sp2sq.getTo() == sq.getDatasetSequence())
1250 // TODO build a better annotation element map and get rid of annotations[]
1251 Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
1252 if (sequenceMapping != null)
1256 for (Entry<Integer, Annotation> ie : sequenceMapping.entrySet())
1258 Integer mpos = Integer
1259 .valueOf(mapIsTo ? sp2sq.getMappedPosition(ie.getKey())
1260 : sp2sq.getPosition(ie.getKey()));
1261 if (mpos >= sq.getStart() && mpos <= sq.getEnd())
1263 mapForsq.put(mpos, ie.getValue());
1266 sequenceMapping = mapForsq;
1268 adjustForAlignment();
1278 * like liftOver but more general.
1280 * Takes an array of int pairs that will be used to update the internal
1281 * sequenceMapping and so shuffle the annotated positions
1284 * - new sequence reference for the annotation row - if null,
1285 * sequenceRef is left unchanged
1287 * array of ints containing corresponding positions
1289 * - column for current coordinate system (-1 for index+1)
1291 * - column for destination coordinate system (-1 for index+1)
1293 * - offset added to index when referencing either coordinate system
1294 * @note no checks are made as to whether from and/or to are sensible
1295 * @note caller should add the remapped annotation to newref if they have not
1298 public void remap(SequenceI newref, HashMap<Integer, int[]> mapping,
1299 int from, int to, int idxoffset)
1301 if (mapping != null)
1303 Map<Integer, Annotation> old = sequenceMapping;
1304 Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
1306 for (int mp[] : mapping.values())
1312 Annotation ann = null;
1315 ann = sequenceMapping.get(Integer.valueOf(idxoffset + index));
1319 if (mp != null && mp.length > from)
1321 ann = sequenceMapping.get(Integer.valueOf(mp[from]));
1328 remap.put(Integer.valueOf(idxoffset + index), ann);
1332 if (to > -1 && to < mp.length)
1334 remap.put(Integer.valueOf(mp[to]), ann);
1339 sequenceMapping = remap;
1343 sequenceRef = newref;
1345 adjustForAlignment();
1349 public String getProperty(String property)
1351 if (properties == null)
1355 return properties.get(property);
1358 public void setProperty(String property, String value)
1360 if (properties == null)
1362 properties = new HashMap<String, String>();
1364 properties.put(property, value);
1367 public boolean hasProperties()
1369 return properties != null && properties.size() > 0;
1372 public Collection<String> getProperties()
1374 if (properties == null)
1376 return Collections.emptyList();
1378 return properties.keySet();
1382 * Returns the Annotation for the given sequence position (base 1) if any,
1388 public Annotation getAnnotationForPosition(int position)
1390 return sequenceMapping == null ? null : sequenceMapping.get(position);
1395 * Set the id to "ann" followed by a counter that increments so as to be
1396 * unique for the lifetime of the JVM
1398 protected final void setAnnotationId()
1400 this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
1404 * Returns the match for the last unmatched opening RNA helix pair symbol
1405 * preceding the given column, or '(' if nothing found to match.
1410 public String getDefaultRnaHelixSymbol(int column)
1412 String result = "(";
1413 if (annotations == null)
1419 * for each preceding column, if it contains an open bracket,
1420 * count whether it is still unmatched at column, if so return its pair
1421 * (likely faster than the fancy alternative using stacks)
1423 for (int col = column - 1; col >= 0; col--)
1425 Annotation annotation = annotations[col];
1426 if (annotation == null)
1430 String displayed = annotation.displayCharacter;
1431 if (displayed == null || displayed.length() != 1)
1435 char symbol = displayed.charAt(0);
1436 if (!Rna.isOpeningParenthesis(symbol))
1442 * found an opening bracket symbol
1443 * count (closing-opening) symbols of this type that follow it,
1444 * up to and excluding the target column; if the count is less
1445 * than 1, the opening bracket is unmatched, so return its match
1447 String closer = String
1448 .valueOf(Rna.getMatchingClosingParenthesis(symbol));
1449 String opener = String.valueOf(symbol);
1451 for (int j = col + 1; j < column; j++)
1453 if (annotations[j] != null)
1455 String s = annotations[j].displayCharacter;
1456 if (closer.equals(s))
1460 else if (opener.equals(s))
1474 protected static synchronized long nextId()
1481 * @return true for rows that have a range of values in their annotation set
1483 public boolean isQuantitative()
1485 return graphMin < graphMax;