HiMap icon indicating copy to clipboard operation
HiMap copied to clipboard

Support for multiple reference ligands

Open michael-robo opened this issue 1 year ago • 0 comments

Hello!

I'm trying to set up maps using a pre-built distance matrix where I have multiple reference ligands. I've attached a zipfile with the script, inputs, and output of "conda list". I'm using HiMap version 1.0.0 .

When I run the script using the existing codebase, I get the following error:

R[write to console]: Error in t(design.mat) %*% diag(null.weight) : non-conformable arguments

Traceback (most recent call last):
  File "/N/project/R-M-01/mrobo/1/mol_enum_02/network/himap/himap_with_matrix.py", line 40, in <module>
    himap.clusters2optimize(sub_arr, sub_ID, clusters2optim = selected_clusters,
  File "/N/slate/mrobo/mambaforge_br200/envs/himap/lib/python3.9/site-packages/himap-0+unknown-py3.9.egg/himap/clustering.py", line 843, in clusters2optimize
    himap.Optimize(n_ar, ID_list = sub_ID_list, ref_lig = sub_refs[k], **kwargs)
  File "/N/slate/mrobo/mambaforge_br200/envs/himap/lib/python3.9/site-packages/himap-0+unknown-py3.9.egg/himap/optimal.py", line 273, in Optimize
    c=py_run_optimization(ref_lig, r_df, r_optim_types, num_edges)
  File "/N/slate/mrobo/mambaforge_br200/envs/himap/lib/python3.9/site-packages/himap-0+unknown-py3.9.egg/himap/optimal.py", line 141, in py_run_optimization
    out=r.run_optimization(*args)
  File "/N/slate/mrobo/mambaforge_br200/envs/himap/lib/python3.9/site-packages/rpy2/robjects/functions.py", line 198, in __call__
    return (super(SignatureTranslatedFunction, self)
  File "/N/slate/mrobo/mambaforge_br200/envs/himap/lib/python3.9/site-packages/rpy2/robjects/functions.py", line 125, in __call__
    res = super(Function, self).__call__(*new_args, **new_kwargs)
  File "/N/slate/mrobo/mambaforge_br200/envs/himap/lib/python3.9/site-packages/rpy2/rinterface_lib/conversion.py", line 45, in _
    cdata = function(*args, **kwargs)
  File "/N/slate/mrobo/mambaforge_br200/envs/himap/lib/python3.9/site-packages/rpy2/rinterface.py", line 680, in __call__
    raise embedded.RRuntimeError(_rinterface._geterrmessage())
rpy2.rinterface_lib.embedded.RRuntimeError: Error in t(design.mat) %*% diag(null.weight) : non-conformable arguments

Investigating the issue myself, I found that the issue was in optimal_design.R . I made the following changes in that file (old lines are commented out):

          #rbind( diag( length( ligand.list))[ which( ligand.list == reference.ligand),])
          rbind( diag( length( ligand.list))[ which( ligand.list %in% reference.ligand),])
     
        #null.weight <- c( rep( 1, nrow(.)), 2)
        #sim.weight <- c( .$SIM_WEIGHT, 2)
        null.weight <- c( rep( 1, nrow(.)), rep(2,length(reference.ligand)))
        sim.weight <- c( .$SIM_WEIGHT, rep(2, length(reference.ligand)))

With this change, using multiple reference ligands is now tolerated.

I won't claim that I know what I'm doing here (in ligand mapping, the R programming language, GitHub etiquette, or life in general), so the first question that I'll ask is whether this is a bug or a feature. If it's a feature, why would using multiple reference ligands be discouraged in this use case, and why isn't there a corresponding error message that fails the program early? If it is a bug, did I fix it correctly without introducing any new issues downstream?

Thanks for your help (and writing the library), Michael Robo Computational Chemistry Staff Scientist Indiana Biosciences Research Institute

himap_bug_report.zip

michael-robo avatar Jan 18 '24 21:01 michael-robo