2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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 jalview.datamodel.Sequence.DBModList;
24 import jalview.datamodel.features.SequenceFeaturesI;
25 import jalview.util.MapList;
26 import jalview.ws.params.InvalidArgumentException;
28 import java.util.BitSet;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Vector;
33 import fr.orsay.lri.varna.models.rna.RNA;
36 * Methods for manipulating a sequence, its metadata and related annotation in
37 * an alignment or dataset.
42 public interface SequenceI extends ASequenceI
45 * Set the display name for the sequence
49 public void setName(String name);
51 public HiddenMarkovModel getHMM();
53 public void setHMM(HiddenMarkovModel hmm);
55 * Get the display name
57 public String getName();
60 * Set start position of first non-gapped symbol in sequence
65 public void setStart(int start);
68 * get start position of first non-gapped residue in sequence
72 public int getStart();
75 * get the displayed id of the sequence
77 * @return true means the id will be returned in the form
78 * DisplayName/Start-End
80 public String getDisplayId(boolean jvsuffix);
83 * set end position for last residue in sequence
87 public void setEnd(int end);
90 * get end position for last residue in sequence getEnd()>getStart() unless
91 * sequence only consists of gap characters
98 * @return length of sequence including gaps
101 public int getLength();
104 * Replace the sequence with the given characters
107 * new sequence characters
109 public void setSequence(char[] sequence);
112 * Replace the sequence with the given string
115 * new sequence string
117 public void setSequence(String sequence);
120 * @return sequence as string
122 public String getSequenceAsString();
125 * get a range on the sequence as a string
128 * (inclusive) position relative to start of sequence including gaps
131 * (exclusive) position relative to start of sequence including gaps
134 * @return String containing all gap and symbols in specified range
136 public String getSequenceAsString(int start, int end);
139 * Answers a copy of the sequence as a character array
143 public char[] getSequence();
146 * get stretch of sequence characters in an array
149 * absolute index into getSequence()
151 * exclusive index of last position in segment to be returned.
153 * @return char[max(0,end-start)];
155 public char[] getSequence(int start, int end);
158 * create a new sequence object with a subsequence of this one but sharing the
159 * same dataset sequence
162 * int index for start position (base 0, inclusive)
164 * int index for end position (base 0, exclusive)
167 * @note implementations may use getSequence to get the sequence data
169 public SequenceI getSubSequence(int start, int end);
172 * get the i'th character in this sequence's local reference frame (ie from
173 * 0-number of characters lying from start-end)
177 * @return character or ' '
179 public char getCharAt(int i);
187 public void setDescription(String desc);
192 * @return DOCUMENT ME!
194 public String getDescription();
197 * Return the alignment column (from 1..) for a sequence position
200 * lying from start to end
202 * @return aligned column for residue (0 if residue is upstream from
203 * alignment, -1 if residue is downstream from alignment) note.
204 * Sequence object returns sequence.getEnd() for positions upstream
205 * currently. TODO: change sequence for
206 * assert(findIndex(seq.getEnd()+1)==-1) and fix incremental bugs
209 public int findIndex(int pos);
212 * Returns the sequence position for an alignment (column) position. If at a
213 * gap, returns the position of the next residue to the right. If beyond the
214 * end of the sequence, returns 1 more than the last residue position.
217 * column index in alignment (from 0..<length)
221 public int findPosition(int i);
224 * Returns the sequence positions for first and last residues lying within the
225 * given column positions [fromColum,toColumn] (where columns are numbered
226 * from 1), or null if no residues are included in the range
229 * - first column base 1. (0 and negative positions are rounded up)
231 * - last column, base 1
232 * @return null if fromColum>toColumn
234 public ContiguousI findPositions(int fromColum, int toColumn);
237 * Returns an int array where indices correspond to each residue in the
238 * sequence and the element value gives its position in the alignment
240 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
241 * residues in SequenceI object
243 public int[] gapMap();
246 * Build a bitset corresponding to sequence gaps
248 * @return a BitSet where set values correspond to gaps in the sequence
250 public BitSet gapBitset();
253 * Returns an int array where indices correspond to each position in sequence
254 * char array and the element value gives the result of findPosition for that
255 * index in the sequence.
257 * @return int[SequenceI.getLength()]
259 public int[] findPositionMap();
262 * Answers true if the sequence is composed of amino acid characters. Note
263 * that implementations may use heuristic methods which are not guaranteed to
264 * give the biologically 'right' answer.
268 public boolean isProtein();
271 * Delete a range of aligned sequence columns, creating a new dataset sequence
272 * if necessary and adjusting start and end positions accordingly.
275 * first column in range to delete (inclusive)
277 * last column in range to delete (exclusive)
279 public void deleteChars(int i, int j);
285 * alignment column number
287 * character to insert
289 public void insertCharAt(int i, char c);
292 * insert given character at alignment column position
295 * alignment column number
299 * character to insert
301 public void insertCharAt(int position, int count, char ch);
304 * Answers a list of all sequence features associated with this sequence. The
305 * list may be held by the sequence's dataset sequence if that is defined.
309 public List<SequenceFeature> getSequenceFeatures();
312 * Answers the object holding features for the sequence
316 SequenceFeaturesI getFeatures();
319 * Replaces the sequence features associated with this sequence with the given
320 * features. If this sequence has a dataset sequence, then this method will
321 * update the dataset sequence's features instead.
325 public void setSequenceFeatures(List<SequenceFeature> features);
333 public void setPDBId(Vector<PDBEntry> ids);
338 * @return DOCUMENT ME!
340 public Vector<PDBEntry> getAllPDBEntries();
343 * Adds the entry to the *normalised* list of PDBIds.
345 * If a PDBEntry is passed with the same entry.getID() string as one already
346 * in the list, or one is added that appears to be the same but has a chain ID
347 * appended, then the existing PDBEntry will be updated with the new
348 * attributes instead, unless the entries have distinct chain codes or
349 * associated structure files.
352 * @return true if the entry was added, false if updated
354 public boolean addPDBId(PDBEntry entry);
357 * update the list of PDBEntrys to include any DBRefEntrys citing structural
360 * @return true if PDBEntry list was modified
362 public boolean updatePDBIds();
364 public String getVamsasId();
366 public void setVamsasId(String id);
369 * set the array of Database references for the sequence.
371 * BH 2019.02.04 changes param to DBModlist
374 * @deprecated - use is discouraged since side-effects may occur if DBRefEntry
375 * set are not normalised.
376 * @throws InvalidArgumentException if the is not one created by Sequence itself
379 public void setDBRefs(DBModList<DBRefEntry> dbs);
381 public DBModList<DBRefEntry> getDBRefs();
384 * add the given entry to the list of DBRefs for this sequence, or replace a
385 * similar one if entry contains a map object and the existing one doesnt.
389 public void addDBRef(DBRefEntry entry);
392 * Adds the given sequence feature and returns true, or returns false if it is
393 * already present on the sequence, or if the feature type is null.
398 public boolean addSequenceFeature(SequenceFeature sf);
400 public void deleteFeature(SequenceFeature sf);
402 public void setDatasetSequence(SequenceI seq);
404 public SequenceI getDatasetSequence();
407 * Returns the top grandparent in the dataset sequences hierarchy
408 * or null if there is no dataset associated with this sequence.
410 public default SequenceI getRootDatasetSequence()
412 if (getDatasetSequence() == null)
416 var sequence = getDatasetSequence();
417 while (sequence.getDatasetSequence() != null)
419 sequence = sequence.getDatasetSequence();
425 * Returns a new array containing this sequence's annotations, or null.
427 public AlignmentAnnotation[] getAnnotation();
430 * Returns true if this sequence has the given annotation (by object
433 public boolean hasAnnotation(AlignmentAnnotation ann);
436 * Add the given annotation, if not already added, and set its sequence ref to
437 * be this sequence. Does nothing if this sequence's annotations already
438 * include this annotation (by identical object reference).
440 public void addAlignmentAnnotation(AlignmentAnnotation annotation);
442 public void removeAlignmentAnnotation(AlignmentAnnotation annotation);
445 * Derive a sequence (using this one's dataset or as the dataset)
447 * @return duplicate sequence with valid dataset sequence
449 public SequenceI deriveSequence();
452 * set the array of associated AlignmentAnnotation for this sequenceI
456 public void setAlignmentAnnotation(AlignmentAnnotation[] annotation);
459 * Get one or more alignment annotations with a particular label.
462 * string which each returned annotation must have as a label.
463 * @return null or array of annotations.
465 public AlignmentAnnotation[] getAnnotation(String label);
468 * Returns a (possibly empty) list of any annotations that match on given
469 * calcId (source) and label (type). Null values do not match.
474 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
478 * Returns a (possibly empty) list of any annotations that match on given
479 * calcId (source), label (type) and description (observation instance).
480 * Null values do not match.
486 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
487 String label, String description);
489 * create a new dataset sequence (if necessary) for this sequence and sets
490 * this sequence to refer to it. This call will move any features or
491 * references on the sequence onto the dataset. It will also make a duplicate
492 * of existing annotation rows for the dataset sequence, rather than relocate
493 * them in order to preserve external references (since 2.8.2).
495 * @return dataset sequence for this sequence
497 public SequenceI createDatasetSequence();
500 * Transfer any database references or annotation from entry under a sequence
502 * <strong>Note: DOES NOT transfer sequence associated alignment annotation
507 * null or mapping from entry's numbering to local start/end
509 public void transferAnnotation(SequenceI entry, Mapping mp);
512 * @return The RNA of the sequence in the alignment
521 public void setRNA(RNA rna);
525 * @return list of insertions (gap characters) in sequence
527 public List<int[]> getInsertions();
530 * Given a pdbId String, return the equivalent PDBEntry if available in the
536 public PDBEntry getPDBEntry(String pdbId);
539 * Get all primary database/accessions for this sequence's data. These
540 * DBRefEntry are expected to resolve to a valid record in the associated
541 * external database, either directly or via a provided 1:1 Mapping.
543 * @return just the primary references (if any) for this sequence, or an empty
546 public List<DBRefEntry> getPrimaryDBRefs();
548 * Answers true if the sequence has annotation for Hidden Markov Model
549 * information content, else false
551 boolean hasHMMAnnotation();
554 * Returns a (possibly empty) list of sequence features that overlap the given
555 * alignment column range, optionally restricted to one or more specified
556 * feature types. If the range is all gaps, then features which enclose it are
557 * included (but not contact features).
560 * start column of range inclusive (1..)
562 * end column of range inclusive (1..)
564 * optional feature types to restrict results to
567 List<SequenceFeature> findFeatures(int fromCol, int toCol, String... types);
570 * Method to call to indicate that the sequence (characters or alignment/gaps)
571 * has been modified. Provided to allow any cursors on residue/column
572 * positions to be invalidated.
574 void sequenceChanged();
578 * @return BitSet corresponding to index [0,length) where Comparison.isGap()
581 BitSet getInsertionsAsBits();
584 * Replaces every occurrence of c1 in the sequence with c2 and returns the
585 * number of characters changed
590 public int replace(char c1, char c2);
593 * Answers the GeneLociI, or null if not known
597 GeneLociI getGeneLoci();
600 * Sets the mapping to gene loci for the sequence
604 * @param chromosomeId
607 void setGeneLoci(String speciesId, String assemblyId,
608 String chromosomeId, MapList map);
612 * Returns the sequence string constructed from the substrings of a sequence
613 * defined by the int[] ranges provided by an iterator. E.g. the iterator
614 * could iterate over all visible regions of the alignment
617 * the iterator to use
618 * @return a String corresponding to the sequence
620 public String getSequenceStringFromIterator(Iterator<int[]> it);
623 * Locate the first position in this sequence which is not contained in an
624 * iterator region. If no such position exists, return 0
627 * iterator over regions
628 * @return first residue not contained in regions
630 public int firstResidueOutsideIterator(Iterator<int[]> it);
634 * Answers true if this sequence has an associated Hidden Markov Model
638 boolean hasHMMProfile();