@@ -350,13 +350,15 @@ private void parseCathDomainList() throws IOException {
350350 parseCathDomainList (buffer );
351351 }
352352
353- private void parseCathDomainList (BufferedReader bufferedReader ) throws IOException {
353+ protected void parseCathDomainList (BufferedReader bufferedReader ) throws IOException {
354354 String line ;
355- // int counter = 0;
355+ int counter = 0 ;
356356 while ( (line = bufferedReader .readLine ()) != null ) {
357357 if ( line .startsWith ("#" ) ) continue ;
358+ if ( line .trim ().isEmpty () ) continue ;
358359 CathDomain cathDomain = parseCathListFileLine (line );
359- // counter++;
360+ if ( cathDomain == null ) continue ;
361+ counter ++;
360362
361363 String pdbId = cathDomain .getPdbIdAndChain ().substring (0 ,4 ); // includes chain letter
362364
@@ -372,6 +374,9 @@ private void parseCathDomainList(BufferedReader bufferedReader) throws IOExcepti
372374
373375 domainMap .put ( cathDomain .getDomainName (), cathDomain );
374376 }
377+ if (counter == 0 ) {
378+ throw new IOException ("Could not parse any CATH domains from the domain list file." );
379+ }
375380 }
376381
377382 private void parseCathNames () throws IOException {
@@ -386,7 +391,9 @@ private void parseCathNames(BufferedReader bufferedReader) throws IOException{
386391 //int counter = 0;
387392 while ( (line = bufferedReader .readLine ()) != null ) {
388393 if ( line .startsWith ("#" ) ) continue ;
394+ if ( line .trim ().isEmpty () ) continue ;
389395 CathNode cathNode = parseCathNamesFileLine (line );
396+ if ( cathNode == null ) continue ;
390397 cathTree .put (cathNode .getNodeId (), cathNode );
391398 }
392399 }
@@ -413,6 +420,7 @@ private void parseCathDomainDescriptionFile(BufferedReader bufferedReader) throw
413420 StringBuilder sseqs = null ;
414421 while ( (line = bufferedReader .readLine ()) != null ) {
415422 if ( line .startsWith ("#" ) ) continue ;
423+ if ( line .trim ().isEmpty () ) continue ;
416424 if ( line .startsWith ("FORMAT" ) ) {
417425 cathDescription = new CathDomain ();
418426 cathDescription .setFormat ( line .substring (10 ) );
@@ -504,8 +512,11 @@ private void parseCathDomainDescriptionFile(BufferedReader bufferedReader) throw
504512 }*/
505513
506514 private CathDomain parseCathListFileLine (String line ) {
515+ String [] token = line .trim ().split ("\\ s+" );
516+ if (token .length < 12 ) {
517+ return null ;
518+ }
507519 CathDomain cathDomain = new CathDomain ();
508- String [] token = line .split ("\\ s+" );
509520 cathDomain .setDomainName (token [0 ]);
510521 cathDomain .setClassId (Integer .parseInt (token [1 ]));
511522 cathDomain .setArchitectureId (Integer .parseInt (token [2 ]));
@@ -522,8 +533,12 @@ private CathDomain parseCathListFileLine(String line) {
522533 }
523534
524535 private CathNode parseCathNamesFileLine (String line ) {
536+ String [] token = line .trim ().split ("\\ s+" ,3 );
537+ if (token .length < 3 ) {
538+ LOGGER .debug ("Invalid line in cath names file, was expecting 3 tokens but got {} tokens: {}" , token .length , line );
539+ return null ;
540+ }
525541 CathNode cathNode = new CathNode ();
526- String [] token = line .split ("\\ s+" ,3 );
527542 cathNode .setNodeId ( token [0 ] );
528543 int idx = token [0 ].lastIndexOf ("." );
529544 if ( idx == -1 ) idx = token [0 ].length ();
@@ -544,8 +559,8 @@ private void parseCathDomall(BufferedReader bufferedReader) throws IOException{
544559 String line ;
545560 while ( ((line = bufferedReader .readLine ()) != null ) ) {
546561 if ( line .startsWith ("#" ) ) continue ;
547- if ( line .length () == 0 ) continue ;
548- String [] token = line .split ("\\ s+" );
562+ if ( line .trim (). isEmpty () ) continue ;
563+ String [] token = line .trim (). split ("\\ s+" );
549564 String chainId = token [0 ];
550565 Integer numberOfDomains = Integer .parseInt ( token [1 ].substring (1 ) );
551566 Integer numberOfFragments = Integer .parseInt ( token [2 ].substring (1 ) );
@@ -671,25 +686,25 @@ protected void downloadFileFromRemote(URL remoteURL, File localFile) throws IOEx
671686 private boolean domainDescriptionFileAvailable (){
672687 String fileName = getDomainDescriptionFileName ();
673688 File f = new File (fileName );
674- return f .exists ();
689+ return f .exists () && FileDownloadUtils . validateFile ( f ) ;
675690 }
676691
677692 private boolean domainListFileAvailable (){
678693 String fileName = getDomainListFileName ();
679694 File f = new File (fileName );
680- return f .exists ();
695+ return f .exists () && FileDownloadUtils . validateFile ( f ) ;
681696 }
682697
683698 private boolean nodeListFileAvailable (){
684699 String fileName = getNodeListFileName ();
685700 File f = new File (fileName );
686- return f .exists ();
701+ return f .exists () && FileDownloadUtils . validateFile ( f ) ;
687702 }
688703
689704 private boolean domallFileAvailable () {
690705 String fileName = getDomallFileName ();
691706 File f = new File (fileName );
692- return f .exists ();
707+ return f .exists () && FileDownloadUtils . validateFile ( f ) ;
693708 }
694709
695710 protected void downloadDomainListFile () throws IOException {
0 commit comments