2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.Enumeration;
25 import java.util.Hashtable;
26 import java.util.List;
28 import java.util.Vector;
31 * Data structure to hold and manipulate a multiple sequence alignment
37 public class Alignment implements AlignmentI
39 protected Alignment dataset;
41 protected List<SequenceI> sequences;
43 protected List<SequenceGroup> groups = java.util.Collections
44 .synchronizedList(new ArrayList<SequenceGroup>());
46 protected char gapCharacter = '-';
48 protected int type = NUCLEOTIDE;
50 public static final int PROTEIN = 0;
52 public static final int NUCLEOTIDE = 1;
54 public boolean hasRNAStructure = false;
57 public AlignmentAnnotation[] annotations;
59 HiddenSequences hiddenSequences = new HiddenSequences(this);
61 public Hashtable alignmentProperties;
63 private void initAlignment(SequenceI[] seqs)
67 if (jalview.util.Comparison.isNucleotide(seqs))
76 sequences = java.util.Collections
77 .synchronizedList(new ArrayList<SequenceI>());
79 for (i = 0; i < seqs.length; i++)
81 sequences.add(seqs[i]);
87 * Make an alignment from an array of Sequences.
91 public Alignment(SequenceI[] seqs)
97 * Make a new alignment from an array of SeqCigars
102 public Alignment(SeqCigar[] alseqs)
104 SequenceI[] seqs = SeqCigar.createAlignmentSequences(alseqs,
105 gapCharacter, new ColumnSelection(), null);
110 * Make a new alignment from an CigarArray JBPNote - can only do this when
111 * compactAlignment does not contain hidden regions. JBPNote - must also check
112 * that compactAlignment resolves to a set of SeqCigars - or construct them
115 * @param compactAlignment
118 public static AlignmentI createAlignment(CigarArray compactAlignment)
120 throw new Error("Alignment(CigarArray) not yet implemented");
121 // this(compactAlignment.refCigars);
127 * @return DOCUMENT ME!
130 public List<SequenceI> getSequences()
136 public List<SequenceI> getSequences(
137 Map<SequenceI, SequenceCollectionI> hiddenReps)
139 // TODO: in jalview 2.8 we don't do anything with hiddenreps - fix design to
145 public SequenceI[] getSequencesArray()
147 if (sequences == null)
149 synchronized (sequences)
151 return sequences.toArray(new SequenceI[sequences.size()]);
161 * @return DOCUMENT ME!
164 public SequenceI getSequenceAt(int i)
166 synchronized (sequences)
168 if (i > -1 && i < sequences.size())
170 return sequences.get(i);
177 * Adds a sequence to the alignment. Recalculates maxLength and size.
182 public void addSequence(SequenceI snew)
186 // maintain dataset integrity
187 if (snew.getDatasetSequence() != null)
189 getDataset().addSequence(snew.getDatasetSequence());
193 // derive new sequence
194 SequenceI adding = snew.deriveSequence();
195 getDataset().addSequence(adding.getDatasetSequence());
199 if (sequences == null)
201 initAlignment(new SequenceI[]
206 synchronized (sequences)
211 if (hiddenSequences != null)
212 hiddenSequences.adjustHeightSequenceAdded();
216 * Adds a sequence to the alignment. Recalculates maxLength and size.
221 public void setSequenceAt(int i, SequenceI snew)
223 SequenceI oldseq = getSequenceAt(i);
225 synchronized (sequences)
227 sequences.set(i, snew);
234 * @return DOCUMENT ME!
237 public List<SequenceGroup> getGroups()
243 public void finalize()
245 if (getDataset() != null)
246 getDataset().removeAlignmentRef();
252 hiddenSequences = null;
256 * decrement the alignmentRefs counter by one and call finalize if it goes to
259 private void removeAlignmentRef()
261 if (--alignmentRefs == 0)
274 public void deleteSequence(SequenceI s)
276 deleteSequence(findIndex(s));
286 public void deleteSequence(int i)
288 if (i > -1 && i < getHeight())
290 synchronized (sequences)
294 hiddenSequences.adjustHeightSequenceDeleted(i);
301 * @see jalview.datamodel.AlignmentI#findGroup(jalview.datamodel.SequenceI)
304 public SequenceGroup findGroup(SequenceI s)
306 synchronized (groups)
308 for (int i = 0; i < this.groups.size(); i++)
310 SequenceGroup sg = groups.get(i);
312 if (sg.getSequences(null).contains(s))
325 * jalview.datamodel.AlignmentI#findAllGroups(jalview.datamodel.SequenceI)
328 public SequenceGroup[] findAllGroups(SequenceI s)
330 ArrayList<SequenceGroup> temp = new ArrayList<SequenceGroup>();
332 synchronized (groups)
334 int gSize = groups.size();
335 for (int i = 0; i < gSize; i++)
337 SequenceGroup sg = groups.get(i);
338 if (sg == null || sg.getSequences(null) == null)
340 this.deleteGroup(sg);
345 if (sg.getSequences(null).contains(s))
351 SequenceGroup[] ret = new SequenceGroup[temp.size()];
352 return temp.toArray(ret);
357 public void addGroup(SequenceGroup sg)
359 synchronized (groups)
361 if (!groups.contains(sg))
363 if (hiddenSequences.getSize() > 0)
365 int i, iSize = sg.getSize();
366 for (i = 0; i < iSize; i++)
368 if (!sequences.contains(sg.getSequenceAt(i)))
370 sg.deleteSequence(sg.getSequenceAt(i), false);
376 if (sg.getSize() < 1)
388 * remove any annotation that references gp
391 * (if null, removes all group associated annotation)
393 private void removeAnnotationForGroup(SequenceGroup gp)
395 if (annotations == null || annotations.length == 0)
399 // remove annotation very quickly
400 AlignmentAnnotation[] t, todelete = new AlignmentAnnotation[annotations.length], tokeep = new AlignmentAnnotation[annotations.length];
404 for (i = 0, p = 0, k = 0; i < annotations.length; i++)
406 if (annotations[i].groupRef != null)
408 todelete[p++] = annotations[i];
412 tokeep[k++] = annotations[i];
418 for (i = 0, p = 0, k = 0; i < annotations.length; i++)
420 if (annotations[i].groupRef == gp)
422 todelete[p++] = annotations[i];
426 tokeep[k++] = annotations[i];
432 // clear out the group associated annotation.
433 for (i = 0; i < p; i++)
435 unhookAnnotation(todelete[i]);
438 t = new AlignmentAnnotation[k];
439 for (i = 0; i < k; i++)
448 public void deleteAllGroups()
450 synchronized (groups)
452 if (annotations != null)
454 removeAnnotationForGroup(null);
456 for (SequenceGroup sg : groups)
466 public void deleteGroup(SequenceGroup g)
468 synchronized (groups)
470 if (groups.contains(g))
472 removeAnnotationForGroup(g);
481 public SequenceI findName(String name)
483 return findName(name, false);
489 * @see jalview.datamodel.AlignmentI#findName(java.lang.String, boolean)
492 public SequenceI findName(String token, boolean b)
494 return findName(null, token, b);
500 * @see jalview.datamodel.AlignmentI#findName(SequenceI, java.lang.String,
504 public SequenceI findName(SequenceI startAfter, String token, boolean b)
509 String sqname = null;
510 if (startAfter != null)
512 // try to find the sequence in the alignment
513 boolean matched = false;
514 while (i < sequences.size())
516 if (getSequenceAt(i++) == startAfter)
527 while (i < sequences.size())
529 sq = getSequenceAt(i);
530 sqname = sq.getName();
531 if (sqname.equals(token) // exact match
532 || (b && // allow imperfect matches - case varies
533 (sqname.equalsIgnoreCase(token))))
535 return getSequenceAt(i);
545 public SequenceI[] findSequenceMatch(String name)
547 Vector matches = new Vector();
550 while (i < sequences.size())
552 if (getSequenceAt(i).getName().equals(name))
554 matches.addElement(getSequenceAt(i));
559 SequenceI[] result = new SequenceI[matches.size()];
560 for (i = 0; i < result.length; i++)
562 result[i] = (SequenceI) matches.elementAt(i);
572 * @see jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SequenceI)
575 public int findIndex(SequenceI s)
579 while (i < sequences.size())
581 if (s == getSequenceAt(i))
596 * jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SearchResults)
599 public int findIndex(SearchResults results)
603 while (i < sequences.size())
605 if (results.involvesSequence(getSequenceAt(i)))
617 * @return DOCUMENT ME!
620 public int getHeight()
622 return sequences.size();
628 * @return DOCUMENT ME!
631 public int getWidth()
635 for (int i = 0; i < sequences.size(); i++)
637 if (getSequenceAt(i).getLength() > maxLength)
639 maxLength = getSequenceAt(i).getLength();
653 public void setGapCharacter(char gc)
656 synchronized (sequences)
658 for (SequenceI seq : sequences)
660 seq.setSequence(seq.getSequenceAsString().replace('.', gc)
661 .replace('-', gc).replace(' ', gc));
669 * @return DOCUMENT ME!
672 public char getGapCharacter()
680 * @see jalview.datamodel.AlignmentI#isAligned()
683 public boolean isAligned()
685 return isAligned(false);
691 * @see jalview.datamodel.AlignmentI#isAligned(boolean)
694 public boolean isAligned(boolean includeHidden)
696 int width = getWidth();
697 if (hiddenSequences == null || hiddenSequences.getSize() == 0)
699 includeHidden = true; // no hidden sequences to check against.
701 for (int i = 0; i < sequences.size(); i++)
703 if (includeHidden || !hiddenSequences.isHidden(getSequenceAt(i)))
705 if (getSequenceAt(i).getLength() != width)
718 * @seejalview.datamodel.AlignmentI#deleteAnnotation(jalview.datamodel.
719 * AlignmentAnnotation)
722 public boolean deleteAnnotation(AlignmentAnnotation aa)
724 return deleteAnnotation(aa, true);
728 public boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook)
732 if (annotations != null)
734 aSize = annotations.length;
742 AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1];
744 boolean swap = false;
747 for (int i = 0; i < aSize; i++)
749 if (annotations[i] == aa)
754 if (tIndex < temp.length)
755 temp[tIndex++] = annotations[i];
763 unhookAnnotation(aa);
770 * remove any object references associated with this annotation
774 private void unhookAnnotation(AlignmentAnnotation aa)
776 if (aa.sequenceRef != null)
778 aa.sequenceRef.removeAlignmentAnnotation(aa);
780 if (aa.groupRef != null)
782 // probably need to do more here in the future (post 2.5.0)
790 * @seejalview.datamodel.AlignmentI#addAnnotation(jalview.datamodel.
791 * AlignmentAnnotation)
794 public void addAnnotation(AlignmentAnnotation aa)
796 addAnnotation(aa, -1);
802 * @seejalview.datamodel.AlignmentI#addAnnotation(jalview.datamodel.
803 * AlignmentAnnotation, int)
806 public void addAnnotation(AlignmentAnnotation aa, int pos)
808 if (aa.getRNAStruc() != null)
810 hasRNAStructure = true;
814 if (annotations != null)
816 aSize = annotations.length + 1;
819 AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize];
821 if (pos == -1 || pos >= aSize)
823 temp[aSize - 1] = aa;
832 for (i = 0; i < (aSize - 1); i++, p++)
840 temp[p] = annotations[i];
849 public void setAnnotationIndex(AlignmentAnnotation aa, int index)
851 if (aa == null || annotations == null || annotations.length - 1 < index)
856 int aSize = annotations.length;
857 AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize];
861 for (int i = 0; i < aSize; i++)
870 temp[i] = annotations[i];
874 temp[i] = annotations[i - 1];
883 * returns all annotation on the alignment
885 public AlignmentAnnotation[] getAlignmentAnnotation()
891 public void setNucleotide(boolean b)
904 public boolean isNucleotide()
906 if (type == NUCLEOTIDE)
917 public boolean hasRNAStructure()
919 // TODO can it happen that structure is removed from alignment?
920 return hasRNAStructure;
924 public void setDataset(Alignment data)
926 if (dataset == null && data == null)
928 // Create a new dataset for this alignment.
929 // Can only be done once, if dataset is not null
930 // This will not be performed
931 SequenceI[] seqs = new SequenceI[getHeight()];
932 SequenceI currentSeq;
933 for (int i = 0; i < getHeight(); i++)
935 currentSeq = getSequenceAt(i);
936 if (currentSeq.getDatasetSequence() != null)
938 seqs[i] = currentSeq.getDatasetSequence();
942 seqs[i] = currentSeq.createDatasetSequence();
946 dataset = new Alignment(seqs);
948 else if (dataset == null && data != null)
952 dataset.addAlignmentRef();
956 * reference count for number of alignments referencing this one.
958 int alignmentRefs = 0;
961 * increase reference count to this alignment.
963 private void addAlignmentRef()
969 public Alignment getDataset()
975 public boolean padGaps()
977 boolean modified = false;
979 // Remove excess gaps from the end of alignment
983 for (int i = 0; i < sequences.size(); i++)
985 current = getSequenceAt(i);
986 for (int j = current.getLength(); j > maxLength; j--)
989 && !jalview.util.Comparison.isGap(current.getCharAt(j)))
1000 for (int i = 0; i < sequences.size(); i++)
1002 current = getSequenceAt(i);
1003 cLength = current.getLength();
1005 if (cLength < maxLength)
1007 current.insertCharAt(cLength, maxLength - cLength, gapCharacter);
1010 else if (current.getLength() > maxLength)
1012 current.deleteChars(maxLength, current.getLength());
1019 * Justify the sequences to the left or right by deleting and inserting gaps
1020 * before the initial residue or after the terminal residue
1023 * true if alignment padded to right, false to justify to left
1024 * @return true if alignment was changed
1027 public boolean justify(boolean right)
1029 boolean modified = false;
1031 // Remove excess gaps from the end of alignment
1033 int ends[] = new int[sequences.size() * 2];
1035 for (int i = 0; i < sequences.size(); i++)
1037 current = getSequenceAt(i);
1038 // This should really be a sequence method
1039 ends[i * 2] = current.findIndex(current.getStart());
1040 ends[i * 2 + 1] = current.findIndex(current.getStart()
1041 + current.getLength());
1042 boolean hitres = false;
1043 for (int j = 0, rs = 0, ssiz = current.getLength(); j < ssiz; j++)
1045 if (!jalview.util.Comparison.isGap(current.getCharAt(j)))
1054 ends[i * 2 + 1] = j;
1055 if (j - ends[i * 2] > maxLength)
1057 maxLength = j - ends[i * 2];
1065 // now edit the flanking gaps to justify to either left or right
1066 int cLength, extent, diff;
1067 for (int i = 0; i < sequences.size(); i++)
1069 current = getSequenceAt(i);
1071 cLength = 1 + ends[i * 2 + 1] - ends[i * 2];
1072 diff = maxLength - cLength; // number of gaps to indent
1073 extent = current.getLength();
1077 if (extent > ends[i * 2 + 1])
1079 current.deleteChars(ends[i * 2 + 1] + 1, extent);
1082 if (ends[i * 2] > diff)
1084 current.deleteChars(0, ends[i * 2] - diff);
1089 if (ends[i * 2] < diff)
1091 current.insertCharAt(0, diff - ends[i * 2], gapCharacter);
1099 if (ends[i * 2] > 0)
1101 current.deleteChars(0, ends[i * 2]);
1103 ends[i * 2 + 1] -= ends[i * 2];
1104 extent -= ends[i * 2];
1106 if (extent > maxLength)
1108 current.deleteChars(maxLength + 1, extent);
1113 if (extent < maxLength)
1115 current.insertCharAt(extent, maxLength - extent, gapCharacter);
1125 public HiddenSequences getHiddenSequences()
1127 return hiddenSequences;
1131 public CigarArray getCompactAlignment()
1133 synchronized (sequences)
1135 SeqCigar alseqs[] = new SeqCigar[sequences.size()];
1137 for (SequenceI seq : sequences)
1139 alseqs[i++] = new SeqCigar(seq);
1141 CigarArray cal = new CigarArray(alseqs);
1142 cal.addOperation(CigarArray.M, getWidth());
1148 public void setProperty(Object key, Object value)
1150 if (alignmentProperties == null)
1151 alignmentProperties = new Hashtable();
1153 alignmentProperties.put(key, value);
1157 public Object getProperty(Object key)
1159 if (alignmentProperties != null)
1160 return alignmentProperties.get(key);
1166 public Hashtable getProperties()
1168 return alignmentProperties;
1171 AlignedCodonFrame[] codonFrameList = null;
1177 * jalview.datamodel.AlignmentI#addCodonFrame(jalview.datamodel.AlignedCodonFrame
1181 public void addCodonFrame(AlignedCodonFrame codons)
1185 if (codonFrameList == null)
1187 codonFrameList = new AlignedCodonFrame[]
1191 AlignedCodonFrame[] t = new AlignedCodonFrame[codonFrameList.length + 1];
1192 System.arraycopy(codonFrameList, 0, t, 0, codonFrameList.length);
1193 t[codonFrameList.length] = codons;
1200 * @see jalview.datamodel.AlignmentI#getCodonFrame(int)
1203 public AlignedCodonFrame getCodonFrame(int index)
1205 return codonFrameList[index];
1212 * jalview.datamodel.AlignmentI#getCodonFrame(jalview.datamodel.SequenceI)
1215 public AlignedCodonFrame[] getCodonFrame(SequenceI seq)
1217 if (seq == null || codonFrameList == null)
1219 Vector cframes = new Vector();
1220 for (int f = 0; f < codonFrameList.length; f++)
1222 if (codonFrameList[f].involvesSequence(seq))
1223 cframes.addElement(codonFrameList[f]);
1225 if (cframes.size() == 0)
1227 AlignedCodonFrame[] cfr = new AlignedCodonFrame[cframes.size()];
1228 cframes.copyInto(cfr);
1235 * @see jalview.datamodel.AlignmentI#getCodonFrames()
1238 public AlignedCodonFrame[] getCodonFrames()
1240 return codonFrameList;
1246 * @seejalview.datamodel.AlignmentI#removeCodonFrame(jalview.datamodel.
1247 * AlignedCodonFrame)
1250 public boolean removeCodonFrame(AlignedCodonFrame codons)
1252 if (codons == null || codonFrameList == null)
1254 boolean removed = false;
1255 int i = 0, iSize = codonFrameList.length;
1258 if (codonFrameList[i] == codons)
1263 System.arraycopy(codonFrameList, i + 1, codonFrameList, i, iSize
1277 public void append(AlignmentI toappend)
1279 if (toappend == this)
1281 System.err.println("Self append may cause a deadlock.");
1283 // TODO test this method for a future 2.5 release
1284 // currently tested for use in jalview.gui.SequenceFetcher
1285 boolean samegap = toappend.getGapCharacter() == getGapCharacter();
1286 char oldc = toappend.getGapCharacter();
1287 boolean hashidden = toappend.getHiddenSequences() != null
1288 && toappend.getHiddenSequences().hiddenSequences != null;
1289 // get all sequences including any hidden ones
1290 List<SequenceI> sqs = (hashidden) ? toappend.getHiddenSequences()
1291 .getFullAlignment().getSequences() : toappend.getSequences();
1296 for (SequenceI addedsq : sqs)
1300 char[] oldseq = addedsq.getSequence();
1301 for (int c = 0; c < oldseq.length; c++)
1303 if (oldseq[c] == oldc)
1305 oldseq[c] = gapCharacter;
1309 addSequence(addedsq);
1313 AlignmentAnnotation[] alan = toappend.getAlignmentAnnotation();
1314 for (int a = 0; alan != null && a < alan.length; a++)
1316 addAnnotation(alan[a]);
1318 AlignedCodonFrame[] acod = toappend.getCodonFrames();
1319 for (int a = 0; acod != null && a < acod.length; a++)
1321 this.addCodonFrame(acod[a]);
1323 List<SequenceGroup> sg = toappend.getGroups();
1326 for (SequenceGroup _sg : sg)
1331 if (toappend.getHiddenSequences() != null)
1333 HiddenSequences hs = toappend.getHiddenSequences();
1334 if (hiddenSequences == null)
1336 hiddenSequences = new HiddenSequences(this);
1338 if (hs.hiddenSequences != null)
1340 for (int s = 0; s < hs.hiddenSequences.length; s++)
1342 // hide the newly appended sequence in the alignment
1343 if (hs.hiddenSequences[s] != null)
1345 hiddenSequences.hideSequence(hs.hiddenSequences[s]);
1350 if (toappend.getProperties() != null)
1352 // we really can't do very much here - just try to concatenate strings
1353 // where property collisions occur.
1354 Enumeration key = toappend.getProperties().keys();
1355 while (key.hasMoreElements())
1357 Object k = key.nextElement();
1358 Object ourval = this.getProperty(k);
1359 Object toapprop = toappend.getProperty(k);
1362 if (ourval.getClass().equals(toapprop.getClass())
1363 && !ourval.equals(toapprop))
1365 if (ourval instanceof String)
1368 this.setProperty(k, ((String) ourval) + "; "
1369 + ((String) toapprop));
1373 if (ourval instanceof Vector)
1376 Enumeration theirv = ((Vector) toapprop).elements();
1377 while (theirv.hasMoreElements())
1379 ((Vector) ourval).addElement(theirv);
1387 // just add new property directly
1388 setProperty(k, toapprop);
1396 public AlignmentAnnotation findOrCreateAnnotation(String name,
1397 String calcId, boolean autoCalc, SequenceI seqRef,
1398 SequenceGroup groupRef)
1400 assert (name != null);
1401 if (annotations != null)
1403 for (AlignmentAnnotation annot : getAlignmentAnnotation())
1405 if (annot.autoCalculated == autoCalc && (name.equals(annot.label))
1406 && (calcId == null || annot.getCalcId().equals(calcId))
1407 && annot.sequenceRef == seqRef
1408 && annot.groupRef == groupRef)
1414 AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
1415 new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
1416 annot.hasText = false;
1417 annot.setCalcId(new String(calcId));
1418 annot.autoCalculated = autoCalc;
1421 annot.setSequenceRef(seqRef);
1423 annot.groupRef = groupRef;
1424 addAnnotation(annot);
1430 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1432 ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
1433 for (AlignmentAnnotation a : getAlignmentAnnotation())
1435 if (a.getCalcId() == calcId
1436 || (a.getCalcId() != null && calcId != null && a.getCalcId()
1446 public void moveSelectedSequencesByOne(SequenceGroup sg,
1447 Map<SequenceI, SequenceCollectionI> map, boolean up)
1449 synchronized (sequences)
1454 for (int i = 1, iSize = sequences.size(); i < iSize; i++)
1456 SequenceI seq = sequences.get(i);
1457 if (!sg.getSequences(map).contains(seq))
1462 SequenceI temp = sequences.get(i - 1);
1463 if (sg.getSequences(null).contains(temp))
1468 sequences.set(i, temp);
1469 sequences.set(i - 1, seq);
1474 for (int i = sequences.size() - 2; i > -1; i--)
1476 SequenceI seq = sequences.get(i);
1477 if (!sg.getSequences(map).contains(seq))
1482 SequenceI temp = sequences.get(i + 1);
1483 if (sg.getSequences(map).contains(temp))
1488 sequences.set(i, temp);
1489 sequences.set(i + 1, seq);
1497 public void validateAnnotation(AlignmentAnnotation alignmentAnnotation)
1499 alignmentAnnotation.validateRangeAndDisplay();
1500 if (isNucleotide() && alignmentAnnotation.isValidStruc())
1502 hasRNAStructure = true;
1507 public int getEndRes()
1509 return getWidth() - 1;
1513 public int getStartRes()
1519 * In the case of AlignmentI - returns the dataset for the alignment, if set
1522 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1525 public AnnotatedCollectionI getContext()
1531 * Returns an iterable collection of annotations on this alignment which match
1532 * the given criteria.
1535 public Iterable<AlignmentAnnotation> findAnnotation(SequenceI datasequence,
1536 String calcId, String label)
1538 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1539 for (AlignmentAnnotation ann : annotations)
1541 // only sequence-linked annotations can qualify (have a datasequence)
1542 if (ann.sequenceRef == null)
1546 boolean matchDatasequence = (ann.sequenceRef.getDatasetSequence() == datasequence);
1547 final String annCalcId = ann.getCalcId();
1548 boolean matchCalcId = (annCalcId != null && annCalcId.equals(calcId));
1549 boolean matchLabel = (ann.label != null && ann.label.equals(label));
1550 if (matchDatasequence && matchCalcId && matchLabel)