Edinburgh-Genome-Foundry / GoldenHinges

:link: Short overhangs design for DNA assembly
https://edinburgh-genome-foundry.github.io/GoldenHinges/
MIT License
11 stars 0 forks source link

Numberjack need"arm64" has 'x86_64' despite compiling with arch arm64 within Goldenhinges #6

Open harirngd opened 1 year ago

harirngd commented 1 year ago

Hi this may be a "duplicate" of the previous issue #5 -but I get the following error when I try a simple GoldenHinges example on OSX. I used the "latest" Numberjack from Github.

(.venv) ➜  goldenhinges python assemble_plasmid.py
/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/Bio/SeqFeature.py:1112: BiopythonParserWarning: Attempting to fix invalid location '7905..951' as it looks like incorrect origin wrapping. Please fix input file, this could have unintended behavior.
  warnings.warn(
Traceback (most recent call last):
  File "/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/Numberjack-1.2.1-py3.11-macosx-13-arm64.egg/Numberjack/__init__.py", line 910, in load
    lib = __import__(solverstring, fromlist=[solverspkg])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/Numberjack-1.2.1-py3.11-macosx-13-arm64.egg/Numberjack/solvers/Mistral.py", line 10, in <module>
    from . import _Mistral
ImportError: dlopen(/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/Numberjack-1.2.1-py3.11-macosx-13-arm64.egg/Numberjack/solvers/_Mistral.cpython-311-darwin.so, 0x0002): tried: '/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/Numberjack-1.2.1-py3.11-macosx-13-arm64.egg/Numberjack/solvers/_Mistral.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/Numberjack-1.2.1-py3.11-macosx-13-arm64.egg/Numberjack/solvers/_Mistral.cpython-311-darwin.so' (no such file), '/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/Numberjack-1.2.1-py3.11-macosx-13-arm64.egg/Numberjack/solvers/_Mistral.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/harijayaram/hjworkbench/goldenhinges/assemble_plasmid.py", line 31, in <module>
    main()
  File "/Users/harijayaram/hjworkbench/goldenhinges/assemble_plasmid.py", line 15, in main
    solution = selector.cut_sequence(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/goldenhinges/OverhangsSelector.py", line 402, in cut_sequence
    solution = self.cut_sequence(
               ^^^^^^^^^^^^^^^^^^
  File "/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/goldenhinges/OverhangsSelector.py", line 463, in cut_sequence
    choices = self.select_from_sets(sets_list, solutions=solutions,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/goldenhinges/OverhangsSelector.py", line 214, in select_from_sets
    solver = model.load("Mistral", variables)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/harijayaram/hjworkbench/goldenhinges/.venv/lib/python3.11/site-packages/Numberjack-1.2.1-py3.11-macosx-13-arm64.egg/Numberjack/__init__.py", line 913, in load
    raise ImportError(
ImportError: ERROR: Failed during import, wrong module name? (Mistral)

Here is my code that is adapted from the Goldenhinges example

import os
from Bio import SeqIO
from goldenhinges import OverhangsSelector
from goldenhinges.reports import write_report_for_cutting_solution

def main():
    """Example of cutting problem defined by a record.

    This example has a long
    """
    genbank_file = "pcmv-abe7-10-chiselannottest (2).gb"
    record = SeqIO.read(genbank_file, "genbank")
    selector = OverhangsSelector(gc_min=0.25, gc_max=0.75, differences=2)
    solution = selector.cut_sequence(
        record, allow_edits=True, equal_segments=20, include_extremities=True
    )

    print("Writing the report...")
    write_report_for_cutting_solution(
        solution=solution,
        target=os.path.join("results", "with_mutations"),
        sequence=record,
        left_flank="CGTCTCA",
        right_flank="TGAGACG",
    )
    print("Done! See the report in results/with_mutations/")

if __name__ == "__main__":
    main()

The Numberjack installation from this github repo proceeded without any error.

veghp commented 1 year ago

Hi, I can add only a few pointers to the comment I made in #5 :

I think I have seen this error before, and that's why we have a few additional comments in the Install section of readme: https://github.com/Edinburgh-Genome-Foundry/GoldenHinges#installation

I don't recall the details, but it won't include or compile the binaries of Mistral, or run it, if you don't have the correct OS, dependencies, or Python version. Another issue is that it was developed for swig3.0, but the default swig command may call a later version which won't work.

Another option is to sidestep this problem and build a standalone environment, using Docker. If that's something you're familiar with, then here is a repo with the necessary Dockerfile and instructions https://github.com/Edinburgh-Genome-Foundry/EGF_Docker_Jupyter

In that, I build Numberjack from source (line 23 onwards)

Zulko commented 1 year ago

Alas Numberjack is getting old, it's reassuring to know it can still be built from sources (great move 👍) but in hindsight it probably wasn't the best choice of constraint solver when compared to e.g. Google OR tools (see the end of this page).

harirngd commented 1 year ago

Hi, I can add only a few pointers to the comment I made in #5 :

I think I have seen this error before, and that's why we have a few additional comments in the Install section of readme: https://github.com/Edinburgh-Genome-Foundry/GoldenHinges#installation

I don't recall the details, but it won't include or compile the binaries of Mistral, or run it, if you don't have the correct OS, dependencies, or Python version. Another issue is that it was developed for swig3.0, but the default swig command may call a later version which won't work.

Another option is to sidestep this problem and build a standalone environment, using Docker. If that's something you're familiar with, then here is a repo with the necessary Dockerfile and instructions https://github.com/Edinburgh-Genome-Foundry/EGF_Docker_Jupyter

In that, I build Numberjack from source (line 23 onwards)

Thanks for this docker based workaround. It worked great !! and I could very easily use the docker image and build a working docker instance on Apple Silicon. Still a relative docker newbie --so capturing the process I used below.

git clone git@github.com:Edinburgh-Genome-Foundry/EGF_Docker_Jupyter.git
cd EGF_Docker_Jupyter
docker build -t hj-image-egf-foundry-jup .
docker run -it --name egf_hj-container -p 8888:8888 hj-image-egf-foundry-jup

I could then open my Browser and navigate to "http://127.0.0.1:8888" and use the Jupyter environment there. Alternatively to use this docker instance command line I could also enter the container and run python there.

# First to copy the test file into the docker container
docker cp "pcmv-abe7-10-chiselannottest (2).gb"  egf_hj-container:/usr/src/app/
docker exec -it egf_hj-container /bin/bash
python3 assemble_plasmid.py
veghp commented 1 year ago

Glad to hear it worked!

Good point about running scripts directly with the docker container. I should add that as an example. Running python straight on the script should also work if the directory is mounted: https://stackoverflow.com/a/62193228