Combining 2 or more MEGA PRESS sessions (SIEMENS TWIX)

Hi,

I attempted to combine multiple sessions into a single, averaged MEGA PRESS acquisition for GSH. Based on previous posts, I used the following sequence of commands (see below). The scripts executed without error but did not merge the sessions (it does just processed both sessions).
Do you have any insights on why this might be happening? (The input files are in SIEMENS Twix format.)
Additionally, the example provided in Osprey, jobSDAT_MEGA_Multidataset.m, fails to complete on both my Mac and Linux machines. Error reported is: “Unable to perform assignment because the size of the left side is 2048-by-1 and the size of the right side is 2048-by-2-by-2”

To your knowledge, how could I combine both sessions properly in Osprey ?

Osprey Version: 2.7 (lastest)
Matlab: 2020a/b
OS: Mac 10.14 (and Linux x86_64 GNU/Linux)

MRSCont = OspreyJob(‘XXXX/OspreyJob.json’);
MRSCont = OspreyLoad(MRSCont);
MRSCont = OspreyProcess(MRSCont);
MRSCont = osp_AverageAllDatasetsAlongExtra(MRSCont);
MRSCont = OspreyFit(MRSCont);
MRSCont = OspreyQuantify(MRSCont);
MRSCont = OspreyOverview(MRSCont);

where OspreyJob.json content is:
{
“seqType”: “MEGA”,
“editTarget”: [“GSH”],
“dataScenario”: “invivo”,
“MM3coModel”: “3to2MM”,
“FWHMMM3co”: “”,
“SpecReg”: “RobSpecReg”,
“SubSpecAlignment”: “L2Norm”,
“UnstableWater”: “0”,
“saveLCM”: “1”,
“savejMRUI”: “1”,
“saveVendor”: “1”,
“saveNII”: “0”,
“savePDF”: “1”,
“method”: “Osprey”,
“ECCmetab”: “1”,
“ECCmm”: “1”,
“includeMetabs”: [“full”],
“style”: “Separate”,
“lolim_range”: “0.5”,
“uplim_range”: “4.0”,
“lolim_rangew”: “2.0”,
“uplim_rangew”: “7.4”,
“bLineKnotSpace”: “0.4”,
“fitMM”: “1”,
“basisSet”: “XXXX/BASIS_Siemens_MEGA_PRESS_GSH131_wMM/BASIS_Siemens_MEGA_PRESS_GSH131_wMM.mat”,
“files”: [“XXXX/meas_MID00028_FID23946_eja_svs_mpress_RM_mpfc1.dat”,“XXXX/meas_MID00032_FID23950_eja_svs_mpress_RM_mpfc2.dat”],
“file_stat”: [“”],
“outputFolder”: [“XXXX/analysis/test”]
}

Hi @JB_75007,

Excuse the late response - I only just saw this thread. Where does the error that you report occur? Can you print the content of MRSCont.files after OspreyJob?

Thanks,
Georg

Hi Georg,

no worries,

Here is the MRSCont.files content after the commands has been ran.

MRSCont.files

ans =

1×2 cell array

