From 48f7c55f44b0526c5f7be8ebf986052ca7dae245 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 30 Nov 2016 12:38:29 +0000 Subject: [PATCH] JAL-2344 use ".cif" for saved mmCIF file (and refactor fetch as file) --- src/MCview/PDBViewer.java | 2 +- src/jalview/datamodel/PDBEntry.java | 14 ++++++++++++-- src/jalview/ws/dbsources/EmblXmlSource.java | 2 +- src/jalview/ws/dbsources/Pdb.java | 17 ++++++++++++----- src/jalview/ws/dbsources/Uniprot.java | 2 +- src/jalview/ws/ebi/EBIFetchClient.java | 4 ++-- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java index 40edc73..f108fc2 100755 --- a/src/MCview/PDBViewer.java +++ b/src/MCview/PDBViewer.java @@ -151,7 +151,7 @@ public class PDBViewer extends JInternalFrame implements Runnable { EBIFetchClient ebi = new EBIFetchClient(); String query = "pdb:" + pdbentry.getId(); - pdbentry.setFile(ebi.fetchDataAsFile(query, "default", ".xml") + pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "xml") .getAbsolutePath()); if (pdbentry.getFile() != null) diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index 97fb08d..8debacf 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -46,11 +46,21 @@ public class PDBEntry public enum Type { - // TODO is FILE needed; if not is this needed or can we + // TODO is FILE needed; if not is this enum needed, or can we // use FileFormatI for PDB, MMCIF? - PDB("pdb", "xml"), MMCIF("mmcif", "mmcif"), FILE("?", "?"); + PDB("pdb", "pdb"), MMCIF("mmcif", "cif"), FILE("?", "?"); + + /* + * file extension for cached structure file; must be one that + * is recognised by Chimera 'open' command + * @see https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/filetypes.html + */ String ext; + /* + * format specifier used in dbfetch request + * @see http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/dbfetch.databases#pdb + */ String format; private Type(String fmt, String ex) diff --git a/src/jalview/ws/dbsources/EmblXmlSource.java b/src/jalview/ws/dbsources/EmblXmlSource.java index b139574..b2fb808 100644 --- a/src/jalview/ws/dbsources/EmblXmlSource.java +++ b/src/jalview/ws/dbsources/EmblXmlSource.java @@ -64,7 +64,7 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy { reply = dbFetch.fetchDataAsFile( emprefx.toLowerCase() + ":" + query.trim(), "display=xml", - ".xml"); + "xml"); } catch (Exception e) { stopQuery(); diff --git a/src/jalview/ws/dbsources/Pdb.java b/src/jalview/ws/dbsources/Pdb.java index 68dda88..982c399 100644 --- a/src/jalview/ws/dbsources/Pdb.java +++ b/src/jalview/ws/dbsources/Pdb.java @@ -38,6 +38,7 @@ import jalview.structure.StructureImportSettings; import jalview.util.MessageManager; import jalview.ws.ebi.EBIFetchClient; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -141,12 +142,19 @@ public class Pdb extends EbiFileRetrievedProxy stopQuery(); return null; } + + /* + * 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 ext = pdbFileFormat.getExtension(); + String fetchFormat = pdbFileFormat.getFormat(); + EBIFetchClient ebi = new EBIFetchClient(); - file = ebi.fetchDataAsFile("pdb:" + id, pdbFileFormat.getFormat(), ext) - .getAbsolutePath(); + File tmpFile = ebi.fetchDataAsFile("pdb:" + id, fetchFormat, ext); + file = tmpFile.getAbsolutePath(); stopQuery(); if (file == null) { @@ -155,8 +163,7 @@ public class Pdb extends EbiFileRetrievedProxy try { // todo get rid of Type and use FileFormatI instead? - // todo get rid of "ext" and just use "tmp"? - FileFormatI fileFormat = pdbFileFormat == Type.PDB ? FileFormat.PDB + FileFormatI fileFormat = (pdbFileFormat == Type.PDB) ? FileFormat.PDB : FileFormat.MMCif; pdbAlignment = new FormatAdapter().readFile(file, DataSourceType.FILE, fileFormat); diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index b6f53cd..3afe8ec 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -165,7 +165,7 @@ public class Uniprot extends DbSourceProxyImpl // uniprotxml parameter required since december 2007 // uniprotkb dbname changed introduced december 2008 File file = ebi.fetchDataAsFile("uniprotkb:" + queries, "uniprotxml", - ".xml"); + "xml"); Vector entries = getUniprotEntries(new FileReader(file)); if (entries != null) diff --git a/src/jalview/ws/ebi/EBIFetchClient.java b/src/jalview/ws/ebi/EBIFetchClient.java index f6928c4..3e8c55e 100644 --- a/src/jalview/ws/ebi/EBIFetchClient.java +++ b/src/jalview/ws/ebi/EBIFetchClient.java @@ -91,7 +91,7 @@ public class EBIFetchClient * @param format * the format wanted * @param extension - * for the temporary file to hold response + * for the temporary file to hold response (without separator) * @return the file holding the response * @throws OutOfMemoryError */ @@ -102,7 +102,7 @@ public class EBIFetchClient File outFile = null; try { - outFile = File.createTempFile("jalview", ext); + outFile = File.createTempFile("jalview", "." + ext); outFile.deleteOnExit(); fetchData(ids, format, outFile); if (outFile.length() == 0) -- 1.7.10.2