Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.datamodel

File SequenceI.java

 

Coverage histogram

../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
6
1
1
658
106
3
0.5
6
1
3

Classes

Class Line # Actions
SequenceI 41 6 3
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.datamodel;
22   
23    import java.util.BitSet;
24    import java.util.Iterator;
25    import java.util.List;
26    import java.util.Vector;
27   
28    import fr.orsay.lri.varna.models.rna.RNA;
29    import jalview.datamodel.Sequence.DBModList;
30    import jalview.datamodel.features.SequenceFeaturesI;
31    import jalview.util.MapList;
32    import jalview.ws.params.InvalidArgumentException;
33   
34    /**
35    * Methods for manipulating a sequence, its metadata and related annotation in
36    * an alignment or dataset.
37    *
38    * @author $author$
39    * @version $Revision$
40    */
 
41    public interface SequenceI extends ASequenceI, ContactMapHolderI
42    {
43    /**
44    * Set the display name for the sequence
45    *
46    * @param name
47    */
48    public void setName(String name);
49   
50    public HiddenMarkovModel getHMM();
51   
52    public void setHMM(HiddenMarkovModel hmm);
53    /**
54    * Get the display name
55    */
56    public String getName();
57   
58    /**
59    * Set start position of first non-gapped symbol in sequence
60    *
61    * @param start
62    * new start position
63    */
64    public void setStart(int start);
65   
66    /**
67    * get start position of first non-gapped residue in sequence
68    *
69    * @return
70    */
71    public int getStart();
72   
73    /**
74    * get the displayed id of the sequence
75    *
76    * @return true means the id will be returned in the form
77    * DisplayName/Start-End
78    */
79    public String getDisplayId(boolean jvsuffix);
80   
81    /**
82    * set end position for last residue in sequence
83    *
84    * @param end
85    */
86    public void setEnd(int end);
87   
88    /**
89    * get end position for last residue in sequence getEnd()>getStart() unless
90    * sequence only consists of gap characters
91    *
92    * @return
93    */
94    public int getEnd();
95   
96    /**
97    * @return length of sequence including gaps
98    *
99    */
100    public int getLength();
101   
102    /**
103    * Replace the sequence with the given characters
104    *
105    * @param sequence
106    * new sequence characters
107    */
108    public void setSequence(char[] sequence);
109   
110    /**
111    * Replace the sequence with the given string
112    *
113    * @param sequence
114    * new sequence string
115    */
116    public void setSequence(String sequence);
117   
118    /**
119    * @return sequence as string
120    */
121    public String getSequenceAsString();
122   
123    /**
124    * get a range on the sequence as a string
125    *
126    * @param start
127    * (inclusive) position relative to start of sequence including gaps
128    * (from 0)
129    * @param end
130    * (exclusive) position relative to start of sequence including gaps
131    * (from 0)
132    *
133    * @return String containing all gap and symbols in specified range
134    */
135    public String getSequenceAsString(int start, int end);
136   
137    /**
138    * Answers a copy of the sequence as a character array
139    *
140    * @return
141    */
142    public char[] getSequence();
143   
144    /**
145    * get stretch of sequence characters in an array
146    *
147    * @param start
148    * absolute index into getSequence()
149    * @param end
150    * exclusive index of last position in segment to be returned.
151    *
152    * @return char[max(0,end-start)];
153    */
154    public char[] getSequence(int start, int end);
155   
156    /**
157    * create a new sequence object with a subsequence of this one but sharing the
158    * same dataset sequence
159    *
160    * @param start
161    * int index for start position (base 0, inclusive)
162    * @param end
163    * int index for end position (base 0, exclusive)
164    *
165    * @return SequenceI
166    * @note implementations may use getSequence to get the sequence data
167    */
168    public SequenceI getSubSequence(int start, int end);
169   
170    /**
171    * get the i'th character in this sequence's local reference frame (ie from
172    * 0-number of characters lying from start-end)
173    *
174    * @param i
175    * index
176    * @return character or ' '
177    */
178    public char getCharAt(int i);
179   
180    /**
181    * DOCUMENT ME!
182    *
183    * @param desc
184    * DOCUMENT ME!
185    */
186    public void setDescription(String desc);
187   
188    /**
189    * DOCUMENT ME!
190    *
191    * @return DOCUMENT ME!
192    */
193    public String getDescription();
194   
195    /**
196    * Return the alignment column (from 1..) for a sequence position
197    *
198    * @param pos
199    * lying from start to end
200    *
201    * @return aligned column for residue (0 if residue is upstream from
202    * alignment, -1 if residue is downstream from alignment) note.
203    * Sequence object returns sequence.getEnd() for positions upstream
204    * currently. TODO: change sequence for
205    * assert(findIndex(seq.getEnd()+1)==-1) and fix incremental bugs
206    *
207    */
208    public int findIndex(int pos);
209   
210    /**
211    * Returns the sequence position for an alignment (column) position. If at a
212    * gap, returns the position of the next residue to the right. If beyond the
213    * end of the sequence, returns 1 more than the last residue position.
214    *
215    * @param i
216    * column index in alignment (from 0..<length)
217    *
218    * @return
219    */
220    public int findPosition(int i);
221   
222    /**
223    * Returns the sequence positions for first and last residues lying within the
224    * given column positions [fromColum,toColumn] (where columns are numbered
225    * from 1), or null if no residues are included in the range
226    *
227    * @param fromColum
228    * - first column base 1. (0 and negative positions are rounded up)
229    * @param toColumn
230    * - last column, base 1
231    * @return null if fromColum>toColumn
232    */
233    public ContiguousI findPositions(int fromColum, int toColumn);
234   
235    /**
236    * Returns an int array where indices correspond to each residue in the
237    * sequence and the element value gives its position in the alignment
238    *
239    * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
240    * residues in SequenceI object
241    */
242    public int[] gapMap();
243   
244    /**
245    * Build a bitset corresponding to sequence gaps
246    *
247    * @return a BitSet where set values correspond to gaps in the sequence
248    */
249    public BitSet gapBitset();
250   
251    /**
252    * Returns an int array where indices correspond to each position in sequence
253    * char array and the element value gives the result of findPosition for that
254    * index in the sequence.
255    *
256    * @return int[SequenceI.getLength()]
257    */
258    public int[] findPositionMap();
259   
260    /**
261    * Answers true if the sequence is composed of amino acid characters. Note
262    * that implementations may use heuristic methods which are not guaranteed to
263    * give the biologically 'right' answer.
264    *
265    * @return
266    */
267    public boolean isProtein();
268   
269    /**
270    * Delete a range of aligned sequence columns, creating a new dataset sequence
271    * if necessary and adjusting start and end positions accordingly.
272    *
273    * @param i
274    * first column in range to delete (inclusive)
275    * @param j
276    * last column in range to delete (exclusive)
277    */
278    public void deleteChars(int i, int j);
279   
280    /**
281    * DOCUMENT ME!
282    *
283    * @param i
284    * alignment column number
285    * @param c
286    * character to insert
287    */
288    public void insertCharAt(int i, char c);
289   
290    /**
291    * insert given character at alignment column position
292    *
293    * @param position
294    * alignment column number
295    * @param count
296    * length of insert
297    * @param ch
298    * character to insert
299    */
300    public void insertCharAt(int position, int count, char ch);
301   
302    /**
303    * Answers a list of all sequence features associated with this sequence. The
304    * list may be held by the sequence's dataset sequence if that is defined.
305    *
306    * @return
307    */
308    public List<SequenceFeature> getSequenceFeatures();
309   
310    /**
311    * Answers the object holding features for the sequence
312    *
313    * @return
314    */
315    SequenceFeaturesI getFeatures();
316   
317    /**
318    * Replaces the sequence features associated with this sequence with the given
319    * features. If this sequence has a dataset sequence, then this method will
320    * update the dataset sequence's features instead.
321    *
322    * @param features
323    */
324    public void setSequenceFeatures(List<SequenceFeature> features);
325   
326    /**
327    * DOCUMENT ME!
328    *
329    * @param id
330    * DOCUMENT ME!
331    */
332    public void setPDBId(Vector<PDBEntry> ids);
333   
334    /**
335    * Returns a list
336    *
337    * @return DOCUMENT ME!
338    */
339    public Vector<PDBEntry> getAllPDBEntries();
340   
341    /**
342    * Adds the entry to the *normalised* list of PDBIds.
343    *
344    * If a PDBEntry is passed with the same entry.getID() string as one already
345    * in the list, or one is added that appears to be the same but has a chain ID
346    * appended, then the existing PDBEntry will be updated with the new
347    * attributes instead, unless the entries have distinct chain codes or
348    * associated structure files.
349    *
350    * @param entry
351    * @return true if the entry was added, false if updated
352    */
353    public boolean addPDBId(PDBEntry entry);
354   
355    /**
356    * update the list of PDBEntrys to include any DBRefEntrys citing structural
357    * databases
358    *
359    * @return true if PDBEntry list was modified
360    */
361    public boolean updatePDBIds();
362   
363    public String getVamsasId();
364   
365    public void setVamsasId(String id);
366   
367    /**
368    * set the array of Database references for the sequence.
369    *
370    * BH 2019.02.04 changes param to DBModlist
371    *
372    * @param dbs
373    * @deprecated - use is discouraged since side-effects may occur if DBRefEntry
374    * set are not normalised.
375    * @throws InvalidArgumentException if the is not one created by Sequence itself
376    */
377    @Deprecated
378    public void setDBRefs(DBModList<DBRefEntry> dbs);
379   
380    public DBModList<DBRefEntry> getDBRefs();
381   
382    /**
383    * add the given entry to the list of DBRefs for this sequence, or replace a
384    * similar one if entry contains a map object and the existing one doesnt.
385    *
386    * @param entry
387    */
388    public void addDBRef(DBRefEntry entry);
389   
390    /**
391    * Adds the given sequence feature and returns true, or returns false if it is
392    * already present on the sequence, or if the feature type is null.
393    *
394    * @param sf
395    * @return
396    */
397    public boolean addSequenceFeature(SequenceFeature sf);
398   
399    public void deleteFeature(SequenceFeature sf);
400   
401    public void setDatasetSequence(SequenceI seq);
402   
403    public SequenceI getDatasetSequence();
404   
405    /**
406    * Returns the top grandparent in the dataset sequences hierarchy
407    * or null if there is no dataset associated with this sequence.
408    */
 
409  4 toggle public default SequenceI getRootDatasetSequence()
410    {
411  4 if (getDatasetSequence() == null)
412    {
413  1 return null;
414    }
415  3 var sequence = getDatasetSequence();
416  4 while (sequence.getDatasetSequence() != null)
417    {
418  1 sequence = sequence.getDatasetSequence();
419    }
420  3 return sequence;
421    }
422   
423    /**
424    * Returns a new array containing this sequence's annotations, or null.
425    */
426    public AlignmentAnnotation[] getAnnotation();
427   
428    /**
429    * Returns true if this sequence has the given annotation (by object
430    * identity).
431    */
432    public boolean hasAnnotation(AlignmentAnnotation ann);
433   
434    /**
435    * Add the given annotation, if not already added, and set its sequence ref to
436    * be this sequence. Does nothing if this sequence's annotations already
437    * include this annotation (by identical object reference).
438    */
439    public void addAlignmentAnnotation(AlignmentAnnotation annotation);
440   
441    public void removeAlignmentAnnotation(AlignmentAnnotation annotation);
442   
443    /**
444    * Derive a sequence (using this one's dataset or as the dataset)
445    *
446    * @return duplicate sequence and any annotation present with valid dataset
447    * sequence
448    */
449    public SequenceI deriveSequence();
450   
451    /**
452    * set the array of associated AlignmentAnnotation for this sequenceI
453    *
454    * @param revealed
455    */
456    public void setAlignmentAnnotation(AlignmentAnnotation[] annotation);
457   
458    /**
459    * Get one or more alignment annotations with a particular label.
460    *
461    * @param label
462    * string which each returned annotation must have as a label.
463    * @return null or array of annotations.
464    */
465    public AlignmentAnnotation[] getAnnotation(String label);
466   
467    /**
468    * Returns a (possibly empty) list of any annotations that match on given
469    * calcId (source) and label (type). Null values do not match.
470    *
471    * @param calcId
472    * @param label
473    */
474    public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
475    String label);
476   
477    /**
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.
481    *
482    * @param calcId
483    * @param label
484    * @param description
485    */
486    public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
487    String label, String description);
488    /**
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).
494    *
495    * @return dataset sequence for this sequence
496    */
497    public SequenceI createDatasetSequence();
498   
499    /**
500    * Transfer any database references or annotation from entry under a sequence
501    * mapping. <br/>
502    * <strong>Note: DOES NOT transfer sequence associated alignment annotation
503    * </strong><br/>
504    *
505    * @param entry
506    * @param mp
507    * null or mapping from entry's numbering to local start/end
508    */
509    public void transferAnnotation(SequenceI entry, Mapping mp);
510   
511    /**
512    * @return The RNA of the sequence in the alignment
513    */
514   
515    public RNA getRNA();
516   
517    /**
518    * @param rna
519    * The RNA.
520    */
521    public void setRNA(RNA rna);
522   
523    /**
524    *
525    * @return list of insertions (gap characters) in sequence
526    */
527    public List<int[]> getInsertions();
528   
529    /**
530    * Given a pdbId String, return the equivalent PDBEntry if available in the
531    * given sequence
532    *
533    * @param pdbId
534    * @return
535    */
536    public PDBEntry getPDBEntry(String pdbId);
537   
538    /**
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.
542    *
543    * @return just the primary references (if any) for this sequence, or an empty
544    * list
545    */
546    public List<DBRefEntry> getPrimaryDBRefs();
547    /**
548    * Answers true if the sequence has annotation for Hidden Markov Model
549    * information content, else false
550    */
551    boolean hasHMMAnnotation();
552   
553    /**
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).
558    *
559    * @param fromCol
560    * start column of range inclusive (1..)
561    * @param toCol
562    * end column of range inclusive (1..)
563    * @param types
564    * optional feature types to restrict results to
565    * @return
566    */
567    List<SequenceFeature> findFeatures(int fromCol, int toCol, String... types);
568   
569    /**
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.
573    */
574    void sequenceChanged();
575   
576    /**
577    *
578    * @return BitSet corresponding to index [0,length) where Comparison.isGap()
579    * returns true.
580    */
581    BitSet getInsertionsAsBits();
582   
583    /**
584    * Replaces every occurrence of c1 in the sequence with c2 and returns the
585    * number of characters changed
586    *
587    * @param c1
588    * @param c2
589    */
590    public int replace(char c1, char c2);
591   
592    /**
593    * Answers the GeneLociI, or null if not known
594    *
595    * @return
596    */
597    GeneLociI getGeneLoci();
598   
599    /**
600    * Sets the mapping to gene loci for the sequence
601    *
602    * @param speciesId
603    * @param assemblyId
604    * @param chromosomeId
605    * @param map
606    */
607    void setGeneLoci(String speciesId, String assemblyId,
608    String chromosomeId, MapList map);
609   
610   
611    /**
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
615    *
616    * @param it
617    * the iterator to use
618    * @return a String corresponding to the sequence
619    */
620    public String getSequenceStringFromIterator(Iterator<int[]> it);
621   
622    /**
623    * Locate the first position in this sequence which is not contained in an
624    * iterator region. If no such position exists, return 0
625    *
626    * @param it
627    * iterator over regions
628    * @return first residue not contained in regions
629    */
630    public int firstResidueOutsideIterator(Iterator<int[]> it);
631   
632    public void addContactListFor(AlignmentAnnotation annotation,
633    ContactMatrixI cm);
634   
635    /**
636    * efficiently insert a char at several different places
637    * @param c
638    * @param inserts
639    */
640    void insertInserts(char c, int[]... inserts);
641   
642    /**
643    * make a single insert in this sequence, but do not call sequenceChanged()
644    * WARNING - CALLERS RESPONSIBILITY TO CALL sequenceChanged() AFTER THIS!
645    * @param i
646    * @param length
647    * @param c
648    */
649    void doInsert(int i, int length, char c);
650   
651    /**
652    * Answers true if this sequence has an associated Hidden Markov Model
653    *
654    * @return
655    */
656    boolean hasHMMProfile();
657    }
658