X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FSequenceIdMatcher.java;h=a84d31bd4a180f3ef35f409a267c491f2a6abb7b;hb=c6492a740f2fbd1a2611f669e6a618335a7858b2;hp=a5c161c39cc629f62aa4102ccef8138b077f4eea;hpb=cba94dacdc6c6cbd9ce811b52cd1dcfe3018f84b;p=jalview.git diff --git a/src/jalview/analysis/SequenceIdMatcher.java b/src/jalview/analysis/SequenceIdMatcher.java index a5c161c..a84d31b 100755 --- a/src/jalview/analysis/SequenceIdMatcher.java +++ b/src/jalview/analysis/SequenceIdMatcher.java @@ -236,6 +236,38 @@ public class SequenceIdMatcher List st = pickbestMatches(candName, matches); return st == null || st.size() == 0 ? null : st.get(0); } + + /** + * returns the SequenceI's with exact word matches to candName + * + * @param candName + * SeqIdName + * @param matches + * List of SequenceI objects - some of which may be duplicates + * @return { word matches to candName } + */ + private List pickwordMatches(SeqIdName candName, + List matches) + { + List best = new ArrayList(); + for (SequenceI match : matches) + { + if (!best.contains(match)) + { + if (candName.equalsCase(match.getDisplayId(true))) + { + // put the exact match at the beginning + best.add(0, match); + } + else + { + best.add(match); + } + addSeq(match); + } + } + return best; + } /** * returns the closest SequenceI in matches to SeqIdName and returns all the @@ -324,14 +356,14 @@ public class SequenceIdMatcher * * @param seqnam * string to query Matcher with. - * @return a new array or (possibly) null + * @return a new array or null of no match exists */ public SequenceI[] findAllIdMatches(String seqnam) { SeqIdName nam = new SeqIdName(seqnam); List m = findAllIdMatches(nam); - if (m != null) + if (m != null && m.size() > 0) { return m.toArray(new SequenceI[m.size()]); } @@ -408,7 +440,8 @@ public class SequenceIdMatcher { matches.addAll(names.remove(nam)); } - List r = pickbestMatches(nam, matches); + List r = (wordBased) ? pickwordMatches(nam, matches) + : pickbestMatches(nam, matches); return r; } }