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.AAFrequency;
24 import jalview.analysis.Conservation;
25 import jalview.renderer.ResidueShader;
26 import jalview.renderer.ResidueShaderI;
27 import jalview.schemes.ColourSchemeI;
29 import java.awt.Color;
30 import java.util.ArrayList;
31 import java.util.List;
35 * Collects a set contiguous ranges on a set of sequences
40 public class SequenceGroup implements AnnotatedCollectionI
46 Conservation conserve;
48 boolean displayBoxes = true;
50 boolean displayText = true;
52 boolean colourText = false;
54 HiddenMarkovModel hmm;
57 * True if the group is defined as a group on the alignment, false if it is
60 boolean isDefined = false;
63 * after Olivier's non-conserved only character display
65 boolean showNonconserved = false;
70 private List<SequenceI> sequences = new ArrayList<>();
73 * representative sequence for this group (if any)
75 private SequenceI seqrep = null;
80 * Colourscheme applied to group if any
82 public ResidueShaderI cs;
84 // start column (base 0)
87 // end column (base 0)
90 public Color outlineColour = Color.black;
92 public Color idColour = null;
94 public int thresholdTextColour = 0;
96 public Color textColour = Color.black;
98 public Color textColour2 = Color.white;
101 * consensus calculation property
103 private boolean ignoreGapsInConsensus = true;
105 private boolean ignoreBelowBackground = true;
108 * consensus calculation property
110 private boolean showSequenceLogo = false;
113 * flag indicating if logo should be rendered normalised
115 private boolean normaliseSequenceLogo;
118 * visibility of rows or represented rows covered by group
120 private boolean hidereps = false;
123 * visibility of columns intersecting this group
125 private boolean hidecols = false;
127 AlignmentAnnotation consensus = null;
129 AlignmentAnnotation conservation = null;
131 private boolean showConsensusHistogram;
133 private AnnotatedCollectionI context;
136 * Creates a new SequenceGroup object.
138 public SequenceGroup()
140 groupName = "JGroup:" + this.hashCode();
141 cs = new ResidueShader();
145 * Creates a new SequenceGroup object.
150 * @param displayBoxes
154 * first column of group
156 * last column of group
158 public SequenceGroup(List<SequenceI> sequences, String groupName,
159 ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
160 boolean colourText, int start, int end)
163 this.sequences = sequences;
164 this.groupName = groupName;
165 this.displayBoxes = displayBoxes;
166 this.displayText = displayText;
167 this.colourText = colourText;
168 this.cs = new ResidueShader(scheme);
171 recalcConservation();
179 public SequenceGroup(SequenceGroup seqsel)
184 sequences = new ArrayList<>();
185 sequences.addAll(seqsel.sequences);
186 if (seqsel.groupName != null)
188 groupName = new String(seqsel.groupName);
190 displayBoxes = seqsel.displayBoxes;
191 displayText = seqsel.displayText;
192 colourText = seqsel.colourText;
193 startRes = seqsel.startRes;
194 endRes = seqsel.endRes;
195 cs = new ResidueShader(seqsel.getColourScheme());
196 if (seqsel.description != null)
198 description = new String(seqsel.description);
200 hidecols = seqsel.hidecols;
201 hidereps = seqsel.hidereps;
202 showNonconserved = seqsel.showNonconserved;
203 showSequenceLogo = seqsel.showSequenceLogo;
204 normaliseSequenceLogo = seqsel.normaliseSequenceLogo;
205 showConsensusHistogram = seqsel.showConsensusHistogram;
206 idColour = seqsel.idColour;
207 outlineColour = seqsel.outlineColour;
208 seqrep = seqsel.seqrep;
209 textColour = seqsel.textColour;
210 textColour2 = seqsel.textColour2;
211 thresholdTextColour = seqsel.thresholdTextColour;
212 width = seqsel.width;
213 ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
214 ignoreBelowBackground = seqsel.ignoreBelowBackground;
215 if (seqsel.conserve != null)
217 recalcConservation(); // safer than
218 // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
223 public boolean isShowSequenceLogo()
225 return showSequenceLogo;
228 public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
230 int iSize = sequences.size();
231 SequenceI[] seqs = new SequenceI[iSize];
232 SequenceI[] inorder = getSequencesInOrder(align);
234 for (int i = 0, ipos = 0; i < inorder.length; i++)
236 SequenceI seq = inorder[i];
238 seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
239 if (seqs[ipos] != null)
241 seqs[ipos].setDescription(seq.getDescription());
242 seqs[ipos].setDBRefs(seq.getDBRefs());
243 seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
244 if (seq.getDatasetSequence() != null)
246 seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
249 if (seq.getAnnotation() != null)
251 AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
252 // Only copy annotation that is either a score or referenced by the
253 // alignment's annotation vector
254 for (int a = 0; a < seq.getAnnotation().length; a++)
256 AlignmentAnnotation tocopy = seq.getAnnotation()[a];
259 boolean found = false;
260 for (int pos = 0; pos < alann.length; pos++)
262 if (alann[pos] == tocopy)
273 AlignmentAnnotation newannot = new AlignmentAnnotation(
274 seq.getAnnotation()[a]);
275 newannot.restrict(startRes, endRes);
276 newannot.setSequenceRef(seqs[ipos]);
277 newannot.adjustForAlignment();
278 seqs[ipos].addAlignmentAnnotation(newannot);
288 if (iSize != inorder.length)
290 SequenceI[] nseqs = new SequenceI[iSize];
291 System.arraycopy(seqs, 0, nseqs, 0, iSize);
299 * If sequence ends in gaps, the end residue can be correctly calculated here
305 public int findEndRes(SequenceI seq)
310 for (int j = 0; j < endRes + 1 && j < seq.getLength(); j++)
312 ch = seq.getCharAt(j);
313 if (!jalview.util.Comparison.isGap((ch)))
321 eres += seq.getStart() - 1;
328 public List<SequenceI> getSequences()
334 public List<SequenceI> getSequences(
335 Map<SequenceI, SequenceCollectionI> hiddenReps)
337 if (hiddenReps == null)
339 // TODO: need a synchronizedCollection here ?
344 List<SequenceI> allSequences = new ArrayList<>();
345 for (SequenceI seq : sequences)
347 allSequences.add(seq);
348 if (hiddenReps.containsKey(seq))
350 SequenceCollectionI hsg = hiddenReps.get(seq);
351 for (SequenceI seq2 : hsg.getSequences())
353 if (seq2 != seq && !allSequences.contains(seq2))
355 allSequences.add(seq2);
365 public SequenceI[] getSequencesAsArray(
366 Map<SequenceI, SequenceCollectionI> map)
368 List<SequenceI> tmp = getSequences(map);
373 return tmp.toArray(new SequenceI[tmp.size()]);
382 * @return DOCUMENT ME!
384 public boolean adjustForRemoveLeft(int col)
386 // return value is true if the group still exists
389 startRes = startRes - col;
394 endRes = endRes - col;
396 if (startRes > endRes)
403 // must delete this group!!
416 * @return DOCUMENT ME!
418 public boolean adjustForRemoveRight(int col)
437 * @return DOCUMENT ME!
439 public String getName()
444 public String getDescription()
455 public void setName(String name)
458 // TODO: URGENT: update dependent objects (annotation row)
461 public void setDescription(String desc)
469 * @return DOCUMENT ME!
471 public Conservation getConservation()
482 public void setConservation(Conservation c)
488 * Add s to this sequence group. If aligment sequence is already contained in
489 * group, it will not be added again, but recalculation may happen if the flag
493 * alignment sequence to be added
495 * true means Group's conservation should be recalculated
497 public void addSequence(SequenceI s, boolean recalc)
499 synchronized (sequences)
501 if (s != null && !sequences.contains(s))
508 recalcConservation();
514 * Max Gaps Threshold (percent) for performing a conservation calculation
516 private int consPercGaps = 25;
519 * @return Max Gaps Threshold for performing a conservation calculation
521 public int getConsPercGaps()
527 * set Max Gaps Threshold (percent) for performing a conservation calculation
529 * @param consPercGaps
531 public void setConsPercGaps(int consPercGaps)
533 this.consPercGaps = consPercGaps;
537 * calculate residue conservation and colourschemes for group - but only if
538 * necessary. returns true if the calculation resulted in a visible change to
541 public boolean recalcConservation()
543 return recalcConservation(false);
547 * calculate residue conservation for group - but only if necessary. returns
548 * true if the calculation resulted in a visible change to group
551 * when set, colourschemes for this group are not refreshed after
554 public boolean recalcConservation(boolean defer)
556 if (cs == null && consensus == null && conservation == null)
560 // TODO: try harder to detect changes in state in order to minimise
561 // recalculation effort
565 ProfilesI cnsns = AAFrequency.calculate(sequences, startRes,
566 endRes + 1, showSequenceLogo);
567 if (consensus != null)
569 _updateConsensusRow(cnsns, sequences.size());
574 cs.setConsensus(cnsns);
578 if ((conservation != null)
579 || (cs != null && cs.conservationApplied()))
581 Conservation c = new Conservation(groupName, sequences, startRes,
584 c.verdict(false, consPercGaps);
585 if (conservation != null)
587 _updateConservationRow(c);
591 if (cs.conservationApplied())
593 cs.setConservation(c);
596 // eager update - will cause a refresh of overview regardless
599 if (cs != null && !defer)
601 // TODO: JAL-2034 should cs.alignmentChanged modify return state
602 cs.alignmentChanged(context != null ? context : this, null);
609 } catch (java.lang.OutOfMemoryError err)
612 System.out.println("Out of memory loading groups: " + err);
617 private void _updateConservationRow(Conservation c)
619 if (conservation == null)
624 conservation.label = "Conservation for " + getName();
625 conservation.description = "Conservation for group " + getName()
626 + " less than " + consPercGaps + "% gaps";
627 // preserve width if already set
628 int aWidth = (conservation.annotations != null) ? (endRes < conservation.annotations.length ? conservation.annotations.length
631 conservation.annotations = null;
632 conservation.annotations = new Annotation[aWidth]; // should be alignment
634 c.completeAnnotations(conservation, null, startRes, endRes + 1);
637 public ProfilesI consensusData = null;
639 private void _updateConsensusRow(ProfilesI cnsns, long nseq)
641 if (consensus == null)
645 consensus.label = "Consensus for " + getName();
646 consensus.description = "Percent Identity";
647 consensusData = cnsns;
648 // preserve width if already set
649 int aWidth = (consensus.annotations != null) ? (endRes < consensus.annotations.length ? consensus.annotations.length
652 consensus.annotations = null;
653 consensus.annotations = new Annotation[aWidth]; // should be alignment width
655 AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
656 ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting
659 // ignoreGapsInConsensusCalculation);
664 * sequence to either add or remove from group
666 * flag passed to delete/addSequence to indicate if group properties
667 * should be recalculated
669 public void addOrRemove(SequenceI s, boolean recalc)
671 synchronized (sequences)
673 if (sequences.contains(s))
675 deleteSequence(s, recalc);
679 addSequence(s, recalc);
690 * true means recalculate conservation
692 public void deleteSequence(SequenceI s, boolean recalc)
694 synchronized (sequences)
700 recalcConservation();
708 * @return the first column selected by this group. Runs from 0<=i<N_cols
711 public int getStartRes()
718 * @return the groups last selected column. Runs from 0<=i<N_cols
721 public int getEndRes()
727 * Set the first column selected by this group. Runs from 0<=i<N_cols
731 public void setStartRes(int i)
737 * Set the groups last selected column. Runs from 0<=i<N_cols
741 public void setEndRes(int i)
747 * @return number of sequences in group
751 return sequences.size();
756 * @return the ith sequence
758 public SequenceI getSequenceAt(int i)
760 return sequences.get(i);
767 public void setColourText(boolean state)
775 * @return DOCUMENT ME!
777 public boolean getColourText()
788 public void setDisplayText(boolean state)
796 * @return DOCUMENT ME!
798 public boolean getDisplayText()
809 public void setDisplayBoxes(boolean state)
811 displayBoxes = state;
817 * @return DOCUMENT ME!
819 public boolean getDisplayBoxes()
825 * computes the width of current set of sequences and returns it
827 * @return DOCUMENT ME!
830 public int getWidth()
832 synchronized (sequences)
834 // MC This needs to get reset when characters are inserted and deleted
835 boolean first = true;
836 for (SequenceI seq : sequences)
838 if (first || seq.getLength() > width)
840 width = seq.getLength();
854 public void setOutlineColour(Color c)
862 * @return DOCUMENT ME!
864 public Color getOutlineColour()
866 return outlineColour;
871 * returns the sequences in the group ordered by the ordering given by al.
872 * this used to return an array with null entries regardless, new behaviour is
873 * below. TODO: verify that this does not affect use in applet or application
877 * @return SequenceI[] intersection of sequences in group with al, ordered by
878 * al, or null if group does not intersect with al
880 public SequenceI[] getSequencesInOrder(AlignmentI al)
882 return getSequencesInOrder(al, true);
886 * return an array representing the intersection of the group with al,
887 * optionally returning an array the size of al.getHeight() where nulls mark
888 * the non-intersected sequences
892 * @return null or array
894 public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
896 synchronized (sequences)
898 int sSize = sequences.size();
899 int alHeight = al.getHeight();
901 SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
904 for (int i = 0; i < alHeight && index < sSize; i++)
906 if (sequences.contains(al.getSequenceAt(i)))
908 seqs[(trim) ? index : i] = al.getSequenceAt(i);
920 if (index < seqs.length)
922 SequenceI[] dummy = seqs;
923 seqs = new SequenceI[index];
926 seqs[index] = dummy[index];
935 * @return the idColour
937 public Color getIdColour()
944 * the idColour to set
946 public void setIdColour(Color idColour)
948 this.idColour = idColour;
952 * @return the representative sequence for this group
955 public SequenceI getSeqrep()
961 * set the representative sequence for this group. Note - this affects the
962 * interpretation of the Hidereps attribute.
965 * the seqrep to set (null means no sequence representative)
968 public void setSeqrep(SequenceI seqrep)
970 this.seqrep = seqrep;
975 * @return true if group has a sequence representative
978 public boolean hasSeqrep()
980 return seqrep != null;
984 * set visibility of sequences covered by (if no sequence representative is
985 * defined) or represented by this group.
989 public void setHidereps(boolean visibility)
991 hidereps = visibility;
996 * @return true if sequences represented (or covered) by this group should be
999 public boolean isHidereps()
1005 * set intended visibility of columns covered by this group
1009 public void setHideCols(boolean visibility)
1011 hidecols = visibility;
1016 * @return true if columns covered by group should be hidden
1018 public boolean isHideCols()
1024 * create a new sequence group from the intersection of this group with an
1025 * alignment Hashtable of hidden representatives
1031 * @return new group containing sequences common to this group and alignment
1033 public SequenceGroup intersect(AlignmentI alignment,
1034 Map<SequenceI, SequenceCollectionI> map)
1036 SequenceGroup sgroup = new SequenceGroup(this);
1037 SequenceI[] insect = getSequencesInOrder(alignment);
1038 sgroup.sequences = new ArrayList<>();
1039 for (int s = 0; insect != null && s < insect.length; s++)
1041 if (map == null || map.containsKey(insect[s]))
1043 sgroup.sequences.add(insect[s]);
1050 * @return the showUnconserved
1052 public boolean getShowNonconserved()
1054 return showNonconserved;
1058 * @param showNonconserved
1059 * the showUnconserved to set
1061 public void setShowNonconserved(boolean displayNonconserved)
1063 this.showNonconserved = displayNonconserved;
1067 * set this alignmentAnnotation object as the one used to render consensus
1072 public void setConsensus(AlignmentAnnotation aan)
1074 if (consensus == null)
1082 * @return automatically calculated consensus row note: the row is a stub if a
1083 * consensus calculation has not yet been performed on the group
1085 public AlignmentAnnotation getConsensus()
1087 // TODO get or calculate and get consensus annotation row for this group
1088 int aWidth = this.getWidth();
1096 if (consensus == null)
1098 consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1099 100f, AlignmentAnnotation.BAR_GRAPH);
1100 consensus.hasText = true;
1101 consensus.autoCalculated = true;
1102 consensus.groupRef = this;
1103 consensus.label = "Consensus for " + getName();
1104 consensus.description = "Percent Identity";
1110 * set this alignmentAnnotation object as the one used to render consensus
1115 public void setConservationRow(AlignmentAnnotation aan)
1117 if (conservation == null)
1124 * get the conservation annotation row for this group
1126 * @return autoCalculated annotation row
1128 public AlignmentAnnotation getConservationRow()
1130 if (conservation == null)
1132 conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
1133 11f, AlignmentAnnotation.BAR_GRAPH);
1136 conservation.hasText = true;
1137 conservation.autoCalculated = true;
1138 conservation.groupRef = this;
1139 conservation.label = "Conservation for " + getName();
1140 conservation.description = "Conservation for group " + getName()
1141 + " less than " + consPercGaps + "% gaps";
1142 return conservation;
1147 * @return true if annotation rows have been instantiated for this group
1149 public boolean hasAnnotationRows()
1151 return consensus != null || conservation != null;
1154 public SequenceI getConsensusSeq()
1157 StringBuffer seqs = new StringBuffer();
1158 for (int i = 0; i < consensus.annotations.length; i++)
1160 if (consensus.annotations[i] != null)
1162 if (consensus.annotations[i].description.charAt(0) == '[')
1164 seqs.append(consensus.annotations[i].description.charAt(1));
1168 seqs.append(consensus.annotations[i].displayCharacter);
1173 SequenceI sq = new Sequence("Group" + getName() + " Consensus",
1175 sq.setDescription("Percentage Identity Consensus "
1176 + ((ignoreGapsInConsensus) ? " without gaps" : ""));
1180 public void setIgnoreGapsConsensus(boolean state)
1182 if (this.ignoreGapsInConsensus != state && consensus != null)
1184 ignoreGapsInConsensus = state;
1185 recalcConservation();
1187 ignoreGapsInConsensus = state;
1190 public boolean getIgnoreGapsConsensus()
1192 return ignoreGapsInConsensus;
1195 public void setIgnoreBelowBackground(boolean state)
1197 if (this.ignoreBelowBackground != state)
1199 ignoreBelowBackground = state;
1201 ignoreBelowBackground = state;
1204 public boolean getIgnoreBelowBackground()
1210 * @param showSequenceLogo
1211 * indicates if a sequence logo is shown for consensus annotation
1213 public void setshowSequenceLogo(boolean showSequenceLogo)
1215 // TODO: decouple calculation from settings update
1216 if (this.showSequenceLogo != showSequenceLogo && consensus != null)
1218 this.showSequenceLogo = showSequenceLogo;
1219 recalcConservation();
1221 this.showSequenceLogo = showSequenceLogo;
1226 * @param showConsHist
1227 * flag indicating if the consensus histogram for this group should
1230 public void setShowConsensusHistogram(boolean showConsHist)
1233 if (showConsensusHistogram != showConsHist && consensus != null)
1235 this.showConsensusHistogram = showConsHist;
1236 recalcConservation();
1238 this.showConsensusHistogram = showConsHist;
1242 * @return the showConsensusHistogram
1244 public boolean isShowConsensusHistogram()
1246 return showConsensusHistogram;
1250 * set flag indicating if logo should be normalised when rendered
1254 public void setNormaliseSequenceLogo(boolean norm)
1256 normaliseSequenceLogo = norm;
1259 public boolean isNormaliseSequenceLogo()
1261 return normaliseSequenceLogo;
1266 * returns a new array with all annotation involving this group
1268 public AlignmentAnnotation[] getAlignmentAnnotation()
1270 // TODO add in other methods like 'getAlignmentAnnotation(String label),
1272 ArrayList<AlignmentAnnotation> annot = new ArrayList<>();
1273 synchronized (sequences)
1275 for (SequenceI seq : sequences)
1277 AlignmentAnnotation[] aa = seq.getAnnotation();
1280 for (AlignmentAnnotation al : aa)
1282 if (al.groupRef == this)
1289 if (consensus != null)
1291 annot.add(consensus);
1293 if (conservation != null)
1295 annot.add(conservation);
1298 return annot.toArray(new AlignmentAnnotation[0]);
1302 public Iterable<AlignmentAnnotation> findAnnotation(String calcId)
1304 List<AlignmentAnnotation> aa = new ArrayList<>();
1309 for (AlignmentAnnotation a : getAlignmentAnnotation())
1311 if (calcId.equals(a.getCalcId()))
1320 public Iterable<AlignmentAnnotation> findAnnotations(SequenceI seq,
1321 String calcId, String label)
1323 ArrayList<AlignmentAnnotation> aa = new ArrayList<>();
1324 for (AlignmentAnnotation ann : getAlignmentAnnotation())
1326 if ((calcId == null || (ann.getCalcId() != null && ann.getCalcId()
1328 && (seq == null || (ann.sequenceRef != null && ann.sequenceRef == seq))
1329 && (label == null || (ann.label != null && ann.label
1339 * Answer true if any annotation matches the calcId passed in (if not null).
1344 public boolean hasAnnotation(String calcId)
1346 if (calcId != null && !"".equals(calcId))
1348 for (AlignmentAnnotation a : getAlignmentAnnotation())
1350 if (a.getCalcId() == calcId)
1360 * Remove all sequences from the group (leaving other properties unchanged).
1364 synchronized (sequences)
1371 * Sets the alignment or group context for this group, and whether it is
1372 * defined as a group
1375 * the context for the group
1377 * whether the group is defined on the alignment or is just a
1379 * @throws IllegalArgumentException
1380 * if setting the context would result in a circular reference chain
1382 public void setContext(AnnotatedCollectionI ctx, boolean defined)
1385 this.isDefined = defined;
1389 * Sets the alignment or group context for this group
1392 * the context for the group
1393 * @throws IllegalArgumentException
1394 * if setting the context would result in a circular reference chain
1396 public void setContext(AnnotatedCollectionI ctx)
1398 AnnotatedCollectionI ref = ctx;
1401 if (ref == this || ref.getContext() == ctx)
1403 throw new IllegalArgumentException(
1404 "Circular reference in SequenceGroup.context");
1406 ref = ref.getContext();
1414 * @see jalview.datamodel.AnnotatedCollectionI#getContext()
1417 public AnnotatedCollectionI getContext()
1422 public boolean isDefined()
1427 public void setColourScheme(ColourSchemeI scheme)
1431 cs = new ResidueShader();
1433 cs.setColourScheme(scheme);
1436 public void setGroupColourScheme(ResidueShaderI scheme)
1441 public ColourSchemeI getColourScheme()
1443 return cs == null ? null : cs.getColourScheme();
1446 public ResidueShaderI getGroupColourScheme()
1452 public boolean isNucleotide()
1454 if (context != null) {
1455 return context.isNucleotide();
1462 * @return true if seq is a member of the group
1465 public boolean contains(SequenceI seq1)
1467 return sequences.contains(seq1);
1473 * @return true if startRes<=apos and endRes>=apos and seq is in the group
1475 public boolean contains(SequenceI seq, int apos)
1477 return (startRes <= apos && endRes >= apos) && sequences.contains(seq);