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.analysis.AlignSeq;
24 import jalview.api.DBRefEntryI;
25 import jalview.datamodel.features.SequenceFeatures;
26 import jalview.datamodel.features.SequenceFeaturesI;
27 import jalview.util.Comparison;
28 import jalview.util.DBRefUtils;
29 import jalview.util.MapList;
30 import jalview.util.StringUtils;
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.Collections;
35 import java.util.Enumeration;
36 import java.util.List;
37 import java.util.ListIterator;
38 import java.util.Vector;
40 import com.stevesoft.pat.Regex;
42 import fr.orsay.lri.varna.models.rna.RNA;
46 * Implements the SequenceI interface for a char[] based sequence object.
51 public class Sequence extends ASequence implements SequenceI
53 private static final Regex limitrx = new Regex(
54 "[/][0-9]{1,}[-][0-9]{1,}$");
56 private static final Regex endrx = new Regex("[0-9]{1,}$");
58 SequenceI datasetSequence;
62 private char[] sequence;
70 Vector<PDBEntry> pdbIds;
79 * This annotation is displayed below the alignment but the positions are tied
80 * to the residues of this sequence
82 * TODO: change to List<>
84 Vector<AlignmentAnnotation> annotation;
87 * The index of the sequence in a MSA
91 private SequenceFeatures sequenceFeatureStore;
94 * Creates a new Sequence object.
99 * string to form a possibly gapped sequence out of
101 * first position of non-gap residue in the sequence
103 * last position of ungapped residues (nearly always only used for
106 public Sequence(String name, String sequence, int start, int end)
109 initSeqAndName(name, sequence.toCharArray(), start, end);
112 public Sequence(String name, char[] sequence, int start, int end)
115 initSeqAndName(name, sequence, start, end);
119 * Stage 1 constructor - assign name, sequence, and set start and end fields.
120 * start and end are updated values from name2 if it ends with /start-end
127 protected void initSeqAndName(String name2, char[] sequence2, int start2,
131 this.sequence = sequence2;
143 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
146 // Does sequence have the /start-end signature?
147 if (limitrx.search(name))
149 name = limitrx.left();
150 endrx.search(limitrx.stringMatched());
151 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
152 endrx.matchedFrom() - 1)));
153 setEnd(Integer.parseInt(endrx.stringMatched()));
157 void checkValidRange()
160 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
163 for (int j = 0; j < sequence.length; j++)
165 if (!jalview.util.Comparison.isGap(sequence[j]))
184 * default constructor
188 sequenceFeatureStore = new SequenceFeatures();
192 * Creates a new Sequence object.
199 public Sequence(String name, String sequence)
201 this(name, sequence, 1, -1);
205 * Creates a new Sequence object with new AlignmentAnnotations but inherits
206 * any existing dataset sequence reference. If non exists, everything is
210 * if seq is a dataset sequence, behaves like a plain old copy
213 public Sequence(SequenceI seq)
215 this(seq, seq.getAnnotation());
219 * Create a new sequence object with new features, DBRefEntries, and PDBIds
220 * but inherits any existing dataset sequence reference, and duplicate of any
221 * annotation that is present in the given annotation array.
224 * the sequence to be copied
225 * @param alAnnotation
226 * an array of annotation including some associated with seq
228 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
231 initSeqFrom(seq, alAnnotation);
235 * does the heavy lifting when cloning a dataset sequence, or coping data from
236 * dataset to a new derived sequence.
239 * - source of attributes.
240 * @param alAnnotation
241 * - alignment annotation present on seq that should be copied onto
244 protected void initSeqFrom(SequenceI seq,
245 AlignmentAnnotation[] alAnnotation)
247 char[] oseq = seq.getSequence();
248 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
249 seq.getStart(), seq.getEnd());
251 description = seq.getDescription();
252 if (seq != datasetSequence)
254 setDatasetSequence(seq.getDatasetSequence());
258 * only copy DBRefs and seqfeatures if we really are a dataset sequence
260 if (datasetSequence == null)
262 if (seq.getDBRefs() != null)
264 DBRefEntry[] dbr = seq.getDBRefs();
265 for (int i = 0; i < dbr.length; i++)
267 addDBRef(new DBRefEntry(dbr[i]));
272 * make copies of any sequence features
274 for (SequenceFeature sf : seq.getSequenceFeatures())
276 addSequenceFeature(new SequenceFeature(sf));
280 if (seq.getAnnotation() != null)
282 AlignmentAnnotation[] sqann = seq.getAnnotation();
283 for (int i = 0; i < sqann.length; i++)
285 if (sqann[i] == null)
289 boolean found = (alAnnotation == null);
292 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
294 found = (alAnnotation[apos] == sqann[i]);
299 // only copy the given annotation
300 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
301 addAlignmentAnnotation(newann);
305 if (seq.getAllPDBEntries() != null)
307 Vector<PDBEntry> ids = seq.getAllPDBEntries();
308 for (PDBEntry pdb : ids)
310 this.addPDBId(new PDBEntry(pdb));
316 public void setSequenceFeatures(List<SequenceFeature> features)
318 if (datasetSequence != null)
320 datasetSequence.setSequenceFeatures(features);
323 sequenceFeatureStore = new SequenceFeatures(features);
327 public synchronized boolean addSequenceFeature(SequenceFeature sf)
329 if (sf.getType() == null)
331 System.err.println("SequenceFeature type may not be null: "
336 if (datasetSequence != null)
338 return datasetSequence.addSequenceFeature(sf);
341 return sequenceFeatureStore.add(sf);
345 public void deleteFeature(SequenceFeature sf)
347 if (datasetSequence != null)
349 datasetSequence.deleteFeature(sf);
353 sequenceFeatureStore.delete(sf);
363 public List<SequenceFeature> getSequenceFeatures()
365 if (datasetSequence != null)
367 return datasetSequence.getSequenceFeatures();
369 return sequenceFeatureStore.getAllFeatures();
373 public SequenceFeaturesI getFeatures()
375 return datasetSequence != null ? datasetSequence.getFeatures()
376 : sequenceFeatureStore;
380 public boolean addPDBId(PDBEntry entry)
384 pdbIds = new Vector<PDBEntry>();
389 for (PDBEntry pdbe : pdbIds)
391 if (pdbe.updateFrom(entry))
396 pdbIds.addElement(entry);
407 public void setPDBId(Vector<PDBEntry> id)
415 * @return DOCUMENT ME!
418 public Vector<PDBEntry> getAllPDBEntries()
420 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
426 * @return DOCUMENT ME!
429 public String getDisplayId(boolean jvsuffix)
431 StringBuffer result = new StringBuffer(name);
434 result.append("/" + start + "-" + end);
437 return result.toString();
447 public void setName(String name)
456 * @return DOCUMENT ME!
459 public String getName()
471 public void setStart(int start)
479 * @return DOCUMENT ME!
482 public int getStart()
494 public void setEnd(int end)
502 * @return DOCUMENT ME!
513 * @return DOCUMENT ME!
516 public int getLength()
518 return this.sequence.length;
528 public void setSequence(String seq)
530 this.sequence = seq.toCharArray();
535 public String getSequenceAsString()
537 return new String(sequence);
541 public String getSequenceAsString(int start, int end)
543 return new String(getSequence(start, end));
547 public char[] getSequence()
555 * @see jalview.datamodel.SequenceI#getSequence(int, int)
558 public char[] getSequence(int start, int end)
564 // JBPNote - left to user to pad the result here (TODO:Decide on this
566 if (start >= sequence.length)
571 if (end >= sequence.length)
573 end = sequence.length;
576 char[] reply = new char[end - start];
577 System.arraycopy(sequence, start, reply, 0, end - start);
583 public SequenceI getSubSequence(int start, int end)
589 char[] seq = getSequence(start, end);
594 int nstart = findPosition(start);
595 int nend = findPosition(end) - 1;
596 // JBPNote - this is an incomplete copy.
597 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
598 nseq.setDescription(description);
599 if (datasetSequence != null)
601 nseq.setDatasetSequence(datasetSequence);
605 nseq.setDatasetSequence(this);
611 * Returns the character of the aligned sequence at the given position (base
612 * zero), or space if the position is not within the sequence's bounds
617 public char getCharAt(int i)
619 if (i >= 0 && i < sequence.length)
636 public void setDescription(String desc)
638 this.description = desc;
644 * @return DOCUMENT ME!
647 public String getDescription()
649 return this.description;
655 * @see jalview.datamodel.SequenceI#findIndex(int)
658 public int findIndex(int pos)
660 // returns the alignment position for a residue
663 // Rely on end being at least as long as the length of the sequence.
664 while ((i < sequence.length) && (j <= end) && (j <= pos))
666 if (!Comparison.isGap(sequence[i]))
674 if ((j == end) && (j < pos))
685 public int findPosition(int i)
689 int seqlen = sequence.length;
690 while ((j < i) && (j < seqlen))
692 if (!Comparison.isGap(sequence[j]))
704 * Returns an int array where indices correspond to each residue in the
705 * sequence and the element value gives its position in the alignment
707 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
708 * residues in SequenceI object
711 public int[] gapMap()
713 String seq = jalview.analysis.AlignSeq.extractGaps(
714 jalview.util.Comparison.GapChars, new String(sequence));
715 int[] map = new int[seq.length()];
719 while (j < sequence.length)
721 if (!jalview.util.Comparison.isGap(sequence[j]))
733 public int[] findPositionMap()
735 int map[] = new int[sequence.length];
738 int seqlen = sequence.length;
742 if (!jalview.util.Comparison.isGap(sequence[j]))
753 public List<int[]> getInsertions()
755 ArrayList<int[]> map = new ArrayList<int[]>();
756 int lastj = -1, j = 0;
758 int seqlen = sequence.length;
761 if (jalview.util.Comparison.isGap(sequence[j]))
772 map.add(new int[] { lastj, j - 1 });
780 map.add(new int[] { lastj, j - 1 });
787 public void deleteChars(int i, int j)
789 int newstart = start, newend = end;
790 if (i >= sequence.length || i < 0)
795 char[] tmp = StringUtils.deleteChars(sequence, i, j);
796 boolean createNewDs = false;
797 // TODO: take a (second look) at the dataset creation validation method for
798 // the very large sequence case
799 int eindex = -1, sindex = -1;
800 boolean ecalc = false, scalc = false;
801 for (int s = i; s < j; s++)
803 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
813 sindex = findIndex(start) - 1;
818 // delete characters including start of sequence
819 newstart = findPosition(j);
820 break; // don't need to search for any more residue characters.
824 // delete characters after start.
827 eindex = findIndex(end) - 1;
832 // delete characters at end of sequence
833 newend = findPosition(i - 1);
834 break; // don't need to search for any more residue characters.
839 newend--; // decrease end position by one for the deleted residue
840 // and search further
846 // deletion occured in the middle of the sequence
847 if (createNewDs && this.datasetSequence != null)
849 // construct a new sequence
850 Sequence ds = new Sequence(datasetSequence);
851 // TODO: remove any non-inheritable properties ?
852 // TODO: create a sequence mapping (since there is a relation here ?)
853 ds.deleteChars(i, j);
854 datasetSequence = ds;
862 public void insertCharAt(int i, int length, char c)
864 char[] tmp = new char[sequence.length + length];
866 if (i >= sequence.length)
868 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
873 System.arraycopy(sequence, 0, tmp, 0, i);
883 if (i < sequence.length)
885 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
892 public void insertCharAt(int i, char c)
894 insertCharAt(i, 1, c);
898 public String getVamsasId()
904 public void setVamsasId(String id)
910 public void setDBRefs(DBRefEntry[] dbref)
912 if (dbrefs == null && datasetSequence != null
913 && this != datasetSequence)
915 datasetSequence.setDBRefs(dbref);
921 DBRefUtils.ensurePrimaries(this);
926 public DBRefEntry[] getDBRefs()
928 if (dbrefs == null && datasetSequence != null
929 && this != datasetSequence)
931 return datasetSequence.getDBRefs();
937 public void addDBRef(DBRefEntry entry)
939 if (datasetSequence != null)
941 datasetSequence.addDBRef(entry);
947 dbrefs = new DBRefEntry[0];
950 for (DBRefEntryI dbr : dbrefs)
952 if (dbr.updateFrom(entry))
955 * found a dbref that either matched, or could be
956 * updated from, the new entry - no need to add it
963 * extend the array to make room for one more
965 // TODO use an ArrayList instead
966 int j = dbrefs.length;
967 DBRefEntry[] temp = new DBRefEntry[j + 1];
968 System.arraycopy(dbrefs, 0, temp, 0, j);
969 temp[temp.length - 1] = entry;
973 DBRefUtils.ensurePrimaries(this);
977 public void setDatasetSequence(SequenceI seq)
981 throw new IllegalArgumentException(
982 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
984 if (seq != null && seq.getDatasetSequence() != null)
986 throw new IllegalArgumentException(
987 "Implementation error: cascading dataset sequences are not allowed.");
989 datasetSequence = seq;
993 public SequenceI getDatasetSequence()
995 return datasetSequence;
999 public AlignmentAnnotation[] getAnnotation()
1001 return annotation == null ? null : annotation
1002 .toArray(new AlignmentAnnotation[annotation.size()]);
1006 public boolean hasAnnotation(AlignmentAnnotation ann)
1008 return annotation == null ? false : annotation.contains(ann);
1012 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1014 if (this.annotation == null)
1016 this.annotation = new Vector<AlignmentAnnotation>();
1018 if (!this.annotation.contains(annotation))
1020 this.annotation.addElement(annotation);
1022 annotation.setSequenceRef(this);
1026 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1028 if (this.annotation != null)
1030 this.annotation.removeElement(annotation);
1031 if (this.annotation.size() == 0)
1033 this.annotation = null;
1039 * test if this is a valid candidate for another sequence's dataset sequence.
1042 private boolean isValidDatasetSequence()
1044 if (datasetSequence != null)
1048 for (int i = 0; i < sequence.length; i++)
1050 if (jalview.util.Comparison.isGap(sequence[i]))
1059 public SequenceI deriveSequence()
1061 Sequence seq = null;
1062 if (datasetSequence == null)
1064 if (isValidDatasetSequence())
1066 // Use this as dataset sequence
1067 seq = new Sequence(getName(), "", 1, -1);
1068 seq.setDatasetSequence(this);
1069 seq.initSeqFrom(this, getAnnotation());
1074 // Create a new, valid dataset sequence
1075 createDatasetSequence();
1078 return new Sequence(this);
1081 private boolean _isNa;
1083 private long _seqhash = 0;
1086 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1090 public boolean isProtein()
1092 if (datasetSequence != null)
1094 return datasetSequence.isProtein();
1096 if (_seqhash != sequence.hashCode())
1098 _seqhash = sequence.hashCode();
1099 _isNa = Comparison.isNucleotide(this);
1107 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1110 public SequenceI createDatasetSequence()
1112 if (datasetSequence == null)
1114 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1115 jalview.util.Comparison.GapChars, getSequenceAsString()),
1116 getStart(), getEnd());
1118 datasetSequence = dsseq;
1120 dsseq.setDescription(description);
1121 // move features and database references onto dataset sequence
1122 dsseq.sequenceFeatureStore = sequenceFeatureStore;
1123 sequenceFeatureStore = null;
1124 dsseq.dbrefs = dbrefs;
1126 // TODO: search and replace any references to this sequence with
1127 // references to the dataset sequence in Mappings on dbref
1128 dsseq.pdbIds = pdbIds;
1130 datasetSequence.updatePDBIds();
1131 if (annotation != null)
1133 // annotation is cloned rather than moved, to preserve what's currently
1135 for (AlignmentAnnotation aa : annotation)
1137 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1138 _aa.sequenceRef = datasetSequence;
1139 _aa.adjustForAlignment(); // uses annotation's own record of
1140 // sequence-column mapping
1141 datasetSequence.addAlignmentAnnotation(_aa);
1145 return datasetSequence;
1152 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1156 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1158 if (annotation != null)
1160 annotation.removeAllElements();
1162 if (annotations != null)
1164 for (int i = 0; i < annotations.length; i++)
1166 if (annotations[i] != null)
1168 addAlignmentAnnotation(annotations[i]);
1175 public AlignmentAnnotation[] getAnnotation(String label)
1177 if (annotation == null || annotation.size() == 0)
1182 Vector<AlignmentAnnotation> subset = new Vector<AlignmentAnnotation>();
1183 Enumeration<AlignmentAnnotation> e = annotation.elements();
1184 while (e.hasMoreElements())
1186 AlignmentAnnotation ann = e.nextElement();
1187 if (ann.label != null && ann.label.equals(label))
1189 subset.addElement(ann);
1192 if (subset.size() == 0)
1196 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1198 e = subset.elements();
1199 while (e.hasMoreElements())
1201 anns[i++] = e.nextElement();
1203 subset.removeAllElements();
1208 public boolean updatePDBIds()
1210 if (datasetSequence != null)
1212 // TODO: could merge DBRefs
1213 return datasetSequence.updatePDBIds();
1215 if (dbrefs == null || dbrefs.length == 0)
1219 boolean added = false;
1220 for (DBRefEntry dbr : dbrefs)
1222 if (DBRefSource.PDB.equals(dbr.getSource()))
1225 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1226 * PDB id is not already present in a 'matching' PDBEntry
1227 * Constructor parses out a chain code if appended to the accession id
1228 * (a fudge used to 'store' the chain code in the DBRef)
1230 PDBEntry pdbe = new PDBEntry(dbr);
1231 added |= addPDBId(pdbe);
1238 public void transferAnnotation(SequenceI entry, Mapping mp)
1240 if (datasetSequence != null)
1242 datasetSequence.transferAnnotation(entry, mp);
1245 if (entry.getDatasetSequence() != null)
1247 transferAnnotation(entry.getDatasetSequence(), mp);
1250 // transfer any new features from entry onto sequence
1251 if (entry.getSequenceFeatures() != null)
1254 List<SequenceFeature> sfs = entry.getSequenceFeatures();
1255 for (SequenceFeature feature : sfs)
1257 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(feature)
1258 : new SequenceFeature[] { new SequenceFeature(feature) };
1261 for (int sfi = 0; sfi < sf.length; sfi++)
1263 addSequenceFeature(sf[sfi]);
1269 // transfer PDB entries
1270 if (entry.getAllPDBEntries() != null)
1272 Enumeration<PDBEntry> e = entry.getAllPDBEntries().elements();
1273 while (e.hasMoreElements())
1275 PDBEntry pdb = e.nextElement();
1279 // transfer database references
1280 DBRefEntry[] entryRefs = entry.getDBRefs();
1281 if (entryRefs != null)
1283 for (int r = 0; r < entryRefs.length; r++)
1285 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1286 if (newref.getMap() != null && mp != null)
1288 // remap ref using our local mapping
1290 // we also assume all version string setting is done by dbSourceProxy
1292 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1293 * newref.setSource(dbSource); }
1301 * @return The index (zero-based) on this sequence in the MSA. It returns
1302 * {@code -1} if this information is not available.
1305 public int getIndex()
1311 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1312 * if this information is undefined.
1315 * position for this sequence. This value is zero-based (zero for
1316 * this first sequence)
1319 public void setIndex(int value)
1325 public void setRNA(RNA r)
1337 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1340 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1341 if (this.annotation != null)
1343 for (AlignmentAnnotation ann : annotation)
1345 if (ann.calcId != null && ann.calcId.equals(calcId)
1346 && ann.label != null && ann.label.equals(label))
1356 public String toString()
1358 return getDisplayId(false);
1362 public PDBEntry getPDBEntry(String pdbIdStr)
1364 if (getDatasetSequence() != null)
1366 return getDatasetSequence().getPDBEntry(pdbIdStr);
1372 List<PDBEntry> entries = getAllPDBEntries();
1373 for (PDBEntry entry : entries)
1375 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1384 public List<DBRefEntry> getPrimaryDBRefs()
1386 if (datasetSequence != null)
1388 return datasetSequence.getPrimaryDBRefs();
1390 if (dbrefs == null || dbrefs.length == 0)
1392 return Collections.emptyList();
1394 synchronized (dbrefs)
1396 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1397 DBRefEntry[] tmp = new DBRefEntry[1];
1398 for (DBRefEntry ref : dbrefs)
1400 if (!ref.isPrimaryCandidate())
1406 MapList mp = ref.getMap().getMap();
1407 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1409 // map only involves a subsequence, so cannot be primary
1413 // whilst it looks like it is a primary ref, we also sanity check type
1414 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1415 DBRefUtils.getCanonicalName(ref.getSource())))
1417 // PDB dbrefs imply there should be a PDBEntry associated
1418 // TODO: tighten PDB dbrefs
1419 // formally imply Jalview has actually downloaded and
1420 // parsed the pdb file. That means there should be a cached file
1421 // handle on the PDBEntry, and a real mapping between sequence and
1422 // extracted sequence from PDB file
1423 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1424 if (pdbentry != null && pdbentry.getFile() != null)
1430 // check standard protein or dna sources
1432 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1433 if (res != null && res[0] == tmp[0])
1447 public List<SequenceFeature> findFeatures(int fromColumn, int toColumn,
1450 int startPos = findPosition(fromColumn - 1); // convert base 1 to base 0
1451 int endPos = findPosition(toColumn - 1);
1453 List<SequenceFeature> result = new ArrayList<>();
1454 if (datasetSequence != null)
1456 result = datasetSequence.getFeatures().findFeatures(startPos, endPos,
1461 result = sequenceFeatureStore.findFeatures(startPos, endPos, types);
1465 * if the start or end column is gapped, startPos or endPos may be to the
1466 * left or right, and we may have included adjacent or enclosing features;
1467 * remove any that are not enclosing, non-contact features
1469 if (endPos > this.end || Comparison.isGap(sequence[fromColumn - 1])
1470 || Comparison.isGap(sequence[toColumn - 1]))
1472 ListIterator<SequenceFeature> it = result.listIterator();
1473 while (it.hasNext())
1475 SequenceFeature sf = it.next();
1476 int featureStartColumn = findIndex(sf.getBegin());
1477 int featureEndColumn = findIndex(sf.getEnd());
1478 boolean noOverlap = featureStartColumn > toColumn
1479 || featureEndColumn < fromColumn;
1482 * reject an 'enclosing' feature if it is actually a contact feature
1484 if (sf.isContactFeature() && featureStartColumn < fromColumn
1485 && featureEndColumn > toColumn)