Source permutation test on specific vertices?

HI

When running the 'process_test_permutation2' on sources is there a way to select which vertices are used (averaging them)? Or a way to create a scout from select vertices and then run the test on these scouts. I can run the test on scouts but not sure how to select specific vertices and run tests on these?

You can create scouts and then run the tests only on them.
https://neuroimage.usc.edu/brainstorm/Tutorials/Scouts#Creating_a_scout

If you need to select some specific scout indices that you don't know how to locate anatomically, you can create a scout and then edit the structure of the surface file to set the Vertices you want in this scout:
https://neuroimage.usc.edu/brainstorm/Tutorials/Scouts#On_the_hard_drive

Hi Francois

Thanks I've been trying this approach. I can get the vertices I need into a modified struct file as scouts - the Desikan-Kiliney one with 68 scouts. I adapted this file so the fields with the vertices corresponding to each anatomical region has only the vertices within that I want. When I run the Perm test I can't get them all into the same test, only one (or two in some cases if they are the same scout on opposite hemispheres - left and right bankssts). How do I get them all into the same test in 'scoutsel'?

I'd prefer not to run a loop and do a separate test on every scout. Also the vertices in scouts will vary across analyses so I can't load them into Brainstorm as a set.

ScoutsData = 

  1×68 struct array with fields:

    Vertices
    Seed
    Color
    Label
    Function
    Region
    Handles
% Process: Perm t-test equal []          H0:(A=B), H1:(A<>B)
sFiles3 = bst_process('CallProcess', 'process_test_permutation2', sFiles1, sFiles2, ...
    'timewindow',     Times, ...
    'scoutsel',       [ScoutsData(1), ScoutsData(2), ScoutsData(3)......, ScoutsData(68)], ...
    'scoutfunc',      1, ...  % Mean
    'isnorm',         0, ...
    'avgtime',        1, ...
    'iszerobad',      1, ...
    'Comment',        '', ...
    'test_type',      'ttest_unequal', ...  % Student's t-test   (unequal variance) t = (mean(A)-mean(B)) / sqrt(var(A)/nA + var(B)/nB)
    'randomizations', 4000, ...
    'tail',           'two');  % Two-tailed
    'scoutsel',       [ScoutsData(1), ScoutsData(2), ScoutsData(3)......, ScoutsData(68)], ...

No, this won't work.

In the parameter scoutsel, you need to keep the format that you get in the script generated automatically from the Pipeline editor window: {'AtlasName1', {'ScoutName1', 'ScoutName2', ...}}.
Example:

% Process: Perm t-test equal [-301ms,500ms]          H0:(A=B), H1:(A<>B)
sFiles = bst_process('CallProcess', 'process_test_permutation2', sFiles, sFiles2, ...
    'timewindow',     [-0.30078125, 0.5], ...
    'scoutsel',       {'Desikan-Killiany', {'bankssts L', 'bankssts R', 'caudalanteriorcingulate L', 'caudalanteriorcingulate R', 'caudalmiddlefrontal L', 'caudalmiddlefrontal R', 'cuneus L', 'cuneus R', 'entorhinal L', 'entorhinal R', 'frontalpole L', 'frontalpole R', 'fusiform L', 'fusiform R', 'inferiorparietal L', 'inferiorparietal R', 'inferiortemporal L', 'inferiortemporal R', 'insula L', 'insula R', 'isthmuscingulate L', 'isthmuscingulate R', 'lateraloccipital L', 'lateraloccipital R', 'lateralorbitofrontal L', 'lateralorbitofrontal R', 'lingual L', 'lingual R', 'medialorbitofrontal L', 'medialorbitofrontal R', 'middletemporal L', 'middletemporal R', 'paracentral L', 'paracentral R', 'parahippocampal L', 'parahippocampal R', 'parsopercularis L', 'parsopercularis R', 'parsorbitalis L', 'parsorbitalis R', 'parstriangularis L', 'parstriangularis R', 'pericalcarine L', 'pericalcarine R', 'postcentral L', 'postcentral R', 'posteriorcingulate L', 'posteriorcingulate R', 'precentral L', 'precentral R', 'precuneus L', 'precuneus R', 'rostralanteriorcingulate L', 'rostralanteriorcingulate R', 'rostralmiddlefrontal L', 'rostralmiddlefrontal R', 'superiorfrontal L', 'superiorfrontal R', 'superiorparietal L', 'superiorparietal R', 'superiortemporal L', 'superiortemporal R', 'supramarginal L', 'supramarginal R', 'temporalpole L', 'temporalpole R', 'transversetemporal L', 'transversetemporal R'}}, ...

This format allows the same script to run without knowing in advance the indices of the vertices, making it reproducible across subjects without any modification.

Therefore you need to edit the atlases and SAVE the modifications in the cortex file before running the script. I recommend you duplicate the Desikan-Killany atlas before modifying it.

Hi Francois,

Thanks. I thought it might work as it works fine when there's two ([ScoutsData(1), ScoutsData(2)]).

I created a duplicate of the DK atlas - Desikan-KIlliney_02. I think the approach you're describing is to overwrite the vertices in this duplicate and save in the Brainstorm database prior to each Perm t analysis. I can write a loop so that it changes the vertices to those required for each analysis (I'm using different vertices for each analysis). This is the script I copied from the tutorials. Would this be the right approach?

