X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fdbsources%2FPdb.java;h=8951a6ef03c251f664c8c2a2e0b92dac2f217855;hb=7d602d0e4b439e56af3e4551ed71f181a8025534;hp=04c23a27ebc185ee20bd8181e0a7afbb53094852;hpb=779c04818839bd05d52a4137218ac9dbe5b4835d;p=jalview.git diff --git a/src/jalview/ws/dbsources/Pdb.java b/src/jalview/ws/dbsources/Pdb.java index 04c23a2..8951a6e 100644 --- a/src/jalview/ws/dbsources/Pdb.java +++ b/src/jalview/ws/dbsources/Pdb.java @@ -29,15 +29,19 @@ import jalview.datamodel.DBRefSource; import jalview.datamodel.PDBEntry; import jalview.datamodel.PDBEntry.Type; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; import jalview.io.FormatAdapter; import jalview.io.PDBFeatureSettings; import jalview.structure.StructureImportSettings; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.ws.ebi.EBIFetchClient; +import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.Vector; import com.stevesoft.pat.Regex; @@ -47,15 +51,19 @@ import com.stevesoft.pat.Regex; */ public class Pdb extends EbiFileRetrievedProxy { + private static final String SEPARATOR = "|"; + + private static final String COLON = ":"; + + private static final int PDB_ID_LENGTH = 4; + + private static Regex ACCESSION_REGEX; + public Pdb() { super(); } - public static final String FEATURE_INSERTION = "INSERTION"; - - public static final String FEATURE_RES_NUM = "RESNUM"; - /* * (non-Javadoc) * @@ -64,7 +72,6 @@ public class Pdb extends EbiFileRetrievedProxy @Override public String getAccessionSeparator() { - // TODO Auto-generated method stub return null; } @@ -76,7 +83,12 @@ public class Pdb extends EbiFileRetrievedProxy @Override public Regex getAccessionValidator() { - return new Regex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)"); + if (ACCESSION_REGEX == null) + { + ACCESSION_REGEX = Platform + .newRegex("([1-9][0-9A-Za-z]{3}):?([ _A-Za-z0-9]?)"); + } + return ACCESSION_REGEX; } /* @@ -110,36 +122,47 @@ public class Pdb extends EbiFileRetrievedProxy public AlignmentI getSequenceRecords(String queries) throws Exception { AlignmentI pdbAlignment = null; - Vector result = new Vector(); String chain = null; String id = null; - if (queries.indexOf(":") > -1) + if (queries.indexOf(COLON) > -1) { - chain = queries.substring(queries.indexOf(":") + 1); - id = queries.substring(0, queries.indexOf(":")); + chain = queries.substring(queries.indexOf(COLON) + 1); + id = queries.substring(0, queries.indexOf(COLON)); } else { id = queries; } - if (queries.length() > 4 && chain == null) + + /* + * extract chain code if it is appended to the id and we + * don't already have one + */ + if (queries.length() > PDB_ID_LENGTH && chain == null) { - chain = queries.substring(4, 5); - id = queries.substring(0, 4); + chain = queries.substring(PDB_ID_LENGTH, PDB_ID_LENGTH + 1); + id = queries.substring(0, PDB_ID_LENGTH); } + if (!isValidReference(id)) { System.err.println("Ignoring invalid pdb query: '" + id + "'"); stopQuery(); return null; } - String ext = StructureImportSettings.getDefaultStructureFileFormat() - .equalsIgnoreCase(Type.MMCIF.toString()) ? ".cif" : ".xml"; + + /* + * ensure that an mmCIF format structure file is saved with extension.cif, + * because the Chimera "open" command recognises this extension + */ + Type pdbFileFormat = StructureImportSettings + .getDefaultStructureFileFormat(); + String ext = pdbFileFormat.getExtension(); + String fetchFormat = pdbFileFormat.getFormat(); + EBIFetchClient ebi = new EBIFetchClient(); - file = ebi.fetchDataAsFile("pdb:" + id, - StructureImportSettings.getDefaultStructureFileFormat().toLowerCase(), - ext) - .getAbsolutePath(); + File tmpFile = ebi.fetchDataAsFile("pdb:" + id, fetchFormat, ext); + file = tmpFile.getAbsolutePath(); stopQuery(); if (file == null) { @@ -147,10 +170,11 @@ public class Pdb extends EbiFileRetrievedProxy } try { - - pdbAlignment = new FormatAdapter().readFile(file, - jalview.io.AppletFormatAdapter.FILE, - StructureImportSettings.getDefaultStructureFileFormat()); + // todo get rid of Type and use FileFormatI instead? + FileFormatI fileFormat = (pdbFileFormat == Type.PDB) ? FileFormat.PDB + : FileFormat.MMCif; + pdbAlignment = new FormatAdapter().readFile(tmpFile, DataSourceType.FILE, + fileFormat); if (pdbAlignment != null) { List toremove = new ArrayList(); @@ -165,18 +189,15 @@ public class Pdb extends EbiFileRetrievedProxy chid = pid.getChainCode(); } - ; - } - if (chain == null - || (chid != null && (chid.equals(chain) - || chid.trim().equals(chain.trim()) || (chain - .trim().length() == 0 && chid.equals("_"))))) + if (chain == null || (chid != null && (chid.equals(chain) + || chid.trim().equals(chain.trim()) + || (chain.trim().length() == 0 && chid.equals("_"))))) { // FIXME seems to result in 'PDB|1QIP|1qip|A' - 1QIP is redundant. // TODO: suggest simplify naming to 1qip|A as default name defined - pdbcs.setName(jalview.datamodel.DBRefSource.PDB + "|" + id - + "|" + pdbcs.getName()); + pdbcs.setName(jalview.datamodel.DBRefSource.PDB + SEPARATOR + id + + SEPARATOR + pdbcs.getName()); // Might need to add more metadata to the PDBEntry object // like below /* @@ -222,8 +243,8 @@ public class Pdb extends EbiFileRetrievedProxy if (pdbAlignment == null || pdbAlignment.getHeight() < 1) { throw new Exception(MessageManager.formatMessage( - "exception.no_pdb_records_for_chain", new String[] { id, - ((chain == null) ? "' '" : chain) })); + "exception.no_pdb_records_for_chain", new String[] + { id, ((chain == null) ? "' '" : chain) })); } } catch (Exception ex) // Problem parsing PDB file @@ -267,7 +288,6 @@ public class Pdb extends EbiFileRetrievedProxy return 0; } - /** * Returns a descriptor for suitable feature display settings with *