2996

Quantification of in vivo magnetic resonance spectroscopy data with pyAMARES, an open-source python library for flexible and robust MRS fitting
Jia Xu1, Rolf F. Schulte2, Baolian Yang3, and Vincent A. Magnotta1,4,5
1Department of Radiology, University of Iowa, Iowa City, IA, United States, 2GE Global Research, Garching bei Munchen, Germany, 3GE Healthcare, Waukesha, WI, United States, 4Department of Psychiatry, University of Iowa, Iowa City, IA, United States, 5Department of Biomedical Engineering, University of Iowa, Iowa City, IA, United States

Synopsis

Keywords: Software Tools, Spectroscopy, quantification; MRS; AMARES; python; FID; MNS; 31P

Motivation: As a mainstream time-domain fitting algorithm for quantifying MRS data, to date, AMARES has been confined to Java and MATLAB, while the dominant language for deep learning, Python, does not yet have an AMARES implementation.

Goal(s): To develop pyAMARES, a python package implementing the AMARES, providing the MRS community with flexible and robust MRS data fitting capabilities.

Approach: PyAMARES imports prior knowledge from spreadsheets as initial values and constraints for fitting MRS data according to the AMARES model function.

Results: PyAMARES effectively fits in vivo MRS data with varied algorithms, proving its versatility as a versatile fitting tool.

Impact: PyAMARES provides accessible, flexible, and robust time-domain MRS fitting in Python, bridging the gap between advanced data analysis and deep learning by Python and the AMARES algorithm, previously limited to Java and MATLAB implementations.

Introduction

In vivo Magnetic Resonance Spectroscopy (MRS) is an invaluable tool for the non-invasive investigation of metabolic processes within biological systems. AMARES1 is a popular time-domain analysis tool that employs prior knowledge to obtain reliable results. However, to date, AMARES is only available in the 32-bit Java-based jMRUI2 and MATLAB-based OXSA3. While there are various Python-based MRS tools such as FSL-MRS4 and Vespa5, the implementation of AMARES within the Python ecosystem remains unexplored. In light of this, we developed a new package, pyAMARES, a Python-based implementation of the AMARES algorithm, to bridge the existing software gap. This package offers the MRS community a flexible, robust, and user-friendly platform that facilitates advanced data analysis and integrates seamlessly with machine learning integration.

Method

pyAMARES fits MRS data to the model function1: $$y_n = \hat{y}_n + e_n = \sum_{k=1}^{K} a_k e^{j \phi_k} e^{-d_k (1 - g_k + g_k t_n) t_n} e^{j 2\pi f_k t_n} + e_n, \quad n = 0, 1, \ldots, N - 1.$$.
Here, n represents the number of points, tn is the time at the nth FID point, and en is Gaussian noise. The parameters ak (amplitude), fk (frequency), dk (damping factor), Φ (phase), and gk (lineshape) can be either fitted or fixed by pyAMARES as needed. Fig. 1 shows the flowchart of pyAMARES. First, the prior knowledge of metabolites to quantify is provided in a spreadsheet, including relative concentration, chemical shifts, and, optionally, phase and linewidth. The prior knowledge will be transformed into initial values and constraints for performing minimization with the lmfit6 module of Python. An HSVD data initializer can be optionally invoked to optimize the initial parameters for better fitting. When necessary, the fitting results can be improved and edited for another round of fitting. The Cramer-Rao Lower Bound (CRLB) is estimated from both the fitting results and the linear relationship between parameters provided by the prior knowledge.

Results

Fig. 2 shows the fitting of non-localized brain 31P MRS data collected at 7T with pyAMARES using two different fitting options, Levenberg-Marquardt and Trust Region Reflective methods. It can be seen that both methods provide good fitting results. Table 1 shows an example quantification results by pyAMARES.

Discussion

pyAMARES is part of the Python ecosystem and can be utilized as a standalone executable or as a library to be integrated with other Python data processing and visualization software. Based on the lmfit module, pyAMARES makes it easy to set relations between parameters, such as fixing amplitude ratios between two metabolites or setting J-coupling constants for multiplets. It supports various fitting methods, such as Levenberg-Marquardt and Trust Region Reflective, to meet diverse user requirements. Moreover, pyAMARES's flexible objective function for minimization allows users to focus on specific spectral regions while ignoring others, like the residual water peak. These unique features make pyAMARES a handy tool for targeted MRS data fitting, simplifying the process while maintaining accuracy.

Conclusion

In this work, we developed pyAMARES, a Python-based implementation of the AMARES algorithm. It fills a notable gap in MRS data fitting with Python, a language dominant in deep learning. Utilizing the lmfit module, pyAMARES simplifies parameter adjustments, offers various fitting methods, and is demonstrated to work effectively in MRS data analysis. This tool not only makes MRS data fitting more accessible but also opens avenues for advanced analysis within the Python ecosystem, showcasing its potential as a robust and user-friendly platform for the MRS community. The source code will be available at https://github.com/HawkMRS/pyAMARES upon release.

Acknowledgements

This research used MR imaging equipment supported in part by NIH grant S10RR028821. VAM is supported in part by NIH grant P50HD103556.

References

1. Vanhamme L, van den Boogaart A, Van Huffel S. Improved method for accurate and efficient quantification of MRS data with use of prior knowledge. J Magn Reson 1997;129(1):35-43.

2. Stefan D, Di Cesare F, Andrasescu A, et al. Quantitation of magnetic resonance spectroscopy signals: the jMRUI software package. Meas Sci Technol 2009;20(10).

3. Purvis LAB, Clarke WT, Biasiolli L, Valkovic L, Robson MD, Rodgers CT. OXSA: An open-source magnetic resonance spectroscopy analysis toolbox in MATLAB. PLoS One 2017;12(9):e0185356.

4. Clarke WT, Stagg CJ, Jbabdi S. FSL-MRS: An end-to-end spectroscopy analysis package. Magnetic Resonance in Medicine 2021;85(6):2950-2964.

5. Soher BJ, Semanchuk P, Todd D, et al. Vespa: Integrated applications for RF pulse design, spectral simulation and MRS data analysis. Magn Reson Med 2023;90(3):823-838.

6. Newville M, Stensitzki T, Allen DB, Rawlik M, Ingargiola A, Nelson A. Lmfit: Non-Linear Least-Square Minimization and Curve-Fitting for Python: 2016. ascl:1606.1014 p.

Figures

Figure 1. Flowchart of pyAMARES

Figure 2. Fitting of in vivo non-localized brain 31P MRS using pyAMARES with different algorithms

Table 1. An example of a fitting results table from pyAMARES. Metabolites with amplitude CRLBs less than 20% are highlighted in green, indicating reliability, while those with CRLBs greater than 20% are marked in red, denoting less reliability.

Proc. Intl. Soc. Mag. Reson. Med. 32 (2024)
2996
DOI: https://doi.org/10.58530/2024/2996