private int residueIndex;
/*
+ * last feature matched when incrementally searching sequence features
+ */
+ private SequenceFeature lastFeature;
+
+ /*
+ * last sequenceIndex used when lastFeature was discovered
+ */
+ private int lastFeatureSequenceIndex;
+
+ /*
* the true sequence position of the start of the
* last sequence searched (when 'ignore hidden regions' does not apply)
*/
/*
* search from the start
*/
+ lastFeature = null;
+ lastFeatureSequenceIndex = 0;
sequenceIndex = 0;
residueIndex = -1;
*/
sequenceIndex = 0;
residueIndex = -1;
+ lastFeature = null;
+ lastFeatureSequenceIndex = 0;
}
@Override
*/
sequenceIndex = 0;
residueIndex = -1;
+ lastFeature = null;
+ lastFeatureSequenceIndex = 0;
}
}
{
if (matchFeatureDesc)
{
- // TODO - record last matched
matched = searchSequenceFeatures(residueIndex, searchPattern);
+ if (matched)
+ {
+ return true;
+ }
+ lastFeature = null;
}
residueIndex = Integer.MAX_VALUE;
}
* sequence to the list of match ids, (but not as a duplicate). Answers true
* if a match was added, else false.
*
- * TODO: allow incremental searching (ie next feature matched after last)
- *
* @param seq
* @param searchPattern
* @return
*/
protected boolean searchSequenceFeatures(int from, Regex searchPattern)
{
- boolean matched = false;
+ if (lastFeatureSequenceIndex != sequenceIndex)
+ {
+ lastFeatureSequenceIndex = sequenceIndex;
+ lastFeature = null;
+ }
SequenceI seq = viewport.getAlignment().getSequenceAt(sequenceIndex);
-
+ long fpos = 0;
SequenceFeaturesI sf = seq.getFeatures();
for (SequenceFeature feature : sf.getAllFeatures(null))
{
+ fpos++;
+ if (lastFeature != null)
+ {
+ // iterate till we find last feature matched
+ if (lastFeature != feature)
+ {
+ continue;
+ }
+ else
+ {
+ lastFeature = null;
+ continue;
+ }
+ }
if (searchPattern.search(feature.type) || (feature.description != null
&& searchPattern.search(feature.description)))
{
searchResults.addResult(seq, feature.getBegin(), feature.getEnd());
- matched = true;
+ lastFeature = feature;
+ return true;
}
}
- return matched;
+ residueIndex = Integer.MAX_VALUE;
+ lastFeature = null;
+ return false;
}
/**
seqs.get(2).getDatasetSequence());
assertEquals(seqs.get(2).getStart(), 1);
assertEquals(seqs.get(2).getEnd(), 3);
+
+ SequenceI sq = null;
+ // search feature descriptions incrementally
+ // assume same order as before
+ f.findNext("Feature", false, false, true, true);
+ assertEquals(f.getSearchResults().getCount(), 1);
+ sq = f.getSearchResults().getMatchingSubSequences().get(0);
+ assertEquals(sq.getSequenceAsString(),
+ seqs.get(0).getSequenceAsString());
+
+ // ..
+ f.findNext("Feature", false, false, true, true);
+ assertEquals(f.getSearchResults().getCount(), 1);
+ sq = f.getSearchResults().getMatchingSubSequences().get(0);
+ assertEquals(sq.getSequenceAsString(),
+ seqs.get(1).getSequenceAsString());
+
+ // ..
+ f.findNext("Feature", false, false, true, true);
+ assertEquals(f.getSearchResults().getCount(), 1);
+ sq = f.getSearchResults().getMatchingSubSequences().get(0);
+ assertEquals(sq.getSequenceAsString(),
+ seqs.get(2).getSequenceAsString());
+
}
}