X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FDBRefUtils.java;h=671142b3fa8013828ec2118bcd284a5968734f24;hb=304e64fb34b32659be1bbfd39fb4e15b2f79586e;hp=fb54bbabaad9e6585e5cee0eb3e20f8a91e8c3a2;hpb=3da878124135ff033f42d19d8733891b09e953cd;p=jalview.git diff --git a/src/jalview/util/DBRefUtils.java b/src/jalview/util/DBRefUtils.java index fb54bba..671142b 100755 --- a/src/jalview/util/DBRefUtils.java +++ b/src/jalview/util/DBRefUtils.java @@ -20,11 +20,7 @@ */ package jalview.util; -import jalview.datamodel.DBRefEntry; -import jalview.datamodel.DBRefSource; -import jalview.datamodel.Mapping; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; +import java.util.Locale; import java.util.ArrayList; import java.util.BitSet; @@ -32,10 +28,15 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import com.stevesoft.pat.Regex; +import jalview.datamodel.DBRefEntry; +import jalview.datamodel.DBRefSource; +import jalview.datamodel.Mapping; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; + /** * Utilities for handling DBRef objects and their collections. */ @@ -74,7 +75,7 @@ public class DBRefUtils // guarantee we always have lowercase entries for canonical string lookups for (String k : canonicalSourceNameLookup.keySet()) { - canonicalSourceNameLookup.put(k.toLowerCase(), + canonicalSourceNameLookup.put(k.toLowerCase(Locale.ROOT), canonicalSourceNameLookup.get(k)); } } @@ -99,7 +100,7 @@ public class DBRefUtils HashSet srcs = new HashSet(); for (String src : sources) { - srcs.add(src.toUpperCase()); + srcs.add(src.toUpperCase(Locale.ROOT)); } int nrefs = dbrefs.size(); @@ -108,7 +109,7 @@ public class DBRefUtils { DBRefEntry dbr = dbrefs.get(ib); String source = getCanonicalName(dbr.getSource()); - if (srcs.contains(source.toUpperCase())) + if (srcs.contains(source.toUpperCase(Locale.ROOT))) { res.add(dbr); } @@ -182,7 +183,7 @@ public class DBRefUtils { return null; } - String canonical = canonicalSourceNameLookup.get(source.toLowerCase()); + String canonical = canonicalSourceNameLookup.get(source.toLowerCase(Locale.ROOT)); return canonical == null ? source : canonical; } @@ -308,6 +309,83 @@ public class DBRefUtils }; + private static Regex PARSE_REGEX; + + private static Regex getParseRegex() + { + return (PARSE_REGEX == null ? PARSE_REGEX = Platform.newRegex( + "([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;\\s*([0-9]+)-([0-9]+)") + : PARSE_REGEX); + } + + /** + * Parses a DBRefEntry and adds it to the sequence, also a PDBEntry if the + * database is PDB. + *

+ * Used by file parsers to generate DBRefs from annotation within file (eg + * Stockholm) + * + * @param dbname + * @param version + * @param acn + * @param seq + * where to annotate with reference + * @return parsed version of entry that was added to seq (if any) + */ + public static DBRefEntry parseToDbRef(SequenceI seq, String dbname, + String version, String acn) + { + DBRefEntry ref = null; + if (dbname != null) + { + String locsrc = DBRefUtils.getCanonicalName(dbname); + if (locsrc.equals(DBRefSource.PDB)) + { + /* + * Check for PFAM style stockhom PDB accession id citation e.g. + * "1WRI A; 7-80;" + */ + Regex r = getParseRegex(); + if (r.search(acn.trim())) + { + String pdbid = r.stringMatched(1); + String chaincode = r.stringMatched(2); + if (chaincode == null) + { + chaincode = " "; + } + // String mapstart = r.stringMatched(3); + // String mapend = r.stringMatched(4); + if (chaincode.equals(" ")) + { + chaincode = "_"; + } + // construct pdb ref. + ref = new DBRefEntry(locsrc, version, pdbid + chaincode); + PDBEntry pdbr = new PDBEntry(); + pdbr.setId(pdbid); + pdbr.setType(PDBEntry.Type.PDB); + pdbr.setChainCode(chaincode); + seq.addPDBId(pdbr); + } + else + { + System.err.println("Malformed PDB DR line:" + acn); + } + } + else + { + // default: + ref = new DBRefEntry(locsrc, version, acn.trim()); + } + } + if (ref != null) + { + seq.addDBRef(ref); + } + return ref; + } + /** * accession ID and DB must be identical. Version is ignored. Map is either not * defined or is a match (or is compatible?) @@ -451,60 +529,6 @@ public class DBRefUtils } /** - * Parses a DBRefEntry and adds it to the sequence, also a PDBEntry if the - * database is PDB. - *

- * Used by file parsers to generate DBRefs from annotation within file (eg - * Stockholm) - * - * @param dbname - * @param version - * @param acn - * @param seq where to annotate with reference - * @return parsed version of entry that was added to seq (if any) - */ - public static DBRefEntry parseToDbRef(SequenceI seq, String dbname, String version, String acn) { - DBRefEntry ref = null; - if (dbname != null) { - String locsrc = DBRefUtils.getCanonicalName(dbname); - if (locsrc.equals(DBRefSource.PDB)) { - /* - * Check for PFAM style stockhom PDB accession id citation e.g. "1WRI A; 7-80;" - */ - Regex r = new com.stevesoft.pat.Regex("([0-9][0-9A-Za-z]{3})\\s*(.?)\\s*;\\s*([0-9]+)-([0-9]+)"); - if (r.search(acn.trim())) { - String pdbid = r.stringMatched(1); - String chaincode = r.stringMatched(2); - if (chaincode == null) { - chaincode = " "; - } - // String mapstart = r.stringMatched(3); - // String mapend = r.stringMatched(4); - if (chaincode.equals(" ")) { - chaincode = "_"; - } - // construct pdb ref. - ref = new DBRefEntry(locsrc, version, pdbid + chaincode); - PDBEntry pdbr = new PDBEntry(); - pdbr.setId(pdbid); - pdbr.setType(PDBEntry.Type.PDB); - pdbr.setChainCode(chaincode); - seq.addPDBId(pdbr); - } else { - System.err.println("Malformed PDB DR line:" + acn); - } - } else { - // default: - ref = new DBRefEntry(locsrc, version, acn); - } - } - if (ref != null) { - seq.addDBRef(ref); - } - return ref; - } - - /** * Returns true if either object is null, or they are equal * * @param o1