-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bids.util.tsvwrite does not correctly write fields and values from struct to output tsv #156
Comments
hey @mnoergaard |
Sounds good, @Remi-Gau. This example file will make it easier to reproduce :-) https://www.dropbox.com/s/hnk2tvytx3lib31/sub-01_recording-autosampler_blood.tsv?dl=0 |
Awesome!! Thanks!!! |
hey @mnoergaard Just to make sure that I get what you want: you would expect that reading the content of a tsv and writing it right away, should not change the content of the file, correct? something like this ⏬ ? %% ensure that reading and then writing does not change the format
% read file
tsv_file = fullfile(pth, 'data', 'sub-01_recording-autosampler_blood.tsv');
output = bids.util.tsvread(tsv_file);
% write file
new_tsv_file = fullfile(pth, 'data', 'sub-01_recording-autosampler_blood_new.tsv');
bids.util.tsvwrite(new_tsv_file, output);
% reread the new file and makes sure its content matches the previous one
new_output = bids.util.tsvread(new_tsv_file);
assertEqual(output, new_output); If so then indeed this test fails.
I also think this is a VERY reasonable behavior to expect. So I will flag this as a bug and try to push a fix. |
Thanks both for this. Is it a recent regression as it seems to work fine with the original functions?
|
yeah I was just looking at the original code from spm to see where I had messed up when porting it. 🤦 |
Not blaming, just curious! Reaching the same conclusion that line 40 should read:
|
Yes I am there too. problem is that it is making the previous tests fail. tsv_file = fullfile(pth, 'sub-01_task-STRUCTURE_events.tsv');
logFile(1, 1).onset = 2;
logFile(1, 1).trial_type = 'motion';
logFile(1, 1).duration = 1;
logFile(1, 1).speed = [];
logFile(1, 1).is_fixation = true;
logFile(2, 1).onset = NaN;
logFile(2, 1).trial_type = 'static';
logFile(2, 1).duration = 4;
logFile(2, 1).is_fixation = 3;
bids.util.tsvwrite(tsv_file, logFile); Dimensions of matrices being concatenated are not consistent.
tsvwrite:40 (/home/remi/github/BIDS-matlab/+bids/+util/tsvwrite.m) This is a "shape" of structure I have used in our lab to collect data event after event while experiments run: but we are not using bids-matlab to save them. So I don't why we should support them. Will rewrite the first test. |
see issue bids-standard#156
I see, with input stored row-wise rather than column-wise. It's a different format but we could try to support it too, by adding a special handling if |
is that something we want to support though? while rewriting the test I realized that this other format allows a slightly more flexible missing of types within the same field. will open a PR to let you see what I meant/ |
@all-contributors please add @mnoergaard for bug, ideas |
I've put up a pull request to add @mnoergaard! 🎉 |
@mnoergaard this should now be fixed. If you pull the latest version of the master branch, this should work as expected. Also added the fiox to |
Nice, @Remi-Gau! Good job! |
Thanks for spotting it and reporting it. 😉 🚀 |
Imported a *.tsv file with 6 columns with 11 rows of values (excluding headers) using bids.util.tsvread.
The data is loaded in as a struct with 6 fields (name of headers) each with the size [11,1] double.
Currently in the code, the [11,1] array gets converted into a cell, and when concatenated into
var
on line 40, this becomes a 2x6 cell.The consequence is that only 2x6 are written to the output *.tsv because the cells in the second row of
var
are not unrolled, and hence not looped through when writing to the file.A quick fix would be to replace the following on line 40:
var = [fn'; horzcat(var{:})];
Then the correct values are written to the output *.tsv file.
The text was updated successfully, but these errors were encountered: