Error from io_LCMBasis function

Hi there!

I am currently trying to use the io_LCMBasis function to convert a Siemens 3T MEGA-sLASER .basis file to the Osprey format. I believe I am correctly following the guidelines from the Osprey documentation, but receiving the error shown below. Am I missing something simple or is this a bug?

Thank you in advance for your help!
Rubi

Osprey v. 2.5.0

MRSCont = OspreyJob('/Users/rubi/Documents/MRS/Osprey_output_slaser/OspreyJob.json');

file = '/Users/rubi/Documents/MRS/megaslaser_basisset';

[BASIS] = io_LCMBasis(file, 0, 'MEGA', 'GABA');

Error using fgets
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in io_readlcmraw_basis (line 27)
line=fgets(fid);

Error in io_LCMBasis (line 63)
[Read]=io_readlcmraw_basis(LCMBasisSet,conjugate);

Error in makebasisset (line 5)
[BASIS] = io_LCMBasis(file, 0, ‘MEGA’, ‘GABA’);

Hi Rubi,

I think io_LCMBasis needs the full path to the basis file with the .basis extension. Something like this: file = ‘/Users/rubi/Documents/MRS/megaslaser_basisset.basis’;

Hope this helps!
Meredith

Hi Meredith,

Thank you for the response! I did try that early on, but got a different error shown below. The documentation here says to use the folder path, so I assumed this was due to the incorrect path format. But if you successfully use it with the full file path, maybe this is the ‘real’ error?

Thanks again!
Rubi

Error using io_readlcmraw_basis
Error: Character vector is not terminated properly.

Error in io_LCMBasis (line 63)
[Read]=io_readlcmraw_basis(LCMBasisSet,conjugate);

Error in makebasisset (line 5)
[BASIS] = io_LCMBasis(file, 0, ‘MEGA’, ‘GABA’);

Hi Rubi,
I have tested io_readlcmraw_basis with the complete path of a .basis file and it works. Maybe you have to test this function first. Your new error ‘Error: Character vector is not terminated properly’ can be caused by a ’ ’ ’ too much or too less.

Best, Heiner

1 Like

I agree with @hraum. If this doesn’t work, please let me know, @rruopp, happy to take a look.

Hi,
I met same problem too. And I tried to use the comp complete path of .basis file, it doesn’t work for me.
The .basis file is dowloaded from the website of LCModel

Best,
Chuyue

