2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
3 * Copyright (C) 2015 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.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.HashMap;
31 import java.util.Iterator;
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 ArrayList<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 _rnasecstr = Rna.GetBasePairs(RNAannot);
106 bps = Rna.GetModeleBP(RNAannot);
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 public float graphMin;
177 public float graphMax;
180 * Score associated with label and description.
182 public double score = Double.NaN;
185 * flag indicating if annotation has a score.
187 public boolean hasScore = false;
189 public GraphLine threshold;
191 // Graphical hints and tips
193 /** Can this row be edited by the user ? */
194 public boolean editable = false;
196 /** Indicates if annotation has a graphical symbol track */
197 public boolean hasIcons; //
199 /** Indicates if annotation has a text character label */
200 public boolean hasText;
202 /** is the row visible */
203 public boolean visible = true;
205 public int graphGroup = -1;
207 /** Displayed height of row in pixels */
208 public int height = 0;
210 public int graph = 0;
212 public int graphHeight = 40;
214 public boolean padGaps = false;
216 public static final int NO_GRAPH = 0;
218 public static final int BAR_GRAPH = 1;
220 public static final int LINE_GRAPH = 2;
222 public boolean belowAlignment = true;
224 public SequenceGroup groupRef = null;
227 * display every column label, even if there is a row of identical labels
229 public boolean showAllColLabels = false;
232 * scale the column label to fit within the alignment column.
234 public boolean scaleColLabel = false;
237 * centre the column labels relative to the alignment column
239 public boolean centreColLabels = false;
241 private boolean isrna;
246 * @see java.lang.Object#finalize()
248 protected void finalize() throws Throwable
255 public static int getGraphValueFromString(String string)
257 if (string.equalsIgnoreCase("BAR_GRAPH"))
261 else if (string.equalsIgnoreCase("LINE_GRAPH"))
271 // JBPNote: what does this do ?
272 public void ConcenStru(CharSequence RNAannot) throws WUSSParseException
274 bps = Rna.GetModeleBP(RNAannot);
278 * Creates a new AlignmentAnnotation object.
281 * short label shown under sequence labels
283 * text displayed on mouseover
285 * set of positional annotation elements
287 public AlignmentAnnotation(String label, String description,
288 Annotation[] annotations)
294 this.description = description;
295 this.annotations = annotations;
297 validateRangeAndDisplay();
301 * Checks if annotation labels represent secondary structures
304 void areLabelsSecondaryStructure()
306 boolean nonSSLabel = false;
308 StringBuffer rnastring = new StringBuffer();
311 for (int i = 0; i < annotations.length; i++)
313 if (annotations[i] == null)
317 if (annotations[i].secondaryStructure == 'H'
318 || annotations[i].secondaryStructure == 'E')
323 // Check for RNA secondary structure
325 // System.out.println(annotations[i].secondaryStructure);
326 // TODO: 2.8.2 should this ss symbol validation check be a function in
327 // RNA/ResidueProperties ?
328 if (annotations[i].secondaryStructure == '('
329 || annotations[i].secondaryStructure == '['
330 || annotations[i].secondaryStructure == '<'
331 || annotations[i].secondaryStructure == '{'
332 || annotations[i].secondaryStructure == 'A'
333 || annotations[i].secondaryStructure == 'B'
334 || annotations[i].secondaryStructure == 'C'
335 || annotations[i].secondaryStructure == 'D'
336 || annotations[i].secondaryStructure == 'E'
337 || annotations[i].secondaryStructure == 'F'
338 || annotations[i].secondaryStructure == 'G'
339 || annotations[i].secondaryStructure == 'H'
340 || annotations[i].secondaryStructure == 'I'
341 || annotations[i].secondaryStructure == 'J'
342 || annotations[i].secondaryStructure == 'K'
343 || annotations[i].secondaryStructure == 'L'
344 || annotations[i].secondaryStructure == 'M'
345 || annotations[i].secondaryStructure == 'N'
346 || annotations[i].secondaryStructure == 'O'
347 || annotations[i].secondaryStructure == 'P'
348 || annotations[i].secondaryStructure == 'Q'
349 || annotations[i].secondaryStructure == 'R'
350 || annotations[i].secondaryStructure == 'S'
351 || annotations[i].secondaryStructure == 'T'
352 || annotations[i].secondaryStructure == 'U'
353 || annotations[i].secondaryStructure == 'V'
354 || annotations[i].secondaryStructure == 'W'
355 || annotations[i].secondaryStructure == 'X'
356 || annotations[i].secondaryStructure == 'Y'
357 || annotations[i].secondaryStructure == 'Z')
364 // System.out.println("displaychar " + annotations[i].displayCharacter);
366 if (annotations[i].displayCharacter == null
367 || annotations[i].displayCharacter.length() == 0)
369 rnastring.append('.');
372 if (annotations[i].displayCharacter.length() == 1)
374 firstChar = annotations[i].displayCharacter.charAt(0);
375 // check to see if it looks like a sequence or is secondary structure
377 if (annotations[i].secondaryStructure != ' '
380 // Uncomment to only catch case where
381 // displayCharacter==secondary
383 // to correctly redisplay SS annotation imported from Stockholm,
384 // exported to JalviewXML and read back in again.
386 // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure
421 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
423 if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
436 rnastring.append(annotations[i].displayCharacter.charAt(1));
439 if (annotations[i].displayCharacter.length() > 0)
448 for (int j = 0; j < annotations.length; j++)
450 if (annotations[j] != null
451 && annotations[j].secondaryStructure != ' ')
453 annotations[j].displayCharacter = String
454 .valueOf(annotations[j].secondaryStructure);
455 annotations[j].secondaryStructure = ' ';
464 _updateRnaSecStr(new AnnotCharSequence());
470 * flyweight access to positions in the alignment annotation row for RNA
476 private class AnnotCharSequence implements CharSequence
482 public AnnotCharSequence()
484 this(0, annotations.length);
487 public AnnotCharSequence(int start, int end)
494 public CharSequence subSequence(int start, int end)
496 return new AnnotCharSequence(offset + start, offset + end);
506 public char charAt(int index)
508 return ((index + offset < 0) || (index + offset) >= max
509 || annotations[index + offset] == null
510 || (annotations[index + offset].secondaryStructure <= ' ') ? ' '
511 : annotations[index + offset].displayCharacter == null
512 || annotations[index + offset].displayCharacter
513 .length() == 0 ? annotations[index + offset].secondaryStructure
514 : annotations[index + offset].displayCharacter
519 public String toString()
521 char[] string = new char[max - offset];
522 int mx = annotations.length;
524 for (int i = offset; i < mx; i++)
526 string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
527 : (annotations[i].displayCharacter == null
528 || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
529 : annotations[i].displayCharacter.charAt(0));
531 return new String(string);
535 private long _lastrnaannot = -1;
537 public String getRNAStruc()
541 String rnastruc = new AnnotCharSequence().toString();
542 if (_lastrnaannot != rnastruc.hashCode())
544 // ensure rna structure contacts are up to date
545 _lastrnaannot = rnastruc.hashCode();
546 _updateRnaSecStr(rnastruc);
554 * Creates a new AlignmentAnnotation object.
569 public AlignmentAnnotation(String label, String description,
570 Annotation[] annotations, float min, float max, int graphType)
573 // graphs are not editable
574 editable = graphType == 0;
577 this.description = description;
578 this.annotations = annotations;
582 validateRangeAndDisplay();
586 * checks graphMin and graphMax, secondary structure symbols, sets graphType
587 * appropriately, sets null labels to the empty string if appropriate.
589 public void validateRangeAndDisplay()
592 if (annotations == null)
594 visible = false; // try to prevent renderer from displaying.
595 return; // this is a non-annotation row annotation - ie a sequence score.
598 int graphType = graph;
599 float min = graphMin;
600 float max = graphMax;
601 boolean drawValues = true;
606 for (int i = 0; i < annotations.length; i++)
608 if (annotations[i] == null)
613 if (drawValues && annotations[i].displayCharacter != null
614 && annotations[i].displayCharacter.length() > 1)
619 if (annotations[i].value > max)
621 max = annotations[i].value;
624 if (annotations[i].value < min)
626 min = annotations[i].value;
628 if (_linecolour == null && annotations[i].colour != null)
630 _linecolour = annotations[i].colour;
633 // ensure zero is origin for min/max ranges on only one side of zero
650 areLabelsSecondaryStructure();
652 if (!drawValues && graphType != NO_GRAPH)
654 for (int i = 0; i < annotations.length; i++)
656 if (annotations[i] != null)
658 annotations[i].displayCharacter = "";
665 * Copy constructor creates a new independent annotation row with the same
666 * associated sequenceRef
670 public AlignmentAnnotation(AlignmentAnnotation annotation)
673 this.label = new String(annotation.label);
674 if (annotation.description != null)
676 this.description = new String(annotation.description);
678 this.graphMin = annotation.graphMin;
679 this.graphMax = annotation.graphMax;
680 this.graph = annotation.graph;
681 this.graphHeight = annotation.graphHeight;
682 this.graphGroup = annotation.graphGroup;
683 this.groupRef = annotation.groupRef;
684 this.editable = annotation.editable;
685 this.autoCalculated = annotation.autoCalculated;
686 this.hasIcons = annotation.hasIcons;
687 this.hasText = annotation.hasText;
688 this.height = annotation.height;
689 this.label = annotation.label;
690 this.padGaps = annotation.padGaps;
691 this.visible = annotation.visible;
692 this.centreColLabels = annotation.centreColLabels;
693 this.scaleColLabel = annotation.scaleColLabel;
694 this.showAllColLabels = annotation.showAllColLabels;
695 this.calcId = annotation.calcId;
696 if (annotation.properties != null)
698 properties = new HashMap<String, String>();
699 for (Map.Entry<String, String> val : annotation.properties.entrySet())
701 properties.put(val.getKey(), val.getValue());
704 if (this.hasScore = annotation.hasScore)
706 this.score = annotation.score;
708 if (annotation.threshold != null)
710 threshold = new GraphLine(annotation.threshold);
712 Annotation[] ann = annotation.annotations;
713 if (annotation.annotations != null)
715 this.annotations = new Annotation[ann.length];
716 for (int i = 0; i < ann.length; i++)
720 annotations[i] = new Annotation(ann[i]);
721 if (_linecolour != null)
723 _linecolour = annotations[i].colour;
728 if (annotation.sequenceRef != null)
730 this.sequenceRef = annotation.sequenceRef;
731 if (annotation.sequenceMapping != null)
734 sequenceMapping = new HashMap<Integer, Annotation>();
735 Iterator<Integer> pos = annotation.sequenceMapping.keySet()
737 while (pos.hasNext())
739 // could optimise this!
741 Annotation a = annotation.sequenceMapping.get(p);
748 for (int i = 0; i < ann.length; i++)
752 sequenceMapping.put(p, annotations[i]);
760 this.sequenceMapping = null;
763 // TODO: check if we need to do this: JAL-952
764 // if (this.isrna=annotation.isrna)
766 // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
768 validateRangeAndDisplay(); // construct hashcodes, etc.
772 * clip the annotation to the columns given by startRes and endRes (inclusive)
773 * and prune any existing sequenceMapping to just those columns.
778 public void restrict(int startRes, int endRes)
780 if (annotations == null)
789 if (startRes >= annotations.length)
791 startRes = annotations.length - 1;
793 if (endRes >= annotations.length)
795 endRes = annotations.length - 1;
797 if (annotations == null)
801 Annotation[] temp = new Annotation[endRes - startRes + 1];
802 if (startRes < annotations.length)
804 System.arraycopy(annotations, startRes, temp, 0, endRes - startRes
807 if (sequenceRef != null)
809 // Clip the mapping, if it exists.
810 int spos = sequenceRef.findPosition(startRes);
811 int epos = sequenceRef.findPosition(endRes);
812 if (sequenceMapping != null)
814 Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
815 Iterator<Integer> e = sequenceMapping.keySet().iterator();
818 Integer pos = e.next();
819 if (pos.intValue() >= spos && pos.intValue() <= epos)
821 newmapping.put(pos, sequenceMapping.get(pos));
824 sequenceMapping.clear();
825 sequenceMapping = newmapping;
832 * set the annotation row to be at least length Annotations
835 * minimum number of columns required in the annotation row
836 * @return false if the annotation row is greater than length
838 public boolean padAnnotation(int length)
840 if (annotations == null)
842 return true; // annotation row is correct - null == not visible and
845 if (annotations.length < length)
847 Annotation[] na = new Annotation[length];
848 System.arraycopy(annotations, 0, na, 0, annotations.length);
852 return annotations.length > length;
859 * @return DOCUMENT ME!
862 public String toString()
864 StringBuilder buffer = new StringBuilder(256);
866 for (int i = 0; i < annotations.length; i++)
868 if (annotations[i] != null)
872 buffer.append(annotations[i].value);
876 buffer.append(annotations[i].secondaryStructure);
880 buffer.append(annotations[i].displayCharacter);
886 // TODO: remove disgusting hack for 'special' treatment of consensus line.
887 if (label.indexOf("Consensus") == 0)
891 for (int i = 0; i < annotations.length; i++)
893 if (annotations[i] != null)
895 buffer.append(annotations[i].description);
902 return buffer.toString();
905 public void setThreshold(GraphLine line)
910 public GraphLine getThreshold()
916 * Attach the annotation to seqRef, starting from startRes position. If
917 * alreadyMapped is true then the indices of the annotation[] array are
918 * sequence positions rather than alignment column positions.
922 * @param alreadyMapped
924 public void createSequenceMapping(SequenceI seqRef, int startRes,
925 boolean alreadyMapped)
932 sequenceRef = seqRef;
933 if (annotations == null)
937 sequenceMapping = new HashMap<Integer, Annotation>();
941 for (int i = 0; i < annotations.length; i++)
943 if (annotations[i] != null)
947 seqPos = seqRef.findPosition(i);
951 seqPos = i + startRes;
954 sequenceMapping.put(new Integer(seqPos), annotations[i]);
961 * When positional annotation and a sequence reference is present, clears and
962 * resizes the annotations array to the current alignment width, and adds
963 * annotation according to aligned positions of the sequenceRef given by
966 public void adjustForAlignment()
968 if (sequenceRef == null)
973 if (annotations == null)
978 int a = 0, aSize = sequenceRef.getLength();
987 Annotation[] temp = new Annotation[aSize];
989 if (sequenceMapping != null)
991 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
993 index = new Integer(a);
994 Annotation annot = sequenceMapping.get(index);
997 position = sequenceRef.findIndex(a) - 1;
999 temp[position] = annot;
1007 * remove any null entries in annotation row and return the number of non-null
1008 * annotation elements.
1012 public int compactAnnotationArray()
1014 int i = 0, iSize = annotations.length;
1017 if (annotations[i] == null)
1021 System.arraycopy(annotations, i + 1, annotations, i, iSize - i
1031 Annotation[] ann = annotations;
1032 annotations = new Annotation[i];
1033 System.arraycopy(ann, 0, annotations, 0, i);
1039 * Associate this annotation with the aligned residues of a particular
1040 * sequence. sequenceMapping will be updated in the following way: null
1041 * sequenceI - existing mapping will be discarded but annotations left in
1042 * mapped positions. valid sequenceI not equal to current sequenceRef: mapping
1043 * is discarded and rebuilt assuming 1:1 correspondence TODO: overload with
1044 * parameter to specify correspondence between current and new sequenceRef
1048 public void setSequenceRef(SequenceI sequenceI)
1050 if (sequenceI != null)
1052 if (sequenceRef != null)
1054 boolean rIsDs = sequenceRef.getDatasetSequence() == null, tIsDs = sequenceI
1055 .getDatasetSequence() == null;
1056 if (sequenceRef != sequenceI
1057 && (rIsDs && !tIsDs && sequenceRef != sequenceI
1058 .getDatasetSequence())
1059 && (!rIsDs && tIsDs && sequenceRef.getDatasetSequence() != sequenceI)
1060 && (!rIsDs && !tIsDs && sequenceRef.getDatasetSequence() != sequenceI
1061 .getDatasetSequence())
1062 && !sequenceRef.equals(sequenceI))
1064 // if sequenceRef isn't intersecting with sequenceI
1065 // throw away old mapping and reconstruct.
1067 if (sequenceMapping != null)
1069 sequenceMapping = null;
1070 // compactAnnotationArray();
1072 createSequenceMapping(sequenceI, 1, true);
1073 adjustForAlignment();
1077 // Mapping carried over
1078 sequenceRef = sequenceI;
1083 // No mapping exists
1084 createSequenceMapping(sequenceI, 1, true);
1085 adjustForAlignment();
1090 // throw away the mapping without compacting.
1091 sequenceMapping = null;
1099 public double getScore()
1108 public void setScore(double score)
1116 * @return true if annotation has an associated score
1118 public boolean hasScore()
1120 return hasScore || !Double.isNaN(score);
1124 * Score only annotation
1127 * @param description
1130 public AlignmentAnnotation(String label, String description, double score)
1132 this(label, description, null);
1137 * copy constructor with edit based on the hidden columns marked in colSel
1139 * @param alignmentAnnotation
1142 public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
1143 ColumnSelection colSel)
1145 this(alignmentAnnotation);
1146 if (annotations == null)
1150 colSel.makeVisibleAnnotation(this);
1153 public void setPadGaps(boolean padgaps, char gapchar)
1155 this.padGaps = padgaps;
1159 for (int i = 0; i < annotations.length; i++)
1161 if (annotations[i] == null)
1163 annotations[i] = new Annotation(String.valueOf(gapchar), null,
1166 else if (annotations[i].displayCharacter == null
1167 || annotations[i].displayCharacter.equals(" "))
1169 annotations[i].displayCharacter = String.valueOf(gapchar);
1176 * format description string for display
1179 * @return Get the annotation description string optionally prefixed by
1180 * associated sequence name (if any)
1182 public String getDescription(boolean seqname)
1184 if (seqname && this.sequenceRef != null)
1186 int i = description.toLowerCase().indexOf("<html>");
1189 // move the html tag to before the sequence reference.
1190 return "<html>" + sequenceRef.getName() + " : "
1191 + description.substring(i + 6);
1193 return sequenceRef.getName() + " : " + description;
1198 public boolean isValidStruc()
1200 return invalidrnastruc == -1;
1203 public long getInvalidStrucPos()
1205 return invalidrnastruc;
1209 * machine readable ID string indicating what generated this annotation
1211 protected String calcId = "";
1214 * properties associated with the calcId
1216 protected Map<String, String> properties = new HashMap<String, String>();
1219 * base colour for line graphs. If null, will be set automatically by
1220 * searching the alignment annotation
1222 public java.awt.Color _linecolour;
1224 public String getCalcId()
1229 public void setCalcId(String calcId)
1231 this.calcId = calcId;
1234 public boolean isRNA()
1240 * transfer annotation to the given sequence using the given mapping from the
1241 * current positions or an existing sequence mapping
1245 * map involving sq as To or From
1247 public void liftOver(SequenceI sq, Mapping sp2sq)
1249 if (sp2sq.getMappedWidth() != sp2sq.getWidth())
1251 // TODO: employ getWord/MappedWord to transfer annotation between cDNA and
1252 // Protein reference frames
1254 "liftOver currently not implemented for transfer of annotation between different types of seqeunce");
1256 boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == sq || sp2sq
1257 .getTo() == sq.getDatasetSequence()) : false;
1259 // TODO build a better annotation element map and get rid of annotations[]
1260 Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
1261 if (sequenceMapping != null)
1265 for (Entry<Integer, Annotation> ie : sequenceMapping.entrySet())
1267 Integer mpos = Integer.valueOf(mapIsTo ? sp2sq
1268 .getMappedPosition(ie.getKey()) : sp2sq.getPosition(ie
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, int[][] mapping, int from, int to,
1310 if (mapping != null)
1312 Map<Integer, Annotation> old = sequenceMapping;
1313 Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
1315 for (int mp[] : mapping)
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<String, String>();
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());
1412 protected static synchronized long nextId()