Commit 8d7c811d authored by jayd1860's avatar jayd1860
Browse files

v1.17

-- Removed group avg pass (grpAvgPass) variable which excludes subject channel data based on standard deviation threshold from the group level averaging.
-- Update .nirs support in Homer3 in some hmr*_Nirs.m user functions and in NirsClass.
-- Update unit test processOpt_*.cfg files for new hmrG_SubjAvg function definition which removes 3 arguments relating to group avg pass variable.
-- Add conversion to full path to convertToStandardPath.m
parent fc6f8b01
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ for ii=1:length(dirs)
    foo = FileClass(dirs(ii));
    if ~foo.IsEmpty()
        files(kk) = foo;
        files(kk).pathfull = fileparts(fullpath(str));
        files(kk).pathfull = convertToStandardPath(fileparts(fullpath(str)));
        kk=kk+1;
    end
end
+4 −0
Original line number Diff line number Diff line
@@ -267,6 +267,10 @@ classdef NirsClass < AcqDataClass & FileLoadSaveClass
        
        % ---------------------------------------------------------
        function val = GetTime(obj, iBlk)
            val = [];
            if iBlk>1
                return
            end
            val = obj.t;
        end
        
+1 −5
Original line number Diff line number Diff line
@@ -63,11 +63,7 @@ classdef RunClass < TreeNodeClass
                return;
            end
            if nargin==1 || isempty(dirname)
                dirname = '.';
            end
            dirname(dirname=='\') = '/';
            if dirname(end) ~= '/'
                dirname(end+1) = '/';
                dirname = convertToStandardPath('.');
            end
            
            if obj.IsNirs()
+30 −80
Original line number Diff line number Diff line
function [yAvg, yAvgStd, tHRF, nTrials, grpAvgPass] = hmrG_SubjAvg_Nirs(yAvgSubjs, yAvgStdSubjs, tHRFSubjs, SDSubjs, nTrialsSubjs, tRange, thresh0)
function [yAvg, tHRF, nTrials] = hmrG_SubjAvg_Nirs(yAvgSubjs, tHRFSubjs, nTrialsSubjs)
% SYNTAX:
% [yAvg, yAvgStd, tHRF, nTrials, grpAvgPass] = hmrG_SubjAvg_Nirs(yAvgSubjs, yAvgStdSubjs, tHRFSubjs, SDSubjs, nTrialsSubjs, tRange, thresh)
% [yAvg, tHRF, nTrials] = hmrG_SubjAvg_Nirs(yAvgSubjs, tHRFSubjs, nTrialsSubjs)
%
% UI NAME:
% Subj_Average
@@ -10,72 +10,51 @@ function [yAvg, yAvgStd, tHRF, nTrials, grpAvgPass] = hmrG_SubjAvg_Nirs(yAvgSubj
%
% INPUTS:
% yAvgSubjs:
% yAvgStdSubjs:
% tHRFSubjs: 
% SDSubjs:
% nTrialsSubjs:
% trange: Defines the range for the block average
% thresh: Threshold for excluding channels if it's data deviates too much
%         from mean 
%
% OUTPUTS:
% yavg: the averaged results
% yAvgStd: the standard deviation across trials
% tHRF: the time vector
% nTrials: the number of trials averaged for each condition across all
%          subjects
% grpAvgPass:
%
% USAGE OPTIONS:
% Subj_Average_on_Concentration_Data: [dcAvg, dcAvgStd, tHRF, nTrials, grpAvgPass] = hmrG_SubjAvg_Nirs(dcAvgSubjs, dcAvgStdSubjs, tHRFSubjs, SDSubjs, nTrialsSubjs, tRange, thresh)
% Subj_Average_on_Delta_OD_Data:      [dodAvg, dodAvgStd, tHRF, nTrials, grpAvgPass] = hmrG_SubjAvg_Nirs(dodAvgSubjs, dodAvgStdSubjs, tHRFSubjs, SDSubjs, nTrialsSubjs, tRange, thresh)
% Subj_Average_on_Concentration_Data: [dcAvg, tHRF, nTrials] = hmrG_SubjAvg_Nirs(dcAvgSubjs, tHRFSubjs, nTrialsSubjs)
% Subj_Average_on_Delta_OD_Data:      [dodAvg, tHRF, nTrials] = hmrG_SubjAvg_Nirs(dodAvgSubjs, tHRFSubjs, nTrialsSubjs)
%
% PARAMETERS:
% tRange: [5.0, 10.0]
% thresh: [5.0]
%

yAvg       = [];
yAvgStd    = [];
tHRF       = [];
nTrials    = [];
grpAvgPass = [];
    
subjCh = [];
nStim = 0;
grp1=[];
nSubj = length(yAvgSubjs);

% chkFlag is a parameter that if true requires, for each channel, ALL corresponding 
% subjects channels to pass before averaging that channel. TBD: Currently we set it to 
% false unconditionally. In the future chkFlag should be a user-settable input parameter.
chkFlag = false;

for iSubj = 1:nSubj
    
    if isempty(yAvgSubjs{iSubj}) || isempty(yAvgStdSubjs{iSubj}) || isempty(tHRFSubjs{iSubj}) || isempty(nTrialsSubjs{iSubj}) || isempty(SDSubjs{iSubj})
    if isempty(yAvgSubjs{iSubj}) || isempty(tHRFSubjs{iSubj}) || isempty(nTrialsSubjs{iSubj})
        continue;
    end
    
    yAvg      = yAvgSubjs{iSubj};
    yAvgStd   = yAvgStdSubjs{iSubj};
    tHRF      = tHRFSubjs{iSubj};
    nTrials   = nTrialsSubjs{iSubj};
    SD        = SDSubjs{iSubj};
        
    nCond = size(nTrials,2);
    
    if ndims(yAvg) == (4-(nCond<2))
        thresh = thresh0 * 1e-6;
        
        if iSubj==1
            lstT = find(tHRF>=tRange(1) & tHRF<=tRange(2));
            grp1 = zeros(size(yAvg,1), size(yAvg,2), size(yAvg,3), nCond);
        end
        
        nCh  = size(yAvg,3);
        if isempty(subjCh)
            subjCh = zeros(size(yAvg,3), nCond);
            grpAvgPass = zeros(size(yAvg,3), nCond, nSubj);
            subjCh = zeros(nCh, nCond);
        end
        
        for iC = 1:nCond
@@ -83,33 +62,21 @@ for iSubj = 1:nSubj
                continue;
            end
            
            % Calculate which channels to include and exclude from the group HRF avg,
            % based on the subjects' standard error and store result in lstPass
            % also need to consider if channel was manually or
            % automatically included
            lstPass = find( (squeeze(mean(yAvgStd(lstT,1,:,iC),1))./sqrt(nTrials(:,iC)+eps)) <= thresh &...
                            (squeeze(mean(yAvgStd(lstT,2,:,iC),1))./sqrt(nTrials(:,iC)+eps)) <= thresh &...
                            nTrials(:,iC)>0 );
            
            if chkFlag==false | length(lstPass)==size(yAvg,3)
            if iSubj==1 | iC>nStim
                    for iPass=1:length(lstPass)
                for iCh = 1:size(yAvg,3)
                    for iHb=1:3
                            grp1(:,iHb,lstPass(iPass),iC) = interp1(tHRF,yAvg(:,iHb,lstPass(iPass),iC),tHRF(:));
                        grp1(:,iHb,iCh,iC) = interp1(tHRF,yAvg(:,iHb,iCh,iC),tHRF(:));
                    end
                end
                    subjCh(size(yAvg,3),iC)=0;
                nStim = iC;
            else
                    for iPass=1:length(lstPass)
                for iCh = 1:size(yAvg,3)
                    for iHb=1:3
                            grp1(:,iHb,lstPass(iPass),iC) = grp1(:,iHb,lstPass(iPass),iC) + interp1(tHRF,yAvg(:,iHb,lstPass(iPass),iC),tHRF(:));
                        grp1(:,iHb,iCh,iC) = grp1(:,iHb,iCh,iC) + interp1(tHRF,yAvg(:,iHb,iCh,iC),tHRF(:));
                    end
                end
            end
                subjCh(lstPass,iC) = subjCh(lstPass,iC) + 1;
            end
            grpAvgPass(lstPass,iC,iSubj) = 1;
            subjCh(:,iC) = subjCh(:,iC) + 1; %#ok<*AGROW>
        end
        
        yAvg = [];
@@ -124,47 +91,35 @@ for iSubj = 1:nSubj
        end
        
    elseif ndims(yAvg) == (3-(nCond<2))
        thresh = thresh0;
        
        if iSubj==1
            lstT  = find(tHRF>=tRange(1) & tHRF<=tRange(2));
            grp1 = zeros(size(yAvg,1),size(yAvg,2),nCond);
        end
        
        nCh  = size(yAvg,2);
        if isempty(subjCh)
            subjCh = zeros(size(yAvg,2),nCond);
            grpAvgPass = zeros(size(yAvg,2),nCond,nSubj);
            subjCh = zeros(nCh, nCond);
        end
        
        for iC = 1:nCond
            if nTrials(:,iC)==0
                continue;
            end
            
            for iWl = 1:2
                % Calculate which channels to include and exclude from the group HRF avg,
                % based on the subjects' standard error and store result in lstPass
                lstWl = find(SD.MeasList(:,4)==iWl);
                lstPass = find( ((squeeze(mean(yAvgStd(lstT,lstWl,iC),1))./sqrt(nTrials(lstWl,iC)'+eps)) <= thresh) &...
                                 nTrials(lstWl,iC)'>0 );
                lstPass = lstWl(lstPass);
                
                if chkFlag==false | length(lstPass)==size(yAvg,2)
                if iSubj==1 | iC>nStim
                        for iPass=1:length(lstPass)
                            grp1(:,lstPass(iPass),iC) = interp1(tHRF,yAvg(:,lstPass(iPass),iC),tHRF(:));
                    for iCh = 1:size(yAvg,2)
                        grp1(:,iCh,iC) = interp1(tHRF,yAvg(:,iCh,iC),tHRF(:));
                    end
                        subjCh(size(yAvg,2),iC)=0;
                    nStim = iC;
                else
                        for iPass=1:length(lstPass)
                            grp1(:,lstPass(iPass),iC) = grp1(:,lstPass(iPass),iC) + interp1(tHRF,yAvg(:,lstPass(iPass),iC),tHRF(:));
                    for iCh = 1:size(yAvg,3)
                        grp1(:,iCh,iC) = grp1(:,iCh,iC) + interp1(tHRF,yAvg(:,iCh,iC),tHRF(:));
                    end
                end
                    subjCh(lstPass,iC) = subjCh(lstPass,iC) + 1;
                subjCh(:,iC) = subjCh(:,iC) + 1;
            end
        end
            grpAvgPass(lstPass,iC,iSubj) = 1;
        end
        
        yAvg = [];
        if ~isempty(grp1)
@@ -175,12 +130,7 @@ for iSubj = 1:nSubj
                    yAvg(:,iCh,iC) = grp1(:,iCh,iC) / subjCh(iCh,iC);
                end
            end            
            grpAvgPass = grpAvgPass(1:size(yAvg,2)/2 ,:,:);            
        end
        
    end
end

% TBD: Calculate Standard deviation
yAvgStd = [];
+3 −2
Original line number Diff line number Diff line
@@ -87,9 +87,10 @@ end

if isempty(tIncMan)
    tIncMan = ones(size(d,1),1);
else
    tIncMan = tIncMan{1};
end

tInc = ones(size(d,1),1);
tInc = tIncMan;

% Calculate the diff of d to to set the threshold if ncssesary
diff_d=diff(d);
Loading