From 1a98eeb582c35656b92274586bebdf7e4116caf4 Mon Sep 17 00:00:00 2001 From: josemduarte Date: Mon, 22 Jul 2024 10:10:52 -0700 Subject: [PATCH] Removing functionality that uses mmtf.rcsb.org, now deprecated --- .../nbio/core/util/FileDownloadUtils.java | 7 ++- .../src/main/java/demo/DemoMmtfReader.java | 47 ------------------- .../nbio/structure/align/util/AtomCache.java | 23 --------- .../nbio/structure/io/LocalPDBDirectory.java | 20 ++++---- .../nbio/structure/io/mmtf/MmtfActions.java | 16 ------- 5 files changed, 11 insertions(+), 102 deletions(-) delete mode 100644 biojava-structure/src/main/java/demo/DemoMmtfReader.java diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java b/biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java index 50fce7b024..3259676ef0 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java @@ -171,15 +171,14 @@ public static void createValidationFiles(URL url, File localDestination, URL has public static void createValidationFiles(URLConnection resourceUrlConnection, File localDestination, URL hashURL, Hash hash){ long size = resourceUrlConnection.getContentLengthLong(); if(size == -1) { - logger.warn("could not find expected file size for resource {}.", resourceUrlConnection.getURL()); + logger.debug("Could not find expected file size for resource {}. Size validation metadata file won't be available for this download.", resourceUrlConnection.getURL()); } else { logger.debug("Content-Length: {}", size); File sizeFile = new File(localDestination.getParentFile(), localDestination.getName() + SIZE_EXT); try (PrintStream sizePrintStream = new PrintStream(sizeFile)) { sizePrintStream.print(size); - sizePrintStream.close(); } catch (FileNotFoundException e) { - logger.warn("could not write size validation file due to exception: {}", e.getMessage()); + logger.warn("Could not write size validation metadata file due to exception: {}", e.getMessage()); } } @@ -192,7 +191,7 @@ public static void createValidationFiles(URLConnection resourceUrlConnection, Fi File hashFile = new File(localDestination.getParentFile(), String.format("%s%s_%s", localDestination.getName(), HASH_EXT, hash)); downloadFile(hashURL, hashFile); } catch (IOException e) { - logger.warn("could not write validation hash file due to exception: {}", e.getMessage()); + logger.warn("Could not write validation hash file due to exception: {}", e.getMessage()); } } diff --git a/biojava-structure/src/main/java/demo/DemoMmtfReader.java b/biojava-structure/src/main/java/demo/DemoMmtfReader.java deleted file mode 100644 index 0dc4b76ab1..0000000000 --- a/biojava-structure/src/main/java/demo/DemoMmtfReader.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * BioJava development code - * - * This code may be freely distributed and modified under the - * terms of the GNU Lesser General Public Licence. This should - * be distributed with the code. If you do not have a copy, - * see: - * - * http://www.gnu.org/copyleft/lesser.html - * - * Copyright for this code is held jointly by the individual - * authors. These should be listed in @author doc comments. - * - * For more information on the BioJava project and its aims, - * or to join the biojava-l mailing list, visit the home page - * at: - * - * http://www.biojava.org/ - * - */ -package demo; - -import java.io.IOException; - -import org.biojava.nbio.structure.Structure; -import org.biojava.nbio.structure.StructureException; -import org.biojava.nbio.structure.io.mmtf.MmtfActions; - -/** - * Class to show how to read a Biojava structure using MMTF - * @author Anthony Bradley - * - */ -public class DemoMmtfReader { - - /** - * Main function to run the demo - * @param args no args to specify - * @throws IOException - * @throws StructureException - */ - public static void main(String[] args) throws IOException, StructureException { - Structure structure = MmtfActions.readFromWeb("4cup"); - System.out.println(structure.getChains().size()); - } - -} diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java index 258fdbf7f3..63fc089a97 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java @@ -38,7 +38,6 @@ import org.biojava.nbio.structure.io.FileParsingParameters; import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior; import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior; -import org.biojava.nbio.structure.io.MMTFFileReader; import org.biojava.nbio.structure.io.PDBFileReader; import org.biojava.nbio.core.util.FileDownloadUtils; import org.biojava.nbio.structure.io.StructureFiletype; @@ -829,34 +828,12 @@ public Structure getStructureForPdbId(PdbId pdbId) throws IOException { case BCIF: logger.debug("loading from bcif"); return loadStructureFromBcifByPdbId(pdbId); - case MMTF: - logger.debug("loading from mmtf"); - return loadStructureFromMmtfByPdbId(pdbId); case PDB: default: logger.debug("loading from pdb"); return loadStructureFromPdbByPdbId(pdbId); } } - - protected Structure loadStructureFromMmtfByPdbId(String pdbId) throws IOException { - return loadStructureFromMmtfByPdbId(new PdbId(pdbId)); - } - - /** - * Load a {@link Structure} from MMTF either from the local file system. - * @param pdbId the input PDB id - * @return the {@link Structure} object of the parsed structure - * @throws IOException error reading from Web or file system - */ - protected Structure loadStructureFromMmtfByPdbId(PdbId pdbId) throws IOException { - logger.debug("Loading structure {} from mmtf file.", pdbId); - MMTFFileReader reader = new MMTFFileReader(); - reader.setFetchBehavior(fetchBehavior); - reader.setObsoleteBehavior(obsoleteBehavior); - return reader.getStructureById(pdbId); - } - protected Structure loadStructureFromCifByPdbId(String pdbId) throws IOException { return loadStructureFromCifByPdbId(new PdbId(pdbId)); } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java index 5de75efee5..5297443a34 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java @@ -133,13 +133,11 @@ public static enum FetchBehavior { Date d = formatter.parse(LAST_REMEDIATION_DATE_STRING); t = d.getTime(); } catch (ParseException e){ - logger.error("Unexpected error! could not parse LAST_REMEDIATION_DATE: "+e.getMessage()); + logger.error("Unexpected error! could not parse LAST_REMEDIATION_DATE: {}", e.getMessage()); } LAST_REMEDIATION_DATE = t; } - protected static final String lineSplit = System.getProperty("file.separator"); - /** Minimum size for a valid structure file (CIF or PDB), in bytes */ public static final long MIN_PDB_FILE_SIZE = 40; // Empty gzip files are 20bytes. Add a few more for buffer. @@ -267,8 +265,8 @@ public FileParsingParameters getFileParsingParameters(){ * if {@link #isAutoFetch()} is false. Note that an obsolete entry may still be * returned even this is FETCH_CURRENT if the entry is found locally. * - * @param fetchFileEvenIfObsolete Whether to fetch obsolete records - * @see #setFetchCurrent(boolean) + * @param behavior Whether to fetch obsolete records + * @see #setFetchBehavior(FetchBehavior) * @since 4.0.0 */ public void setObsoleteBehavior(ObsoleteBehavior behavior) { @@ -530,9 +528,9 @@ protected File downloadStructure(PdbId pdbId) throws IOException { } /** - * Download a file from the ftp server +/- its validation metadata, replacing any existing files if needed + * Download a file from the http server +/- its validation metadata, replacing any existing files if needed * @param pdbId PDB ID - * @param pathOnServer Path on the FTP server, e.g. data/structures/divided/pdb + * @param pathOnServer Path on the http server, e.g. data/structures/divided/pdb * @param obsolete Whether or not file should be saved to the obsolete location locally * @param existingFile if not null and checkServerFileDate is true, the last modified date of the * server file and this file will be compared to decide whether to download or not @@ -548,9 +546,7 @@ private File downloadStructure(PdbId pdbId, String pathOnServer, boolean obsolet String ftp; String filename = getFilename(id); - if (filename.endsWith(".mmtf.gz")){ - ftp = CodecUtils.getMmtfEntryUrl(id, true, false); - } else if (filename.endsWith(".bcif") || filename.endsWith(".bcif.gz")) { + if (filename.endsWith(".bcif") || filename.endsWith(".bcif.gz")) { // TODO this should be configurable ftp = DEFAULT_BCIF_FILE_SERVER + filename; } else { @@ -578,8 +574,8 @@ private File downloadStructure(PdbId pdbId, String pathOnServer, boolean obsolet } } - logger.info("Fetching " + ftp); - logger.info("Writing to "+ realFile); + logger.info("Fetching {}", ftp); + logger.info("Writing to {}", realFile); FileDownloadUtils.createValidationFiles(url, realFile, null, FileDownloadUtils.Hash.UNKNOWN); FileDownloadUtils.downloadFile(url, realFile); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfActions.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfActions.java index 7b9cd4642f..0b8572ab8c 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfActions.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfActions.java @@ -85,22 +85,6 @@ public static void writeToOutputStream(Structure structure, OutputStream outputS outputStream.write(outputBytes,0,outputBytes.length); } - - /** - * Get a Biojava structure from the mmtf REST service. - * @param pdbId the PDB code of the required structure - * @return a Structure object relating to the input byte array - * @throws IOException - */ - public static Structure readFromWeb(String pdbId) throws IOException { - // Get the reader - this is the bit that people need to implement. - MmtfStructureReader mmtfStructureReader = new MmtfStructureReader(); - // Do the inflation - new StructureDataToAdapter(new GenericDecoder(ReaderUtils.getDataFromUrl(pdbId)), mmtfStructureReader); - // Get the structue - return mmtfStructureReader.getStructure(); - } - /** * Read a Biojava structure from an {@link InputStream} * @param inStream the {@link InputStream} to read from