% Process: Select files using search query
sFiles = bst_process('CallProcess', 'process_select_search', [], [], ...
'search', '(([path CONTAINS "1_B9_hold"] AND [name CONTAINS "t-test unequal"]))');

DataMat = in_bst_data(sFiles(1).FileName)

sStudy = bst_get('Study', sFiles(1).iStudy);
sSubject = bst_get('Subject', sStudy.BrainStormSubject);
CortexFile = sSubject.Surface(sSubject.iCortex).FileName;

% Load surface file
sCortex = in_tess_bst(CortexFile);
Scouts_OLD = sCortex.Atlas(8).Scouts

% Save file
bst_save(file_fullpath(CortexFile), sCortex, 'v7');

Yes, this is what I had in mind.
But creating one new atlas for each analysis (adding a different tag describing the condition for each atlas name) would work as well: you would run this only once, and you could review visually after the computation that the location of the vertices for each scout were really what you expected.

This is the script I copied from the tutorials. Would this be the right approach?

It looks like you don't need this variable DataMat. Remove this line unless this is useful to define which vertices you keep in each condition.
The script here does not set the list of vertices, but I guess you posted it for what was around (loading and saving), and this looks good.

This worked for changing the scouts. The new scouts are visible in head models. I can't get the new scouts to run in the Perm test though.

The issue is that some of the scouts are empty now (= []). The test seems to run if only the scouts with vertices are included in 'scoutsel'. The scouts with and without vertices are going to change across analyses which are done within a loop. Is there a way to run this test without having to select the individual scouts within the Atlas every time? Or to ignore those that are empty = []?

% Process: Perm t-test equal []          H0:(A=B), H1:(A<>B)
sFiles3 = bst_process('CallProcess', 'process_test_permutation2', sFiles1, sFiles2, ...
    'timewindow',     Times, ...
    'scoutsel',       {'Desikan-Killiany_02', {'bankssts L', 'bankssts R', 'caudalanteriorcingulate L', 'caudalanteriorcingulate R', 'caudalmiddlefrontal L', 'caudalmiddlefrontal R', 'cuneus L', 'cuneus R', 'entorhinal L', 'entorhinal R', 'frontalpole L', 'frontalpole R', 'fusiform L', 'fusiform R', 'inferiorparietal L', 'inferiorparietal R', 'inferiortemporal L', 'inferiortemporal R', 'insula L', 'insula R', 'isthmuscingulate L', 'isthmuscingulate R', 'lateraloccipital L', 'lateraloccipital R', 'lateralorbitofrontal L', 'lateralorbitofrontal R', 'lingual L', 'lingual R', 'medialorbitofrontal L', 'medialorbitofrontal R', 'middletemporal L', 'middletemporal R', 'paracentral L', 'paracentral R', 'parahippocampal L', 'parahippocampal R', 'parsopercularis L', 'parsopercularis R', 'parsorbitalis L', 'parsorbitalis R', 'parstriangularis L', 'parstriangularis R', 'pericalcarine L', 'pericalcarine R', 'postcentral L', 'postcentral R', 'posteriorcingulate L', 'posteriorcingulate R', 'precentral L', 'precentral R', 'precuneus L', 'precuneus R', 'rostralanteriorcingulate L', 'rostralanteriorcingulate R', 'rostralmiddlefrontal L', 'rostralmiddlefrontal R', 'superiorfrontal L', 'superiorfrontal R', 'superiorparietal L', 'superiorparietal R', 'superiortemporal L', 'superiortemporal R', 'supramarginal L', 'supramarginal R', 'temporalpole L', 'temporalpole R', 'transversetemporal L', 'transversetemporal R'}}, ...
    'scoutfunc',      1, ...  % Mean
    'isnorm',         0, ...
    'avgtime',        1, ...
    'iszerobad',      1, ...
    'Comment',        '', ...
    'test_type',      'ttest_unequal', ...  % Student's t-test   (unequal variance) t = (mean(A)-mean(B)) / sqrt(var(A)/nA + var(B)/nB)
    'randomizations', 4000, ...
    'tail',           'two');  % Two-tailed

