<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
UNSUBSCRIBE please</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> fieldtrip <fieldtrip-bounces@science.ru.nl> on behalf of fieldtrip-request@science.ru.nl <fieldtrip-request@science.ru.nl><br>
<b>Sent:</b> 26 October 2021 10:00<br>
<b>To:</b> fieldtrip@science.ru.nl <fieldtrip@science.ru.nl><br>
<b>Subject:</b> fieldtrip Digest, Vol 131, Issue 24</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Send fieldtrip mailing list submissions to<br>
        fieldtrip@science.ru.nl<br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
or, via email, send a message with subject or body 'help' to<br>
        fieldtrip-request@science.ru.nl<br>
<br>
You can reach the person managing the list at<br>
        fieldtrip-owner@science.ru.nl<br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of fieldtrip digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. ft_sourceanalysis single trial reconstruction (CHATEAUX Manon)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 25 Oct 2021 17:02:10 +0000<br>
From: CHATEAUX Manon <manon.CHATEAUX@univ-amu.fr><br>
To: "fieldtrip@science.ru.nl" <fieldtrip@science.ru.nl><br>
Subject: [FieldTrip] ft_sourceanalysis single trial reconstruction<br>
Message-ID: <3e60d083352245d4a8e12b5f938486ce@univ-amu.fr><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Dear FieldTrip community,<br>
<br>
I want to compute coherence between brain sources and an EMG channel that I selected. Here is the pipeline I am using :<br>
<br>
  *   Preprocess MEG and EMG data<br>
  *   Process single subject MRI data to get (a) the head model, (b) the source model with leadfields<br>
  *   Reconstruct MEG data using beamformer techniques in the time domain.<br>
  *   Compute coherence between source data and EMG data<br>
<br>
To be able to compute coherence, I need to reconstruct data for all trials and not as an average of trials. But I encountered a problem at this level.<br>
<br>
Here is the code I used first :<br>
<br>
% Compute noise-covariance matrix<br>
<br>
    cfg            = [];<br>
    cfg.covariance = 'yes'; %default takes the whole time window to estimate the noise covariance matrix<br>
    cfg.keeptrials = 'yes';<br>
<br>
    tlcontr_MEG    = ft_timelockanalysis(cfg, MEG_contr);<br>
<br>
% Compute inverse modelling with mne : source data averaged over<br>
% trails<br>
    cfg                = [];<br>
    cfg.method         = 'mne';<br>
    cfg.sourcemodel    = leadfield;<br>
    cfg.headmodel      = headmodel;<br>
    cfg.mne.lambda     = 3; %%????<br>
    cfg.mne.keepfilter = 'yes';<br>
    cfg.rawtrial       = 'no';<br>
<br>
    source_MEG_contr   = ft_sourceanalysis(cfg,tlcontr_MEG);<br>
<br>
% Get source data for all trials : project trials by hand<br>
<br>
    FILTER = source_MEG_contr.avg.filter(cellfun(@(a) ~isempty(a),source_MEG_contr.avg.filter));<br>
   for triali = 1 : length(MEG_contr.trial)<br>
        source_MEG_contr_trials.pow{triali} = cell2mat(cellfun(@(a) sum((a*MEG_contr.trial{triali}).^2,1),FILTER,'UniformOutput',false)');<br>
        disp(['Trial n° ' num2str(triali) ' out of ' num2str(length(MEG_contr.trial))])<br>
<br>
    end<br>
<br>
source_MEG_contr_trials  is to be the structure that contains source data for all trials. As you can see I computed it by hand, following a thread that I found on the website.<br>
Then I found it was possible to use ft_sourceanalysis again, to project all trials through the filter computed at the first use of the function. So I replaced the last paragraph of code with the following :<br>
<br>
    % project all trials through common spatial filter to get source data<br>
    % for separate trials<br>
    cfg=[];<br>
    cfg.method             = 'mne';<br>
    cfg.sourcemodel        = leadfield;       % previously computed grid<br>
    cfg.headmodel          = headmodel;        % previously computed volume conduction model<br>
    cfg.rawtrial           = 'yes';      % project each single trial through the filter to reconstruct single trial data<br>
<br>
    cfg.sourcemodel.filter = source_MEG_contr.avg.filter; % use the common filter computed in the previous step!<br>
    source_MEG_contr_trials      = ft_sourceanalysis(cfg, tlcontr_MEG); % contains the source estimates for all trials/both conditions<br>
<br>
<br>
I preferred this "automatic" way rather than the manual one because it allows me to keep the FieldTrip shape of structures more easily and display results using FieldTrip functions.<br>
<br>
However, I realized that it returned completely different results. After trying to understand the steps performed in the second use of ft_sourceanalysis, I realized that filters used to compute trial source data from trial channel data (l. 295 in ft_inverse_mne
 of fieldtrip-20210921 : estimate.mom{i} = sourcemodel.filter{i}*dat) were different from filters in cfg.sourcemodel.filter.<br>
In fact, channel labels are taken from the leadfield structure. Lines (channel dimension) in filter matrices (in cfg.sourcemodel.filter) are reorganized so that it matches channel order from data.label (= tlcontr_MEG.label).<br>
See l.404-410 in ft_sourceanalysis of fieldtrip-20210921 :<br>
[dum, chansel] = match_str(data.label, sourcemodel.label);<br>
sourcemodel.label = sourcemodel.label(chansel);<br>
for i=1:numel(sourcemodel.filter)<br>
   if ~isempty(sourcemodel.filter{i})<br>
     sourcemodel.filter{i} = sourcemodel.filter{i}(:, chansel);<br>
   end<br>
end<br>
<br>
Thus, if I understand it correctly, this step assumes that lines in filter matrices (which come from source_MEG_contr structure) are organized in the same way as channels in leadfields. However, this is not actually the case here because<br>
<br>
  1.  source_MEG_contr.avg.label and data.label (= tlcontr_MEG.label) are equal.<br>
  2.  I don't understand why but leadfields.label is different from the original alphanumerical channel organization - A1 A2 A3 etc...- found in raw data (as well as in source_MEG_contr, and in tlcontr_MEG).<br>
<br>
So I think that in my case, lines in filter matrices should not be reorganized (when they are not, I get the same results as by hand) but as leadfield structure is also used when I compute source_MEG_contr from tlcontr_MEG, I am not sure I can trust source_MEG_contr
 either.<br>
<br>
I would truly appreciate if someone could proofread and pinpoint some problems in this reasoning to help me solve this annoying problem. In the meantime I will try to recompute the leadfield structure so that channel order is the same everywhere.<br>
<br>
Thank you in advance for your help and the time you will spend reading through this message!<br>
<br>
Manon Châteaux<br>
phD Student at Aix-Marseille University<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20211025/7e931bbe/attachment-0001.htm">http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20211025/7e931bbe/attachment-0001.htm</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
_______________________________________________<br>
fieldtrip mailing list<br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
<a href="https://doi.org/10.1371/journal.pcbi.1002202">https://doi.org/10.1371/journal.pcbi.1002202</a><br>
<br>
<br>
------------------------------<br>
<br>
End of fieldtrip Digest, Vol 131, Issue 24<br>
******************************************<br>
</div>
</span></font></div>
</body>
</html>