Dear Francois and other BST developers/experts,
I have a couple of source images for t-tests between two levels of two factors. For example, t-test image 1 (High_x - Low_x) and t-test image 2 (High_y - Low_y). What I would like to do is a logical AND for the positive values only in each t-test image. Is there currently a way to do this in Brainstorm? If not, I suppose I could export each image into Matlab, do the calculations, then import them back into Brainstorm. But if that’s what is necessary I could use some advice/instructions on how to do that too.
Thanks in advance,
Will
Hi Will,
There is no process to do that automatically in Brainstorm for now. What I suggest is that you use the close interaction between BST’s GUI and the Matlab environment to compute what you need. Here is the procedure:
- right click over one of the t-test image (say: t-test image 1) as it appears in BST’s database tree and go to File > Import into Matlab
- you are then prompted for a variable: enter timage1 for instance
- the results structure of t-test image 1 is saved into a Matlab variable named timage1 that is directly accessible from the Matlab command line; type tiomage1 at the Matlab prompt to display that structure
- proceed in a similar manner for t-test image 2; export into a variable called timage2
- Do the operation you like on timage1.ImageGridAmp (which contains the actual cortical source map) and timage2.ImageGridAmp; store the resulting image map in a variable named, e.g. my_image
- To import the resulting image back into brainstorm, initialize a new source image/results structure with my_results = timage1; and then replace the image map with your results: my_results.ImageGridAmp = my_image
- Import this result into brainstorm by right-clicking over your database selecting File > Import from Matlab. When prompted for a variable name, enter my_results. A new database source entry should appear in your tree and you will be able to visualize your boolean map.
Let me know if something remains unclear
Thanks, Sylvain. This looks very promising. Unfortunately, when I export the t-test image and view its structure, I see nothing called ImageGridAmp. Also, when I try to do an operation on ttestimage.ImageGridAmp, I get an error saying “Reference to non-existent field ‘ImageGridAmp’”. I do see something called "SurfaceFile: [1x52 char]. Is that the same thing?
-Will
That’s right. I forgot to mention statistics images are not stored in the ImageGridAmp field but rather in pmap and tmap.See below for an example:
|- Type: ‘results’
|- Comment: ‘uttest: 100504_0837’
|- Time: [1x1801 double]
|- ChannelFlag: [15002x1 double]
|- pmap: [15002x1801 double]
|- tmap: [15002x1801 double]
|- SurfaceFile: ‘subject/tess_cortex_concat_15000V.mat’
|- pThreshold: 0.01
pmap is computed from the tmap by applying the threshold pThreshold, which can be performed using BST’s GUI (just right-click over the results entry in the data tree).
I also forgot to mention that, to create a new result file from Matlab following the procedure I described in my previous message, you need to create a copy of a result file and then replace its contents by proceeding how it is described above. It’s not entirely straightforward but still only requires a couple of operations. Let me know if you need a more detailed description.
Hi Sylvain. I tried following the steps you kindly provided, and at first it looked like things were going to work. Unfortunately, when I imported the result from Matlab, the results from my group analyses disappeared from Brainstorm. I tried refreshing the tree, reloading the database, restarting Brainstorm and Matlab, but they appear to be gone. Here’s the error message I’m now getting when Brainstorm starts up:
BST> Loading configuration file…
Warning: Database error : Study has no subject defined :
‘Group_analysis/@intra/brainstormstudy.mat’. Ignoring…
> In tree_createNodeStudiesDB at 139
In tree_updateModel at 47
In db_setCurrentProtocol at 62
In bst_startup at 535
In brainstorm at 79
BST> Done.
Perhaps this has something to do with the fact that I was visualizing the original group results when I imported the newly processes results from Matlab?
I followed your instructions for exporting two results to Matlab: freq_ttest and img_ttest.
I then did the following in Matlab:
my_image = (frq_ttest.pmap >= 0) & (img_ttest.pmap >= 0);
my_results = frq_ttest;
my_results.pmap = my_image;
I then right-clicked on the “Group analysis” level of Brainstorm and selected “Import from Matlab”, entered “my_results” and it appeared to work until my previous group results disappeared. I can certainly re-create them, but I would appreciate any insight into where I went wrong.
Thanks,
Will
What may have happened is that you have skipped the part where you need to duplicate a results file before importing your modified map into brainstorm. I know this is confusing at this point, but this should work 
So please make a copy of a results source file using the cp command from Matlab or your favorite File Explorer tool. In BrainStorm, Reload/refresh the node where the file is supposed to sit. You should see the file appear in the tree now.
Then import the my_image structure from Matlab.
Does it work any better?
In trying to re-create the group-level (intra-subject) analyses that disappeared, it seems that I’m not currently able to. When I select multiple conditions from one subject’s data in group space and try to average across them, nothing appears in the display tree and I get the following error:
Warning: Database error : Study has no subject defined :
‘Group_analysis/@intra/brainstormstudy.mat’. Ignoring…
> In tree_createNodeStudiesDB at 139
In tree_updateModel at 47
In tree_updateNode at 144
In db_reloadStudies at 79
In db_addCondition at 152
In bst_getContext at 620
In bst_batch>GetOutputStudy at 1378
In bst_batch>BatchAverage at 448
In bst_batch at 105
In panel_statRun>CreatePanel/CallBatch at 809
In panel_statRun>CreatePanel/ButtonRun_Callback at 467
In bst_safeCall at 31
In panel_statRun>@(h,ev)bst_safeCall(@ButtonRun_Callback) at 385
And there is no “intra-subject” tab under the “Group analysis” heading. This happens even after re-loading the database and restarting both Brainstorm and Matlab. I would appreciate any advice you can give.
Thanks in advance,
Will
It might well be that when you imported your ‘my_results’ structure you have right-clicked over the ‘intra’ study entry in the database, hence you have unintentionally replaced a study entry by a source map. BST did not check whether this was an authorized operation and the database got corrupted.
One thing you may want to do is to locate the intra folder in your brainstorm database. It should be sitting somewhere by the other individual data in brainstorm format (try ‘Locate on Disk’ from the data tree over an individual subject). Then locate the brainstormstudy.mat file which size should be abnormally enormous (>1MB) because it contains a source map. It would normally be a couple of KB large only. Delete that file and reload the entire database.
You may not be able to recover your group data but at least the individual entries should be accessible.
Let me know how it goes.
OK, the procedure you described for fixing the database did actually work for me. Now I can see my previous results and visualize new ones. Thank you!