From: Jim Procter Date: Fri, 13 Nov 2015 15:23:21 +0000 (+0000) Subject: JAL-1965 alternate ‘bestMatch’ picker for word matches, normalises list and places... X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c6492a740f2fbd1a2611f669e6a618335a7858b2;p=jalview.git JAL-1965 alternate ‘bestMatch’ picker for word matches, normalises list and places exact case match at beginning of list --- 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; } }