2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.datamodel;
24 * Data structure to hold and manipulate a multiple sequence alignment
30 public class Alignment implements AlignmentI
32 protected Alignment dataset;
34 protected List<SequenceI> sequences;
36 protected List<SequenceGroup> groups = java.util.Collections
37 .synchronizedList(new ArrayList<SequenceGroup>());
39 protected char gapCharacter = '-';
41 protected int type = NUCLEOTIDE;
43 public static final int PROTEIN = 0;
45 public static final int NUCLEOTIDE = 1;
47 public boolean hasRNAStructure = false;
50 public AlignmentAnnotation[] annotations;
52 HiddenSequences hiddenSequences = new HiddenSequences(this);
54 public Hashtable alignmentProperties;
56 private void initAlignment(SequenceI[] seqs)
60 if (jalview.util.Comparison.isNucleotide(seqs))
69 sequences = java.util.Collections
70 .synchronizedList(new ArrayList<SequenceI>());
72 for (i = 0; i < seqs.length; i++)
74 sequences.add(seqs[i]);
80 * Make an alignment from an array of Sequences.
84 public Alignment(SequenceI[] seqs)
90 * Make a new alignment from an array of SeqCigars
95 public Alignment(SeqCigar[] alseqs)
97 SequenceI[] seqs = SeqCigar.createAlignmentSequences(alseqs,
98 gapCharacter, new ColumnSelection(), null);
103 * Make a new alignment from an CigarArray JBPNote - can only do this when
104 * compactAlignment does not contain hidden regions. JBPNote - must also check
105 * that compactAlignment resolves to a set of SeqCigars - or construct them
108 * @param compactAlignment
111 public static AlignmentI createAlignment(CigarArray compactAlignment)
113 throw new Error("Alignment(CigarArray) not yet implemented");
114 // this(compactAlignment.refCigars);
120 * @return DOCUMENT ME!
123 public List<SequenceI> getSequences()
129 public List<SequenceI> getSequences(
130 Map<SequenceI, SequenceCollectionI> hiddenReps)
132 // TODO: in jalview 2.8 we don't do anything with hiddenreps - fix design to
138 public SequenceI[] getSequencesArray()
140 if (sequences == null)
142 synchronized (sequences)
144 return sequences.toArray(new SequenceI[sequences.size()]);
154 * @return DOCUMENT ME!
157 public SequenceI getSequenceAt(int i)
159 synchronized (sequences)
161 if (i > -1 && i < sequences.size())
163 return sequences.get(i);
170 * Adds a sequence to the alignment. Recalculates maxLength and size.
175 public void addSequence(SequenceI snew)
179 // maintain dataset integrity
180 if (snew.getDatasetSequence() != null)
182 getDataset().addSequence(snew.getDatasetSequence());
186 // derive new sequence
187 SequenceI adding = snew.deriveSequence();
188 getDataset().addSequence(adding.getDatasetSequence());
192 if (sequences == null)
194 initAlignment(new SequenceI[]
199 synchronized (sequences)
204 if (hiddenSequences != null)
205 hiddenSequences.adjustHeightSequenceAdded();
209 * Adds a sequence to the alignment. Recalculates maxLength and size.
214 public void setSequenceAt(int i, SequenceI snew)
216 SequenceI oldseq = getSequenceAt(i);
218 synchronized (sequences)
220 sequences.set(i, snew);
227 * @return DOCUMENT ME!
230 public List<SequenceGroup> getGroups()
236 public void finalize()
238 if (getDataset() != null)
239 getDataset().removeAlignmentRef();
245 hiddenSequences = null;
249 * decrement the alignmentRefs counter by one and call finalize if it goes to
252 private void removeAlignmentRef()
254 if (--alignmentRefs == 0)
267 public void deleteSequence(SequenceI s)
269 deleteSequence(findIndex(s));
279 public void deleteSequence(int i)
281 if (i > -1 && i < getHeight())
283 synchronized (sequences)
287 hiddenSequences.adjustHeightSequenceDeleted(i);
294 * @see jalview.datamodel.AlignmentI#findGroup(jalview.datamodel.SequenceI)
297 public SequenceGroup findGroup(SequenceI s)
299 synchronized (groups)
301 for (int i = 0; i < this.groups.size(); i++)
303 SequenceGroup sg = groups.get(i);
305 if (sg.getSequences(null).contains(s))
318 * jalview.datamodel.AlignmentI#findAllGroups(jalview.datamodel.SequenceI)
321 public SequenceGroup[] findAllGroups(SequenceI s)
323 ArrayList<SequenceGroup> temp = new ArrayList<SequenceGroup>();
325 synchronized (groups)
327 int gSize = groups.size();
328 for (int i = 0; i < gSize; i++)
330 SequenceGroup sg = groups.get(i);
331 if (sg == null || sg.getSequences(null) == null)
333 this.deleteGroup(sg);
338 if (sg.getSequences(null).contains(s))
344 SequenceGroup[] ret = new SequenceGroup[temp.size()];
345 return temp.toArray(ret);
350 public void addGroup(SequenceGroup sg)
352 synchronized (groups)
354 if (!groups.contains(sg))
356 if (hiddenSequences.getSize() > 0)
358 int i, iSize = sg.getSize();
359 for (i = 0; i < iSize; i++)
361 if (!sequences.contains(sg.getSequenceAt(i)))
363 sg.deleteSequence(sg.getSequenceAt(i), false);
369 if (sg.getSize() < 1)
381 * remove any annotation that references gp
384 * (if null, removes all group associated annotation)
386 private void removeAnnotationForGroup(SequenceGroup gp)
388 if (annotations == null || annotations.length == 0)
392 // remove annotation very quickly
393 AlignmentAnnotation[] t, todelete = new AlignmentAnnotation[annotations.length], tokeep = new AlignmentAnnotation[annotations.length];
397 for (i = 0, p = 0, k = 0; i < annotations.length; i++)
399 if (annotations[i].groupRef != null)
401 todelete[p++] = annotations[i];
405 tokeep[k++] = annotations[i];
411 for (i = 0, p = 0, k = 0; i < annotations.length; i++)
413 if (annotations[i].groupRef == gp)
415 todelete[p++] = annotations[i];
419 tokeep[k++] = annotations[i];
425 // clear out the group associated annotation.
426 for (i = 0; i < p; i++)
428 unhookAnnotation(todelete[i]);
431 t = new AlignmentAnnotation[k];
432 for (i = 0; i < k; i++)
441 public void deleteAllGroups()
443 synchronized (groups)
445 if (annotations != null)
447 removeAnnotationForGroup(null);
455 public void deleteGroup(SequenceGroup g)
457 synchronized (groups)
459 if (groups.contains(g))
461 removeAnnotationForGroup(g);
469 public SequenceI findName(String name)
471 return findName(name, false);
477 * @see jalview.datamodel.AlignmentI#findName(java.lang.String, boolean)
480 public SequenceI findName(String token, boolean b)
482 return findName(null, token, b);
488 * @see jalview.datamodel.AlignmentI#findName(SequenceI, java.lang.String,
492 public SequenceI findName(SequenceI startAfter, String token, boolean b)
497 String sqname = null;
498 if (startAfter != null)
500 // try to find the sequence in the alignment
501 boolean matched = false;
502 while (i < sequences.size())
504 if (getSequenceAt(i++) == startAfter)
515 while (i < sequences.size())
517 sq = getSequenceAt(i);
518 sqname = sq.getName();
519 if (sqname.equals(token) // exact match
520 || (b && // allow imperfect matches - case varies
521 (sqname.equalsIgnoreCase(token))))
523 return getSequenceAt(i);
533 public SequenceI[] findSequenceMatch(String name)
535 Vector matches = new Vector();
538 while (i < sequences.size())
540 if (getSequenceAt(i).getName().equals(name))
542 matches.addElement(getSequenceAt(i));
547 SequenceI[] result = new SequenceI[matches.size()];
548 for (i = 0; i < result.length; i++)
550 result[i] = (SequenceI) matches.elementAt(i);
560 * @see jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SequenceI)
563 public int findIndex(SequenceI s)
567 while (i < sequences.size())
569 if (s == getSequenceAt(i))
584 * jalview.datamodel.AlignmentI#findIndex(jalview.datamodel.SearchResults)
587 public int findIndex(SearchResults results)
591 while (i < sequences.size())
593 if (results.involvesSequence(getSequenceAt(i)))
605 * @return DOCUMENT ME!
608 public int getHeight()
610 return sequences.size();
616 * @return DOCUMENT ME!
619 public int getWidth()
623 for (int i = 0; i < sequences.size(); i++)
625 if (getSequenceAt(i).getLength() > maxLength)
627 maxLength = getSequenceAt(i).getLength();
641 public void setGapCharacter(char gc)
644 synchronized (sequences)
646 for (SequenceI seq : sequences)
648 seq.setSequence(seq.getSequenceAsString().replace('.', gc)
649 .replace('-', gc).replace(' ', gc));
657 * @return DOCUMENT ME!
660 public char getGapCharacter()
668 * @see jalview.datamodel.AlignmentI#isAligned()
671 public boolean isAligned()
673 return isAligned(false);
679 * @see jalview.datamodel.AlignmentI#isAligned(boolean)
682 public boolean isAligned(boolean includeHidden)
684 int width = getWidth();
685 if (hiddenSequences == null || hiddenSequences.getSize() == 0)
687 includeHidden = true; // no hidden sequences to check against.
689 for (int i = 0; i < sequences.size(); i++)
691 if (includeHidden || !hiddenSequences.isHidden(getSequenceAt(i)))
693 if (getSequenceAt(i).getLength() != width)
706 * @seejalview.datamodel.AlignmentI#deleteAnnotation(jalview.datamodel.
707 * AlignmentAnnotation)
710 public boolean deleteAnnotation(AlignmentAnnotation aa)
712 return deleteAnnotation(aa, true);
716 public boolean deleteAnnotation(AlignmentAnnotation aa, boolean unhook)
720 if (annotations != null)
722 aSize = annotations.length;
730 AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize - 1];
732 boolean swap = false;
735 for (int i = 0; i < aSize; i++)
737 if (annotations[i] == aa)
742 if (tIndex < temp.length)
743 temp[tIndex++] = annotations[i];
751 unhookAnnotation(aa);
758 * remove any object references associated with this annotation
762 private void unhookAnnotation(AlignmentAnnotation aa)
764 if (aa.sequenceRef != null)
766 aa.sequenceRef.removeAlignmentAnnotation(aa);
768 if (aa.groupRef != null)
770 // probably need to do more here in the future (post 2.5.0)
778 * @seejalview.datamodel.AlignmentI#addAnnotation(jalview.datamodel.
779 * AlignmentAnnotation)
782 public void addAnnotation(AlignmentAnnotation aa)
784 addAnnotation(aa, -1);
790 * @seejalview.datamodel.AlignmentI#addAnnotation(jalview.datamodel.
791 * AlignmentAnnotation, int)
794 public void addAnnotation(AlignmentAnnotation aa, int pos)
796 if (aa.getRNAStruc() != null)
798 hasRNAStructure = true;
802 if (annotations != null)
804 aSize = annotations.length + 1;
807 AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize];
809 if (pos == -1 || pos >= aSize)
811 temp[aSize - 1] = aa;
820 for (i = 0; i < (aSize - 1); i++, p++)
828 temp[p] = annotations[i];
837 public void setAnnotationIndex(AlignmentAnnotation aa, int index)
839 if (aa == null || annotations == null || annotations.length - 1 < index)
844 int aSize = annotations.length;
845 AlignmentAnnotation[] temp = new AlignmentAnnotation[aSize];
849 for (int i = 0; i < aSize; i++)
858 temp[i] = annotations[i];
862 temp[i] = annotations[i - 1];
871 * returns all annotation on the alignment
873 public AlignmentAnnotation[] getAlignmentAnnotation()
879 public void setNucleotide(boolean b)
892 public boolean isNucleotide()
894 if (type == NUCLEOTIDE)
905 public boolean hasRNAStructure()
907 // TODO can it happen that structure is removed from alignment?
908 return hasRNAStructure;
912 public void setDataset(Alignment data)
914 if (dataset == null && data == null)
916 // Create a new dataset for this alignment.
917 // Can only be done once, if dataset is not null
918 // This will not be performed
919 SequenceI[] seqs = new SequenceI[getHeight()];
920 SequenceI currentSeq;
921 for (int i = 0; i < getHeight(); i++)
923 currentSeq = getSequenceAt(i);
924 if (currentSeq.getDatasetSequence() != null)
926 seqs[i] = currentSeq.getDatasetSequence();
930 seqs[i] = currentSeq.createDatasetSequence();
934 dataset = new Alignment(seqs);
936 else if (dataset == null && data != null)
940 dataset.addAlignmentRef();
944 * reference count for number of alignments referencing this one.
946 int alignmentRefs = 0;
949 * increase reference count to this alignment.
951 private void addAlignmentRef()
957 public Alignment getDataset()
963 public boolean padGaps()
965 boolean modified = false;
967 // Remove excess gaps from the end of alignment
971 for (int i = 0; i < sequences.size(); i++)
973 current = getSequenceAt(i);
974 for (int j = current.getLength(); j > maxLength; j--)
977 && !jalview.util.Comparison.isGap(current.getCharAt(j)))
988 for (int i = 0; i < sequences.size(); i++)
990 current = getSequenceAt(i);
991 cLength = current.getLength();
993 if (cLength < maxLength)
995 current.insertCharAt(cLength, maxLength - cLength, gapCharacter);
998 else if (current.getLength() > maxLength)
1000 current.deleteChars(maxLength, current.getLength());
1007 * Justify the sequences to the left or right by deleting and inserting gaps
1008 * before the initial residue or after the terminal residue
1011 * true if alignment padded to right, false to justify to left
1012 * @return true if alignment was changed
1015 public boolean justify(boolean right)
1017 boolean modified = false;
1019 // Remove excess gaps from the end of alignment
1021 int ends[] = new int[sequences.size() * 2];
1023 for (int i = 0; i < sequences.size(); i++)
1025 current = getSequenceAt(i);
1026 // This should really be a sequence method
1027 ends[i * 2] = current.findIndex(current.getStart());
1028 ends[i * 2 + 1] = current.findIndex(current.getStart()
1029 + current.getLength());
1030 boolean hitres = false;
1031 for (int j = 0, rs = 0, ssiz = current.getLength(); j < ssiz; j++)
1033 if (!jalview.util.Comparison.isGap(current.getCharAt(j)))
1042 ends[i * 2 + 1] = j;
1043 if (j - ends[i * 2] > maxLength)
1045 maxLength = j - ends[i * 2];
1053 // now edit the flanking gaps to justify to either left or right
1054 int cLength, extent, diff;
1055 for (int i = 0; i < sequences.size(); i++)
1057 current = getSequenceAt(i);
1059 cLength = 1 + ends[i * 2 + 1] - ends[i * 2];
1060 diff = maxLength - cLength; // number of gaps to indent
1061 extent = current.getLength();
1065 if (extent > ends[i * 2 + 1])
1067 current.deleteChars(ends[i * 2 + 1] + 1, extent);
1070 if (ends[i * 2] > diff)
1072 current.deleteChars(0, ends[i * 2] - diff);
1077 if (ends[i * 2] < diff)
1079 current.insertCharAt(0, diff - ends[i * 2], gapCharacter);
1087 if (ends[i * 2] > 0)
1089 current.deleteChars(0, ends[i * 2]);
1091 ends[i * 2 + 1] -= ends[i * 2];
1092 extent -= ends[i * 2];
1094 if (extent > maxLength)
1096 current.deleteChars(maxLength + 1, extent);
1101 if (extent < maxLength)
1103 current.insertCharAt(extent, maxLength - extent, gapCharacter);
1113 public HiddenSequences getHiddenSequences()
1115 return hiddenSequences;
1119 public CigarArray getCompactAlignment()
1121 synchronized (sequences)
1123 SeqCigar alseqs[] = new SeqCigar[sequences.size()];
1125 for (SequenceI seq : sequences)
1127 alseqs[i++] = new SeqCigar(seq);
1129 CigarArray cal = new CigarArray(alseqs);
1130 cal.addOperation(CigarArray.M, getWidth());
1136 public void setProperty(Object key, Object value)
1138 if (alignmentProperties == null)
1139 alignmentProperties = new Hashtable();
1141 alignmentProperties.put(key, value);
1145 public Object getProperty(Object key)
1147 if (alignmentProperties != null)
1148 return alignmentProperties.get(key);
1154 public Hashtable getProperties()
1156 return alignmentProperties;
1159 AlignedCodonFrame[] codonFrameList = null;
1165 * jalview.datamodel.AlignmentI#addCodonFrame(jalview.datamodel.AlignedCodonFrame
1169 public void addCodonFrame(AlignedCodonFrame codons)
1173 if (codonFrameList == null)
1175 codonFrameList = new AlignedCodonFrame[]
1179 AlignedCodonFrame[] t = new AlignedCodonFrame[codonFrameList.length + 1];
1180 System.arraycopy(codonFrameList, 0, t, 0, codonFrameList.length);
1181 t[codonFrameList.length] = codons;
1188 * @see jalview.datamodel.AlignmentI#getCodonFrame(int)
1191 public AlignedCodonFrame getCodonFrame(int index)
1193 return codonFrameList[index];
1200 * jalview.datamodel.AlignmentI#getCodonFrame(jalview.datamodel.SequenceI)
1203 public AlignedCodonFrame[] getCodonFrame(SequenceI seq)
1205 if (seq == null || codonFrameList == null)
1207 Vector cframes = new Vector();
1208 for (int f = 0; f < codonFrameList.length; f++)
1210 if (codonFrameList[f].involvesSequence(seq))
1211 cframes.addElement(codonFrameList[f]);
1213 if (cframes.size() == 0)
1215 AlignedCodonFrame[] cfr = new AlignedCodonFrame[cframes.size()];
1216 cframes.copyInto(cfr);
1223 * @see jalview.datamodel.AlignmentI#getCodonFrames()
1226 public AlignedCodonFrame[] getCodonFrames()
1228 return codonFrameList;
1234 * @seejalview.datamodel.AlignmentI#removeCodonFrame(jalview.datamodel.
1235 * AlignedCodonFrame)
1238 public boolean removeCodonFrame(AlignedCodonFrame codons)
1240 if (codons == null || codonFrameList == null)
1242 boolean removed = false;
1243 int i = 0, iSize = codonFrameList.length;
1246 if (codonFrameList[i] == codons)
1251 System.arraycopy(codonFrameList, i + 1, codonFrameList, i, iSize
1265 public void append(AlignmentI toappend)
1267 if (toappend == this)
1269 System.err.println("Self append may cause a deadlock.");
1271 // TODO test this method for a future 2.5 release
1272 // currently tested for use in jalview.gui.SequenceFetcher
1273 boolean samegap = toappend.getGapCharacter() == getGapCharacter();
1274 char oldc = toappend.getGapCharacter();
1275 boolean hashidden = toappend.getHiddenSequences() != null
1276 && toappend.getHiddenSequences().hiddenSequences != null;
1277 // get all sequences including any hidden ones
1278 List<SequenceI> sqs = (hashidden) ? toappend.getHiddenSequences()
1279 .getFullAlignment().getSequences() : toappend.getSequences();
1284 for (SequenceI addedsq : sqs)
1288 char[] oldseq = addedsq.getSequence();
1289 for (int c = 0; c < oldseq.length; c++)
1291 if (oldseq[c] == oldc)
1293 oldseq[c] = gapCharacter;
1297 addSequence(addedsq);
1301 AlignmentAnnotation[] alan = toappend.getAlignmentAnnotation();
1302 for (int a = 0; alan != null && a < alan.length; a++)
1304 addAnnotation(alan[a]);
1306 AlignedCodonFrame[] acod = toappend.getCodonFrames();
1307 for (int a = 0; acod != null && a < acod.length; a++)
1309 this.addCodonFrame(acod[a]);
1311 List<SequenceGroup> sg = toappend.getGroups();
1314 for (SequenceGroup _sg : sg)
1319 if (toappend.getHiddenSequences() != null)
1321 HiddenSequences hs = toappend.getHiddenSequences();
1322 if (hiddenSequences == null)
1324 hiddenSequences = new HiddenSequences(this);
1326 if (hs.hiddenSequences != null)
1328 for (int s = 0; s < hs.hiddenSequences.length; s++)
1330 // hide the newly appended sequence in the alignment
1331 if (hs.hiddenSequences[s] != null)
1333 hiddenSequences.hideSequence(hs.hiddenSequences[s]);
1338 if (toappend.getProperties() != null)
1340 // we really can't do very much here - just try to concatenate strings
1341 // where property collisions occur.
1342 Enumeration key = toappend.getProperties().keys();
1343 while (key.hasMoreElements())
1345 Object k = key.nextElement();
1346 Object ourval = this.getProperty(k);
1347 Object toapprop = toappend.getProperty(k);
1350 if (ourval.getClass().equals(toapprop.getClass())
1351 && !ourval.equals(toapprop))
1353 if (ourval instanceof String)
1356 this.setProperty(k, ((String) ourval) + "; "
1357 + ((String) toapprop));
1361 if (ourval instanceof Vector)
1364 Enumeration theirv = ((Vector) toapprop).elements();
1365 while (theirv.hasMoreElements())
1367 ((Vector) ourval).addElement(theirv);
1375 // just add new property directly
1376 setProperty(k, toapprop);
1384 public AlignmentAnnotation findOrCreateAnnotation(String name,
1385 String calcId, boolean autoCalc, SequenceI seqRef,
1386 SequenceGroup groupRef)
1388 assert (name != null);
1389 if (annotations != null)
1391 for (AlignmentAnnotation annot : getAlignmentAnnotation())
1393 if (annot.autoCalculated == autoCalc && (name.equals(annot.label))
1394 && (calcId == null || annot.getCalcId().equals(calcId))
1395 && annot.sequenceRef == seqRef
1396 && annot.groupRef == groupRef)
1402 AlignmentAnnotation annot = new AlignmentAnnotation(name, name,
1403 new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH);
1404 annot.hasText = false;
1405 annot.setCalcId(new String(calcId));
1406 annot.autoCalculated = autoCalc;
1409 annot.setSequenceRef(seqRef);
1411 annot.groupRef = groupRef;
1412 addAnnotation(annot);
1418 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1420 ArrayList<AlignmentAnnotation> aa = new ArrayList<AlignmentAnnotation>();
1421 for (AlignmentAnnotation a : getAlignmentAnnotation())
1423 if (a.getCalcId() == calcId
1424 || (a.getCalcId() != null && calcId != null && a.getCalcId()
1434 public void moveSelectedSequencesByOne(SequenceGroup sg,
1435 Map<SequenceI, SequenceCollectionI> map, boolean up)
1437 synchronized (sequences)
1442 for (int i = 1, iSize = sequences.size(); i < iSize; i++)
1444 SequenceI seq = sequences.get(i);
1445 if (!sg.getSequences(map).contains(seq))
1450 SequenceI temp = sequences.get(i - 1);
1451 if (sg.getSequences(null).contains(temp))
1456 sequences.set(i, temp);
1457 sequences.set(i - 1, seq);
1462 for (int i = sequences.size() - 2; i > -1; i--)
1464 SequenceI seq = sequences.get(i);
1465 if (!sg.getSequences(map).contains(seq))
1470 SequenceI temp = sequences.get(i + 1);
1471 if (sg.getSequences(map).contains(temp))
1476 sequences.set(i, temp);
1477 sequences.set(i + 1, seq);
1484 public void validateAnnotation(AlignmentAnnotation alignmentAnnotation)
1486 alignmentAnnotation.validateRangeAndDisplay();
1487 if (isNucleotide() && alignmentAnnotation.isValidStruc())
1489 hasRNAStructure = true;
1493 public int getEndRes()
1495 return getWidth()-1;
1497 public int getStartRes()