Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand Down
47 changes: 0 additions & 47 deletions biojava-structure/src/main/java/demo/DemoMmtfReader.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down