From c5a0089e655866fb5b90817489cc0ab0a9ce85e9 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Fri, 12 May 2023 00:10:16 +0200
Subject: [PATCH] add TM-score to compare-structures action

---
 actions/ost-compare-structures | 24 +++++++++++++++++++++++-
 modules/doc/actions.rst        |  6 ++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/actions/ost-compare-structures b/actions/ost-compare-structures
index f94d79bc1..dce074bfa 100644
--- a/actions/ost-compare-structures
+++ b/actions/ost-compare-structures
@@ -277,6 +277,13 @@ def _ParseArgs():
               "https://github.com/kliment-olechnovic/voronota). Searches PATH "
               "if not set."))
 
+    parser.add_argument(
+        "--usalign-exec",
+        dest="usalign_exec",
+        default=None,
+        help=("Path to USalign executable to compute TM-score. If not given, "
+              "an OpenStructure internal copy of USalign code is used."))
+
     parser.add_argument(
         "--qs-score",
         dest="qs_score",
@@ -346,6 +353,16 @@ def _ParseArgs():
               "as string in form <num><inscode>. The respective scores are "
               "available as keys \"patch_qs\" and \"patch_dockq\""))
 
+    parser.add_argument(
+        "--tm-score",
+        dest="tm_score",
+        default=False,
+        action="store_true",
+        help=("Computes TM-score with the USalign tool. Also computes a "
+              "chain mapping in case of complexes that is stored in the "
+              "same format as the default mapping. TM-score and the mapping "
+              "are available as keys \"tm_score\" and \"usalign_mapping\""))
+
     return parser.parse_args()
 
 def _Rename(ent):
@@ -483,7 +500,8 @@ def _Process(model, reference, args):
     scorer = scoring.Scorer(model, reference,
                             resnum_alignments = args.residue_number_alignment,
                             cad_score_exec = args.cad_exec,
-                            custom_mapping = mapping)
+                            custom_mapping = mapping,
+                            usalign_exec = args.usalign_exec)
 
     ir = _GetInconsistentResidues(scorer.aln)
     if len(ir) > 0 and args.enforce_consistency:
@@ -559,6 +577,10 @@ def _Process(model, reference, args):
         out["patch_qs"] = scorer.patch_qs
         out["patch_dockq"] = scorer.patch_dockq
 
+    if args.tm_score:
+        out["tm_score"] = scorer.tm_score
+        out["usalign_mapping"] = scorer.usalign_mapping
+
     if args.dump_structures:
         try:
             io.SavePDB(scorer.model, model.GetName() + args.dump_suffix)
diff --git a/modules/doc/actions.rst b/modules/doc/actions.rst
index c8ddb6da5..3b6fdc277 100644
--- a/modules/doc/actions.rst
+++ b/modules/doc/actions.rst
@@ -250,6 +250,12 @@ Details on the usage (output of ``ost compare-structures --help``):
                           Residues are represented as string in form
                           <num><inscode>. The respective scores are available as
                           keys "patch_qs" and "patch_dockq"
+    --tm-score            Computes TM-score with the USalign tool. Also computes
+                          a chain mapping in case of complexes that is stored
+                          in the same format as the default mapping. TM-score
+                          and the mapping are available as keys "tm_score" and
+                          "usalign_mapping"
+
 
 
 .. _ost compare ligand structures:
-- 
GitLab