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 java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.Iterator;
29 import java.util.Map.Entry;
31 import jalview.analysis.Rna;
32 import jalview.analysis.SecStrConsensus.SimpleBP;
33 import jalview.analysis.WUSSParseException;
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;
168 * map of positions in the associated annotation
170 private Map<Integer, Annotation> sequenceMapping;
173 public float graphMin;
176 public float graphMax;
179 * Score associated with label and description.
181 public double score = Double.NaN;
184 * flag indicating if annotation has a score.
186 public boolean hasScore = false;
188 public GraphLine threshold;
190 // Graphical hints and tips
192 /** Can this row be edited by the user ? */
193 public boolean editable = false;
195 /** Indicates if annotation has a graphical symbol track */
196 public boolean hasIcons; //
198 /** Indicates if annotation has a text character label */
199 public boolean hasText;
201 /** is the row visible */
202 public boolean visible = true;
204 public int graphGroup = -1;
206 /** Displayed height of row in pixels */
207 public int height = 0;
209 public int graph = 0;
211 public int graphHeight = 40;
213 public boolean padGaps = false;
215 public static final int NO_GRAPH = 0;
217 public static final int BAR_GRAPH = 1;
219 public static final int LINE_GRAPH = 2;
221 public boolean belowAlignment = true;
223 public SequenceGroup groupRef = null;
226 * display every column label, even if there is a row of identical labels
228 public boolean showAllColLabels = false;
231 * scale the column label to fit within the alignment column.
233 public boolean scaleColLabel = false;
236 * centre the column labels relative to the alignment column
238 public boolean centreColLabels = false;
240 private boolean isrna;
245 * @see java.lang.Object#finalize()
247 protected void finalize() throws Throwable
254 public static int getGraphValueFromString(String string)
256 if (string.equalsIgnoreCase("BAR_GRAPH"))
260 else if (string.equalsIgnoreCase("LINE_GRAPH"))
270 // JBPNote: what does this do ?
271 public void ConcenStru(CharSequence RNAannot) throws WUSSParseException
273 bps = Rna.GetModeleBP(RNAannot);
277 * Creates a new AlignmentAnnotation object.
280 * short label shown under sequence labels
282 * text displayed on mouseover
284 * set of positional annotation elements
286 public AlignmentAnnotation(String label, String description,
287 Annotation[] annotations)
293 this.description = description;
294 this.annotations = annotations;
296 validateRangeAndDisplay();
300 * Checks if annotation labels represent secondary structures
303 void areLabelsSecondaryStructure()
305 boolean nonSSLabel = false;
307 StringBuffer rnastring = new StringBuffer();
310 for (int i = 0; i < annotations.length; i++)
312 if (annotations[i] == null)
316 if (annotations[i].secondaryStructure == 'H'
317 || annotations[i].secondaryStructure == 'E')
322 // Check for RNA secondary structure
324 // System.out.println(annotations[i].secondaryStructure);
325 // TODO: 2.8.2 should this ss symbol validation check be a function in
326 // RNA/ResidueProperties ?
327 if (annotations[i].secondaryStructure == '('
328 || annotations[i].secondaryStructure == '['
329 || annotations[i].secondaryStructure == '<'
330 || annotations[i].secondaryStructure == '{'
331 || annotations[i].secondaryStructure == 'A'
332 || annotations[i].secondaryStructure == 'B'
333 || annotations[i].secondaryStructure == 'C'
334 || annotations[i].secondaryStructure == 'D'
335 || annotations[i].secondaryStructure == 'E'
336 || annotations[i].secondaryStructure == 'F'
337 || annotations[i].secondaryStructure == 'G'
338 || annotations[i].secondaryStructure == 'H'
339 || annotations[i].secondaryStructure == 'I'
340 || annotations[i].secondaryStructure == 'J'
341 || annotations[i].secondaryStructure == 'K'
342 || annotations[i].secondaryStructure == 'L'
343 || annotations[i].secondaryStructure == 'M'
344 || annotations[i].secondaryStructure == 'N'
345 || annotations[i].secondaryStructure == 'O'
346 || annotations[i].secondaryStructure == 'P'
347 || annotations[i].secondaryStructure == 'Q'
348 || annotations[i].secondaryStructure == 'R'
349 || annotations[i].secondaryStructure == 'S'
350 || annotations[i].secondaryStructure == 'T'
351 || annotations[i].secondaryStructure == 'U'
352 || annotations[i].secondaryStructure == 'V'
353 || annotations[i].secondaryStructure == 'W'
354 || annotations[i].secondaryStructure == 'X'
355 || annotations[i].secondaryStructure == 'Y'
356 || annotations[i].secondaryStructure == 'Z')
363 // System.out.println("displaychar " + annotations[i].displayCharacter);
365 if (annotations[i].displayCharacter == null
366 || annotations[i].displayCharacter.length() == 0)
368 rnastring.append('.');
371 if (annotations[i].displayCharacter.length() == 1)
373 firstChar = annotations[i].displayCharacter.charAt(0);
374 // check to see if it looks like a sequence or is secondary structure
376 if (annotations[i].secondaryStructure != ' '
379 // Uncomment to only catch case where
380 // displayCharacter==secondary
382 // to correctly redisplay SS annotation imported from Stockholm,
383 // exported to JalviewXML and read back in again.
385 // annotations[i].displayCharacter.charAt(0)==annotations[i].secondaryStructure
420 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
422 if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
435 rnastring.append(annotations[i].displayCharacter.charAt(1));
438 if (annotations[i].displayCharacter.length() > 0)
447 for (int j = 0; j < annotations.length; j++)
449 if (annotations[j] != null
450 && annotations[j].secondaryStructure != ' ')
452 annotations[j].displayCharacter = String
453 .valueOf(annotations[j].secondaryStructure);
454 annotations[j].secondaryStructure = ' ';
463 _updateRnaSecStr(new AnnotCharSequence());
469 * flyweight access to positions in the alignment annotation row for RNA
475 private class AnnotCharSequence implements CharSequence
481 public AnnotCharSequence()
483 this(0, annotations.length);
486 public AnnotCharSequence(int start, int end)
493 public CharSequence subSequence(int start, int end)
495 return new AnnotCharSequence(offset + start, offset + end);
505 public char charAt(int index)
507 return ((index + offset < 0) || (index + offset) >= max
508 || annotations[index + offset] == null
509 || (annotations[index + offset].secondaryStructure <= ' ') ? ' '
510 : annotations[index + offset].displayCharacter == null
511 || annotations[index + offset].displayCharacter
512 .length() == 0 ? annotations[index + offset].secondaryStructure
513 : annotations[index + offset].displayCharacter
518 public String toString()
520 char[] string = new char[max - offset];
521 int mx = annotations.length;
523 for (int i = offset; i < mx; i++)
525 string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
526 : (annotations[i].displayCharacter == null
527 || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
528 : annotations[i].displayCharacter.charAt(0));
530 return new String(string);
534 private long _lastrnaannot = -1;
536 public String getRNAStruc()
540 String rnastruc = new AnnotCharSequence().toString();
541 if (_lastrnaannot != rnastruc.hashCode())
543 // ensure rna structure contacts are up to date
544 _lastrnaannot = rnastruc.hashCode();
545 _updateRnaSecStr(rnastruc);
553 * Creates a new AlignmentAnnotation object.
568 public AlignmentAnnotation(String label, String description,
569 Annotation[] annotations, float min, float max, int graphType)
572 // graphs are not editable
573 editable = graphType == 0;
576 this.description = description;
577 this.annotations = annotations;
581 validateRangeAndDisplay();
585 * checks graphMin and graphMax, secondary structure symbols, sets graphType
586 * appropriately, sets null labels to the empty string if appropriate.
588 public void validateRangeAndDisplay()
591 if (annotations == null)
593 visible = false; // try to prevent renderer from displaying.
594 return; // this is a non-annotation row annotation - ie a sequence score.
597 int graphType = graph;
598 float min = graphMin;
599 float max = graphMax;
600 boolean drawValues = true;
605 for (int i = 0; i < annotations.length; i++)
607 if (annotations[i] == null)
612 if (drawValues && annotations[i].displayCharacter != null
613 && annotations[i].displayCharacter.length() > 1)
618 if (annotations[i].value > max)
620 max = annotations[i].value;
623 if (annotations[i].value < min)
625 min = annotations[i].value;
627 if (_linecolour == null && annotations[i].colour != null)
629 _linecolour = annotations[i].colour;
632 // ensure zero is origin for min/max ranges on only one side of zero
649 areLabelsSecondaryStructure();
651 if (!drawValues && graphType != NO_GRAPH)
653 for (int i = 0; i < annotations.length; i++)
655 if (annotations[i] != null)
657 annotations[i].displayCharacter = "";
664 * Copy constructor creates a new independent annotation row with the same
665 * associated sequenceRef
669 public AlignmentAnnotation(AlignmentAnnotation annotation)
672 this.label = new String(annotation.label);
673 if (annotation.description != null)
675 this.description = new String(annotation.description);
677 this.graphMin = annotation.graphMin;
678 this.graphMax = annotation.graphMax;
679 this.graph = annotation.graph;
680 this.graphHeight = annotation.graphHeight;
681 this.graphGroup = annotation.graphGroup;
682 this.groupRef = annotation.groupRef;
683 this.editable = annotation.editable;
684 this.autoCalculated = annotation.autoCalculated;
685 this.hasIcons = annotation.hasIcons;
686 this.hasText = annotation.hasText;
687 this.height = annotation.height;
688 this.label = annotation.label;
689 this.padGaps = annotation.padGaps;
690 this.visible = annotation.visible;
691 this.centreColLabels = annotation.centreColLabels;
692 this.scaleColLabel = annotation.scaleColLabel;
693 this.showAllColLabels = annotation.showAllColLabels;
694 this.calcId = annotation.calcId;
695 if (annotation.properties!=null)
697 properties = new HashMap<String,String>();
698 for (Map.Entry<String, String> val:annotation.properties.entrySet())
700 properties.put(val.getKey(), val.getValue());
703 if (this.hasScore = annotation.hasScore)
705 this.score = annotation.score;
707 if (annotation.threshold != null)
709 threshold = new GraphLine(annotation.threshold);
711 Annotation[] ann = annotation.annotations;
712 if (annotation.annotations != null)
714 this.annotations = new Annotation[ann.length];
715 for (int i = 0; i < ann.length; i++)
719 annotations[i] = new Annotation(ann[i]);
720 if (_linecolour != null)
722 _linecolour = annotations[i].colour;
727 if (annotation.sequenceRef != null)
729 this.sequenceRef = annotation.sequenceRef;
730 if (annotation.sequenceMapping != null)
733 sequenceMapping = new HashMap<Integer, Annotation>();
734 Iterator<Integer> pos = annotation.sequenceMapping.keySet()
736 while (pos.hasNext())
738 // could optimise this!
740 Annotation a = annotation.sequenceMapping.get(p);
747 for (int i = 0; i < ann.length; i++)
751 sequenceMapping.put(p, annotations[i]);
759 this.sequenceMapping = null;
762 // TODO: check if we need to do this: JAL-952
763 // if (this.isrna=annotation.isrna)
765 // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
767 validateRangeAndDisplay(); // construct hashcodes, etc.
771 * clip the annotation to the columns given by startRes and endRes (inclusive)
772 * and prune any existing sequenceMapping to just those columns.
777 public void restrict(int startRes, int endRes)
779 if (annotations == null)
788 if (startRes >= annotations.length)
790 startRes = annotations.length - 1;
792 if (endRes >= annotations.length)
794 endRes = annotations.length - 1;
796 if (annotations == null)
800 Annotation[] temp = new Annotation[endRes - startRes + 1];
801 if (startRes < annotations.length)
803 System.arraycopy(annotations, startRes, temp, 0, endRes - startRes
806 if (sequenceRef != null)
808 // Clip the mapping, if it exists.
809 int spos = sequenceRef.findPosition(startRes);
810 int epos = sequenceRef.findPosition(endRes);
811 if (sequenceMapping != null)
813 Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
814 Iterator<Integer> e = sequenceMapping.keySet().iterator();
817 Integer pos = e.next();
818 if (pos.intValue() >= spos && pos.intValue() <= epos)
820 newmapping.put(pos, sequenceMapping.get(pos));
823 sequenceMapping.clear();
824 sequenceMapping = newmapping;
831 * set the annotation row to be at least length Annotations
834 * minimum number of columns required in the annotation row
835 * @return false if the annotation row is greater than length
837 public boolean padAnnotation(int length)
839 if (annotations == null)
841 return true; // annotation row is correct - null == not visible and
844 if (annotations.length < length)
846 Annotation[] na = new Annotation[length];
847 System.arraycopy(annotations, 0, na, 0, annotations.length);
851 return annotations.length > length;
858 * @return DOCUMENT ME!
861 public String toString()
863 StringBuilder buffer = new StringBuilder(256);
865 for (int i = 0; i < annotations.length; i++)
867 if (annotations[i] != null)
871 buffer.append(annotations[i].value);
875 buffer.append(annotations[i].secondaryStructure);
879 buffer.append(annotations[i].displayCharacter);
885 // TODO: remove disgusting hack for 'special' treatment of consensus line.
886 if (label.indexOf("Consensus") == 0)
890 for (int i = 0; i < annotations.length; i++)
892 if (annotations[i] != null)
894 buffer.append(annotations[i].description);
901 return buffer.toString();
904 public void setThreshold(GraphLine line)
909 public GraphLine getThreshold()
915 * Attach the annotation to seqRef, starting from startRes position. If
916 * alreadyMapped is true then the indices of the annotation[] array are
917 * sequence positions rather than alignment column positions.
921 * @param alreadyMapped
923 public void createSequenceMapping(SequenceI seqRef, int startRes,
924 boolean alreadyMapped)
931 sequenceRef = seqRef;
932 if (annotations == null)
936 sequenceMapping = new HashMap<Integer, Annotation>();
940 for (int i = 0; i < annotations.length; i++)
942 if (annotations[i] != null)
946 seqPos = seqRef.findPosition(i);
950 seqPos = i + startRes;
953 sequenceMapping.put(new Integer(seqPos), annotations[i]);
959 public void adjustForAlignment()
961 if (sequenceRef == null)
966 if (annotations == null)
971 int a = 0, aSize = sequenceRef.getLength();
980 Annotation[] temp = new Annotation[aSize];
983 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
985 index = new Integer(a);
986 if (sequenceMapping.containsKey(index))
988 position = sequenceRef.findIndex(a) - 1;
990 temp[position] = sequenceMapping.get(index);
998 * remove any null entries in annotation row and return the number of non-null
999 * annotation elements.
1003 public int compactAnnotationArray()
1005 int i = 0, iSize = annotations.length;
1008 if (annotations[i] == null)
1012 System.arraycopy(annotations, i + 1, annotations, i, iSize - i
1022 Annotation[] ann = annotations;
1023 annotations = new Annotation[i];
1024 System.arraycopy(ann, 0, annotations, 0, i);
1030 * Associate this annotion with the aligned residues of a particular sequence.
1031 * sequenceMapping will be updated in the following way: null sequenceI -
1032 * existing mapping will be discarded but annotations left in mapped
1033 * positions. valid sequenceI not equal to current sequenceRef: mapping is
1034 * discarded and rebuilt assuming 1:1 correspondence TODO: overload with
1035 * parameter to specify correspondence between current and new sequenceRef
1039 public void setSequenceRef(SequenceI sequenceI)
1041 if (sequenceI != null)
1043 if (sequenceRef != null)
1045 boolean rIsDs=sequenceRef.getDatasetSequence()==null,tIsDs=sequenceI.getDatasetSequence()==null;
1046 if (sequenceRef != sequenceI
1047 && (rIsDs && !tIsDs && sequenceRef != sequenceI
1048 .getDatasetSequence())
1049 && (!rIsDs && tIsDs && sequenceRef.getDatasetSequence() != sequenceI)
1050 && (!rIsDs && !tIsDs && sequenceRef.getDatasetSequence() != sequenceI
1051 .getDatasetSequence())
1052 && !sequenceRef.equals(sequenceI))
1054 // if sequenceRef isn't intersecting with sequenceI
1055 // throw away old mapping and reconstruct.
1057 if (sequenceMapping != null)
1059 sequenceMapping = null;
1060 // compactAnnotationArray();
1062 createSequenceMapping(sequenceI, 1, true);
1063 adjustForAlignment();
1067 // Mapping carried over
1068 sequenceRef = sequenceI;
1073 // No mapping exists
1074 createSequenceMapping(sequenceI, 1, true);
1075 adjustForAlignment();
1080 // throw away the mapping without compacting.
1081 sequenceMapping = null;
1089 public double getScore()
1098 public void setScore(double score)
1106 * @return true if annotation has an associated score
1108 public boolean hasScore()
1110 return hasScore || !Double.isNaN(score);
1114 * Score only annotation
1117 * @param description
1120 public AlignmentAnnotation(String label, String description, double score)
1122 this(label, description, null);
1127 * copy constructor with edit based on the hidden columns marked in colSel
1129 * @param alignmentAnnotation
1132 public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
1133 ColumnSelection colSel)
1135 this(alignmentAnnotation);
1136 if (annotations == null)
1140 colSel.makeVisibleAnnotation(this);
1143 public void setPadGaps(boolean padgaps, char gapchar)
1145 this.padGaps = padgaps;
1149 for (int i = 0; i < annotations.length; i++)
1151 if (annotations[i] == null)
1153 annotations[i] = new Annotation(String.valueOf(gapchar), null,
1156 else if (annotations[i].displayCharacter == null
1157 || annotations[i].displayCharacter.equals(" "))
1159 annotations[i].displayCharacter = String.valueOf(gapchar);
1166 * format description string for display
1169 * @return Get the annotation description string optionally prefixed by
1170 * associated sequence name (if any)
1172 public String getDescription(boolean seqname)
1174 if (seqname && this.sequenceRef != null)
1176 int i = description.toLowerCase().indexOf("<html>");
1179 // move the html tag to before the sequence reference.
1180 return "<html>" + sequenceRef.getName() + " : "
1181 + description.substring(i + 6);
1183 return sequenceRef.getName() + " : " + description;
1188 public boolean isValidStruc()
1190 return invalidrnastruc == -1;
1193 public long getInvalidStrucPos()
1195 return invalidrnastruc;
1199 * machine readable ID string indicating what generated this annotation
1201 protected String calcId = "";
1204 * properties associated with the calcId
1206 protected Map<String, String> properties = new HashMap<String, String>();
1209 * base colour for line graphs. If null, will be set automatically by
1210 * searching the alignment annotation
1212 public java.awt.Color _linecolour;
1214 public String getCalcId()
1219 public void setCalcId(String calcId)
1221 this.calcId = calcId;
1224 public boolean isRNA()
1230 * transfer annotation to the given sequence using the given mapping from the
1231 * current positions or an existing sequence mapping
1235 * map involving sq as To or From
1237 public void liftOver(SequenceI sq, Mapping sp2sq)
1239 if (sp2sq.getMappedWidth() != sp2sq.getWidth())
1241 // TODO: employ getWord/MappedWord to transfer annotation between cDNA and Protein reference frames
1242 throw new Error("liftOver currently not implemented for transfer of annotation between different types of seqeunce");
1244 boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == sq || sp2sq
1245 .getTo() == sq.getDatasetSequence()) : false;
1247 // TODO build a better annotation element map and get rid of annotations[]
1248 Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
1249 if (sequenceMapping != null)
1253 for (Entry<Integer, Annotation> ie : sequenceMapping.entrySet())
1255 Integer mpos = Integer.valueOf(mapIsTo ? sp2sq
1256 .getMappedPosition(ie.getKey()) : sp2sq.getPosition(ie
1258 if (mpos >= sq.getStart() && mpos <= sq.getEnd())
1260 mapForsq.put(mpos, ie.getValue());
1263 sequenceMapping = mapForsq;
1265 adjustForAlignment();
1275 * like liftOver but more general.
1277 * Takes an array of int pairs that will be used to update the internal
1278 * sequenceMapping and so shuffle the annotated positions
1281 * - new sequence reference for the annotation row - if null,
1282 * sequenceRef is left unchanged
1284 * array of ints containing corresponding positions
1286 * - column for current coordinate system (-1 for index+1)
1288 * - column for destination coordinate system (-1 for index+1)
1290 * - offset added to index when referencing either coordinate system
1291 * @note no checks are made as to whether from and/or to are sensible
1292 * @note caller should add the remapped annotation to newref if they have not
1295 public void remap(SequenceI newref, int[][] mapping, int from, int to,
1298 if (mapping != null)
1300 Map<Integer, Annotation> old = sequenceMapping;
1301 Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
1303 for (int mp[] : mapping)
1309 Annotation ann = null;
1312 ann = sequenceMapping.get(Integer.valueOf(idxoffset + index));
1316 if (mp != null && mp.length > from)
1318 ann = sequenceMapping.get(Integer.valueOf(mp[from]));
1325 remap.put(Integer.valueOf(idxoffset + index), ann);
1329 if (to > -1 && to < mp.length)
1331 remap.put(Integer.valueOf(mp[to]), ann);
1336 sequenceMapping = remap;
1340 sequenceRef = newref;
1342 adjustForAlignment();
1346 public String getProperty(String property)
1348 if (properties == null)
1352 return properties.get(property);
1355 public void setProperty(String property, String value)
1357 if (properties==null)
1359 properties = new HashMap<String,String>();
1361 properties.put(property, value);
1364 public boolean hasProperties()
1366 return properties != null && properties.size() > 0;
1369 public Collection<String> getProperties()
1371 if (properties == null)
1373 return Collections.emptyList();
1375 return properties.keySet();
1379 * Returns the Annotation for the given sequence position (base 1) if any,
1385 public Annotation getAnnotationForPosition(int position)
1387 return sequenceMapping == null ? null : sequenceMapping.get(position);
1392 * Set the id to "ann" followed by a counter that increments so as to be
1393 * unique for the lifetime of the JVM
1395 protected final void setAnnotationId()
1397 this.annotationId = ANNOTATION_ID_PREFIX + Long.toString(nextId());
1400 protected static synchronized long nextId()