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
44 * Identifers for different types of profile data
46 public static final int SEQUENCE_PROFILE = 0;
48 public static final int STRUCTURE_PROFILE = 1;
50 public static final int CDNA_PROFILE = 2;
53 * If true, this annotations is calculated every edit, eg consensus, quality
54 * or conservation graphs
56 public boolean autoCalculated = false;
59 * unique ID for this annotation, used to match up the same annotation row
60 * shown in multiple views and alignments
62 public String annotationId;
65 * the sequence this annotation is associated with (or null)
67 public SequenceI sequenceRef;
69 /** label shown in dropdown menus and in the annotation label area */
72 /** longer description text shown as a tooltip */
73 public String description;
75 /** Array of annotations placed in the current coordinate system */
76 public Annotation[] annotations;
78 public ArrayList<SimpleBP> bps = null;
81 * RNA secondary structure contact positions
83 public SequenceFeature[] _rnasecstr = null;
86 * position of annotation resulting in invalid WUSS parsing or -1. -2 means
87 * there was no RNA structure in this annotation
89 private long invalidrnastruc = -2;
92 * Updates the _rnasecstr field Determines the positions that base pair and
93 * the positions of helices based on secondary structure from a Stockholm file
97 private void _updateRnaSecStr(CharSequence RNAannot)
101 _rnasecstr = Rna.GetBasePairs(RNAannot);
102 bps = Rna.GetModeleBP(RNAannot);
103 invalidrnastruc = -1;
104 } catch (WUSSParseException px)
106 // DEBUG System.out.println(px);
107 invalidrnastruc = px.getProblemPos();
109 if (invalidrnastruc > -1)
113 Rna.HelixMap(_rnasecstr);
114 // setRNAStruc(RNAannot);
116 if (_rnasecstr != null && _rnasecstr.length > 0)
118 // show all the RNA secondary structure annotation symbols.
120 showAllColLabels = true;
121 scaleColLabel = true;
124 // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup());
128 private void _markRnaHelices()
131 // Figure out number of helices
132 // Length of rnasecstr is the number of pairs of positions that base pair
133 // with each other in the secondary structure
134 for (int x = 0; x < _rnasecstr.length; x++)
138 * System.out.println(this.annotation._rnasecstr[x] + " Begin" +
139 * this.annotation._rnasecstr[x].getBegin());
141 // System.out.println(this.annotation._rnasecstr[x].getFeatureGroup());
145 val = Integer.valueOf(_rnasecstr[x].getFeatureGroup());
150 } catch (NumberFormatException q)
155 annotations[_rnasecstr[x].getBegin()].value = val;
156 annotations[_rnasecstr[x].getEnd()].value = val;
158 // annotations[_rnasecstr[x].getBegin()].displayCharacter = "" + val;
159 // annotations[_rnasecstr[x].getEnd()].displayCharacter = "" + val;
164 * map of positions in the associated annotation
166 private Map<Integer, Annotation> sequenceMapping;
169 public float graphMin;
172 public float graphMax;
175 * Score associated with label and description.
177 public double score = Double.NaN;
180 * flag indicating if annotation has a score.
182 public boolean hasScore = false;
184 public GraphLine threshold;
186 // Graphical hints and tips
188 /** Can this row be edited by the user ? */
189 public boolean editable = false;
191 /** Indicates if annotation has a graphical symbol track */
192 public boolean hasIcons; //
194 /** Indicates if annotation has a text character label */
195 public boolean hasText;
197 /** is the row visible */
198 public boolean visible = true;
200 public int graphGroup = -1;
202 /** Displayed height of row in pixels */
203 public int height = 0;
205 public int graph = 0;
207 public int graphHeight = 40;
209 public boolean padGaps = false;
211 public static final int NO_GRAPH = 0;
213 public static final int BAR_GRAPH = 1;
215 public static final int LINE_GRAPH = 2;
217 public boolean belowAlignment = true;
219 public SequenceGroup groupRef = null;
222 * display every column label, even if there is a row of identical labels
224 public boolean showAllColLabels = false;
227 * scale the column label to fit within the alignment column.
229 public boolean scaleColLabel = false;
232 * centre the column labels relative to the alignment column
234 public boolean centreColLabels = false;
236 private boolean isrna;
241 * @see java.lang.Object#finalize()
243 protected void finalize() throws Throwable
250 public static int getGraphValueFromString(String string)
252 if (string.equalsIgnoreCase("BAR_GRAPH"))
256 else if (string.equalsIgnoreCase("LINE_GRAPH"))
266 // JBPNote: what does this do ?
267 public void ConcenStru(CharSequence RNAannot) throws WUSSParseException
269 bps = Rna.GetModeleBP(RNAannot);
273 * Creates a new AlignmentAnnotation object.
276 * short label shown under sequence labels
278 * text displayed on mouseover
280 * set of positional annotation elements
282 public AlignmentAnnotation(String label, String description,
283 Annotation[] annotations)
288 this.description = description;
289 this.annotations = annotations;
291 validateRangeAndDisplay();
295 * Checks if annotation labels represent secondary structures
298 void areLabelsSecondaryStructure()
300 boolean nonSSLabel = false;
302 StringBuffer rnastring = new StringBuffer();
305 for (int i = 0; i < annotations.length; i++)
307 if (annotations[i] == null)
311 if (annotations[i].secondaryStructure == 'H'
312 || annotations[i].secondaryStructure == 'E')
317 // Check for RNA secondary structure
319 // System.out.println(annotations[i].secondaryStructure);
320 // TODO: 2.8.2 should this ss symbol validation check be a function in
321 // RNA/ResidueProperties ?
322 if (annotations[i].secondaryStructure == '('
323 || annotations[i].secondaryStructure == '['
324 || annotations[i].secondaryStructure == '<'
325 || annotations[i].secondaryStructure == '{'
326 || annotations[i].secondaryStructure == 'A'
327 || annotations[i].secondaryStructure == 'B'
328 || annotations[i].secondaryStructure == 'C'
329 || annotations[i].secondaryStructure == 'D'
330 || annotations[i].secondaryStructure == 'E'
331 || annotations[i].secondaryStructure == 'F'
332 || annotations[i].secondaryStructure == 'G'
333 || annotations[i].secondaryStructure == 'H'
334 || annotations[i].secondaryStructure == 'I'
335 || annotations[i].secondaryStructure == 'J'
336 || annotations[i].secondaryStructure == 'K'
337 || annotations[i].secondaryStructure == 'L'
338 || annotations[i].secondaryStructure == 'M'
339 || annotations[i].secondaryStructure == 'N'
340 || annotations[i].secondaryStructure == 'O'
341 || annotations[i].secondaryStructure == 'P'
342 || annotations[i].secondaryStructure == 'Q'
343 || annotations[i].secondaryStructure == 'R'
344 || annotations[i].secondaryStructure == 'S'
345 || annotations[i].secondaryStructure == 'T'
346 || annotations[i].secondaryStructure == 'U'
347 || annotations[i].secondaryStructure == 'V'
348 || annotations[i].secondaryStructure == 'W'
349 || annotations[i].secondaryStructure == 'X'
350 || annotations[i].secondaryStructure == 'Y'
351 || annotations[i].secondaryStructure == 'Z')
358 // System.out.println("displaychar " + annotations[i].displayCharacter);
360 if (annotations[i].displayCharacter == null
361 || annotations[i].displayCharacter.length() == 0)
363 rnastring.append('.');
366 if (annotations[i].displayCharacter.length() == 1)
368 firstChar = annotations[i].displayCharacter.charAt(0);
369 // check to see if it looks like a sequence or is secondary structure
371 if (annotations[i].secondaryStructure != ' '
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
415 && firstChar < jalview.schemes.ResidueProperties.aaIndex.length)
417 if (jalview.schemes.ResidueProperties.aaIndex[firstChar] < 23) // TODO:
430 rnastring.append(annotations[i].displayCharacter.charAt(1));
433 if (annotations[i].displayCharacter.length() > 0)
442 for (int j = 0; j < annotations.length; j++)
444 if (annotations[j] != null
445 && annotations[j].secondaryStructure != ' ')
447 annotations[j].displayCharacter = String
448 .valueOf(annotations[j].secondaryStructure);
449 annotations[j].secondaryStructure = ' ';
458 _updateRnaSecStr(new AnnotCharSequence());
462 annotationId = this.hashCode() + "";
466 * flyweight access to positions in the alignment annotation row for RNA
472 private class AnnotCharSequence implements CharSequence
478 public AnnotCharSequence()
480 this(0, annotations.length);
483 public AnnotCharSequence(int start, int end)
490 public CharSequence subSequence(int start, int end)
492 return new AnnotCharSequence(offset + start, offset + end);
502 public char charAt(int index)
504 return ((index + offset < 0) || (index + offset) >= max
505 || annotations[index + offset] == null
506 || (annotations[index + offset].secondaryStructure <= ' ') ? ' '
507 : annotations[index + offset].displayCharacter == null
508 || annotations[index + offset].displayCharacter
509 .length() == 0 ? annotations[index + offset].secondaryStructure
510 : annotations[index + offset].displayCharacter
515 public String toString()
517 char[] string = new char[max - offset];
518 int mx = annotations.length;
520 for (int i = offset; i < mx; i++)
522 string[i] = (annotations[i] == null || (annotations[i].secondaryStructure <= 32)) ? ' '
523 : (annotations[i].displayCharacter == null
524 || annotations[i].displayCharacter.length() == 0 ? annotations[i].secondaryStructure
525 : annotations[i].displayCharacter.charAt(0));
527 return new String(string);
531 private long _lastrnaannot = -1;
533 public String getRNAStruc()
537 String rnastruc = new AnnotCharSequence().toString();
538 if (_lastrnaannot != rnastruc.hashCode())
540 // ensure rna structure contacts are up to date
541 _lastrnaannot = rnastruc.hashCode();
542 _updateRnaSecStr(rnastruc);
550 * Creates a new AlignmentAnnotation object.
565 public AlignmentAnnotation(String label, String description,
566 Annotation[] annotations, float min, float max, int graphType)
568 // graphs are not editable
569 editable = graphType == 0;
572 this.description = description;
573 this.annotations = annotations;
577 validateRangeAndDisplay();
581 * checks graphMin and graphMax, secondary structure symbols, sets graphType
582 * appropriately, sets null labels to the empty string if appropriate.
584 public void validateRangeAndDisplay()
587 if (annotations == null)
589 visible = false; // try to prevent renderer from displaying.
590 return; // this is a non-annotation row annotation - ie a sequence score.
593 int graphType = graph;
594 float min = graphMin;
595 float max = graphMax;
596 boolean drawValues = true;
601 for (int i = 0; i < annotations.length; i++)
603 if (annotations[i] == null)
608 if (drawValues && annotations[i].displayCharacter != null
609 && annotations[i].displayCharacter.length() > 1)
614 if (annotations[i].value > max)
616 max = annotations[i].value;
619 if (annotations[i].value < min)
621 min = annotations[i].value;
623 if (_linecolour == null && annotations[i].colour != null)
625 _linecolour = annotations[i].colour;
628 // ensure zero is origin for min/max ranges on only one side of zero
645 areLabelsSecondaryStructure();
647 if (!drawValues && graphType != NO_GRAPH)
649 for (int i = 0; i < annotations.length; i++)
651 if (annotations[i] != null)
653 annotations[i].displayCharacter = "";
660 * Copy constructor creates a new independent annotation row with the same
661 * associated sequenceRef
665 public AlignmentAnnotation(AlignmentAnnotation annotation)
667 this.label = new String(annotation.label);
668 if (annotation.description != null)
670 this.description = new String(annotation.description);
672 this.graphMin = annotation.graphMin;
673 this.graphMax = annotation.graphMax;
674 this.graph = annotation.graph;
675 this.graphHeight = annotation.graphHeight;
676 this.graphGroup = annotation.graphGroup;
677 this.groupRef = annotation.groupRef;
678 this.editable = annotation.editable;
679 this.autoCalculated = annotation.autoCalculated;
680 this.hasIcons = annotation.hasIcons;
681 this.hasText = annotation.hasText;
682 this.height = annotation.height;
683 this.label = annotation.label;
684 this.padGaps = annotation.padGaps;
685 this.visible = annotation.visible;
686 this.centreColLabels = annotation.centreColLabels;
687 this.scaleColLabel = annotation.scaleColLabel;
688 this.showAllColLabels = annotation.showAllColLabels;
689 this.calcId = annotation.calcId;
690 if (annotation.properties!=null)
692 properties = new HashMap<String,String>();
693 for (Map.Entry<String, String> val:annotation.properties.entrySet())
695 properties.put(val.getKey(), val.getValue());
698 if (this.hasScore = annotation.hasScore)
700 this.score = annotation.score;
702 if (annotation.threshold != null)
704 threshold = new GraphLine(annotation.threshold);
706 Annotation[] ann = annotation.annotations;
707 if (annotation.annotations != null)
709 this.annotations = new Annotation[ann.length];
710 for (int i = 0; i < ann.length; i++)
714 annotations[i] = new Annotation(ann[i]);
715 if (_linecolour != null)
717 _linecolour = annotations[i].colour;
722 if (annotation.sequenceRef != null)
724 this.sequenceRef = annotation.sequenceRef;
725 if (annotation.sequenceMapping != null)
728 sequenceMapping = new HashMap<Integer, Annotation>();
729 Iterator<Integer> pos = annotation.sequenceMapping.keySet()
731 while (pos.hasNext())
733 // could optimise this!
735 Annotation a = annotation.sequenceMapping.get(p);
742 for (int i = 0; i < ann.length; i++)
746 sequenceMapping.put(p, annotations[i]);
754 this.sequenceMapping = null;
757 // TODO: check if we need to do this: JAL-952
758 // if (this.isrna=annotation.isrna)
760 // _rnasecstr=new SequenceFeature[annotation._rnasecstr];
762 validateRangeAndDisplay(); // construct hashcodes, etc.
766 * clip the annotation to the columns given by startRes and endRes (inclusive)
767 * and prune any existing sequenceMapping to just those columns.
772 public void restrict(int startRes, int endRes)
774 if (annotations == null)
783 if (startRes >= annotations.length)
785 startRes = annotations.length - 1;
787 if (endRes >= annotations.length)
789 endRes = annotations.length - 1;
791 if (annotations == null)
795 Annotation[] temp = new Annotation[endRes - startRes + 1];
796 if (startRes < annotations.length)
798 System.arraycopy(annotations, startRes, temp, 0, endRes - startRes
801 if (sequenceRef != null)
803 // Clip the mapping, if it exists.
804 int spos = sequenceRef.findPosition(startRes);
805 int epos = sequenceRef.findPosition(endRes);
806 if (sequenceMapping != null)
808 Map<Integer, Annotation> newmapping = new HashMap<Integer, Annotation>();
809 Iterator<Integer> e = sequenceMapping.keySet().iterator();
812 Integer pos = e.next();
813 if (pos.intValue() >= spos && pos.intValue() <= epos)
815 newmapping.put(pos, sequenceMapping.get(pos));
818 sequenceMapping.clear();
819 sequenceMapping = newmapping;
826 * set the annotation row to be at least length Annotations
829 * minimum number of columns required in the annotation row
830 * @return false if the annotation row is greater than length
832 public boolean padAnnotation(int length)
834 if (annotations == null)
836 return true; // annotation row is correct - null == not visible and
839 if (annotations.length < length)
841 Annotation[] na = new Annotation[length];
842 System.arraycopy(annotations, 0, na, 0, annotations.length);
846 return annotations.length > length;
853 * @return DOCUMENT ME!
856 public String toString()
858 StringBuilder buffer = new StringBuilder(256);
860 for (int i = 0; i < annotations.length; i++)
862 if (annotations[i] != null)
866 buffer.append(annotations[i].value);
870 buffer.append(annotations[i].secondaryStructure);
874 buffer.append(annotations[i].displayCharacter);
880 // TODO: remove disgusting hack for 'special' treatment of consensus line.
881 if (label.indexOf("Consensus") == 0)
885 for (int i = 0; i < annotations.length; i++)
887 if (annotations[i] != null)
889 buffer.append(annotations[i].description);
896 return buffer.toString();
899 public void setThreshold(GraphLine line)
904 public GraphLine getThreshold()
910 * Attach the annotation to seqRef, starting from startRes position. If
911 * alreadyMapped is true then the indices of the annotation[] array are
912 * sequence positions rather than alignment column positions.
916 * @param alreadyMapped
918 public void createSequenceMapping(SequenceI seqRef, int startRes,
919 boolean alreadyMapped)
926 sequenceRef = seqRef;
927 if (annotations == null)
931 sequenceMapping = new HashMap<Integer, Annotation>();
935 for (int i = 0; i < annotations.length; i++)
937 if (annotations[i] != null)
941 seqPos = seqRef.findPosition(i);
945 seqPos = i + startRes;
948 sequenceMapping.put(new Integer(seqPos), annotations[i]);
954 public void adjustForAlignment()
956 if (sequenceRef == null)
961 if (annotations == null)
966 int a = 0, aSize = sequenceRef.getLength();
975 Annotation[] temp = new Annotation[aSize];
978 for (a = sequenceRef.getStart(); a <= sequenceRef.getEnd(); a++)
980 index = new Integer(a);
981 if (sequenceMapping.containsKey(index))
983 position = sequenceRef.findIndex(a) - 1;
985 temp[position] = sequenceMapping.get(index);
993 * remove any null entries in annotation row and return the number of non-null
994 * annotation elements.
998 public int compactAnnotationArray()
1000 int i = 0, iSize = annotations.length;
1003 if (annotations[i] == null)
1007 System.arraycopy(annotations, i + 1, annotations, i, iSize - i
1017 Annotation[] ann = annotations;
1018 annotations = new Annotation[i];
1019 System.arraycopy(ann, 0, annotations, 0, i);
1025 * Associate this annotion with the aligned residues of a particular sequence.
1026 * sequenceMapping will be updated in the following way: null sequenceI -
1027 * existing mapping will be discarded but annotations left in mapped
1028 * positions. valid sequenceI not equal to current sequenceRef: mapping is
1029 * discarded and rebuilt assuming 1:1 correspondence TODO: overload with
1030 * parameter to specify correspondence between current and new sequenceRef
1034 public void setSequenceRef(SequenceI sequenceI)
1036 if (sequenceI != null)
1038 if (sequenceRef != null)
1040 boolean rIsDs=sequenceRef.getDatasetSequence()==null,tIsDs=sequenceI.getDatasetSequence()==null;
1041 if (sequenceRef != sequenceI
1042 && (rIsDs && !tIsDs && sequenceRef != sequenceI
1043 .getDatasetSequence())
1044 && (!rIsDs && tIsDs && sequenceRef.getDatasetSequence() != sequenceI)
1045 && (!rIsDs && !tIsDs && sequenceRef.getDatasetSequence() != sequenceI
1046 .getDatasetSequence())
1047 && !sequenceRef.equals(sequenceI))
1049 // if sequenceRef isn't intersecting with sequenceI
1050 // throw away old mapping and reconstruct.
1052 if (sequenceMapping != null)
1054 sequenceMapping = null;
1055 // compactAnnotationArray();
1057 createSequenceMapping(sequenceI, 1, true);
1058 adjustForAlignment();
1062 // Mapping carried over
1063 sequenceRef = sequenceI;
1068 // No mapping exists
1069 createSequenceMapping(sequenceI, 1, true);
1070 adjustForAlignment();
1075 // throw away the mapping without compacting.
1076 sequenceMapping = null;
1084 public double getScore()
1093 public void setScore(double score)
1101 * @return true if annotation has an associated score
1103 public boolean hasScore()
1105 return hasScore || !Double.isNaN(score);
1109 * Score only annotation
1112 * @param description
1115 public AlignmentAnnotation(String label, String description, double score)
1117 this(label, description, null);
1122 * copy constructor with edit based on the hidden columns marked in colSel
1124 * @param alignmentAnnotation
1127 public AlignmentAnnotation(AlignmentAnnotation alignmentAnnotation,
1128 ColumnSelection colSel)
1130 this(alignmentAnnotation);
1131 if (annotations == null)
1135 colSel.makeVisibleAnnotation(this);
1138 public void setPadGaps(boolean padgaps, char gapchar)
1140 this.padGaps = padgaps;
1144 for (int i = 0; i < annotations.length; i++)
1146 if (annotations[i] == null)
1148 annotations[i] = new Annotation(String.valueOf(gapchar), null,
1151 else if (annotations[i].displayCharacter == null
1152 || annotations[i].displayCharacter.equals(" "))
1154 annotations[i].displayCharacter = String.valueOf(gapchar);
1161 * format description string for display
1164 * @return Get the annotation description string optionally prefixed by
1165 * associated sequence name (if any)
1167 public String getDescription(boolean seqname)
1169 if (seqname && this.sequenceRef != null)
1171 int i = description.toLowerCase().indexOf("<html>");
1174 // move the html tag to before the sequence reference.
1175 return "<html>" + sequenceRef.getName() + " : "
1176 + description.substring(i + 6);
1178 return sequenceRef.getName() + " : " + description;
1183 public boolean isValidStruc()
1185 return invalidrnastruc == -1;
1188 public long getInvalidStrucPos()
1190 return invalidrnastruc;
1194 * machine readable ID string indicating what generated this annotation
1196 protected String calcId = "";
1199 * properties associated with the calcId
1201 protected Map<String, String> properties = new HashMap<String, String>();
1204 * base colour for line graphs. If null, will be set automatically by
1205 * searching the alignment annotation
1207 public java.awt.Color _linecolour;
1209 public String getCalcId()
1214 public void setCalcId(String calcId)
1216 this.calcId = calcId;
1219 public boolean isRNA()
1225 * transfer annotation to the given sequence using the given mapping from the
1226 * current positions or an existing sequence mapping
1230 * map involving sq as To or From
1232 public void liftOver(SequenceI sq, Mapping sp2sq)
1234 if (sp2sq.getMappedWidth() != sp2sq.getWidth())
1236 // TODO: employ getWord/MappedWord to transfer annotation between cDNA and Protein reference frames
1237 throw new Error("liftOver currently not implemented for transfer of annotation between different types of seqeunce");
1239 boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == sq || sp2sq
1240 .getTo() == sq.getDatasetSequence()) : false;
1242 // TODO build a better annotation element map and get rid of annotations[]
1243 Map<Integer, Annotation> mapForsq = new HashMap<Integer, Annotation>();
1244 if (sequenceMapping != null)
1248 for (Entry<Integer, Annotation> ie : sequenceMapping.entrySet())
1250 Integer mpos = Integer.valueOf(mapIsTo ? sp2sq
1251 .getMappedPosition(ie.getKey()) : sp2sq.getPosition(ie
1253 if (mpos >= sq.getStart() && mpos <= sq.getEnd())
1255 mapForsq.put(mpos, ie.getValue());
1258 sequenceMapping = mapForsq;
1260 adjustForAlignment();
1270 * like liftOver but more general.
1272 * Takes an array of int pairs that will be used to update the internal
1273 * sequenceMapping and so shuffle the annotated positions
1276 * - new sequence reference for the annotation row - if null,
1277 * sequenceRef is left unchanged
1279 * array of ints containing corresponding positions
1281 * - column for current coordinate system (-1 for index+1)
1283 * - column for destination coordinate system (-1 for index+1)
1285 * - offset added to index when referencing either coordinate system
1286 * @note no checks are made as to whether from and/or to are sensible
1287 * @note caller should add the remapped annotation to newref if they have not
1290 public void remap(SequenceI newref, int[][] mapping, int from, int to,
1293 if (mapping != null)
1295 Map<Integer, Annotation> old = sequenceMapping;
1296 Map<Integer, Annotation> remap = new HashMap<Integer, Annotation>();
1298 for (int mp[] : mapping)
1304 Annotation ann = null;
1307 ann = sequenceMapping.get(Integer.valueOf(idxoffset + index));
1311 if (mp != null && mp.length > from)
1313 ann = sequenceMapping.get(Integer.valueOf(mp[from]));
1320 remap.put(Integer.valueOf(idxoffset + index), ann);
1324 if (to > -1 && to < mp.length)
1326 remap.put(Integer.valueOf(mp[to]), ann);
1331 sequenceMapping = remap;
1335 sequenceRef = newref;
1337 adjustForAlignment();
1341 public String getProperty(String property)
1343 if (properties == null)
1347 return properties.get(property);
1350 public void setProperty(String property, String value)
1352 if (properties==null)
1354 properties = new HashMap<String,String>();
1356 properties.put(property, value);
1359 public boolean hasProperties()
1361 return properties != null && properties.size() > 0;
1364 public Collection<String> getProperties()
1366 if (properties == null)
1368 return Collections.emptyList();
1370 return properties.keySet();
1374 * Returns the Annotation for the given sequence position (base 1) if any,
1380 public Annotation getAnnotationForPosition(int position)
1382 return sequenceMapping == null ? null : sequenceMapping.get(position);