X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=5232f8e4370609161f49d1d83e1b5e849e64a1f4;hb=bbc8fc127287ad3a11f0b470d37d741ddca162ff;hp=3b0ca46f83e01ac83aae1e3c7116fc5b1a09f71a;hpb=f3fa435d421eb9f071a526f802801c4a21ee2dc4;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 3b0ca46..5232f8e 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -195,6 +195,7 @@ public class Alignment implements AlignmentI, AutoCloseable { synchronized (sequences) { + if (i > -1 && i < sequences.size()) { return sequences.get(i); @@ -291,6 +292,32 @@ public class Alignment implements AlignmentI, AutoCloseable } /** + * Inserts a sequence at a point in the alignment. + * + * @param i + * the index of the position the sequence is to be inserted in. + */ + @Override + public void insertSequenceAt(int i, SequenceI snew) + { + synchronized (sequences) + { + if (sequences.size() > i) + { + sequences.add(i, snew); + return; + + } + else + { + sequences.add(snew); + hiddenSequences.adjustHeightSequenceAdded(); + } + return; + } + } + + /** * DOCUMENT ME! * * @return DOCUMENT ME! @@ -590,15 +617,17 @@ public class Alignment implements AlignmentI, AutoCloseable @Override public SequenceI findName(SequenceI startAfter, String token, boolean b) { - + if (token == null) + return null; int i = 0; SequenceI sq = null; String sqname = null; + int nseq = sequences.size(); if (startAfter != null) { // try to find the sequence in the alignment boolean matched = false; - while (i < sequences.size()) + while (i < nseq) { if (getSequenceAt(i++) == startAfter) { @@ -611,7 +640,7 @@ public class Alignment implements AlignmentI, AutoCloseable i = 0; } } - while (i < sequences.size()) + while (i < nseq) { sq = getSequenceAt(i); sqname = sq.getName(); @@ -714,7 +743,7 @@ public class Alignment implements AlignmentI, AutoCloseable public int getWidth() { int maxLength = -1; - + for (int i = 0; i < sequences.size(); i++) { maxLength = Math.max(maxLength, getSequenceAt(i).getLength()); @@ -1193,7 +1222,8 @@ public class Alignment implements AlignmentI, AutoCloseable int maxLength = -1; SequenceI current; - for (int i = 0; i < sequences.size(); i++) + int nseq = sequences.size(); + for (int i = 0; i < nseq; i++) { current = getSequenceAt(i); for (int j = current.getLength(); j > maxLength; j--) @@ -1210,7 +1240,7 @@ public class Alignment implements AlignmentI, AutoCloseable maxLength++; int cLength; - for (int i = 0; i < sequences.size(); i++) + for (int i = 0; i < nseq; i++) { current = getSequenceAt(i); cLength = current.getLength(); @@ -1602,34 +1632,50 @@ public class Alignment implements AlignmentI, AutoCloseable String calcId, boolean autoCalc, SequenceI seqRef, SequenceGroup groupRef) { - if (annotations != null) + AlignmentAnnotation annot = annotations == null ? null + : AlignmentAnnotation.findFirstAnnotation( + Arrays.asList(getAlignmentAnnotation()), name, calcId, + autoCalc, seqRef, groupRef); + + if (annot == null) { - for (AlignmentAnnotation annot : getAlignmentAnnotation()) + + annot = new AlignmentAnnotation(name, name, new Annotation[1], 0f, 0f, + AlignmentAnnotation.BAR_GRAPH); + annot.hasText = false; + if (calcId != null) { - if (annot.autoCalculated == autoCalc && (name.equals(annot.label)) - && (calcId == null || annot.getCalcId().equals(calcId)) - && annot.sequenceRef == seqRef - && annot.groupRef == groupRef) - { - return annot; - } + annot.setCalcId(calcId); } + annot.autoCalculated = autoCalc; + if (seqRef != null) + { + annot.setSequenceRef(seqRef); + } + annot.groupRef = groupRef; + addAnnotation(annot); } - AlignmentAnnotation annot = new AlignmentAnnotation(name, name, - new Annotation[1], 0f, 0f, AlignmentAnnotation.BAR_GRAPH); - annot.hasText = false; - if (calcId != null) + return annot; + } + + + @Override + public AlignmentAnnotation updateFromOrCopyAnnotation( + AlignmentAnnotation ala) + { + AlignmentAnnotation annot = AlignmentAnnotation.findFirstAnnotation( + Arrays.asList(getAlignmentAnnotation()), ala.label, ala.calcId, + ala.autoCalculated, ala.sequenceRef, ala.groupRef); + if (annot == null) { - annot.setCalcId(new String(calcId)); + annot = new AlignmentAnnotation(ala); + addAnnotation(annot); } - annot.autoCalculated = autoCalc; - if (seqRef != null) + else { - annot.setSequenceRef(seqRef); + annot.updateAlignmentAnnotationFrom(ala); } - annot.groupRef = groupRef; - addAnnotation(annot); - + validateAnnotation(annot); return annot; } @@ -2029,4 +2075,18 @@ public class Alignment implements AlignmentI, AutoCloseable } } + @Override + public List getHmmSequences() + { + List result = new ArrayList<>(); + for (int i = 0; i < sequences.size(); i++) + { + SequenceI seq = sequences.get(i); + if (seq.hasHMMProfile()) + { + result.add(seq); + } + } + return result; + } }