MathOnco / valis

Virtual Alignment of pathoLogy Image Series
https://valis.readthedocs.io/en/latest/
MIT License
119 stars 29 forks source link

Unable to initialize valis-wsi due to Maven/toolchain config issue #28

Open NichD opened 1 year ago

NichD commented 1 year ago

Hello - I've been trying to use valis-wsi to register a series of Leica CZI H&E slide images. I've had some success using Matlab tools to register this dataset, and I wanted to compare those results to Valis.

Unfortunately, I can't get valis-wsi to initialize in the registration.Valis call, as it seems that a call using Maven is failing. This is after I've downloaded and verified pyvips and libvips, and verified that the latter is on the PATH. I've also verified Maven is on the PATH, but am still encountering issues.

Here is a sample script I have, which points to a directory of image files. I've also included the error message below.

import os vipsbin = r"C:\git\vips-dev-8.13\bin" mvnbin = r"C:\git\apache-maven-3.8.6\bin" os.environ['PATH'] = vipsbin + ';' + mvnbin + ';' + os.environ['PATH']

from valis import registration from matplotlib import pyplot as plt

# taken from https://pypi.org/project/valis-wsi/#description

slide_src_dir = r"C:\data\Data_RW\histology\Move Folder\EXP22001880\EXP22001892\FRG686" results_dst_dir = "./valis" registered_slide_dst_dir = results_dst_dir + "/reg" reference_slide = "FRG686_10-Stitching.czi"

# Create a Valis object and use it to register the slides in slide_src_dir, aligning towards the reference slide. registrar = registration.Valis(slide_src_dir, results_dst_dir, reference_img_f=reference_slide) rigid_registrar, non_rigid_registrar, error_df = registrar.register()

# Perform micro-registration on higher resolution images, aligning directly to the reference image registrar.register_micro(max_non_rigid_registartion_dim_px=2000, align_to_reference=True)

# Save all registered slides as ome.tiff registrar.warp_and_save_slides(registered_slide_dst_dir, crop="overlap")

# Kill the JVM registration.kill_jvm()

And the error message I receive:

(dev) PS C:\git\elephas\valis_test> python .\valis_test.py Failed to bootstrap the artifact.

