X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FFinder.java;h=21fa2f15869af2a9f5739784554f99c5504de971;hb=35fc4fb5b48e97eab1ee8758ae6f3fcc2322fd90;hp=181cc9f0639ea6d475b10d46bfa0b93fe37ee24b;hpb=13a74c42398c4a2d3794242efec6e52b949b5e5d;p=jalview.git diff --git a/src/jalview/analysis/Finder.java b/src/jalview/analysis/Finder.java index 181cc9f..21fa2f1 100644 --- a/src/jalview/analysis/Finder.java +++ b/src/jalview/analysis/Finder.java @@ -29,6 +29,7 @@ import java.util.Locale; 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; @@ -62,6 +63,11 @@ public class Finder implements FinderI private AlignViewportI viewport; /* + * feature renderer model - if available + */ + FeatureRenderer frm = null; + + /* * sequence index in alignment to search from */ private int sequenceIndex; @@ -73,6 +79,16 @@ public class Finder implements FinderI 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) */ @@ -106,6 +122,8 @@ public class Finder implements FinderI /* * search from the start */ + lastFeature = null; + lastFeatureSequenceIndex = 0; sequenceIndex = 0; residueIndex = -1; @@ -117,6 +135,8 @@ public class Finder implements FinderI */ sequenceIndex = 0; residueIndex = -1; + lastFeature = null; + lastFeatureSequenceIndex = 0; } @Override @@ -134,6 +154,8 @@ public class Finder implements FinderI */ sequenceIndex = 0; residueIndex = -1; + lastFeature = null; + lastFeatureSequenceIndex = 0; } } @@ -387,8 +409,12 @@ public class Finder implements FinderI { if (matchFeatureDesc) { - // TODO - record last matched matched = searchSequenceFeatures(residueIndex, searchPattern); + if (matched) + { + return true; + } + lastFeature = null; } residueIndex = Integer.MAX_VALUE; } @@ -557,28 +583,62 @@ public class Finder implements FinderI * 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); - SequenceFeaturesI sf = seq.getFeatures(); - for (SequenceFeature feature : sf.getAllFeatures(null)) + + // TODO - stash feature list and search incrementally + List allFeatures = null; + if (frm != null) + { + allFeatures = frm.findFeaturesAtResidue(seq, seq.getStart(), + seq.getEnd()); + } + else { + allFeatures = sf.getAllFeatures(null); + } + // 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, feature.getBegin(), feature.getEnd()); - matched = true; + lastFeature = feature; + return true; } } - return matched; + residueIndex = Integer.MAX_VALUE; + lastFeature = null; + return false; } /** @@ -673,4 +733,10 @@ public class Finder implements FinderI { return searchResults; } + + @Override + public void setFeatureRenderer(FeatureRenderer featureRenderer) + { + frm = featureRenderer; + } }