{'/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00074_FID18924_eja_svs_mpress_RM_mpfc1.dat'}    {'/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00079_FID18929_eja_svs_mpress_RM_mpfc2.dat’}

Thanks !

JB

Commands used:

addpath(genpath(‘/Users/rdoc/fMRI/osprey-v.2.7.0’));
MRSCont = OspreyJob(‘/Users/rdoc/Desktop/Osprey_Analysis/FINAL_ANALYSIS/OspreyJob2.json’);
MRSCont = OspreyLoad(MRSCont);
MRSCont = OspreyProcess(MRSCont);
MRSCont = osp_AverageAllDatasetsAlongExtra(MRSCont);
MRSCont = OspreyFit(MRSCont);
MRSCont = OspreyQuantify(MRSCont);
MRSCont = OspreyOverview(MRSCont);

OspreyJob2.json

{
“seqType”: “MEGA”,
“editTarget”: [“GSH”],
“dataScenario”: “invivo”,
“MM3coModel”: “3to2MM”,
“FWHMMM3co”: “”,
“SpecReg”: “RobSpecReg”,
“SubSpecAlignment”: “L2Norm”,
“UnstableWater”: “0”,
“saveLCM”: “0”,
“savejMRUI”: “0”,
“saveVendor”: “0”,
“saveNII”: “0”,
“savePDF”: “1”,
“method”: “Osprey”,
“ECCmetab”: “1”,
“ECCmm”: “1”,
“includeMetabs”: [“full”],
“style”: “Separate”,
“lolim_range”: “0.5”,
“uplim_range”: “4.0”,
“lolim_rangew”: “2.0”,
“uplim_rangew”: “7.4”,
“bLineKnotSpace”: “0.4”,
“fitMM”: “1”,
“basisSet”: “/Users/rdoc/Desktop/Osprey_Analysis/BASIS_Siemens_MEGA_PRESS_GSH131_wMM/BASIS_Siemens_MEGA_PRESS_GSH131_wMM.mat”,
“files”: [“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00074_FID18924_eja_svs_mpress_RM_mpfc1.dat”,“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00079_FID18929_eja_svs_mpress_RM_mpfc2.dat”],
“file_stat”: [“”],
“outputFolder”: [“/Users/rdoc/Desktop/Osprey_Analysis/FINAL_ANALYSIS/TMP”]
}

Also, please not that the commands did not generate any error messages, it does just not combine the 2 sessions.

Any idea why ?

Thanks,

JB

Hi @JB_75007,

Sorry for the delay. I have talked to Yvonne at Editingschool in Mexico and she mentioned that this is still an issue.

I have looked into it now and the problem arises from the json jobfile itself. For Osprey to correctly identify the input files have to appear as cell array with a certain dimensionality. Unfortunatly this was not correctly read/preserved for the json jobfile definition. I have just added a fix to the GitHub branch to solve this issue.

However, you also have to change something in your jobfile post. You have defined the files in a single cell array. However, it has to be a cell array of cells (each subject has a cell array of experiments then).

Your definition:

[“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00074_FID18924_eja_svs_mpress_RM_mpfc1.dat”,“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00079_FID18929_eja_svs_mpress_RM_mpfc2.dat”],

Add a second pair of brackets around it:

[[“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00074_FID18924_eja_svs_mpress_RM_mpfc1.dat”,“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00079_FID18929_eja_svs_mpress_RM_mpfc2.dat”]],

For multiple subjects, it should be ( I just increased the NOVA_XX index as an example for another subject):

[[“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00074_FID18924_eja_svs_mpress_RM_mpfc1.dat”,“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_022_twix/meas_MID00079_FID18929_eja_svs_mpress_RM_mpfc2.dat”],
[“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_023_twix/meas_MID00074_FID18924_eja_svs_mpress_RM_mpfc1.dat”,“/Users/rdoc/Desktop/Osprey_Analysis/NOVA_023_twix/meas_MID00079_FID18929_eja_svs_mpress_RM_mpfc2.dat”]],

You can strat the GUI after running OspreyJob and OspreyLoad to confirm that it is working fine. You should be able to switch between the experiments in the top left corner then. Then run OspreyProcess and osp_AverageAllDatasetsAlongExtra. Afterward, you should no longer be able to switch between experiments in the Process Tab because they were averaged.

Best,
Helge

Hi @Helge
It seems to work just fine. However, I do receive error messages when trying to export the PDF and the LCModel files during the process, i.e. when using “saveLCM”: “1”, and “savePDF”: “1” (I need to set them to 0 to avoid crashes).
Also, would you think it would be possible to export the combine sessions in RAW LCModel file format ?

Again, thanks,

JB

Hi @JB_75007,

Can you post the error messages so that I can take a look? It should be possible to export the RAW LCModel files after fixing the saveLCM issue.

Note, that you can also use the LCModel wrapper in Osprey directly to do the modeling with LCModel if you want to.

Best,
Helge

Hi Helge,

This is the error message if I set up saveLCM to 1.


> 
> MRSCont = OspreyProcess(MRSCont);
> Timestamp December 10, 2024 10:21:49 Osprey 2.9.0  OspreyProcess
> Processing data from dataset   1 out of   1 total datasets...
> 
> ... done.
> Elapsed time 23.431587 seconds
> Writing table to file = /Users/rdoc/Desktop/Osprey_Analysis/FINAL_ANALYSIS/Analysis_Post_batch/QM_processed_spectra.tsv
> Writing table to file = /Users/rdoc/Desktop/Osprey_Analysis/FINAL_ANALYSIS/Analysis_Post_batch/QM_processed_spectra.json
> Error using fprintf
> Function is not defined for 'cell' inputs.
> 
> Error in io_writelcm (line 83)
> fprintf(fid,'\n SEQ= ''%s''', in.seq);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Error in osp_saveLCM (line 70)
>        RF              = io_writelcm(op_takesubspec(MRSCont.processed.metab{kk},1),outfileA,te);
>                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Error in OspreyProcess (line 840)
>    [MRSCont] = osp_saveLCM(MRSCont);
>                ^^^^^^^^^^^^^^^^^^^^

Concerning the LCModel wrapper, does it also work for the MEGA PRESS edited sequence ?

Also adding the error message when trying to save the pdf files:

(...)
Writing table to file = /Users/rdoc/Desktop/Osprey_Analysis/FINAL_ANALYSIS/Analysis_Post_batch/QM_processed_spectra.tsv
Writing table to file = /Users/rdoc/Desktop/Osprey_Analysis/FINAL_ANALYSIS/Analysis_Post_batch/QM_processed_spectra.json
Index in position 2 exceeds array bounds.

Error in osp_plotProcess (line 984)
       plot(ax_proc, procDataToPlot.ppm, real(procDataToPlot.specs(:,1))/max(real(procDataToPlot.specs(procDataToPlot.ppm>ppmmin&procDataToPlot.ppm<ppmmax))), 'Color',MRSCont.colormap.Foreground, 'LineWidth', 1.5);
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^
Error in osp_plotModule (line 358)
               temp = osp_plotProcess(MRSCont, kk,which,SubSpec,Exp); % Create figure
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in osp_plotAllPDF (line 54)
                           osp_plotModule(MRSCont, 'OspreyProcess', kk,[1 ss], Names{mm});
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in OspreyProcess (line 835)
   osp_plotAllPDF(MRSCont, 'OspreyProcess')
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Thanks !

JB

Hi @JB_75007,

I have just fixed the underlying issue in the develop branch. You should now be able to do the analysis the following way:

  • Set the fit method to LCModel (opts.fit.method in the .m file or method in the json)
  • Set saveLCM to 0
  • Run OspreyJob, OspreyLoad, OspreyProcess, and osp_AverageAllDatasetsAlongExtra as always
  • Run MRSCont = osp_saveLCM(MRSCont) to create the .RAW files of the averaged data and file paths in the MRSCont
  • Run all downstream steps: OspreyFit, OspreyCoreg, OspreySeg, OspreyQuantify, OspreyOverview

You can also take a look at the exampledata/sdat/MEGA/jobSDAT_MEGA_LCModel.m file for the input settings. For example, you need to set bLineKnotSpace to “Inf” in the json file if you don’t want to use a baseline in LCModel, and you can change the 3 ppm MM model.

Best,
Helge