Possible solutions:

  • Double check the endpoint for correctness (https://search.maven.org/).
  • Add needed repositories to ~/.jgorc [repositories] block (see README).
  • Try with an explicit version number (release metadata might be wrong).

Full Maven error output:

Traceback (most recent call last): File "C:\git\elephas\valis_test\valis_test.py", line 21, in registrar = registration.Valis(slide_src_dir, results_dst_dir, reference_img_f=reference_slide) File "C:\git\python_envs\dev\lib\site-packages\valis\registration.py", line 1610, in init self.get_imgs_in_dir() File "C:\git\python_envs\dev\lib\site-packages\valis\registration.py", line 1755, in get_imgs_in_dir if slide_tools.get_img_type(f) is not None: File "C:\git\python_envs\dev\lib\site-packages\valis\slide_tools.py", line 147, in get_img_type slide_io.init_jvm() File "C:\git\python_envs\dev\lib\site-packages\valis\slide_io.py", line 208, in init_jvm scyjava.start_jvm([f"-Xmx{mem_gb}G"]) File "C:\git\python_envs\dev\lib\site-packages\scyjava_java.py", line 177, in startjvm , workspace = jgo.resolve_dependencies( File "C:\git\python_envs\dev\lib\site-packages\jgo\jgo.py", line 665, in resolve_dependencies raise e File "C:\git\python_envs\dev\lib\site-packages\jgo\jgo.py", line 636, in resolve_dependencies mvn_out = run_and_combine_outputs(mvn, mvn_args) File "C:\git\python_envs\dev\lib\site-packages\jgo\jgo.py", line 274, in run_and_combine_outputs return subprocess.check_output(command_string, stderr=subprocess.STDOUT) File "C:\Program Files\Python39\lib\subprocess.py", line 424, in check_output return run(popenargs, stdout=PIPE, timeout=timeout, check=True, File "C:\Program Files\Python39\lib\subprocess.py", line 528, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '('C:\git\apache-maven-3.8.6\bin\mvn.CMD', '-B', '-f', 'C:\Users\NPDan\.jgo\ome\formats-gpl\LATEST\dc8f1caa0a5878494c2f101093d1f134928f44dbbc2ed07f928b4eded0617664\pom.xml', 'dependency:resolve')' returned non-zero exit status 1.

Unfortunately, the python script fails on Valis initialization (registrar = registration.Valis(slide_src_dir, results_dst_dir, reference_img_f=reference_slide)). Any insight or help with this would be welcome. Thanks in advance!

cdgatenbee commented 1 year ago

Hi @NichD, Sorry to hear you're having this issue. I believe it's the scyjava package (https://github.com/scijava/scyjava) that is trying to use Maven to download the bio-formats jar file. What happens when you do the following?

import jpype
import scyjava

scyjava.config.endpoints.append('ome:formats-gpl')
scyjava.start_jvm()
loci = jpype.JPackage("loci")
loci.common.DebugTools.setRootLevel("ERROR")

I think it should try to initialize the bio formats jar (which is used to read the images), and then download it if it isn't already available.

Best, Chandler

NichD commented 1 year ago

Hello @cdgatenbee

Thank you for your swift reply. I attempted to execute the lines you shared. I get the same error I was previously seeing when I call scyjava.start_jvm() - see below.

import jpype import scyjava scyjava.config.endpoints.append('ome:formats-gpl') scyjava.start_jvm() Failed to bootstrap the artifact.

Possible solutions:

  • Double check the endpoint for correctness (https://search.maven.org/).
  • Add needed repositories to ~/.jgorc [repositories] block (see README).
  • Try with an explicit version number (release metadata might be wrong).

Full Maven error output:

Traceback (most recent call last): File "", line 1, in File "C:\git\python_envs\dev\lib\site-packages\scyjava_java.py", line 177, in startjvm , workspace = jgo.resolve_dependencies( File "C:\git\python_envs\dev\lib\site-packages\jgo\jgo.py", line 665, in resolve_dependencies raise e File "C:\git\python_envs\dev\lib\site-packages\jgo\jgo.py", line 636, in resolve_dependencies mvn_out = run_and_combine_outputs(mvn, mvn_args) File "C:\git\python_envs\dev\lib\site-packages\jgo\jgo.py", line 274, in run_and_combine_outputs return subprocess.check_output(command_string, stderr=subprocess.STDOUT) File "C:\Program Files\Python39\lib\subprocess.py", line 424, in check_output return run(popenargs, stdout=PIPE, timeout=timeout, check=True, File "C:\Program Files\Python39\lib\subprocess.py", line 528, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '('C:\git\apache-maven-3.8.6\bin\mvn.CMD', '-B', '-f', 'C:\Users\NPDan\.jgo\ome\formats-gpl\LATEST\dc8f1caa0a5878494c2f101093d1f134928f44dbbc2ed07f928b4eded0617664\pom.xml', 'dependency:resolve')' returned non-zero exit status 1.

loci = jpype.JPackage("loci") loci.common.DebugTools.setRootLevel("ERROR") Traceback (most recent call last): File "", line 1, in RuntimeError: Unable to import 'loci.common' without JVM

Clearly something isn't happy with my java environment. Should my JAVA_HOME variable point to the JRE I have installed, or the JDK? Any other suggestions?

NichD commented 1 year ago

Also, would it matter that I have Java 19 (recently downloaded)? Would reverting to Java 17 resolve this?

Thanks!

cdgatenbee commented 1 year ago

Hi @NichD, Sorry for the delayed response. I believe your JAVA_HOME should be pointing to your JDK. When I echo $JAVA_HOME on my M1 Mac it points to my mambaforge JVM (mambaforge/lib/jvm), and on my intel Mac it was "usr/libexec/java_home". As far as versions go, mine is Java 17, so unfortunately I can't say if Java 19 is the problem or not. Also, as a last resort, and if you haven't already, you could try installing the packages in a conda/mamba environment? That might ensure that scyjava is linked up to the JVM correctly.

NichD commented 1 year ago

Hi @cdgatenbee - It's my turn to apologize as I've been traveling for much of this month. I'll update my Java install to use 17 and, failing that, try installing via Anaconda. Thank you for the suggestions.

NichD commented 1 year ago

@cdgatenbee I wanted to follow up with you. I was not able to get VALIS working on my Windows laptop, but I was able to get the install completed on a Linux system. I did need to install Maven on that system in order to use the JVM and execute the image registration.

I found a related ImageJ - Maven thread here. I suspect there's still some issues with the JAVA_HOME and Maven paths, which I may revisit on my Windows system when I have time.

You may want to update the installation instructions to include download and install of Maven, as that seemed to be necessary on both systems. Thanks for your help and let me know if I can assist at all!

cdgatenbee commented 1 year ago

Sorry you weren't able to get VALIS working on your Windows machine, @NichD. I wish I could have been more helpful. I agree that I need to update the installation instructions to include the need for Maven, and will do so soon.

Best, -Chandler

seiryoku-zenyo commented 4 months ago

any updates on this?

I can't register images on Windows neither. Exact same error.

cdgatenbee commented 4 months ago

Hi @seiryoku-zenyo,

I've made some updates to help with other Windows issues, but the challenge is that I don't have a Windows machine to debug with, so right now I can only make best guesses at what the issues are. I am working on trying to get access to a Windows machine at work though, so hopefully soon I'll be better able to work on issues like these. In the meantime, can you see if the Docker container will work for you?

Best, -Chandler