X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FSequenceIdMatcher.java;h=8de046dcc1b795ece7afc5e7cb2d9f13f8cd34a7;hb=d9c7868a610eff29a8eddb160b6dc78a94a72470;hp=f7c7cb48ce11baea6baf2afac6369bd94bf2ac98;hpb=f679765cb36b8c3889cd0fa7ab7d7923844d0827;p=jalview.git diff --git a/src/jalview/analysis/SequenceIdMatcher.java b/src/jalview/analysis/SequenceIdMatcher.java index f7c7cb4..8de046d 100755 --- a/src/jalview/analysis/SequenceIdMatcher.java +++ b/src/jalview/analysis/SequenceIdMatcher.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) - * Copyright (C) $$Year-Rel$$ The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) + * Copyright (C) 2015 The Jalview Authors * * This file is part of Jalview. * @@ -46,7 +46,7 @@ public class SequenceIdMatcher } /** - * add more sequences to this matcher - also used by the constructor + * Adds sequences to this matcher * * @param seqs */ @@ -54,26 +54,36 @@ public class SequenceIdMatcher { for (SequenceI seq : seqs) { - // TODO: deal with ID collisions - SequenceI should be appended to list - // associated with this key. - names.put(new SeqIdName(seq.getDisplayId(true)), seq); - SequenceI dbseq = seq; - while (dbseq.getDatasetSequence() != null) - { - dbseq = dbseq.getDatasetSequence(); - } - // add in any interesting identifiers - if (dbseq.getDBRef() != null) + add(seq); + } + } + + /** + * Adds one sequence to this matcher + * + * @param seq + */ + public void add(SequenceI seq) + { + // TODO: deal with ID collisions - SequenceI should be appended to list + // associated with this key. + names.put(new SeqIdName(seq.getDisplayId(true)), seq); + SequenceI dbseq = seq; + while (dbseq.getDatasetSequence() != null) + { + dbseq = dbseq.getDatasetSequence(); + } + // add in any interesting identifiers + if (dbseq.getDBRefs() != null) + { + DBRefEntry dbr[] = dbseq.getDBRefs(); + SeqIdName sid = null; + for (int r = 0; r < dbr.length; r++) { - DBRefEntry dbr[] = dbseq.getDBRef(); - SeqIdName sid = null; - for (int r = 0; r < dbr.length; r++) + sid = new SeqIdName(dbr[r].getAccessionId()); + if (!names.containsKey(sid)) { - sid = new SeqIdName(dbr[r].getAccessionId()); - if (!names.containsKey(sid)) - { - names.put(sid, seq); - } + names.put(sid, seq); } } } @@ -272,7 +282,7 @@ public class SequenceIdMatcher return r; } - private class SeqIdName + class SeqIdName { String id; @@ -280,7 +290,7 @@ public class SequenceIdMatcher { if (s != null) { - id = new String(s); + id = s.toLowerCase(); } else { @@ -304,13 +314,13 @@ public class SequenceIdMatcher } if (s instanceof SeqIdName) { - return this.equals(((SeqIdName) s).id); + return this.stringequals(((SeqIdName) s).id); } else { if (s instanceof String) { - return this.equals((String) s); + return this.stringequals(((String) s).toLowerCase()); } } @@ -334,7 +344,7 @@ public class SequenceIdMatcher * @param s * @return boolean */ - public boolean equals(String s) + private boolean stringequals(String s) { if (id.length() > s.length()) { @@ -347,5 +357,15 @@ public class SequenceIdMatcher .indexOf(s.charAt(id.length())) > -1)) : false; } } + + /** + * toString method returns the wrapped sequence id. For debugging purposes + * only, behaviour not guaranteed not to change. + */ + @Override + public String toString() + { + return id; + } } }