[med-svn] [Git][med-team/biojava4-live][upstream] 2 commits: New upstream version 4.2.12
Andreas Tille
gitlab at salsa.debian.org
Thu Jan 10 10:48:51 GMT 2019
Andreas Tille pushed to branch upstream at Debian Med / biojava4-live
Commits:
3aba982f by Andreas Tille at 2019-01-10T09:49:06Z
New upstream version 4.2.12
- - - - -
8d48abfe by Andreas Tille at 2019-01-10T10:33:38Z
New upstream version 4.2.12+dfsg
- - - - -
29 changed files:
- biojava-aa-prop/pom.xml
- biojava-alignment/pom.xml
- biojava-core/pom.xml
- biojava-core/src/main/java/org/biojava/nbio/core/sequence/loader/UniprotProxySequenceReader.java
- biojava-genome/pom.xml
- biojava-integrationtest/pom.xml
- biojava-modfinder/pom.xml
- biojava-ontology/pom.xml
- biojava-phylo/pom.xml
- biojava-protein-disorder/pom.xml
- biojava-sequencing/pom.xml
- biojava-structure-gui/pom.xml
- biojava-structure/pom.xml
- biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java
- biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java
- biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java
- biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompGroupFactory.java
- biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java
- biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java
- biojava-structure/src/main/java/org/biojava/nbio/structure/io/util/FileDownloadUtils.java
- biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmResult.java
- biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java
- biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java
- biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java
- + biojava-structure/src/test/java/org/biojava/nbio/structure/test/util/GlobalsHelper.java
- + biojava-structure/src/test/resources/atp.cif.gz
- biojava-survival/pom.xml
- biojava-ws/pom.xml
- pom.xml
Changes:
=====================================
biojava-aa-prop/pom.xml
=====================================
@@ -2,7 +2,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>biojava-aa-prop</artifactId>
@@ -70,12 +70,12 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</dependency>
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-structure</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</dependency>
<!-- logging dependencies (managed by parent pom, don't set versions or scopes here) -->
=====================================
biojava-alignment/pom.xml
=====================================
@@ -4,7 +4,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<artifactId>biojava-alignment</artifactId>
<name>biojava-alignment</name>
@@ -46,7 +46,7 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -74,7 +74,7 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-phylo</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</dependency>
</dependencies>
</project>
=====================================
biojava-core/pom.xml
=====================================
@@ -3,7 +3,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>biojava-core</artifactId>
=====================================
biojava-core/src/main/java/org/biojava/nbio/core/sequence/loader/UniprotProxySequenceReader.java
=====================================
@@ -88,7 +88,7 @@ public class UniprotProxySequenceReader<C extends Compound> implements ProxySequ
private static final String TREMBLID_PATTERN = "[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2}";
public static final Pattern UP_AC_PATTERN = Pattern.compile("(" + SPID_PATTERN + "|" + TREMBLID_PATTERN + ")");
- private static String uniprotbaseURL = "http://www.uniprot.org"; //"http://pir.uniprot.org";
+ private static String uniprotbaseURL = "https://www.uniprot.org"; //"http://pir.uniprot.org";
private static String uniprotDirectoryCache = null;
private String sequence;
private CompoundSet<C> compoundSet;
@@ -414,6 +414,61 @@ public class UniprotProxySequenceReader<C extends Compound> implements ProxySequ
fw.write(sb.toString());
fw.close();
}
+
+ /**
+ * Open a URL connection.
+ *
+ * Follows redirects.
+ * @param url
+ * @throws IOException
+ */
+ private static HttpURLConnection openURLConnection(URL url) throws IOException {
+ // This method should be moved to a utility class in BioJava 5.0
+
+ final int timeout = 5000;
+ final String useragent = "BioJava";
+
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setRequestProperty("User-Agent", useragent);
+ conn.setInstanceFollowRedirects(true);
+ conn.setConnectTimeout(timeout);
+ conn.setReadTimeout(timeout);
+
+ int status = conn.getResponseCode();
+ while (status == HttpURLConnection.HTTP_MOVED_TEMP
+ || status == HttpURLConnection.HTTP_MOVED_PERM
+ || status == HttpURLConnection.HTTP_SEE_OTHER) {
+ // Redirect!
+ String newUrl = conn.getHeaderField("Location");
+
+ if(newUrl.equals(url.toString())) {
+ throw new IOException("Cyclic redirect detected at "+newUrl);
+ }
+
+ // Preserve cookies
+ String cookies = conn.getHeaderField("Set-Cookie");
+
+ // open the new connection again
+ url = new URL(newUrl);
+ conn.disconnect();
+ conn = (HttpURLConnection) url.openConnection();
+ if(cookies != null) {
+ conn.setRequestProperty("Cookie", cookies);
+ }
+ conn.addRequestProperty("User-Agent", useragent);
+ conn.setInstanceFollowRedirects(true);
+ conn.setConnectTimeout(timeout);
+ conn.setReadTimeout(timeout);
+ conn.connect();
+
+ status = conn.getResponseCode();
+
+ logger.info("Redirecting from {} to {}", url, newUrl);
+ }
+ conn.connect();
+
+ return conn;
+ }
private StringBuilder fetchUniprotXML(String uniprotURL)
throws IOException, CompoundNotFoundException {
@@ -423,11 +478,9 @@ public class UniprotProxySequenceReader<C extends Compound> implements ProxySequ
int attempt = 5;
List<String> errorCodes = new ArrayList<String>();
while(attempt > 0) {
- HttpURLConnection uniprotConnection = (HttpURLConnection) uniprot.openConnection();
- uniprotConnection.setRequestProperty("User-Agent", "BioJava");
- uniprotConnection.connect();
+ HttpURLConnection uniprotConnection = openURLConnection(uniprot);
int statusCode = uniprotConnection.getResponseCode();
- if (statusCode == 200) {
+ if (statusCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(
new InputStreamReader(
uniprotConnection.getInputStream()));
=====================================
biojava-genome/pom.xml
=====================================
@@ -3,7 +3,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>biojava-genome</artifactId>
@@ -85,13 +85,13 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-alignment</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
=====================================
biojava-integrationtest/pom.xml
=====================================
@@ -4,7 +4,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<artifactId>biojava-integrationtest</artifactId>
<packaging>jar</packaging>
@@ -32,7 +32,7 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-structure</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</dependency>
<!-- logging dependencies (managed by parent pom, don't set versions or scopes here) -->
<dependency>
=====================================
biojava-modfinder/pom.xml
=====================================
@@ -4,7 +4,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<artifactId>biojava-modfinder</artifactId>
<name>biojava-modfinder</name>
@@ -31,7 +31,7 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-structure</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
=====================================
biojava-ontology/pom.xml
=====================================
@@ -4,7 +4,7 @@
<parent>
<groupId>org.biojava</groupId>
<artifactId>biojava</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<artifactId>biojava-ontology</artifactId>
=====================================
biojava-phylo/pom.xml
=====================================
@@ -3,7 +3,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>biojava-phylo</artifactId>
@@ -44,7 +44,7 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
=====================================
biojava-protein-disorder/pom.xml
=====================================
@@ -3,7 +3,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<artifactId>biojava-protein-disorder</artifactId>
<packaging>jar</packaging>
@@ -63,7 +63,7 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</dependency>
<!-- logging dependencies (managed by parent pom, don't set versions or
scopes here) -->
=====================================
biojava-sequencing/pom.xml
=====================================
@@ -3,7 +3,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>biojava-sequencing</artifactId>
@@ -47,7 +47,7 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
<!-- logging dependencies (managed by parent pom, don't set versions or scopes here) -->
=====================================
biojava-structure-gui/pom.xml
=====================================
@@ -3,7 +3,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>biojava-structure-gui</artifactId>
@@ -25,13 +25,13 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-structure</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
=====================================
biojava-structure/pom.xml
=====================================
@@ -4,7 +4,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<artifactId>biojava-structure</artifactId>
<name>biojava-structure</name>
@@ -22,13 +22,13 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-alignment</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
=====================================
biojava-structure/src/main/java/org/biojava/nbio/structure/StructureIO.java
=====================================
@@ -119,6 +119,11 @@ public class StructureIO {
public static void setAtomCache(AtomCache c){
cache = c;
}
+
+ public static AtomCache getAtomCache() {
+ checkInitAtomCache();
+ return cache;
+ }
/**
* Returns the first biologicalAssembly that is available for a protein structure. For more documentation on quaternary structures see:
=====================================
biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java
=====================================
@@ -636,6 +636,7 @@ public class CathInstallation implements CathDatabase{
protected void downloadFileFromRemote(URL remoteURL, File localFile) throws IOException{
// System.out.println("downloading " + remoteURL + " to: " + localFile);
+ LOGGER.info("Downloading file {} to local file {}", remoteURL, localFile);
long timeS = System.currentTimeMillis();
File tempFile = File.createTempFile(FileDownloadUtils.getFilePrefix(localFile), "."+ FileDownloadUtils.getFileExtension(localFile));
@@ -665,7 +666,7 @@ public class CathInstallation implements CathDatabase{
disp = disp / 1024.0;
}
long timeE = System.currentTimeMillis();
- LOGGER.info("Downloaded file {} ({}) to local file {} in {} sec.", remoteURL, String.format("%.1f",disp) + unit, localFile, (timeE - timeS)/1000);
+ LOGGER.info("Downloaded {} in {} sec. to {}", String.format("%.1f",disp) + unit, (timeE - timeS)/1000, localFile);
}
private boolean domainDescriptionFileAvailable(){
=====================================
biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java
=====================================
@@ -35,6 +35,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.nio.file.Files;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -127,6 +128,9 @@ public abstract class LocalPDBDirectory implements StructureIOFile {
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.
+
private File path;
private List<String> extensions;
@@ -402,8 +406,9 @@ public abstract class LocalPDBDirectory implements StructureIOFile {
* Attempts to delete all versions of a structure from the local directory.
* @param pdbId
* @return True if one or more files were deleted
+ * @throws IOException if the file cannot be deleted
*/
- public boolean deleteStructure(String pdbId){
+ public boolean deleteStructure(String pdbId) throws IOException{
boolean deleted = false;
// Force getLocalFile to check in obsolete locations
ObsoleteBehavior obsolete = getObsoleteBehavior();
@@ -421,7 +426,7 @@ public abstract class LocalPDBDirectory implements StructureIOFile {
// delete file
boolean success = existing.delete();
if(success) {
- logger.info("Deleting "+existing.getAbsolutePath());
+ logger.debug("Deleting "+existing.getAbsolutePath());
}
deleted = deleted || success;
@@ -430,7 +435,7 @@ public abstract class LocalPDBDirectory implements StructureIOFile {
if(parent != null) {
success = parent.delete();
if(success) {
- logger.info("Deleting "+parent.getAbsolutePath());
+ logger.debug("Deleting "+parent.getAbsolutePath());
}
}
@@ -660,8 +665,9 @@ public abstract class LocalPDBDirectory implements StructureIOFile {
* Searches for previously downloaded files
* @param pdbId
* @return A file pointing to the existing file, or null if not found
+ * @throws IOException If the file exists but is empty and can't be deleted
*/
- public File getLocalFile(String pdbId) {
+ public File getLocalFile(String pdbId) throws IOException {
// Search for existing files
@@ -687,6 +693,11 @@ public abstract class LocalPDBDirectory implements StructureIOFile {
for(String ex : getExtensions() ){
File f = new File(searchdir,prefix + pdbId.toLowerCase() + ex) ;
if ( f.exists()) {
+ // delete files that are too short to have contents
+ if( f.length() < MIN_PDB_FILE_SIZE ) {
+ Files.delete(f.toPath());
+ return null;
+ }
return f;
}
}
@@ -697,9 +708,11 @@ public abstract class LocalPDBDirectory implements StructureIOFile {
}
protected boolean checkFileExists(String pdbId){
- File path = getLocalFile(pdbId);
- if ( path != null)
- return true;
+ try {
+ File path = getLocalFile(pdbId);
+ if ( path != null)
+ return true;
+ } catch(IOException e) {}
return false;
}
=====================================
biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/ChemCompGroupFactory.java
=====================================
@@ -68,9 +68,8 @@ public class ChemCompGroupFactory {
* again. Note that this change can have unexpected behavior of
* code executed afterwards.
* <p>
- * Changing the provider does not reset the cache, so Chemical
- * Component definitions already downloaded from previous providers
- * will be used. To reset the cache see {@link #getCache()).
+ * Changing the provider also resets the cache, so any groups
+ * previously accessed will be reread or re-downloaded.
*
* @param provider
*/
@@ -84,6 +83,15 @@ public class ChemCompGroupFactory {
public static ChemCompProvider getChemCompProvider(){
return chemCompProvider;
}
+
+ /**
+ * Force the in-memory cache to be reset.
+ *
+ * Note that the ChemCompProvider may have additional memory or disk caches that need to be cleared too.
+ */
+ public static void clearCache() {
+ cache.clear();
+ }
public static Group getGroupFromChemCompDictionary(String recordName) {
=====================================
biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/DownloadChemCompProvider.java
=====================================
@@ -42,6 +42,7 @@ import java.util.zip.GZIPOutputStream;
import org.biojava.nbio.core.util.InputStreamProvider;
import org.biojava.nbio.structure.align.util.HTTPConnectionTools;
import org.biojava.nbio.structure.align.util.UserConfiguration;
+import org.biojava.nbio.structure.io.LocalPDBDirectory;
import org.biojava.nbio.structure.io.mmcif.model.ChemComp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -85,6 +86,8 @@ public class DownloadChemCompProvider implements ChemCompProvider {
protectedIDs.add("AUX");
protectedIDs.add("NUL");
}
+
+ private static ChemCompProvider fallback = null; // Fallback provider if the download fails
/** by default we will download only some of the files. User has to request that all files should be downloaded...
*
@@ -92,25 +95,28 @@ public class DownloadChemCompProvider implements ChemCompProvider {
boolean downloadAll = false;
public DownloadChemCompProvider(){
- logger.debug("Initialising DownloadChemCompProvider");
-
- // note that path is static, so this is just to make sure that all non-static methods will have path initialised
- initPath();
+ this(null);
}
public DownloadChemCompProvider(String cacheFilePath){
logger.debug("Initialising DownloadChemCompProvider");
// note that path is static, so this is just to make sure that all non-static methods will have path initialised
- path = new File(cacheFilePath);
+ if(cacheFilePath != null) {
+ path = new File(cacheFilePath);
+ }
}
- private static void initPath(){
-
+ /**
+ * Get this provider's cache path
+ * @return
+ */
+ public static File getPath(){
if (path==null) {
UserConfiguration config = new UserConfiguration();
path = new File(config.getCacheFilePath());
}
+ return path;
}
/**
@@ -127,7 +133,7 @@ public class DownloadChemCompProvider implements ChemCompProvider {
// this makes sure there is a file separator between every component,
// if path has a trailing file separator or not, it will work for both cases
- File dir = new File(path, CHEM_COMP_CACHE_DIRECTORY);
+ File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY);
File f = new File(dir, "components.cif.gz");
if ( ! f.exists()) {
@@ -161,7 +167,7 @@ public class DownloadChemCompProvider implements ChemCompProvider {
logger.info("Installing individual chem comp files ...");
- File dir = new File(path, CHEM_COMP_CACHE_DIRECTORY);
+ File dir = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY);
File f = new File(dir, "components.cif.gz");
@@ -212,7 +218,7 @@ public class DownloadChemCompProvider implements ChemCompProvider {
*/
private void writeID(String contents, String currentID) throws IOException{
- String localName = DownloadChemCompProvider.getLocalFileName(currentID);
+ String localName = getLocalFileName(currentID);
try ( PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(localName))) ) {
@@ -272,7 +278,10 @@ public class DownloadChemCompProvider implements ChemCompProvider {
ChemComp chemComp = dict.getChemComp(recordName);
- return chemComp;
+ // May be null if the file was corrupt. Fall back on ReducedChemCompProvider in that case
+ if(chemComp != null) {
+ return chemComp;
+ }
} catch (IOException e) {
@@ -296,9 +305,12 @@ public class DownloadChemCompProvider implements ChemCompProvider {
// see https://github.com/biojava/biojava/issues/315
// probably a network error happened. Try to use the ReducedChemCOmpProvider
- ReducedChemCompProvider reduced = new ReducedChemCompProvider();
+ if( fallback == null) {
+ fallback = new ReducedChemCompProvider();
+ }
- return reduced.getChemComp(recordName);
+ logger.warn("Falling back to ReducedChemCompProvider for {}. This could indicate a network error.", recordName);
+ return fallback.getChemComp(recordName);
}
@@ -313,16 +325,15 @@ public class DownloadChemCompProvider implements ChemCompProvider {
recordName = "_" + recordName;
}
- initPath();
-
- File f = new File(path, CHEM_COMP_CACHE_DIRECTORY);
+ File f = new File(getPath(), CHEM_COMP_CACHE_DIRECTORY);
if (! f.exists()){
logger.info("Creating directory " + f);
boolean success = f.mkdir();
// we've checked in initPath that path is writable, so there's no need to check if it succeeds
// in the unlikely case that in the meantime it isn't writable at least we log an error
- if (!success) logger.error("Directory {} could not be created",f);
+ if (!success)
+ logger.error("Directory {} could not be created",f);
}
@@ -337,6 +348,14 @@ public class DownloadChemCompProvider implements ChemCompProvider {
File f = new File(fileName);
+ // delete files that are too short to have contents
+ if( f.length() < LocalPDBDirectory.MIN_PDB_FILE_SIZE ) {
+ // Delete defensively.
+ // Note that if delete is unsuccessful, we re-download the file anyways
+ f.delete();
+ return false;
+ }
+
return f.exists();
}
=====================================
biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmcif/SimpleMMcifParser.java
=====================================
@@ -212,6 +212,9 @@ public class SimpleMMcifParser implements MMcifParser {
// the first line is a data_PDBCODE line, test if this looks like a mmcif file
line = buf.readLine();
+ while( line != null && (line.isEmpty() || line.startsWith(COMMENT_CHAR))) {
+ line = buf.readLine();
+ }
if (line == null || !line.startsWith(MMCIF_TOP_HEADER)){
logger.error("This does not look like a valid mmCIF file! The first line should start with 'data_', but is: '" + line+"'");
triggerDocumentEnd();
=====================================
biojava-structure/src/main/java/org/biojava/nbio/structure/io/util/FileDownloadUtils.java
=====================================
@@ -21,9 +21,6 @@
*/
package org.biojava.nbio.structure.io.util;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -36,6 +33,15 @@ import java.net.URLConnection;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class FileDownloadUtils {
@@ -240,6 +246,41 @@ public class FileDownloadUtils {
connection.setConnectTimeout(timeout);
return connection;
}
+
+ /**
+ * Recursively delete a folder & contents
+ *
+ * @param dir directory to delete
+ */
+ public static void deleteDirectory(Path dir) throws IOException {
+ if(dir == null || !Files.exists(dir))
+ return;
+ Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
+ if (e != null) {
+ throw e;
+ }
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ }
+ /**
+ * Recursively delete a folder & contents
+ *
+ * @param dir directory to delete
+ */
+ public static void deleteDirectory(String dir) throws IOException {
+ deleteDirectory(Paths.get(dir));
+ }
+
public static void main(String[] args) {
String url;
=====================================
biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmResult.java
=====================================
@@ -81,7 +81,7 @@ public class CeSymmResult {
// If the refinement was attempted
if (params.getRefineMethod() != RefineMethod.NOT_REFINED) {
// Check for minimum length
- if (multipleAlignment.getCoreLength() < params.getMinCoreLength())
+ if (multipleAlignment == null || multipleAlignment.getCoreLength() < params.getMinCoreLength())
return false;
// Allow 90% of original TM-Score theshold
if (multipleAlignment.getScore(MultipleAlignmentScorer.AVGTM_SCORE) < params
=====================================
biojava-structure/src/test/java/org/biojava/nbio/structure/TestAtomCache.java
=====================================
@@ -46,7 +46,7 @@ public class TestAtomCache {
private AtomCache cache;
@Before
- public void setUp() {
+ public void setUp() throws IOException {
cache = new AtomCache();
// Delete files which were cached in previous tests
=====================================
biojava-structure/src/test/java/org/biojava/nbio/structure/TestExperimentalTechniques.java
=====================================
@@ -31,7 +31,7 @@ import static org.junit.Assert.*;
public class TestExperimentalTechniques {
@Test
- public void test4LNC() throws IOException, StructureException {
+ public void test6F2Q() throws IOException, StructureException {
// a multiple experimental techniques PDB entry (X-RAY + NEUTRON DIFFRACTION)
@@ -40,9 +40,9 @@ public class TestExperimentalTechniques {
StructureIO.setAtomCache(cache);
cache.setUseMmCif(false);
- Structure sPdb = StructureIO.getStructure("4LNC");
+ Structure sPdb = StructureIO.getStructure("6F2Q");
cache.setUseMmCif(true);
- Structure sCif = StructureIO.getStructure("4LNC");
+ Structure sCif = StructureIO.getStructure("6F2Q");
comparePdbToCif(sPdb, sCif);
=====================================
biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java
=====================================
@@ -20,26 +20,52 @@
*/
package org.biojava.nbio.structure.align.util;
-import org.biojava.nbio.structure.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.zip.GZIPOutputStream;
+
+import org.biojava.nbio.structure.AtomPositionMap;
+import org.biojava.nbio.structure.Chain;
+import org.biojava.nbio.structure.Group;
+import org.biojava.nbio.structure.ResidueRangeAndLength;
+import org.biojava.nbio.structure.Structure;
+import org.biojava.nbio.structure.StructureException;
+import org.biojava.nbio.structure.StructureIO;
+import org.biojava.nbio.structure.StructureIdentifier;
+import org.biojava.nbio.structure.StructureTools;
+import org.biojava.nbio.structure.SubstructureIdentifier;
import org.biojava.nbio.structure.io.LocalPDBDirectory;
import org.biojava.nbio.structure.io.LocalPDBDirectory.FetchBehavior;
import org.biojava.nbio.structure.io.LocalPDBDirectory.ObsoleteBehavior;
import org.biojava.nbio.structure.io.MMCIFFileReader;
+import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
+import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
+import org.biojava.nbio.structure.io.mmcif.model.ChemComp;
+import org.biojava.nbio.structure.io.util.FileDownloadUtils;
import org.biojava.nbio.structure.scop.ScopDatabase;
import org.biojava.nbio.structure.scop.ScopFactory;
+import org.biojava.nbio.structure.test.util.GlobalsHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-
-import static org.junit.Assert.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -49,22 +75,24 @@ import static org.junit.Assert.*;
*/
public class AtomCacheTest {
+ private static Logger logger = LoggerFactory.getLogger(AtomCacheTest.class);
private AtomCache cache;
- private String previousPDB_DIR;
@Before
public void setUp() {
- previousPDB_DIR = System.getProperty(UserConfiguration.PDB_DIR, null);
+ GlobalsHelper.pushState();
+
cache = new AtomCache();
cache.setObsoleteBehavior(ObsoleteBehavior.FETCH_OBSOLETE);
+ StructureIO.setAtomCache(cache);
+
// Use a fixed SCOP version for stability
ScopFactory.setScopDatabase(ScopFactory.VERSION_1_75B);
}
@After
public void tearDown() {
- if (previousPDB_DIR != null)
- System.setProperty(UserConfiguration.PDB_DIR, previousPDB_DIR);
+ GlobalsHelper.restoreState();
}
/**
@@ -312,4 +340,125 @@ public class AtomCacheTest {
}
+ /**
+ * Test for #703 - Chemical component cache poisoning
+ *
+ * Handle empty CIF files
+ * @throws IOException
+ * @throws StructureException
+ */
+ @Test
+ public void testEmptyChemComp() throws IOException, StructureException {
+ Path tmpCache = Paths.get(System.getProperty("java.io.tmpdir"),"BIOJAVA_TEST_CACHE");
+ logger.info("Testing AtomCache at {}", tmpCache.toString());
+ System.setProperty(UserConfiguration.PDB_DIR, tmpCache.toString());
+ System.setProperty(UserConfiguration.PDB_CACHE_DIR, tmpCache.toString());
+
+ FileDownloadUtils.deleteDirectory(tmpCache);
+ Files.createDirectory(tmpCache);
+ try {
+ cache.setPath(tmpCache.toString());
+ cache.setCachePath(tmpCache.toString());
+ cache.setUseMmCif(true);
+ ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider(tmpCache.toString()));
+
+ // Create an empty chemcomp
+ Path chemCompCif = tmpCache.resolve(Paths.get("chemcomp", "ATP.cif.gz"));
+ Files.createDirectories(chemCompCif.getParent());
+ Files.createFile(chemCompCif);
+ assertTrue(Files.exists(chemCompCif));
+ assertEquals(0, Files.size(chemCompCif));
+
+ // Copy stub file into place
+ Path testCif = tmpCache.resolve(Paths.get("data", "structures", "divided", "mmCIF", "ab","1abc.cif.gz"));
+ Files.createDirectories(testCif.getParent());
+ URL resource = AtomCacheTest.class.getResource("/atp.cif.gz");
+ File src = new File(resource.getPath());
+ FileDownloadUtils.copy(src, testCif.toFile());
+
+ // Load structure
+ Structure s = cache.getStructure("1ABC");
+
+ // Should have re-downloaded the file
+ assertTrue(Files.size(chemCompCif) > LocalPDBDirectory.MIN_PDB_FILE_SIZE);
+
+ // Structure should have valid ChemComp now
+ assertNotNull(s);
+
+ Group g = s.getChainByPDB("A").getAtomGroup(0);
+ assertTrue(g.getPDBName().equals("ATP"));
+
+ // should be unknown
+ ChemComp chem = g.getChemComp();
+ assertNotNull(chem);
+ assertTrue(chem.getAtoms().size() > 0);
+ assertEquals("NON-POLYMER", chem.getType());
+ } finally {
+ FileDownloadUtils.deleteDirectory(tmpCache);
+ }
+ }
+
+ /**
+ * Test for #703 - Chemical component cache poisoning
+ *
+ * Handle empty CIF files
+ * @throws IOException
+ * @throws StructureException
+ */
+ @Test
+ public void testEmptyGZChemComp() throws IOException, StructureException {
+
+ Path tmpCache = Paths.get(System.getProperty("java.io.tmpdir"),"BIOJAVA_TEST_CACHE");
+ logger.info("Testing AtomCache at {}", tmpCache.toString());
+ System.setProperty(UserConfiguration.PDB_DIR, tmpCache.toString());
+ System.setProperty(UserConfiguration.PDB_CACHE_DIR, tmpCache.toString());
+
+ FileDownloadUtils.deleteDirectory(tmpCache);
+ Files.createDirectory(tmpCache);
+ try {
+ cache.setPath(tmpCache.toString());
+ cache.setCachePath(tmpCache.toString());
+ cache.setUseMmCif(true);
+ ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider(tmpCache.toString()));
+
+
+ // Create an empty chemcomp
+ Path sub = tmpCache.resolve(Paths.get("chemcomp", "ATP.cif.gz"));
+ Files.createDirectories(sub.getParent());
+ try(GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(sub.toFile()))) {
+ // don't write anything
+ out.flush();
+ }
+ assertTrue(Files.exists(sub));
+ assertTrue(0 < Files.size(sub) && Files.size(sub) < LocalPDBDirectory.MIN_PDB_FILE_SIZE);
+
+ // Copy stub file into place
+ Path testCif = tmpCache.resolve(Paths.get("data", "structures", "divided", "mmCIF", "ab","1abc.cif.gz"));
+ Files.createDirectories(testCif.getParent());
+ URL resource = AtomCacheTest.class.getResource("/atp.cif.gz");
+ File src = new File(resource.getPath());
+ FileDownloadUtils.copy(src, testCif.toFile());
+
+ // Load structure
+ Structure s = cache.getStructure("1ABC");
+
+ // Should have re-downloaded the file
+ assertTrue(Files.size(sub) > LocalPDBDirectory.MIN_PDB_FILE_SIZE);
+
+ // Structure should have valid ChemComp
+ assertNotNull(s);
+
+ Group g = s.getChainByPDB("A").getAtomGroup(0);
+ assertTrue(g.getPDBName().equals("ATP"));
+
+ // should be unknown
+ ChemComp chem = g.getChemComp();
+ assertNotNull(chem);
+ assertTrue(chem.getAtoms().size() > 0);
+ assertEquals("NON-POLYMER", chem.getType());
+ } finally {
+ FileDownloadUtils.deleteDirectory(tmpCache);
+ }
+ }
+
}
=====================================
biojava-structure/src/test/java/org/biojava/nbio/structure/test/util/GlobalsHelper.java
=====================================
@@ -0,0 +1,124 @@
+package org.biojava.nbio.structure.test.util;
+
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import org.biojava.nbio.structure.StructureIO;
+import org.biojava.nbio.structure.align.util.AtomCache;
+import org.biojava.nbio.structure.align.util.UserConfiguration;
+import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
+import org.biojava.nbio.structure.io.mmcif.ChemCompProvider;
+import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
+import org.biojava.nbio.structure.scop.ScopDatabase;
+import org.biojava.nbio.structure.scop.ScopFactory;
+
+/**
+ * Helper class to manage all the global state changes in BioJava.
+ * For instance, this should be used in tests before modifying PDB_PATH.
+ *
+ * Used by tests during setup and teardown to ensure a clean environment
+ *
+ * This class is a singleton.
+ * @author Spencer Bliven
+ *
+ */
+public final class GlobalsHelper {
+
+ private static class PathInfo {
+ public final String pdbPath;
+ public final String pdbCachePath;
+ public final AtomCache atomCache;
+ public final ChemCompProvider chemCompProvider;
+ public final String downloadChemCompProviderPath;
+ public final ScopDatabase scop;
+
+ public PathInfo() {
+ pdbPath = System.getProperty(UserConfiguration.PDB_DIR, null);
+ pdbCachePath = System.getProperty(UserConfiguration.PDB_CACHE_DIR, null);
+ atomCache = StructureIO.getAtomCache();
+ chemCompProvider = ChemCompGroupFactory.getChemCompProvider();
+ downloadChemCompProviderPath = DownloadChemCompProvider.getPath().getPath();
+ scop = ScopFactory.getSCOP();
+ }
+ }
+
+ // Saves defaults as stack
+ private static Deque<PathInfo> stack = new LinkedList<>();
+ static {
+ // Save default state
+ pushState();
+ }
+
+ /**
+ * GlobalsHelper should not be instantiated.
+ */
+ private GlobalsHelper() {}
+
+ /**
+ * Save current global state to the stack
+ */
+ public static void pushState() {
+ PathInfo paths = new PathInfo();
+ stack.addFirst(paths);
+ }
+
+ /**
+ * Sets a new PDB_PATH and PDB_CACHE_PATH consistently.
+ *
+ * Previous values can be restored with {@link #restoreState()}.
+ * @param path
+ */
+ public static void setPdbPath(String path, String cachePath) {
+ pushState();
+ if(path == null || cachePath == null) {
+ UserConfiguration config = new UserConfiguration();
+ if(path == null) {
+ path = config.getPdbFilePath();
+ }
+ if(cachePath == null) {
+ cachePath = config.getCacheFilePath();
+ }
+ }
+ System.setProperty(UserConfiguration.PDB_DIR, path);
+ System.setProperty(UserConfiguration.PDB_CACHE_DIR, path);
+
+ AtomCache cache = new AtomCache(path);
+ StructureIO.setAtomCache(cache);
+
+ // Note side effect setting the path for all DownloadChemCompProvider due to static state
+ ChemCompProvider provider = new DownloadChemCompProvider(path);
+ ChemCompGroupFactory.setChemCompProvider(provider);
+ }
+
+ /**
+ * Restore global state to the previous settings
+ * @throws NoSuchElementException if there is no prior state to restore
+ */
+ public static void restoreState() {
+ PathInfo paths = stack.removeFirst();
+
+ if(paths.pdbPath == null) {
+ System.clearProperty(UserConfiguration.PDB_DIR);
+ } else {
+ System.setProperty(UserConfiguration.PDB_DIR, paths.pdbPath);
+ }
+ if(paths.pdbCachePath == null) {
+ System.clearProperty(UserConfiguration.PDB_CACHE_DIR);
+ } else {
+ System.setProperty(UserConfiguration.PDB_CACHE_DIR, paths.pdbCachePath);
+ }
+
+ StructureIO.setAtomCache(paths.atomCache);
+
+ // Use side effect setting the path for all DownloadChemCompProvider due to static state
+ new DownloadChemCompProvider(paths.downloadChemCompProviderPath);
+
+ ChemCompGroupFactory.setChemCompProvider(paths.chemCompProvider);
+
+ ScopFactory.setScopDatabase(paths.scop);
+ }
+
+
+}
=====================================
biojava-structure/src/test/resources/atp.cif.gz
=====================================
Binary files /dev/null and b/biojava-structure/src/test/resources/atp.cif.gz differ
=====================================
biojava-survival/pom.xml
=====================================
@@ -4,7 +4,7 @@
<parent>
<groupId>org.biojava</groupId>
<artifactId>biojava</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<artifactId>biojava-survival</artifactId>
=====================================
biojava-ws/pom.xml
=====================================
@@ -3,7 +3,7 @@
<parent>
<artifactId>biojava</artifactId>
<groupId>org.biojava</groupId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
</parent>
<artifactId>biojava-ws</artifactId>
<name>biojava-ws</name>
@@ -19,7 +19,7 @@
<dependency>
<groupId>org.biojava</groupId>
<artifactId>biojava-core</artifactId>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
=====================================
pom.xml
=====================================
@@ -12,7 +12,7 @@
<groupId>org.biojava</groupId>
<artifactId>biojava</artifactId>
<packaging>pom</packaging>
- <version>4.2.11</version>
+ <version>4.2.12</version>
<name>biojava</name>
<description>BioJava is an open-source project dedicated to providing a Java framework for processing biological
data. It provides analytical and statistical routines, parsers for common file formats and allows the
@@ -44,7 +44,7 @@
<developerConnection>scm:git:git at github.com:biojava/biojava.git</developerConnection>
<url>https://github.com/biojava/biojava</url>
- <tag>biojava-4.2.11</tag>
+ <tag>biojava-4.2.12</tag>
</scm>
<!-- This section required for release at Maven Central. For a full list
@@ -212,12 +212,14 @@
<version>2.10.3</version>
<configuration>
<!-- we need to allow script in comments or otherwise we can't use google analytics js in footer below - JD 2017-06-06 -->
- <additionalparam>--allow-script-in-comments</additionalparam>
+ <!-- requires java 8u121
+ <additionalparam>--><!--allow-script-in-comments</additionalparam>
<maxmemory>256m</maxmemory>
<footer><script src="http://www.google-analytics.com/urchin.js"
type="text/javascript"></script><script
type="text/javascript">_uacct =
"UA-1326640-1";urchinTracker();</script></footer>
+ -->
</configuration>
</plugin>
@@ -271,6 +273,12 @@
<version>2.7</version>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ </plugin>
+
</plugins>
</pluginManagement>
View it on GitLab: https://salsa.debian.org/med-team/biojava4-live/compare/9eaa739bafda061ec60a5a2851afd718e8a2c032...8d48abfeaece53f6aa10519dcddb356fd0240205
--
View it on GitLab: https://salsa.debian.org/med-team/biojava4-live/compare/9eaa739bafda061ec60a5a2851afd718e8a2c032...8d48abfeaece53f6aa10519dcddb356fd0240205
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20190110/698fac5d/attachment-0001.html>
More information about the debian-med-commit
mailing list