import com.stevesoft.pat.Regex;
import jalview.api.AlignViewportI;
+import jalview.api.FeatureRenderer;
import jalview.api.FinderI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SearchResultMatchI;
private AlignViewportI viewport;
/*
+ * feature renderer model - if available
+ */
+ FeatureRenderer frm = null;
+
+ /*
* sequence index in alignment to search from
*/
private int sequenceIndex;
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)
{
matched = searchSequenceFeatures(residueIndex, searchPattern);
+ if (matched)
+ {
+ return true;
+ }
+ lastFeature = null;
}
residueIndex = Integer.MAX_VALUE;
}
*/
protected boolean searchSequenceFeatures(int from, Regex searchPattern)
{
- boolean matched = false;
+ if (lastFeatureSequenceIndex != sequenceIndex)
+ {
+ lastFeatureSequenceIndex = sequenceIndex;
+ lastFeature = null;
+ }
SequenceI seq = viewport.getAlignment().getSequenceAt(sequenceIndex);
-
SequenceFeaturesI sf = seq.getFeatures();
- for (SequenceFeature feature : sf.getAllFeatures(null))
+
+ // TODO - stash feature list and search incrementally
+ List<SequenceFeature> allFeatures = null;
+ if (frm != null)
+ {
+ allFeatures = frm.findFeaturesAtResidue(seq, seq.getStart(),
+ seq.getEnd());
+ }
+ else
{
+ //allFeatures = sf.getAllFeatures(null);
+ allFeatures = sf.getAllFeatures();
+ }
+ // so we can check we are advancing when debugging
+ long fpos = 0;
+
+ for (SequenceFeature feature : allFeatures)
+ {
+ 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, seq.findIndex(feature.getBegin()),
- seq.findIndex(feature.getEnd()));
- matched = true;
+ searchResults.addResult(seq, feature.getBegin(), feature.getEnd());
+ lastFeature = feature;
+ return true;
}
}
- return matched;
+ residueIndex = Integer.MAX_VALUE;
+ lastFeature = null;
+ return false;
}
/**
{
return searchResults;
}
+
+ @Override
+ public void setFeatureRenderer(FeatureRenderer featureRenderer)
+ {
+ frm = featureRenderer;
+ }
}