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 @@ -35,11 +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 LATEST_VERSION = VERSION_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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -41,41 +43,43 @@
*/
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 = "CathDomainList";
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 CATH_DOWNLOAD = "http://release.cathdb.info/";
public static final String domallFileName = "cath-domain-boundaries-v%s.txt";

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";

String cathDownloadUrl;
public static final String NEWLINE = System.getProperty("line.separator");;
public static final String FILESPLIT = System.getProperty("file.separator");;

public static final String NEWLINE;
public static final String FILESPLIT ;

static {
NEWLINE = System.getProperty("line.separator");
FILESPLIT = System.getProperty("file.separator");
}

private String cathVersion;

private String cathDownloadUrl;

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<String, List<CathDomain>> pdbMap;
Map<String, CathDomain> domainMap;
Map<String, CathNode> cathTree;
Map<String, List<CathFragment>> fragmentMap;
private Map<String, List<CathDomain>> pdbMap;
private Map<String, CathDomain> domainMap;
private Map<String, CathNode> cathTree;
private Map<String, List<CathFragment>> fragmentMap;



Expand All @@ -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<String, List<CathDomain>>();
domainMap = new HashMap<String ,CathDomain>();
Expand All @@ -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() {
Expand Down Expand Up @@ -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) );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(){
Expand All @@ -680,33 +697,33 @@ 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 + "/" + 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);
}

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);
Expand All @@ -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;
}
Expand All @@ -728,7 +745,7 @@ public void ensureDomainListInstalled(){
try {
parseCathDomainList();
} catch (Exception e){
e.printStackTrace();
LOGGER.error(e.getMessage(), e);
installedDomainList.set(false);
return;
}
Expand All @@ -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;
}
Expand All @@ -751,7 +768,7 @@ public void ensureDomainDescriptionInstalled(){
try {
parseCathDomainDescriptionFile();
} catch (Exception e){
e.printStackTrace();
LOGGER.error(e.getMessage(), e);
installedDomainDescription.set(false);
return;
}
Expand All @@ -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;
}
Expand All @@ -774,7 +791,7 @@ public void ensureNodeListInstalled(){
try {
parseCathNames();
} catch (Exception e){
e.printStackTrace();
LOGGER.error(e.getMessage(), e);
installedNodeList.set(false);
return;
}
Expand All @@ -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;
}
Expand All @@ -804,7 +821,7 @@ public void ensureDomallInstalled() {
try {
parseCathDomall();
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.getMessage(), e);
installedDomall.set(false);
return;
}
Expand All @@ -814,5 +831,6 @@ public void ensureDomallInstalled() {
public void setCathVersion(String cathVersion) {
this.cathVersion = cathVersion;
}


}