Hi Chuyue,
You have the newest version of Osprey, am I right? I just have used the script of the older one. I see, that the option ‘conjugate’ is new:
[BASIS] = io_LCMBasis(LCMBasisSet, addMMFlag, sequence, editTarget, conjugate)
, but should set to 1 for default:
if nargin < 5
conjugate = 1;
if nargin < 4
editTarget = ‘none’;
if nargin < 3
addMMFlag = 1;
if nargin < 2
sequence = ‘unedited’;
end
end
end
end
To define the default values, addMMFlag and sequence are swapped, but that shouldn’t be the problem because you have defined these (in your example nargin = 4).
I know this error especially when the end of a string isn’t defined (e.g. missing ').
To limit the reason for this error, you can try
[Read] = io_readlcmraw_basis(file,1)
and see if you have a more informative error message which can help.

Best,
Heiner

Hi @NSniper,

I don’t have an answer, but at this stage I would be trying to narrow the scope a bit… unfortunately your error message doesn’t identify a particular line in io_readlcmraw_basis, which makes it a bit less obvious.

I would suggest,

  1. Confirm that the “correct” io_readlcmraw_basis function is being called… if you also have FID-A installed separately from Osprey, this may complicate matters. At the matlab prompt, type which io_readlcmraw_basis, the response should be the libraries/FID-A subfolder of your Osprey installation. If you see anything else, remove that folder from your matlab search path and try again. This probably won’t solve your problem, but will avoid confusion later.

  2. Try calling io_readlcmraw_basis directly, like this:
    io_readlcmraw_basis('D:/software_backup/mrs-basis-sets-LCModel/7t/gamma_press_te10_7t_v1.basis');
    Do you see the same error? [EDIT: already suggested by @hraum – sorry, I missed that in the previous reply]

  1. Try changing to the basis set folder and run io_readlcmraw_basis again, eg:
cd D:/software_backup/mrs-basis-sets/LCModel/7t/
io_readlcmraw_basis('gamma_press_te10_7t_v1.basis')
  1. Do you have any other .basis files you could check with?

  2. A bit of a long shot, but I wonder if something with your system’s language settings/character encoding might be creating an issue. Could you please check, initially, the output of:

get(0,'Language')
java.util.locale.getDefault()

Let me know how that goes, and I can hopefully come back with some further suggestions…

Alex.

Hi Heiner,

Thank you for the reply. I use the newest 2.5.0 version of Osprey. And I tried use [Read] = io_readlcmraw_basis(file,1), but there still the same error:
image
I found there is only one input in the io_readlcmraw_basis function as it mentioned in the code:

% USAGE:
% out=io_readlcmraw_basis(filename);
%
% DESCRIPTION:
% Reads entire LCModel .basis file into multiple FID-A data structures in MATLAB.
%
% INPUTS:
% filename = filename of LCModel .basis file.
%
% OUTPUTS:
% out = Input basis set saved as a structure in which each field is
% an individual metabolite basis spectrum in FID-A structure
% format.

function [out]=io_readlcmraw_basis(filename)
So I tried [Read] = io_readlcmraw_basis(file), but there is still the same error:
image

Best,
Chuyue

Hi again @NSniper,

Please ignore my earlier response. I’ve just done some local testing and found an issue in io_readlcmraw_basis.m; I’ll come back in 5-10 minutes with a fix…

Alex.

Hi Alex,
Than you for the advice, I have removed FID-A from matlab path, but it not work, I tried directly calling, reading different basis set, but still the same error occured. And I tried check the language setting, but java.util.locale.getDefault not work, I used java.lang.System.getProperty instead of it.

pwd

ans =

'D:\software_backup\mrs-basis-sets-LCModel\7t'

io_readlcmraw_basis(‘D:/software_backup/mrs-basis-sets-LCModel/7t/gamma_press_te10_7t_v1.basis’);
Error using io_readlcmraw_basis
Error: Character vector is not terminated properly.

io_readlcmraw_basis(‘D:/software_backup/mrs-basis-sets-LCModel/7t/gamma_press_te288_7t_v1.basis’)
Error using io_readlcmraw_basis
Error: Character vector is not terminated properly.

io_readlcmraw_basis(‘gamma_press_te288_7t_v1.basis’)
Error using io_readlcmraw_basis
Error: Character vector is not terminated properly.

io_readlcmraw_basis(‘gamma_press_te10_7t_v1.basis’)
Error using io_readlcmraw_basis
Error: Character vector is not terminated properly.

io_readlcmraw_basis(‘basis_siemens_steam5.BASIS’)
Error using io_readlcmraw_basis
Error: Character vector is not terminated properly.

io_readlcmraw_basis(‘D:/software_backup/mrs-basis-sets-LCModel/7t/basis_siemens_steam5.BASIS’)
Error using io_readlcmraw_basis
Error: Character vector is not terminated properly.

get(0,‘Language’)
java.util.locale.getDefault()

ans =

'en_US'

Unable to resolve the name ‘java.util.locale.getDefault’.

java.lang.System.getProperty(‘user.language’)

ans =

en

Best,
Chuyue

Dear @NSniper,

Please try with the attached version of io_readlcmraw_basis (again, you might need to adjust your path to make sure this one is used).

If you look at your basis set, I think you’ll find tags like “METABO_CONTAM” and METABO_SINGLET", which are included in some basis sets generated by some software, but not all. The script was confusing these for METABOlite names, extracting random bits of strings (which may have included quotes), and using these in eval’d code… hence the error message without line numbers. Around line 182 is where the invalid metabolite names were being eval’d.

You could also probably just delete the METABO_CONTAM and METABO_SINGLET lines from your basis file, unless they’re being used for something.

Hope this works for you :slight_smile:

Alex.
io_readlcmraw_basis.m (10.2 KB)

Hi Chuyue,
to your comment that you’ve found only one input to io_readlcmraw_basis, like alex said, please check if you use the right script. When I look at the default branch (develop) in github
(osprey/libraries/FID-A/inputOutput/io_readlcmraw_basis.m at develop · schorschinho/osprey · GitHub), in line 19 you should see also the second input ‘conjugate’. Also in your first error message, you see that your io_LCMBasis script works with io_readlcmraw_basis with two inputs.
So your io_LCMBasis script and the used function don’t fit together.

Best,
Heiner

Hi, Alex and Heiner,
Thank you for your advices. It is the problem of io_readlcmraw_basis,. I ajdusted the path and used io_readlcmraw_basis provided by Alex, and it worked.

Best,
Chuyue

Great – glad to hear it.

I’ve tested the fix a bit further, on all the basis sets I had available, and updated the code very slightly to handle extra white space inside the quotes. So the attached version is preferable.

@Helge, I’ll submit this as a patch to Osprey.

io_readlcmraw_basis.m (10.2 KB)

2 Likes