You should not leave in the data structure scouts with no vertices.
This is not a possible use case from the interface, and therefore there are many places in the code where this is not going to be handled correctly.
Remove the scouts that have no vertices from the atlas structures.

I put in code to remove the rows with no vertices from a temporary scout struct. Then I called the labels for this in the Perm test. This seems to work.

ScoutsUSE = sCortex.Atlas(8).Scouts
ScoutsUSE = ScoutsUSE(~cellfun(@isempty,{ScoutsUSE.Vertices}));

    'scoutsel',       {'Desikan-Killiany_02', {ScoutsUSE.Label}}, ...

I'm trying to stimulate the recordings for the above scouts - "Simulate > Simulate recordings from scout".

I can't see the channel file in the intra-subject folder. How do I create this?

Also can these models show the t value along with color bar?

You need to have a channel file available in the folder where you run the simulation, indeed.
You can either copy-paste it from another folder (your own recordings), or right-click on the folder > Use default EEG cap... to use a template.
https://neuroimage.usc.edu/brainstorm/Tutorials/Simulations#Simulate_MEG.2FEEG_from_synthetic_dipoles

HI Francois,

Under Common files I already have a channel file so I don't think any other channel file needs to be imported. I don't see this option to import for the group folders. When I try to copy/paste this file to the group folder with the Stat file from scouts analysis I get the message - invalid destination. Also tried c/p a subject channel file with same result.

The location where the channel file appears depends on how you configured your subjects. If you are using a shared channel file, the channel file would exclusively be located in the "Common files" folders.

Note that this is not recommended to work with shared channel files, because of the risks of manipulation errors or misunderstanding (cf. your last comment) :
https://neuroimage.usc.edu/brainstorm/Tutorials/CreateProtocol#Create_your_first_protocol

For my protocol under - Default channel file: (Sensors names and positions) I have it set to "No, use one channel file per acquisition run". I have a channel file under common files (under the group analysis folder) and under the task folder in each subject folder. Is it possible to simulate recordings from scout for a group level stat file?

Oh I see, sorry for the misunderstanding.
Yes, you can use this folder Group analysis to simulate data, but it is not really "group analysis". It might be more appropriate to create a new subject named "Simulation" for example.

That worked thanks Francois. I added the files to this new simulation folder, computed head model and applied stat threshold. I can simulate the recordings but there's a difficulty as the scouts have to be selected first (the scouts vary from test to test) or it won't run.

Is there a way to have the scouts displayed according to t-value as in the sources Perm t test files rather than p.am?

I'm not sure I understand what this means in your pipeline.
If you need help improving this, please post some more information (screen captures, script...)

Is there a way to have the scouts displayed according to t-value as in the sources Perm t test files rather than p.am?

This was actually some kind of bug. Using the correct units was never implemented correctly...
I tried to develop this feature in these commits:

Please update Brainstorm and try again.
You'll have to apply again the stat threshold to the source files, otherwise the 't' units are not saved in the new file.

@Raymundo.Cassani @edelaire
I guess this will have other bad side effects in some specific cases.
Could you please check briefly on some files that it works on your end (especially for NIRS, that I'm not really competent to test)? - Thanks

Thanks, I re-did this. Before I got the p.am source map but now I get the perm file and when I try to open it I get this error message;

image

I can see t-values on the perm stat file and the file from applying the stat threshold.

I think I have a solution to this thanks.

now I get the perm file and when I try to open it I get this error message;

Of course, I forgot this: Time series figure: Use DisplayUnits from the files (fix) · brainstorm-tools/brainstorm3@9f46ab3 · GitHub

Please update again, and try again.

I apologize in advance, I've haven't been testing enough this change before posting it, so you might see other weird messages or behaviors. Please report them all, I'll fix them next week.
Thanks

Thanks Francois, I updated. The source file was produced and I can open again but it is based on p.am values and not t-values. Also stat files are back to 'no units'.