2525
2626import org .biojava .nbio .structure .align .util .UserConfiguration ;
2727import org .biojava .nbio .structure .io .util .FileDownloadUtils ;
28+ import org .slf4j .Logger ;
29+ import org .slf4j .LoggerFactory ;
2830import org .biojava .nbio .core .util .InputStreamProvider ;
2931
3032import java .io .*;
4143 */
4244public class CathInstallation implements CathDatabase {
4345
46+ private static final Logger LOGGER = LoggerFactory .getLogger (CathInstallation .class );
47+
4448 public static final String DEFAULT_VERSION = CathFactory .DEFAULT_VERSION ;
4549
46- String cathVersion ;
47-
48- public static final String domainListFileName = "CathDomainList" ;
50+ public static final String domainListFileName = "cath-domain-list-v%s.txt" ;
51+ // 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
4952 public static final String domainDescriptionFileName = "CathDomainDescriptionFile" ;
5053 public static final String nodeListFileName = "CathNames" ;
51- public static final String domallFileName = "CathDomall" ;
52-
53- public static final String CATH_DOWNLOAD = "http://release.cathdb.info/" ;
54+ public static final String domallFileName = "cath-domain-boundaries-v%s.txt" ;
55+
56+ public static final String CATH_DOWNLOAD_URL = "http://download.cathdb.info/cath/releases/" ;
57+ public static final String CATH_DOWNLOAD_LATEST_RELEASE_DIR = "latest-release" ;
58+ public static final String CATH_DOWNLOAD_PREV_RELEASE_DIR = "previous-releases" ;
59+ public static final String CATH_DOWNLOAD_CLASSIFICATION_DATA_DIR = "cath-classification-data" ;
5460
55- String cathDownloadUrl ;
61+ public static final String NEWLINE = System .getProperty ("line.separator" );;
62+ public static final String FILESPLIT = System .getProperty ("file.separator" );;
5663
57- public static final String NEWLINE ;
58- public static final String FILESPLIT ;
59-
60- static {
61- NEWLINE = System .getProperty ("line.separator" );
62- FILESPLIT = System .getProperty ("file.separator" );
63- }
64+
65+ private String cathVersion ;
6466
67+ private String cathDownloadUrl ;
68+
6569 private String cacheLocation ;
6670
67- AtomicBoolean installedDomainList ;
68- AtomicBoolean installedDomainDescription ;
69- AtomicBoolean installedNodeList ;
70- AtomicBoolean installedDomall ;
71+ private AtomicBoolean installedDomainList ;
72+ private AtomicBoolean installedDomainDescription ;
73+ private AtomicBoolean installedNodeList ;
74+ private AtomicBoolean installedDomall ;
7175
72- final boolean useCathDomainDescriptionFile ;
73- final boolean parseCathFragments ;
76+ private final boolean useCathDomainDescriptionFile ;
77+ private final boolean parseCathFragments ;
7478
75- Map <String , List <CathDomain >> pdbMap ;
76- Map <String , CathDomain > domainMap ;
77- Map <String , CathNode > cathTree ;
78- Map <String , List <CathFragment >> fragmentMap ;
79+ private Map <String , List <CathDomain >> pdbMap ;
80+ private Map <String , CathDomain > domainMap ;
81+ private Map <String , CathNode > cathTree ;
82+ private Map <String , List <CathFragment >> fragmentMap ;
7983
8084
8185
@@ -91,7 +95,7 @@ public CathInstallation(String cacheLocation, boolean usingCDDF, boolean parseCF
9195 installedDomall = new AtomicBoolean (false );
9296
9397 cathVersion = DEFAULT_VERSION ;
94- cathDownloadUrl = CATH_DOWNLOAD ;
98+ cathDownloadUrl = CATH_DOWNLOAD_URL ;
9599
96100 pdbMap = new HashMap <String , List <CathDomain >>();
97101 domainMap = new HashMap <String ,CathDomain >();
@@ -110,19 +114,32 @@ public CathInstallation() {
110114 }
111115
112116 public String getDomainListFileName () {
113- return cacheLocation + domainListFileName + ".v" + cathVersion ;
117+ return cacheLocation + buildFileName ( domainListFileName ) ;
114118 }
115119
116120 public String getDomainDescriptionFileName () {
117- return cacheLocation + domainDescriptionFileName + ".v" + cathVersion ;
121+ return cacheLocation + buildFileName ( domainDescriptionFileName ) ;
118122 }
119123
120124 public String getNodeListFileName () {
121- return cacheLocation + nodeListFileName + ".v" + cathVersion ;
125+ return cacheLocation + buildFileName ( nodeListFileName ) ;
122126 }
123127
124128 public String getDomallFileName () {
125- return cacheLocation + domallFileName + ".v" + cathVersion ;
129+ return cacheLocation + buildFileName (domallFileName );
130+ }
131+
132+ private String buildFileName (String fileNameTemplate ) {
133+ return String .format (fileNameTemplate , cathVersion );
134+ }
135+
136+ private String buildUrl (String remoteFileName ) {
137+ String remoteFileNameWithVer = buildFileName (remoteFileName );
138+ String releasesDir = CATH_DOWNLOAD_LATEST_RELEASE_DIR ;
139+ if (!cathVersion .equals (CathFactory .LATEST_VERSION )) {
140+ releasesDir = CATH_DOWNLOAD_PREV_RELEASE_DIR ;
141+ }
142+ return cathDownloadUrl + releasesDir + "/v" + cathVersion + "/" + CATH_DOWNLOAD_CLASSIFICATION_DATA_DIR + "/" + remoteFileNameWithVer ;
126143 }
127144
128145 public String getCathDownloadUrl () {
@@ -418,7 +435,7 @@ private void parseCathDomainDescriptionFile(BufferedReader bufferedReader) throw
418435 try {
419436 cathDescription .setDate ( dateFormat .parse ( line .substring (10 ) ) );
420437 } catch (ParseException e ) {
421- e . printStackTrace ( );
438+ LOGGER . error ( e . getMessage (), e );
422439 }
423440 } else if ( line .startsWith ("NAME" ) ) {
424441 name .append ( line .substring (10 ) );
@@ -622,7 +639,7 @@ private void parseCathDomall(BufferedReader bufferedReader) throws IOException{
622639 }
623640 }
624641
625- protected void downloadFileFromRemote (URL remoteURL , File localFile ) throws FileNotFoundException , IOException {
642+ protected void downloadFileFromRemote (URL remoteURL , File localFile ) throws IOException {
626643// System.out.println("downloading " + remoteURL + " to: " + localFile);
627644
628645 long timeS = System .currentTimeMillis ();
@@ -653,7 +670,7 @@ protected void downloadFileFromRemote(URL remoteURL, File localFile) throws File
653670 disp = disp / 1024.0 ;
654671 }
655672 long timeE = System .currentTimeMillis ();
656- System . out . println ( "downloaded " + String .format ("%.1f" ,disp ) + unit + " in " + (timeE - timeS )/1000 + " sec." );
673+ LOGGER . info ( "Downloaded file {} ({}) to local file {} in {} sec." , remoteURL , String .format ("%.1f" ,disp ) + unit , localFile , (timeE - timeS )/1000 );
657674 }
658675
659676 private boolean domainDescriptionFileAvailable (){
@@ -680,33 +697,33 @@ private boolean domallFileAvailable() {
680697 return f .exists ();
681698 }
682699
683- protected void downloadDomainListFile () throws FileNotFoundException , IOException {
700+ protected void downloadDomainListFile () throws IOException {
684701 String remoteFilename = domainListFileName ;
685- URL url = new URL (cathDownloadUrl + "v" + cathVersion + "/" + remoteFilename );
702+ URL url = new URL (buildUrl ( remoteFilename ));
686703 String localFileName = getDomainListFileName ();
687704 File localFile = new File (localFileName );
688705 downloadFileFromRemote (url , localFile );
689706 }
690707
691- protected void downloadDomainDescriptionFile () throws FileNotFoundException , IOException {
708+ protected void downloadDomainDescriptionFile () throws IOException {
692709 String remoteFilename = domainDescriptionFileName ;
693- URL url = new URL (cathDownloadUrl + "v" + cathVersion + "/" + remoteFilename );
710+ URL url = new URL (buildUrl ( remoteFilename ) );
694711 String localFileName = getDomainDescriptionFileName ();
695712 File localFile = new File (localFileName );
696713 downloadFileFromRemote (url , localFile );
697714 }
698715
699- protected void downloadNodeListFile () throws FileNotFoundException , IOException {
716+ protected void downloadNodeListFile () throws IOException {
700717 String remoteFilename = nodeListFileName ;
701- URL url = new URL (cathDownloadUrl + "v" + cathVersion + "/" + remoteFilename );
718+ URL url = new URL (buildUrl ( remoteFilename ) );
702719 String localFileName = getNodeListFileName ();
703720 File localFile = new File (localFileName );
704721 downloadFileFromRemote (url , localFile );
705722 }
706723
707724 protected void downloadDomallFile () throws IOException {
708725 String remoteFileName = domallFileName ;
709- URL url = new URL (cathDownloadUrl + "v" + cathVersion + "/" + remoteFileName );
726+ URL url = new URL (buildUrl ( remoteFileName ) );
710727 String localFileName = getDomallFileName ();
711728 File localFile = new File (localFileName );
712729 downloadFileFromRemote (url , localFile );
@@ -719,7 +736,7 @@ public void ensureDomainListInstalled(){
719736 try {
720737 downloadDomainListFile ();
721738 } catch (Exception e ){
722- e . printStackTrace ( );
739+ LOGGER . error ( "Could not download CATH domain list file. Error: {}" , e . getMessage () );
723740 installedDomainList .set (false );
724741 return ;
725742 }
@@ -728,7 +745,7 @@ public void ensureDomainListInstalled(){
728745 try {
729746 parseCathDomainList ();
730747 } catch (Exception e ){
731- e . printStackTrace ( );
748+ LOGGER . error ( e . getMessage (), e );
732749 installedDomainList .set (false );
733750 return ;
734751 }
@@ -742,7 +759,7 @@ public void ensureDomainDescriptionInstalled(){
742759 try {
743760 downloadDomainDescriptionFile ();
744761 } catch (Exception e ){
745- e . printStackTrace ( );
762+ LOGGER . error ( "Could not download CATH domain description file. Error: {}" , e . getMessage () );
746763 installedDomainDescription .set (false );
747764 return ;
748765 }
@@ -751,7 +768,7 @@ public void ensureDomainDescriptionInstalled(){
751768 try {
752769 parseCathDomainDescriptionFile ();
753770 } catch (Exception e ){
754- e . printStackTrace ( );
771+ LOGGER . error ( e . getMessage (), e );
755772 installedDomainDescription .set (false );
756773 return ;
757774 }
@@ -765,7 +782,7 @@ public void ensureNodeListInstalled(){
765782 try {
766783 downloadNodeListFile ();
767784 } catch (Exception e ){
768- e . printStackTrace ( );
785+ LOGGER . error ( "Could not download CATH node list file. Error: {}" , e . getMessage () );
769786 installedNodeList .set (false );
770787 return ;
771788 }
@@ -774,7 +791,7 @@ public void ensureNodeListInstalled(){
774791 try {
775792 parseCathNames ();
776793 } catch (Exception e ){
777- e . printStackTrace ( );
794+ LOGGER . error ( e . getMessage (), e );
778795 installedNodeList .set (false );
779796 return ;
780797 }
@@ -795,7 +812,7 @@ public void ensureDomallInstalled() {
795812 try {
796813 downloadDomallFile ();
797814 } catch (Exception e ) {
798- e . printStackTrace ( );
815+ LOGGER . error ( "Could not download CATH domain all file. Error: {}" , e . getMessage () );
799816 installedDomall .set (false );
800817 return ;
801818 }
@@ -804,7 +821,7 @@ public void ensureDomallInstalled() {
804821 try {
805822 parseCathDomall ();
806823 } catch (Exception e ) {
807- e . printStackTrace ( );
824+ LOGGER . error ( e . getMessage (), e );
808825 installedDomall .set (false );
809826 return ;
810827 }
@@ -814,5 +831,6 @@ public void ensureDomallInstalled() {
814831 public void setCathVersion (String cathVersion ) {
815832 this .cathVersion = cathVersion ;
816833 }
834+
817835
818836}
0 commit comments