Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] generateNetwork raises TypeError when links_file is supplied #231

Closed
jasmin-guven opened this issue Jan 17, 2024 · 3 comments · Fixed by #233
Closed

[BUG] generateNetwork raises TypeError when links_file is supplied #231

jasmin-guven opened this issue Jan 17, 2024 · 3 comments · Fixed by #233
Labels
bug Something isn't working

Comments

@jasmin-guven
Copy link

Describe the bug
Supplying a links_file to generateNetwork raises a TypeError. The error is raised because on line 407 the wrong variable is given to the default_kwargs dictionary:

    # Create a dictionary of default keyword arguments.
    default_kwargs = {
        "name": f"{work_dir}/outputs/lomap",
        "links_file": lf,
        "output": True,
        "output_no_graph": True,
        "output_no_images": True,
        "threed": True,
        "max3d": 3.0,
        "time": 3,
        "parallel": 10,
    }

To fix, I just changed lf to links_file and it works:

    # Create a dictionary of default keyword arguments.
    default_kwargs = {
        "name": f"{work_dir}/outputs/lomap",
        "links_file": links_file,
        "output": True,
        "output_no_graph": True,
        "output_no_images": True,
        "threed": True,
        "max3d": 3.0,
        "time": 3,
        "parallel": 10,
    }

To Reproduce
Steps to reproduce the behavior:

  1. Run the code :
transformations, lomap_scores = bss.Align.generateNetwork(ligands, plot_network=False, names=names, work_dir=workdir, links_file="/home/jguven/projects/irap/inputs/ligands/table_1_links.txt") 
  1. This is the exception that was raised / this is what went wrong.
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:6                                                                                    │
│                                                                                                  │
│   3 names = [functions.get_filenames(file) for file in files]                                    │
│   4 table_1_links_file = table_1_workdir + "table_1_links.txt"                                   │
│   5 ligands = [bss.IO.readMolecules(file)[0] for file in files]                                  │
│ ❱ 6 transformations, lomap_scores = bss.Align.generateNetwork(ligands, plot_network=False, n     │
│   7                                                                                              │
│                                                                                                  │
│ /home/jguven/Software/miniconda3/envs/obss-d/lib/python3.9/site-packages/BioSimSpace/Align/_alig │
│ n.py:421 in generateNetwork                                                                      │
│                                                                                                  │
│    418 │   total_kwargs = {**default_kwargs, **kwargs}                                           │
│    419 │                                                                                         │
│    420 │   # Create the DBMolecules object.                                                      │
│ ❱  421 │   db_mol = _lomap.DBMolecules(f"{work_dir}/inputs", **total_kwargs)                     │
│    422 │                                                                                         │
│    423 │   # Create the similarity matrices.                                                     │
│    424 │   strict, loose = db_mol.build_matrices()                                               │
│                                                                                                  │
│ /home/jguven/Software/miniconda3/envs/obss-d/lib/python3.9/site-packages/lomap/dbmol.py:295 in   │
│ __init__                                                                                         │
│                                                                                                  │
│    292 │   │   │   self.inv_dic_mapping[mol.getName()] = mol.getID()                             │
│    293 │   │                                                                                     │
│    294 │   │   if self.options['links_file']:                                                    │
│ ❱  295 │   │   │   self.parse_links_file(self.options['links_file'])                             │
│    296 │   │                                                                                     │
│    297 │   │   if self.options['known_actives_file']:                                            │
│    298 │   │   │   self.parse_known_actives_file(self.options['known_actives_file'])             │
│                                                                                                  │
│ /home/jguven/Software/miniconda3/envs/obss-d/lib/python3.9/site-packages/lomap/dbmol.py:459 in   │
│ parse_links_file                                                                                 │
│                                                                                                  │
│    456 │                                                                                         │
│    457 │   def parse_links_file(self, links_file):                                               │
│    458 │   │   try:                                                                              │
│ ❱  459 │   │   │   with open(links_file, "r") as lf:                                             │
│    460 │   │   │   │   for line in lf:                                                           │
│    461 │   │   │   │   │   mols = line.split()                                                   │
│    462 │   │   │   │   │   if (len(mols) < 2 or len(mols) > 4):                                  │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: expected str, bytes or os.PathLike object, not TextIOWrapper

Context

  • OS: Linux Ubuntu 22.04 LTS
  • Version of Python: 3.9.18
  • Version of BioSimSpace: 2023.5.0.dev
  • I confirm that I have checked this bug still exists in the latest released version of BioSimSpace: [yes]
@jasmin-guven jasmin-guven added the bug Something isn't working label Jan 17, 2024
@lohedges
Copy link
Contributor

Thanks for this. I'm not sure when this got changed. Will fix tomorrow.

@lohedges
Copy link
Contributor

Ah, this issue here is that the user supplied links file is modified and written to the inputs directory. We need to pass the path to the new file in the default_kwargs dictionary. In your case, you are re-using the input one, which isn't always guaranteed to work given the remapping of file names.

lohedges added a commit that referenced this issue Jan 18, 2024
@lohedges
Copy link
Contributor

I've pushed a fix here. If you are able to test, that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants