@@ -369,8 +369,22 @@ int msa2lddt(int argc, const char **argv, const Command& command, int makeReport
369
369
seqDbrAA.open (DBReader<unsigned int >::NOSORT);
370
370
DBReader<unsigned int > seqDbr3Di ((par.db1 +" _ss" ).c_str (), (par.db1 +" _ss.index" ).c_str (), par.threads , DBReader<unsigned int >::USE_INDEX|DBReader<unsigned int >::USE_DATA);
371
371
seqDbr3Di.open (DBReader<unsigned int >::NOSORT);
372
- DBReader<unsigned int > seqDbrCA ((par.db1 +" _ca" ).c_str (), (par.db1 +" _ca.index" ).c_str (), par.threads , DBReader<unsigned int >::USE_INDEX|DBReader<unsigned int >::USE_DATA);
373
- seqDbrCA.open (DBReader<unsigned int >::NOSORT);
372
+
373
+ // Check for CA database
374
+ DBReader<unsigned int > *seqDbrCA = NULL ;
375
+ bool caExist = FileUtil::fileExists ((par.db1 + " _ca.dbtype" ).c_str ());
376
+ if (caExist == false ) {
377
+ Debug (Debug::INFO) << " Did not find " << FileUtil::baseName (par.db1 ) << " C-alpha database, not calculating LDDT\n " ;
378
+ } else {
379
+ seqDbrCA = new DBReader<unsigned int >(
380
+ (par.db1 + " _ca" ).c_str (),
381
+ (par.db1 + " _ca.index" ).c_str (),
382
+ par.threads ,
383
+ DBReader<unsigned int >::USE_INDEX|DBReader<unsigned int >::USE_DATA
384
+ );
385
+ seqDbrCA->open (DBReader<unsigned int >::NOSORT);
386
+ }
387
+
374
388
IndexReader headerDB (par.db1 , par.threads , IndexReader::HEADERS, touch ? IndexReader::PRELOAD_INDEX : 0 );
375
389
376
390
// Read in MSA, mapping headers to database indices
@@ -394,20 +408,21 @@ int msa2lddt(int argc, const char **argv, const Command& command, int makeReport
394
408
for (size_t i = 0 ; i < subset.size (); i++)
395
409
subset[i] = i;
396
410
397
- std::tie (perColumnScore, perColumnCount, lddtScore, numCols) = calculate_lddt (cigars_aa, subset, indices, lengths, &seqDbrCA, par.pairThreshold );
398
-
399
-
400
- std::string scores;
401
- for (float score : perColumnScore) {
402
- if (scores.length () > 0 ) scores += " ," ;
403
- scores += std::to_string (score);
411
+ if (caExist) {
412
+ std::tie (perColumnScore, perColumnCount, lddtScore, numCols) = calculate_lddt (cigars_aa, subset, indices, lengths, seqDbrCA, par.pairThreshold );
413
+ std::string scores;
414
+ for (float score : perColumnScore) {
415
+ if (scores.length () > 0 ) scores += " ," ;
416
+ scores += std::to_string (score);
417
+ }
418
+ Debug (Debug::INFO) << " Average MSA LDDT: " << lddtScore << ' \n ' ;
419
+ Debug (Debug::INFO) << " Columns considered: " << numCols << " /" << alnLength << ' \n ' ;
420
+ Debug (Debug::INFO) << " Column scores: " << scores << ' \n ' ;
404
421
}
405
- std::cout << " Average MSA LDDT: " << lddtScore << ' \n ' ;
406
- std::cout << " Columns considered: " << numCols << " /" << alnLength << ' \n ' ;
407
- std::cout << " Column scores: " << scores << ' \n ' ;
408
422
409
423
// Write clustal format MSA HTML
410
424
if (makeReport) {
425
+ Debug (Debug::INFO) << " Generating report\n " ;
411
426
DBWriter resultWriter (par.db3 .c_str (), (par.db3 + " .index" ).c_str (), static_cast <unsigned int >(par.threads ), par.compressed , Parameters::DBTYPE_OMIT_FILE);
412
427
resultWriter.open ();
413
428
@@ -470,34 +485,46 @@ R"html(<!DOCTYPE html>
470
485
for (size_t i = 0 ; i < cigars_aa.size (); i++) {
471
486
std::string seq_aa = expand (cigars_aa[i]);
472
487
std::string seq_ss = expand (cigars_ss[i]);
473
- std::string seq_ca = getXYZstring (indices[i], lengths[i], &seqDbrCA);
474
488
std::string entry;
475
489
entry.append (" {\" name\" :\" " );
476
490
entry.append (headers[i]);
477
491
entry.append (" \" ,\" aa\" : \" " );
478
492
entry.append (seq_aa);
479
493
entry.append (" \" ,\" ss\" : \" " );
480
494
entry.append (seq_ss);
481
- entry.append (" \" ,\" ca\" : \" " );
482
- entry.append (seq_ca);
483
- entry.append (" \" }" );
484
- if (i != cigars_aa.size () - 1 )
495
+ entry.append (" \" " );
496
+ if (caExist) {
497
+ std::string seq_ca = getXYZstring (indices[i], lengths[i], seqDbrCA);
498
+ entry.append (" ,\" ca\" : \" " );
499
+ entry.append (seq_ca);
500
+ entry.append (" \" " );
501
+ }
502
+ entry.append (" }" );
503
+ if (i != cigars_aa.size () - 1 ) {
485
504
entry.append (" ," );
505
+ } else {
506
+ entry.append (" ]" );
507
+ }
486
508
resultWriter.writeData (entry.c_str (), entry.length (), 0 , 0 , false , false );
487
- }
488
-
489
- std::string middle = " ],\" scores\" : [" ;
490
- resultWriter.writeData (middle.c_str (), middle.length (), 0 , 0 , false , false );
509
+ }
491
510
492
511
// Per-column scores, as [score, score, ...]
493
- // TODO: optionally save this as .csv
494
- for (int i = 0 ; i < alnLength; i++) {
495
- std::string entry = (perColumnCount[i] == 0 ) ? " -1" : std::to_string (perColumnScore[i]);
496
- if (i != alnLength - 1 )
497
- entry.append (" ," );
498
- resultWriter.writeData (entry.c_str (), entry.length (), 0 , 0 , false , false );
512
+ std::string middle = " " ;
513
+
514
+ if (caExist) {
515
+ middle.append (" ,\" scores\" : [" );
516
+ for (int i = 0 ; i < alnLength; i++) {
517
+ std::string entry = (perColumnCount[i] == 0 ) ? " -1" : std::to_string (perColumnScore[i]);
518
+ if (i != alnLength - 1 ) {
519
+ entry.append (" ," );
520
+ }
521
+ middle.append (entry);
522
+ }
523
+ middle.append (" ]" );
499
524
}
500
- std::string end = " ]," ;
525
+ resultWriter.writeData (middle.c_str (), middle.length (), 0 , 0 , false , false );
526
+
527
+ std::string end = " " ;
501
528
502
529
if (par.guideTree != " " ) {
503
530
std::string tree;
@@ -508,25 +535,37 @@ R"html(<!DOCTYPE html>
508
535
tree += line;
509
536
newick.close ();
510
537
}
511
- end.append (" \" tree\" : \" " );
538
+ end.append (" , \" tree\" : \" " );
512
539
end.append (tree);
513
- end.append (" \" , " );
540
+ end.append (" \" " );
514
541
}
515
- end.append (" \" statistics\" : {" );
542
+ end.append (" ,\" statistics\" : {" );
543
+
544
+ bool hasPrev = false ;
516
545
if (par.reportPaths ) {
517
546
end.append (" \" db\" :\" " );
518
547
end.append (par.db1 );
519
548
end.append (" \" ,\" msaFile\" :\" " );
520
549
end.append (par.db2 );
521
- end.append (" \" ," );
550
+ end.append (" \" " );
551
+ hasPrev = true ;
552
+ }
553
+ if (caExist) {
554
+ if (hasPrev) {
555
+ end.append (" ," );
556
+ }
557
+ end.append (" \" msaLDDT\" :" );
558
+ end.append (std::to_string (lddtScore));
559
+ hasPrev = true ;
522
560
}
523
- end.append (" \" msaLDDT\" :" );
524
- end.append (std::to_string (lddtScore));
525
-
526
561
if (par.reportCommand != " " ) {
527
- end.append (" ,\" cmdString\" :\" " );
562
+ if (hasPrev) {
563
+ end.append (" ," );
564
+ }
565
+ end.append (" \" cmdString\" :\" " );
528
566
end.append (par.reportCommand );
529
567
end.append (" \" " );
568
+ hasPrev = true ;
530
569
}
531
570
end.append (" }}" );
532
571
@@ -544,9 +583,10 @@ R"html(<!DOCTYPE html>
544
583
}
545
584
546
585
seqDbrAA.close ();
547
- seqDbrCA.close ();
548
586
seqDbr3Di.close ();
549
-
587
+ if (caExist) {
588
+ seqDbrCA->close ();
589
+ }
550
590
return EXIT_SUCCESS;
551
591
}
552
592
0 commit comments