X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FSequenceIdMatcher.java;h=0744937743bcba699e34bc0421f06133144b08ca;hb=d4b1e4d0c74b1c6d0f3c3556b10be91a6aaea475;hp=7c974e26873a4dc72bb95abd3f71100be68f9e6d;hpb=7ae574fd34bd7ffd1ea23be7602d6b3dc57aa49f;p=jalview.git diff --git a/src/jalview/analysis/SequenceIdMatcher.java b/src/jalview/analysis/SequenceIdMatcher.java index 7c974e2..0744937 100755 --- a/src/jalview/analysis/SequenceIdMatcher.java +++ b/src/jalview/analysis/SequenceIdMatcher.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -49,6 +49,7 @@ public class SequenceIdMatcher names.put(new SeqIdName(seqs[i].getName()), seqs[i]); } } + /** * returns the closest SequenceI in matches to SeqIdName and returns all the matches * to the names hash. @@ -56,22 +57,28 @@ public class SequenceIdMatcher * @param matches Vector of SequenceI objects * @return SequenceI closest SequenceI to SeqIdName */ - private SequenceI pickbestMatch(SeqIdName candName, Vector matches) { - SequenceI match=null; - if (candName==null || matches==null || matches.size()==0) + private SequenceI pickbestMatch(SeqIdName candName, Vector matches) + { + SequenceI match = null; + if (candName == null || matches == null || matches.size() == 0) + { return null; - match=(SequenceI) matches.elementAt(0); + } + match = (SequenceI) matches.elementAt(0); matches.removeElementAt(0); names.put(new SeqIdName(match.getName()), match); - int matchlen=match.getName().length(); - int namlen=candName.id.length(); - while (matches.size()>0) { + int matchlen = match.getName().length(); + int namlen = candName.id.length(); + while (matches.size() > 0) + { // look through for a better one. - SequenceI cand=(SequenceI) matches.elementAt(0); + SequenceI cand = (SequenceI) matches.elementAt(0); names.put(new SeqIdName(cand.getName()), cand); int candlen = cand.getName().length(); // keep the one with an id 'closer' to the given seqnam string - if (Math.abs(matchlen-namlen)>Math.abs(candlen-namlen) && candlen>matchlen) { + if (Math.abs(matchlen - namlen) > Math.abs(candlen - namlen) && + candlen > matchlen) + { match = cand; matchlen = candlen; } @@ -91,10 +98,11 @@ public class SequenceIdMatcher } SequenceI findIdMatch(String seqnam) - { - SeqIdName nam = new SeqIdName(seqnam); - return findIdMatch(nam); + { + SeqIdName nam = new SeqIdName(seqnam); + return findIdMatch(nam); } + /** * findIdMatch * @@ -140,7 +148,7 @@ public class SequenceIdMatcher private SequenceI findIdMatch(jalview.analysis.SequenceIdMatcher.SeqIdName nam) { - Vector matches=new Vector(); + Vector matches = new Vector(); while (names.containsKey(nam)) { matches.addElement(names.remove(nam)); @@ -154,15 +162,19 @@ public class SequenceIdMatcher SeqIdName(String s) { - if (s!=null) + if (s != null) + { id = new String(s); + } else + { id = ""; + } } public int hashCode() { - return ((id.length()>=4) ? id.substring(0, 4).hashCode() : id.hashCode()); + return ( (id.length() >= 4) ? id.substring(0, 4).hashCode() : id.hashCode()); } public boolean equals(Object s) @@ -188,39 +200,47 @@ public class SequenceIdMatcher * JBPNote: This is a heuristic that will fail for arbritrarily extended sequence id's * (like portions of an aligned set of repeats from one sequence) */ - private String WORD_SEP="~. |#\\/<>!\"£$%^*)}[@',?_"; - - /** - * matches if one ID properly contains another at a whitespace boundary. - * TODO: (JBPNote) These are not efficient. should use char[] for speed - * todo: (JBPNote) Set separator characters appropriately - * @param s SeqIdName - * @return boolean - */ + private String WORD_SEP = "~. |#\\/<>!\"£$%^*)}[@',?_"; + + /** + * matches if one ID properly contains another at a whitespace boundary. + * TODO: (JBPNote) These are not efficient. should use char[] for speed + * todo: (JBPNote) Set separator characters appropriately + * @param s SeqIdName + * @return boolean + */ public boolean equals(SeqIdName s) { - if (id.length()>s.id.length()) { + if (id.length() > s.id.length()) + { return id.startsWith(s.id) ? - (WORD_SEP.indexOf(id.charAt(s.id.length()))>-1) + (WORD_SEP.indexOf(id.charAt(s.id.length())) > -1) : false; - } else + } + else + { return s.id.startsWith(id) ? (s.id.equals(id) ? true : - (WORD_SEP.indexOf(s.id.charAt(id.length()))>-1)) + (WORD_SEP.indexOf(s.id.charAt(id.length())) > -1)) : false; + } } public boolean equals(String s) { - if (id.length()>s.length()) { + if (id.length() > s.length()) + { return id.startsWith(s) ? - (WORD_SEP.indexOf(id.charAt(s.length()))>-1) + (WORD_SEP.indexOf(id.charAt(s.length())) > -1) : false; - } else + } + else + { return s.startsWith(id) ? (s.equals(id) ? true : - (WORD_SEP.indexOf(s.charAt(id.length()))>-1)) + (WORD_SEP.indexOf(s.charAt(id.length())) > -1)) : false; + } } } }