From 372ea6a7ade562bb2148fbd3ac08f8c88eaaaf58 Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Thu, 28 Jul 2016 10:26:26 -0700 Subject: [PATCH 1/2] Some work towards fixing #544 --- .../nbio/structure/cath/CathFactory.java | 3 +- .../nbio/structure/cath/CathInstallation.java | 40 +++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java index d80664affa..c84873b86d 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java @@ -37,7 +37,8 @@ public class CathFactory { public static final String VERSION_3_5_0 = "3.5.0"; public static final String VERSION_4_0_0 = "4.0.0"; - public static final String LATEST_VERSION = VERSION_4_0_0; + public static final String VERSION_4_1_0 = "4_1_0"; + public static final String LATEST_VERSION = VERSION_4_1_0; public static String DEFAULT_VERSION = LATEST_VERSION; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java index 77346f0cc6..52988fcc21 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java @@ -45,37 +45,37 @@ public class CathInstallation implements CathDatabase{ String cathVersion; - public static final String domainListFileName = "CathDomainList"; + public static final String domainListFileName = "cath-domain-list-v4_1_0.txt"; public static final String domainDescriptionFileName = "CathDomainDescriptionFile"; public static final String nodeListFileName = "CathNames"; public static final String domallFileName = "CathDomall"; + + //http://download.cathdb.info/cath/releases/latest-release/v4_1_0/cath-classification-data/cath-domain-list-v4_1_0.txt - public static final String CATH_DOWNLOAD = "http://release.cathdb.info/"; + public static final String CATH_DOWNLOAD = "http://download.cathdb.info/cath/releases/latest-release/"; + public static final String CATH_DOWNLOAD_SUFFIX = "cath-classification-data"; - String cathDownloadUrl; + private String cathDownloadUrl; - public static final String NEWLINE; - public static final String FILESPLIT ; + public static final String NEWLINE = System.getProperty("line.separator");; + public static final String FILESPLIT = System.getProperty("file.separator");; - static { - NEWLINE = System.getProperty("line.separator"); - FILESPLIT = System.getProperty("file.separator"); - } + private String cacheLocation ; - AtomicBoolean installedDomainList; - AtomicBoolean installedDomainDescription; - AtomicBoolean installedNodeList; - AtomicBoolean installedDomall; + private AtomicBoolean installedDomainList; + private AtomicBoolean installedDomainDescription; + private AtomicBoolean installedNodeList; + private AtomicBoolean installedDomall; - final boolean useCathDomainDescriptionFile; - final boolean parseCathFragments; + private final boolean useCathDomainDescriptionFile; + private final boolean parseCathFragments; - Map> pdbMap; - Map domainMap; - Map cathTree; - Map> fragmentMap; + private Map> pdbMap; + private Map domainMap; + private Map cathTree; + private Map> fragmentMap; @@ -682,7 +682,7 @@ private boolean domallFileAvailable() { protected void downloadDomainListFile() throws FileNotFoundException, IOException{ String remoteFilename = domainListFileName; - URL url = new URL(cathDownloadUrl + "v" + cathVersion + "/" + remoteFilename); + URL url = new URL(cathDownloadUrl + "v" + cathVersion + "/" + CATH_DOWNLOAD_SUFFIX + "/" + remoteFilename); String localFileName = getDomainListFileName(); File localFile = new File(localFileName); downloadFileFromRemote(url, localFile); From 5a583e7ca887518bab9091215ffd988d343ed41f Mon Sep 17 00:00:00 2001 From: Jose Manuel Duarte Date: Thu, 28 Jul 2016 11:29:26 -0700 Subject: [PATCH 2/2] Fixing #544 and improving logging --- .../nbio/structure/cath/CathFactory.java | 6 +- .../nbio/structure/cath/CathInstallation.java | 84 +++++++++++-------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java index c84873b86d..1b185fc01b 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathFactory.java @@ -35,12 +35,12 @@ */ public class CathFactory { - public static final String VERSION_3_5_0 = "3.5.0"; - public static final String VERSION_4_0_0 = "4.0.0"; + public static final String VERSION_3_5_0 = "3_5_0"; + public static final String VERSION_4_0_0 = "4_0_0"; public static final String VERSION_4_1_0 = "4_1_0"; public static final String LATEST_VERSION = VERSION_4_1_0; - public static String DEFAULT_VERSION = LATEST_VERSION; + public static final String DEFAULT_VERSION = LATEST_VERSION; private static CathDatabase cath; diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java index 52988fcc21..ff5db84d83 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java @@ -25,6 +25,8 @@ import org.biojava.nbio.structure.align.util.UserConfiguration; import org.biojava.nbio.structure.io.util.FileDownloadUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.biojava.nbio.core.util.InputStreamProvider; import java.io.*; @@ -41,27 +43,29 @@ */ public class CathInstallation implements CathDatabase{ + private static final Logger LOGGER = LoggerFactory.getLogger(CathInstallation.class); + public static final String DEFAULT_VERSION = CathFactory.DEFAULT_VERSION; - String cathVersion; - - public static final String domainListFileName = "cath-domain-list-v4_1_0.txt"; + public static final String domainListFileName = "cath-domain-list-v%s.txt"; + // TODO I don't know what are the new file nams for domainDescriptionFileName and nodeListFileName in the new CATH 4.1.0 servers, must find out! - JD 2016-07-28 public static final String domainDescriptionFileName = "CathDomainDescriptionFile"; public static final String nodeListFileName = "CathNames"; - public static final String domallFileName = "CathDomall"; + public static final String domallFileName = "cath-domain-boundaries-v%s.txt"; - //http://download.cathdb.info/cath/releases/latest-release/v4_1_0/cath-classification-data/cath-domain-list-v4_1_0.txt - - public static final String CATH_DOWNLOAD = "http://download.cathdb.info/cath/releases/latest-release/"; - public static final String CATH_DOWNLOAD_SUFFIX = "cath-classification-data"; - - private String cathDownloadUrl; + public static final String CATH_DOWNLOAD_URL = "http://download.cathdb.info/cath/releases/"; + public static final String CATH_DOWNLOAD_LATEST_RELEASE_DIR = "latest-release"; + public static final String CATH_DOWNLOAD_PREV_RELEASE_DIR = "previous-releases"; + public static final String CATH_DOWNLOAD_CLASSIFICATION_DATA_DIR = "cath-classification-data"; public static final String NEWLINE = System.getProperty("line.separator");; public static final String FILESPLIT = System.getProperty("file.separator");; + private String cathVersion; + private String cathDownloadUrl; + private String cacheLocation ; private AtomicBoolean installedDomainList; @@ -91,7 +95,7 @@ public CathInstallation(String cacheLocation, boolean usingCDDF, boolean parseCF installedDomall = new AtomicBoolean(false); cathVersion = DEFAULT_VERSION; - cathDownloadUrl = CATH_DOWNLOAD; + cathDownloadUrl = CATH_DOWNLOAD_URL; pdbMap = new HashMap>(); domainMap = new HashMap(); @@ -110,19 +114,32 @@ public CathInstallation() { } public String getDomainListFileName() { - return cacheLocation + domainListFileName + ".v" + cathVersion; + return cacheLocation + buildFileName(domainListFileName); } public String getDomainDescriptionFileName() { - return cacheLocation + domainDescriptionFileName + ".v" + cathVersion; + return cacheLocation + buildFileName(domainDescriptionFileName); } public String getNodeListFileName() { - return cacheLocation + nodeListFileName + ".v" + cathVersion; + return cacheLocation + buildFileName(nodeListFileName); } public String getDomallFileName() { - return cacheLocation + domallFileName + ".v" + cathVersion; + return cacheLocation + buildFileName(domallFileName); + } + + private String buildFileName(String fileNameTemplate) { + return String.format(fileNameTemplate, cathVersion); + } + + private String buildUrl(String remoteFileName) { + String remoteFileNameWithVer = buildFileName(remoteFileName); + String releasesDir = CATH_DOWNLOAD_LATEST_RELEASE_DIR; + if (!cathVersion.equals(CathFactory.LATEST_VERSION)) { + releasesDir = CATH_DOWNLOAD_PREV_RELEASE_DIR; + } + return cathDownloadUrl + releasesDir + "/v" + cathVersion + "/" + CATH_DOWNLOAD_CLASSIFICATION_DATA_DIR + "/" + remoteFileNameWithVer; } public String getCathDownloadUrl() { @@ -418,7 +435,7 @@ private void parseCathDomainDescriptionFile(BufferedReader bufferedReader) throw try { cathDescription.setDate( dateFormat.parse( line.substring(10) ) ); } catch (ParseException e) { - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); } } else if ( line.startsWith("NAME") ) { name.append( line.substring(10) ); @@ -622,7 +639,7 @@ private void parseCathDomall(BufferedReader bufferedReader) throws IOException{ } } - protected void downloadFileFromRemote(URL remoteURL, File localFile) throws FileNotFoundException, IOException{ + protected void downloadFileFromRemote(URL remoteURL, File localFile) throws IOException{ // System.out.println("downloading " + remoteURL + " to: " + localFile); long timeS = System.currentTimeMillis(); @@ -653,7 +670,7 @@ protected void downloadFileFromRemote(URL remoteURL, File localFile) throws File disp = disp / 1024.0; } long timeE = System.currentTimeMillis(); - System.out.println("downloaded " + String.format("%.1f",disp) + unit + " in " + (timeE - timeS)/1000 + " sec."); + LOGGER.info("Downloaded file {} ({}) to local file {} in {} sec.", remoteURL, String.format("%.1f",disp) + unit, localFile, (timeE - timeS)/1000); } private boolean domainDescriptionFileAvailable(){ @@ -680,25 +697,25 @@ private boolean domallFileAvailable() { return f.exists(); } - protected void downloadDomainListFile() throws FileNotFoundException, IOException{ + protected void downloadDomainListFile() throws IOException{ String remoteFilename = domainListFileName; - URL url = new URL(cathDownloadUrl + "v" + cathVersion + "/" + CATH_DOWNLOAD_SUFFIX + "/" + remoteFilename); + URL url = new URL(buildUrl(remoteFilename)); String localFileName = getDomainListFileName(); File localFile = new File(localFileName); downloadFileFromRemote(url, localFile); } - protected void downloadDomainDescriptionFile() throws FileNotFoundException, IOException{ + protected void downloadDomainDescriptionFile() throws IOException{ String remoteFilename = domainDescriptionFileName; - URL url = new URL(cathDownloadUrl + "v" + cathVersion + "/" + remoteFilename); + URL url = new URL(buildUrl(remoteFilename)); String localFileName = getDomainDescriptionFileName(); File localFile = new File(localFileName); downloadFileFromRemote(url, localFile); } - protected void downloadNodeListFile() throws FileNotFoundException, IOException{ + protected void downloadNodeListFile() throws IOException{ String remoteFilename = nodeListFileName; - URL url = new URL(cathDownloadUrl + "v" + cathVersion + "/" + remoteFilename); + URL url = new URL(buildUrl(remoteFilename)); String localFileName = getNodeListFileName(); File localFile = new File(localFileName); downloadFileFromRemote(url, localFile); @@ -706,7 +723,7 @@ protected void downloadNodeListFile() throws FileNotFoundException, IOException{ protected void downloadDomallFile() throws IOException { String remoteFileName = domallFileName; - URL url = new URL(cathDownloadUrl + "v" + cathVersion + "/" + remoteFileName); + URL url = new URL(buildUrl(remoteFileName)); String localFileName = getDomallFileName(); File localFile = new File(localFileName); downloadFileFromRemote(url, localFile); @@ -719,7 +736,7 @@ public void ensureDomainListInstalled(){ try { downloadDomainListFile(); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error("Could not download CATH domain list file. Error: {}", e.getMessage()); installedDomainList.set(false); return; } @@ -728,7 +745,7 @@ public void ensureDomainListInstalled(){ try { parseCathDomainList(); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); installedDomainList.set(false); return; } @@ -742,7 +759,7 @@ public void ensureDomainDescriptionInstalled(){ try { downloadDomainDescriptionFile(); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error("Could not download CATH domain description file. Error: {}", e.getMessage()); installedDomainDescription.set(false); return; } @@ -751,7 +768,7 @@ public void ensureDomainDescriptionInstalled(){ try { parseCathDomainDescriptionFile(); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); installedDomainDescription.set(false); return; } @@ -765,7 +782,7 @@ public void ensureNodeListInstalled(){ try { downloadNodeListFile(); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error("Could not download CATH node list file. Error: {}", e.getMessage()); installedNodeList.set(false); return; } @@ -774,7 +791,7 @@ public void ensureNodeListInstalled(){ try { parseCathNames(); } catch (Exception e){ - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); installedNodeList.set(false); return; } @@ -795,7 +812,7 @@ public void ensureDomallInstalled() { try { downloadDomallFile(); } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Could not download CATH domain all file. Error: {}", e.getMessage()); installedDomall.set(false); return; } @@ -804,7 +821,7 @@ public void ensureDomallInstalled() { try { parseCathDomall(); } catch (Exception e) { - e.printStackTrace(); + LOGGER.error(e.getMessage(), e); installedDomall.set(false); return; } @@ -814,5 +831,6 @@ public void ensureDomallInstalled() { public void setCathVersion(String cathVersion) { this.cathVersion = cathVersion; } + }