From c6492a740f2fbd1a2611f669e6a618335a7858b2 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 13 Nov 2015 15:23:21 +0000 Subject: [PATCH 1/1] =?utf8?q?JAL-1965=20alternate=20=E2=80=98bestMatch=E2=80?= =?utf8?q?=99=20picker=20for=20word=20matches,=20normalises=20list=20and=20p?= =?utf8?q?laces=20exact=20case=20match=20at=20beginning=20of=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/analysis/SequenceIdMatcher.java | 39 ++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) 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; } } -- 1.7.10.2