X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=3a79ac60c5eaa2136a42dd659ce6df699766bb07;hb=ceba202c97c435a5a0f70307961ba74316bd8312;hp=1956df7f10be8f6664575bbf5d92b8f94ca124c0;hpb=97761a98a97b49dcdf65e574aeff21f62f8a70b7;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 1956df7..3a79ac6 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -47,7 +47,7 @@ import java.util.Vector; * @author JimP * */ -public class Alignment implements AlignmentI +public class Alignment implements AlignmentI, AutoCloseable { private Alignment dataset; @@ -292,6 +292,32 @@ public class Alignment implements AlignmentI } /** + * 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! @@ -303,15 +329,20 @@ public class Alignment implements AlignmentI } @Override - public void finalize() throws Throwable + public void close() { if (getDataset() != null) { - getDataset().removeAlignmentRef(); + try + { + getDataset().removeAlignmentRef(); + } catch (Throwable e) + { + e.printStackTrace(); + } } nullReferences(); - super.finalize(); } /** @@ -586,7 +617,8 @@ public class Alignment implements AlignmentI @Override public SequenceI findName(SequenceI startAfter, String token, boolean b) { - + if (token == null) + return null; int i = 0; SequenceI sq = null; String sqname = null; @@ -1600,34 +1632,50 @@ public class Alignment implements AlignmentI 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; } @@ -2027,4 +2075,18 @@ public class Alignment implements AlignmentI } } + @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; + } }