X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=42303660de8a07b5f50bd7454509edaf43460a2d;hb=bea1d9b563d2fea018de3dbde9112dd59149126e;hp=950ee0515ce493393a9051afae74a768749d6eac;hpb=17e4ea278bc9a5fb280db1252ce78b7a295215f5;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 950ee05..4230366 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -27,6 +27,7 @@ import jalview.util.Comparison; import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.util.StringUtils; +import jalview.workers.InformationThread; import java.util.ArrayList; import java.util.Arrays; @@ -82,6 +83,9 @@ public class Sequence extends ASequence implements SequenceI private String vamsasId; + HiddenMarkovModel hmm; + + boolean isHMMConsensusSequence = false; private DBModList dbrefs; // controlled access /** @@ -254,6 +258,21 @@ public class Sequence extends ASequence implements SequenceI } /** + * Create a new sequence object from a characters array using default values + * of 1 and -1 for start and end. The array used to create the sequence is + * copied and is not stored internally. + * + * @param name + * sequence name + * @param sequence + * list of residues + */ + public Sequence(String name, char[] sequence) + { + this(name, Arrays.copyOf(sequence, sequence.length), 1, -1); + } + + /** * Creates a new Sequence object with new AlignmentAnnotations but inherits * any existing dataset sequence reference. If non exists, everything is * copied. @@ -361,6 +380,10 @@ public class Sequence extends ASequence implements SequenceI this.addPDBId(new PDBEntry(pdb)); } } + if (seq.getHMM() != null) + { + this.hmm = new HiddenMarkovModel(seq.getHMM(), this); + } } @Override @@ -472,18 +495,19 @@ public class Sequence extends ASequence implements SequenceI } /** - * DOCUMENT ME! + * Answers the sequence name, with '/start-end' appended if jvsuffix is true * - * @return DOCUMENT ME! + * @return */ @Override public String getDisplayId(boolean jvsuffix) { - StringBuffer result = new StringBuffer(name); - if (jvsuffix) + if (!jvsuffix) { - result.append("/" + start + "-" + end); + return name; } + StringBuilder result = new StringBuilder(name); + result.append("/").append(start).append("-").append(end); return result.toString(); } @@ -522,6 +546,7 @@ public class Sequence extends ASequence implements SequenceI public void setStart(int start) { this.start = start; + sequenceChanged(); } /** @@ -1067,7 +1092,8 @@ public class Sequence extends ASequence implements SequenceI @Override public ContiguousI findPositions(int fromColumn, int toColumn) { - if (toColumn < fromColumn || fromColumn < 1) + fromColumn = Math.max(fromColumn, 1); + if (toColumn < fromColumn) { return null; } @@ -1413,6 +1439,7 @@ public class Sequence extends ASequence implements SequenceI @Override public void addDBRef(DBRefEntry entry) { + // TODO JAL-3980 maintain as sorted list if (datasetSequence != null) { datasetSequence.addDBRef(entry); @@ -1423,6 +1450,7 @@ public class Sequence extends ASequence implements SequenceI { dbrefs = new DBModList<>(); } + // TODO JAL-3979 LOOK UP RATHER THAN SWEEP FOR EFFICIENCY for (int ib = 0, nb = dbrefs.size(); ib < nb; ib++) { @@ -1797,13 +1825,30 @@ public class Sequence extends ASequence implements SequenceI public List getAlignmentAnnotations(String calcId, String label) { + return getAlignmentAnnotations(calcId, label, null, true); + } + + @Override + public List getAlignmentAnnotations(String calcId, + String label, String description) + { + return getAlignmentAnnotations(calcId, label, description, false); + } + + private List getAlignmentAnnotations(String calcId, + String label, String description, boolean ignoreDescription) + { List result = new ArrayList<>(); if (this.annotation != null) { for (AlignmentAnnotation ann : annotation) { - if (ann.calcId != null && ann.calcId.equals(calcId) - && ann.label != null && ann.label.equals(label)) + String id = ann.getCalcId(); + if ((id != null && id.equals(calcId)) + && (ann.label != null && ann.label.equals(label)) + && ((ignoreDescription && description == null) + || (ann.description != null + && ann.description.equals(description)))) { result.add(ann); } @@ -1922,6 +1967,33 @@ public class Sequence extends ASequence implements SequenceI } } + @Override + public HiddenMarkovModel getHMM() + { + return hmm; + } + + @Override + public void setHMM(HiddenMarkovModel hmm) + { + this.hmm = hmm; + } + + @Override + public boolean hasHMMAnnotation() + { + if (this.annotation == null) { + return false; + } + for (AlignmentAnnotation ann : annotation) + { + if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId())) + { + return true; + } + } + return false; + } /** * {@inheritDoc} */ @@ -1935,15 +2007,6 @@ public class Sequence extends ASequence implements SequenceI List result = getFeatures().findFeatures(startPos, endPos, types); - if (datasetSequence != null) - { - result = datasetSequence.getFeatures().findFeatures(startPos, endPos, - types); - } - else - { - result = sequenceFeatureStore.findFeatures(startPos, endPos, types); - } /* * if end column is gapped, endPos may be to the right, @@ -2095,4 +2158,10 @@ public class Sequence extends ASequence implements SequenceI // otherwise, sequence was completely hidden return 0; } + + @Override + public boolean hasHMMProfile() + { + return hmm != null; + } }