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.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()
249 protected void finalize() throws Throwable
256 public static int getGraphValueFromString(String string)
258 if (string.equalsIgnoreCase("BAR_GRAPH"))
262 else if (string.equalsIgnoreCase("LINE_GRAPH"))
272 // JBPNote: what does this do ?
273 public void ConcenStru(CharSequence RNAannot) throws WUSSParseException
275 bps = Rna.GetModeleBP(RNAannot);
279 * Creates a new AlignmentAnnotation object.
282 * short label shown under sequence labels
284 * text displayed on mouseover
286 * set of positional annotation elements
288 public AlignmentAnnotation(String label, String description,
289 Annotation[] annotations)
295 this.description = description;
296 this.annotations = annotations;
298 validateRangeAndDisplay();
302 * Checks if annotation labels represent secondary structures
305 void areLabelsSecondaryStructure()
307 boolean nonSSLabel = false;
309 StringBuffer rnastring = new StringBuffer();
312 for (int i = 0; i < annotations.length; i++)
314 if (annotations[i] == null)
318 if (annotations[i].secondaryStructure == 'H'
319 || annotations[i].secondaryStructure == 'E')
324 // Check for RNA secondary structure
326 // System.out.println(annotations[i].secondaryStructure);
327 // TODO: 2.8.2 should this ss symbol validation check be a function in
328 // RNA/ResidueProperties ?
329 if (annotations[i].secondaryStructure == '('
330 || annotations[i].secondaryStructure == '['
331 || annotations[i].secondaryStructure == '<'
332 || annotations[i].secondaryStructure == '{'
333 || annotations[i].secondaryStructure == 'A'
334 || annotations[i].secondaryStructure == 'B'
335 || annotations[i].secondaryStructure == 'C'
336 || annotations[i].secondaryStructure == 'D'
337 || annotations[i].secondaryStructure == 'E'
338 || annotations[i].secondaryStructure == 'F'
339 || annotations[i].secondaryStructure == 'G'
340 || annotations[i].secondaryStructure == 'H'
341 || annotations[i].secondaryStructure == 'I'
342 || annotations[i].secondaryStructure == 'J'
343 || annotations[i].secondaryStructure == 'K'
344 || annotations[i].secondaryStructure == 'L'
345 || annotations[i].secondaryStructure == 'M'
346 || annotations[i].secondaryStructure == 'N'
347 || annotations[i].secondaryStructure == 'O'
348 || annotations[i].secondaryStructure == 'P'
349 || annotations[i].secondaryStructure == 'Q'
350 || annotations[i].secondaryStructure == 'R'
351 || annotations[i].secondaryStructure == 'S'
352 || annotations[i].secondaryStructure == 'T'
353 || annotations[i].secondaryStructure == 'U'
354 || annotations[i].secondaryStructure == 'V'
355 || annotations[i].secondaryStructure == 'W'
356 || annotations[i].secondaryStructure == 'X'
357 || annotations[i].secondaryStructure == 'Y'
358 || annotations[i].secondaryStructure == 'Z')
365 // System.out.println("displaychar " + annotations[i].displayCharacter);
367 if (annotations[i].displayCharacter == null
368 || annotations[i].displayCharacter.length() == 0)
370 rnastring.append('.');
373 if (annotations[i].displayCharacter.length() == 1)
375 firstChar = annotations[i].displayCharacter.charAt(0);
376 // check to see if it looks like a sequence or is secondary structure
378 if (annotations[i].secondaryStructure != ' '
381 // Uncomment to only catch case where
382 // displayCharacter==secondary
384 // to correctly redisplay SS annotation imported from Stockholm,
385 // exported to JalviewXML and read back in again.
387 // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure
422 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
424 if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
437 rnastring.append(annotations[i].displayCharacter.charAt(1));
440 if (annotations[i].displayCharacter.length() > 0)
449 for (int j = 0; j < annotations.length; j++)
451 if (annotations[j] != null
452 && annotations[j].secondaryStructure != ' ')
454 annotations[j].displayCharacter = String
455 .valueOf(annotations[j].secondaryStructure);
456 annotations[j].secondaryStructure = ' ';
465 _updateRnaSecStr(new AnnotCharSequence());
471 * flyweight access to positions in the alignment annotation row for RNA
477 private class AnnotCharSequence implements CharSequence
483 public AnnotCharSequence()
485 this(0, annotations.length);
488 public AnnotCharSequence(int start, int end)
495 public CharSequence subSequence(int start, int end)
497 return new AnnotCharSequence(offset + start, offset + end);
507 public char charAt(int index)
509 return ((index + offset < 0) || (index + offset) >= max
510 || annotations[index + offset] == null
511 || (annotations[index + offset].secondaryStructure <= ' ') ? ' '
512 : annotations[index + offset].displayCharacter == null
513 || annotations[index + offset].displayCharacter
514 .length() == 0 ? annotations[index + offset].secondaryStructure
515 : annotations[index + offset].displayCharacter
520 public String toString()
522 char[] string = new char[max - offset];
523 int mx = annotations.length;
525 for (int i = offset; i < mx; i++)
527 string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
528 : (annotations[i].displayCharacter == null
529 || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
530 : annotations[i].displayCharacter.charAt(0));
532 return new String(string);
536 private long _lastrnaannot = -1;
538 public String getRNAStruc()
542 String rnastruc = new AnnotCharSequence().toString();
543 if (_lastrnaannot != rnastruc.hashCode())
545 // ensure rna structure contacts are up to date
546 _lastrnaannot = rnastruc.hashCode();
547 _updateRnaSecStr(rnastruc);
555 * Creates a new AlignmentAnnotation object.
570 public AlignmentAnnotation(String label, String description,
571 Annotation[] annotations, float min, float max, int graphType)
574 // graphs are not editable
575 editable = graphType == 0;
578 this.description = description;
579 this.annotations = annotations;
583 validateRangeAndDisplay();
587 * checks graphMin and graphMax, secondary structure symbols, sets graphType
588 * appropriately, sets null labels to the empty string if appropriate.
590 public void validateRangeAndDisplay()
593 if (annotations == null)
595 visible = false; // try to prevent renderer from displaying.
596 return; // this is a non-annotation row annotation - ie a sequence score.
599 int graphType = graph;
600 float min = graphMin;
601 float max = graphMax;
602 boolean drawValues = true;
607 for (int i = 0; i < annotations.length; i++)
609 if (annotations[i] == null)
614 if (drawValues && annotations[i].displayCharacter != null
615 && annotations[i].displayCharacter.length() > 1)
620 if (annotations[i].value > max)
622 max = annotations[i].value;
625 if (annotations[i].value < min)
627 min = annotations[i].value;
629 if (_linecolour == null && annotations[i].colour != null)
631 _linecolour = annotations[i].colour;
634 // ensure zero is origin for min/max ranges on only one side of zero
651 areLabelsSecondaryStructure();
653 if (!drawValues && graphType != NO_GRAPH)
655 for (int i = 0; i < annotations.length; i++)
657 if (annotations[i] != null)
659 annotations[i].displayCharacter = "";
666 * Copy constructor creates a new independent annotation row with the same
667 * associated sequenceRef
671 public AlignmentAnnotation(AlignmentAnnotation annotation)
674 this.label = new String(annotation.label);
675 if (annotation.description != null)
677 this.description = new String(annotation.description);
679 this.graphMin = annotation.graphMin;
680 this.graphMax = annotation.graphMax;
681 this.graph = annotation.graph;
682 this.graphHeight = annotation.graphHeight;
683 this.graphGroup = annotation.graphGroup;
684 this.groupRef = annotation.groupRef;
685 this.editable = annotation.editable;
686 this.autoCalculated = annotation.autoCalculated;
687 this.hasIcons = annotation.hasIcons;
688 this.hasText = annotation.hasText;
689 this.height = annotation.height;
690 this.label = annotation.label;
691 this.padGaps = annotation.padGaps;
692 this.visible = annotation.visible;
693 this.centreColLabels = annotation.centreColLabels;
694 this.scaleColLabel = annotation.scaleColLabel;
695 this.showAllColLabels = annotation.showAllColLabels;
696 this.calcId = annotation.calcId;
697 if (annotation.properties != null)
699 properties = new HashMap<String, String>();
700 for (Map.Entry<String, String> val : annotation.properties.entrySet())
702 properties.put(val.getKey(), val.getValue());
705 if (this.hasScore = annotation.hasScore)
707 this.score = annotation.score;
709 if (annotation.threshold != null)
711 threshold = new GraphLine(annotation.threshold);
713 Annotation[] ann = annotation.annotations;
714 if (annotation.annotations != null)
716 this.annotations = new Annotation[ann.length];
717 for (int i = 0; i < ann.length; i++)
721 annotations[i] = new Annotation(ann[i]);
722 if (_linecolour != null)
724 _linecolour = annotations[i].colour;
729 if (annotation.sequenceRef != null)
731 this.sequenceRef = annotation.sequenceRef;
732 if (annotation.sequenceMapping != null)
735 sequenceMapping = new HashMap<Integer, Annotation>();
736 Iterator<Integer> pos = annotation.sequenceMapping.keySet()
738 while (pos.hasNext())
740 // could optimise this!
742 Annotation a = annotation.sequenceMapping.get(p);
749 for (int i = 0; i < ann.length; i++)
753 sequenceMapping.put(p, annotations[i]);
761 this.sequenceMapping = null;
764 // TODO: check if we need to do this: JAL-952
765 // if (this.isrna=annotation.isrna)
767 // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
769 validateRangeAndDisplay(); // construct hashcodes, etc.
773 * clip the annotation to the columns given by startRes and endRes (inclusive)
774 * and prune any existing sequenceMapping to just those columns.
779 public void restrict(int startRes, int endRes)
781 if (annotations == null)
790 if (startRes >= annotations.length)
792 startRes = annotations.length - 1;
794 if (endRes >= annotations.length)
796 endRes = annotations.length - 1;
798 if (annotations == null)
802 Annotation[] temp = new Annotation[endRes - startRes + 1];
803 if (startRes < annotations.length)
805 System.arraycopy(annotations, startRes, temp, 0, endRes - startRes
808 if (sequenceRef != null)
810 // Clip the mapping, if it exists.
811 int spos = sequenceRef.findPosition(startRes);
812 int epos = sequenceRef.findPosition(endRes);
813 if (sequenceMapping != null)
815 Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
816 Iterator<Integer> e = sequenceMapping.keySet().iterator();
819 Integer pos = e.next();
820 if (pos.intValue() >= spos && pos.intValue() <= epos)
822 newmapping.put(pos, sequenceMapping.get(pos));
825 sequenceMapping.clear();
826 sequenceMapping = newmapping;
833 * set the annotation row to be at least length Annotations
836 * minimum number of columns required in the annotation row
837 * @return false if the annotation row is greater than length
839 public boolean padAnnotation(int length)
841 if (annotations == null)
843 return true; // annotation row is correct - null == not visible and
846 if (annotations.length < length)
848 Annotation[] na = new Annotation[length];
849 System.arraycopy(annotations, 0, na, 0, annotations.length);
853 return annotations.length > length;
860 * @return DOCUMENT ME!
863 public String toString()
865 StringBuilder buffer = new StringBuilder(256);
867 for (int i = 0; i < annotations.length; i++)
869 if (annotations[i] != null)
873 buffer.append(annotations[i].value);
877 buffer.append(annotations[i].secondaryStructure);
881 buffer.append(annotations[i].displayCharacter);
887 // TODO: remove disgusting hack for 'special' treatment of consensus line.
888 if (label.indexOf("Consensus") == 0)
892 for (int i = 0; i < annotations.length; i++)
894 if (annotations[i] != null)
896 buffer.append(annotations[i].description);
903 return buffer.toString();
906 public void setThreshold(GraphLine line)
911 public GraphLine getThreshold()
917 * Attach the annotation to seqRef, starting from startRes position. If
918 * alreadyMapped is true then the indices of the annotation[] array are
919 * sequence positions rather than alignment column positions.
923 * @param alreadyMapped
924 * - annotation are at aligned columns
926 public void createSequenceMapping(SequenceI seqRef, int startRes,
927 boolean alreadyMapped)
934 sequenceRef = seqRef;
935 if (annotations == null)
939 sequenceMapping = new HashMap<Integer, Annotation>();
943 for (int i = 0; i < annotations.length; i++)
945 if (annotations[i] != null)
949 seqPos = seqRef.findPosition(i);
953 seqPos = i + startRes;
956 sequenceMapping.put(new Integer(seqPos), annotations[i]);
963 * When positional annotation and a sequence reference is present, clears and
964 * resizes the annotations array to the current alignment width, and adds
965 * annotation according to aligned positions of the sequenceRef given by
968 public void adjustForAlignment()
970 if (sequenceRef == null)
975 if (annotations == null)
980 int a = 0, aSize = sequenceRef.getLength();
989 Annotation[] temp = new Annotation[aSize];
991 if (sequenceMapping != null)
993 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
995 index = new Integer(a);
996 Annotation annot = sequenceMapping.get(index);
999 position = sequenceRef.findIndex(a) - 1;
1001 temp[position] = annot;
1009 * remove any null entries in annotation row and return the number of non-null
1010 * annotation elements.
1014 public int compactAnnotationArray()
1016 int i = 0, iSize = annotations.length;
1019 if (annotations[i] == null)
1023 System.arraycopy(annotations, i + 1, annotations, i, iSize - i
1033 Annotation[] ann = annotations;
1034 annotations = new Annotation[i];
1035 System.arraycopy(ann, 0, annotations, 0, i);
1041 * Associate this annotation with the aligned residues of a particular
1042 * sequence. sequenceMapping will be updated in the following way: null
1043 * sequenceI - existing mapping will be discarded but annotations left in
1044 * mapped positions. valid sequenceI not equal to current sequenceRef: mapping
1045 * is discarded and rebuilt assuming 1:1 correspondence TODO: overload with
1046 * parameter to specify correspondence between current and new sequenceRef
1050 public void setSequenceRef(SequenceI sequenceI)
1052 if (sequenceI != null)
1054 if (sequenceRef != null)
1056 boolean rIsDs = sequenceRef.getDatasetSequence() == null, tIsDs = sequenceI
1057 .getDatasetSequence() == null;
1058 if (sequenceRef != sequenceI
1059 && (rIsDs && !tIsDs && sequenceRef != sequenceI
1060 .getDatasetSequence())
1061 && (!rIsDs && tIsDs && sequenceRef.getDatasetSequence() != sequenceI)
1062 && (!rIsDs && !tIsDs && sequenceRef.getDatasetSequence() != sequenceI
1063 .getDatasetSequence())
1064 && !sequenceRef.equals(sequenceI))
1066 // if sequenceRef isn't intersecting with sequenceI
1067 // throw away old mapping and reconstruct.
1069 if (sequenceMapping != null)
1071 sequenceMapping = null;
1072 // compactAnnotationArray();
1074 createSequenceMapping(sequenceI, 1, true);
1075 adjustForAlignment();
1079 // Mapping carried over
1080 sequenceRef = sequenceI;
1085 // No mapping exists
1086 createSequenceMapping(sequenceI, 1, true);
1087 adjustForAlignment();
1092 // throw away the mapping without compacting.
1093 sequenceMapping = null;
1101 public double getScore()
1110 public void setScore(double score)
1118 * @return true if annotation has an associated score
1120 public boolean hasScore()
1122 return hasScore || !Double.isNaN(score);
1126 * Score only annotation
1129 * @param description
1132 public AlignmentAnnotation(String label, String description, double score)
1134 this(label, description, null);
1139 * copy constructor with edit based on the hidden columns marked in colSel
1141 * @param alignmentAnnotation
1144 public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
1145 ColumnSelection colSel)
1147 this(alignmentAnnotation);
1148 if (annotations == null)
1152 colSel.makeVisibleAnnotation(this);
1155 public void setPadGaps(boolean padgaps, char gapchar)
1157 this.padGaps = padgaps;
1161 for (int i = 0; i < annotations.length; i++)
1163 if (annotations[i] == null)
1165 annotations[i] = new Annotation(String.valueOf(gapchar), null,
1168 else if (annotations[i].displayCharacter == null
1169 || annotations[i].displayCharacter.equals(" "))
1171 annotations[i].displayCharacter = String.valueOf(gapchar);
1178 * format description string for display
1181 * @return Get the annotation description string optionally prefixed by
1182 * associated sequence name (if any)
1184 public String getDescription(boolean seqname)
1186 if (seqname && this.sequenceRef != null)
1188 int i = description.toLowerCase().indexOf("<html>");
1191 // move the html tag to before the sequence reference.
1192 return "<html>" + sequenceRef.getName() + " : "
1193 + description.substring(i + 6);
1195 return sequenceRef.getName() + " : " + description;
1200 public boolean isValidStruc()
1202 return invalidrnastruc == -1;
1205 public long getInvalidStrucPos()
1207 return invalidrnastruc;
1211 * machine readable ID string indicating what generated this annotation
1213 protected String calcId = "";
1216 * properties associated with the calcId
1218 protected Map<String, String> properties = new HashMap<String, String>();
1221 * base colour for line graphs. If null, will be set automatically by
1222 * searching the alignment annotation
1224 public java.awt.Color _linecolour;
1226 public String getCalcId()
1231 public void setCalcId(String calcId)
1233 this.calcId = calcId;
1236 public boolean isRNA()
1242 * transfer annotation to the given sequence using the given mapping from the
1243 * current positions or an existing sequence mapping
1247 * map involving sq as To or From
1249 public void liftOver(SequenceI sq, Mapping sp2sq)
1251 if (sp2sq.getMappedWidth() != sp2sq.getWidth())
1253 // TODO: employ getWord/MappedWord to transfer annotation between cDNA and
1254 // Protein reference frames
1256 "liftOver currently not implemented for transfer of annotation between different types of seqeunce");
1258 boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == sq || sp2sq
1259 .getTo() == sq.getDatasetSequence()) : false;
1261 // TODO build a better annotation element map and get rid of annotations[]
1262 Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
1263 if (sequenceMapping != null)
1267 for (Entry<Integer, Annotation> ie : sequenceMapping.entrySet())
1269 Integer mpos = Integer.valueOf(mapIsTo ? sp2sq
1270 .getMappedPosition(ie.getKey()) : sp2sq.getPosition(ie
1272 if (mpos >= sq.getStart() && mpos <= sq.getEnd())
1274 mapForsq.put(mpos, ie.getValue());
1277 sequenceMapping = mapForsq;
1279 adjustForAlignment();
1289 * like liftOver but more general.
1291 * Takes an array of int pairs that will be used to update the internal
1292 * sequenceMapping and so shuffle the annotated positions
1295 * - new sequence reference for the annotation row - if null,
1296 * sequenceRef is left unchanged
1298 * array of ints containing corresponding positions
1300 * - column for current coordinate system (-1 for index+1)
1302 * - column for destination coordinate system (-1 for index+1)
1304 * - offset added to index when referencing either coordinate system
1305 * @note no checks are made as to whether from and/or to are sensible
1306 * @note caller should add the remapped annotation to newref if they have not
1309 public void remap(SequenceI newref, HashMap<Integer, int[]> mapping,
1313 if (mapping != null)
1315 Map<Integer, Annotation> old = sequenceMapping;
1316 Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
1318 for (int mp[] : mapping.values())
1324 Annotation ann = null;
1327 ann = sequenceMapping.get(Integer.valueOf(idxoffset + index));
1331 if (mp != null && mp.length > from)
1333 ann = sequenceMapping.get(Integer.valueOf(mp[from]));
1340 remap.put(Integer.valueOf(idxoffset + index), ann);
1344 if (to > -1 && to < mp.length)
1346 remap.put(Integer.valueOf(mp[to]), ann);
1351 sequenceMapping = remap;
1355 sequenceRef = newref;
1357 adjustForAlignment();
1361 public String getProperty(String property)
1363 if (properties == null)
1367 return properties.get(property);
1370 public void setProperty(String property, String value)
1372 if (properties == null)
1374 properties = new HashMap<String, String>();
1376 properties.put(property, value);
1379 public boolean hasProperties()
1381 return properties != null && properties.size() > 0;
1384 public Collection<String> getProperties()
1386 if (properties == null)
1388 return Collections.emptyList();
1390 return properties.keySet();
1394 * Returns the Annotation for the given sequence position (base 1) if any,
1400 public Annotation getAnnotationForPosition(int position)
1402 return sequenceMapping == null ? null : sequenceMapping.get(position);
1407 * Set the id to "ann" followed by a counter that increments so as to be
1408 * unique for the lifetime of the JVM
1410 protected final void setAnnotationId()
1412 this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
1415 protected static synchronized long nextId()