From: Jim Procter Date: Fri, 13 Nov 2015 12:42:20 +0000 (+0000) Subject: JAL-1965 hang onto original string so best match (including case) can be picked X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7bc5d8715387d242abc3dcf26b1f0fdd757f6c30;p=jalview.git JAL-1965 hang onto original string so best match (including case) can be picked --- diff --git a/src/jalview/analysis/SequenceIdMatcher.java b/src/jalview/analysis/SequenceIdMatcher.java index ad36ebe..17ff216 100755 --- a/src/jalview/analysis/SequenceIdMatcher.java +++ b/src/jalview/analysis/SequenceIdMatcher.java @@ -270,9 +270,12 @@ public class SequenceIdMatcher addSeq(cand); int q, w, candlen = cand.getName().length(); // keep the one with an id 'closer' to the given seqnam string - if ((q = Math.abs(matchlen - namlen)) > (w = Math.abs(candlen - - namlen)) - && candlen > matchlen) + boolean is_closer = ((q = Math.abs(matchlen - namlen)) > (w = Math + .abs(candlen - namlen)) && candlen > matchlen); + // if not closer, then check if current best is actually identical in case + // as + // well + if (is_closer || (!candName.equalsCase(best.get(0).getName()))) { best.clear(); match = cand; @@ -281,6 +284,7 @@ public class SequenceIdMatcher } if (q == w && candlen == matchlen) { + // equivalently good, and matches with case as well. so // record any ties best.add(cand); } @@ -407,13 +411,14 @@ public class SequenceIdMatcher private class SeqIdName { - String id; + String id, origid; SeqIdName(String s) { if (s != null) { id = new String(s).toLowerCase(); + origid = new String(s); } else { @@ -528,5 +533,22 @@ public class SequenceIdMatcher { return id; } + + public boolean equalsCase(String s) + { + if (origid.length() > s.length()) + { + return check_wordmatch(origid, s); + } + else + { + return check_wordmatch(s, origid); + } + } + + public boolean equalsCase(SeqIdName sid) + { + return equalsCase(sid.origid); + } } }