Commit d735fe16 authored by jayd1860's avatar jayd1860
Browse files

Merge branch 'master' of https://github.com/BUNPC/Homer3

parents dfc8110d 8b546dc7
Loading
Loading
Loading
Loading
+60 −53
Original line number Diff line number Diff line
% SYNTAX:
% pValues = hmrS_CalcPvalue(yRuns, stimRuns, baselineRange, hrfTimeWindow)
% [pValuesS, pValuesS_cond]  = hmrS_CalcPvalue(yRuns, stimRuns, mlActRuns, baselineRange, hrfTimeWindow)
%
% UI NAME:
% Pvalues_on_Session
@@ -10,21 +10,21 @@
% INPUTS:
% yRuns:
% stimRuns:
% mlActRuns:
% baselineRange:
% hrfTimeWindow:
%
% OUTPUTS:
% pValues:
%
% pValuesS:
% pValuesS_cond
% USAGE OPTIONS:
% Pvalues_on_Session_Concentration_Data: pValues = hmrS_CalcPvalue(dcRuns, stimRuns, baselineRange, hrfTimeWindow)
% Pvalues_on_Session_Delta_OD_Data:      pValues = hmrS_CalcPvalue(dodRuns, stimRuns, baselineRange, hrfTimeWindow)
% Pvalues_on_Session_Concentration_Data: [pValuesS, pValuesS_cond] = hmrS_CalcPvalue(dcRuns, stimRuns, mlActRuns, baselineRange, hrfTimeWindow)
%
% PARAMETERS:
% baselineRange: [-2.0, 0.0]
% hrfTimeWindow: [-2.0, 20.0]
%
function pValues = hmrS_CalcPvalue(yRuns, stimRuns,baselineRange, hrfTimeWindow)

function [pValuesS, pValuesS_cond] = hmrS_CalcPvalue(yRuns, stimRuns, mlActRuns, baselineRange, hrfTimeWindow)

pValues = cell(length(yRuns{1}),1);

@@ -36,8 +36,10 @@ t = snirf.GetTimeCombined();
s = snirf.GetStims(t);
ncond = size(s,2);
fq = abs(1/(t(1)-t(2)));
nDataBlks = length(yRuns{1});

%% BASELINE vs CONDITION, PAIRED T-TEST
for iBlk = 1:nDataBlks
    for cond = 1:ncond % for each condition
        for iRun = 1:length(yRuns)
            
@@ -50,13 +52,18 @@ for cond = 1:ncond % for each condition
            
            % extract HRF at baselineRange and at hrfTimeWindow
            lst_stim = find(s(:,cond)==1);
        for iBlk = 1:length(yRuns)
            
            % get active measuremnt list for each run
            % 1) IS THIS HOW WE EXTRACT MEASLISTACT
            if ~exist('mlActAuto')
                mlActAuto{iBlk} = ones(size(ml,1),1);
            if isempty(mlActRuns{iRun})
                mlActRuns{iRun} = cell(length(nDataBlks),1);
            end
            mlAct = mlActAuto{iBlk};
            ml    = yRuns{iRun}(iBlk).GetMeasListSrcDetPairs();
            
            if isempty(mlActRuns{iRun}{iBlk})
                mlActRuns{iRun}{iBlk} = ones(size(ml,1),1);
            end
            mlAct = mlActRuns{iRun}{iBlk}(1:size(ml,1));
            
            % GetDataMatrix() extract data in old homer2 dimensions (time X Hb X channel)
            y = yRuns{iRun}(iBlk).GetDataMatrix();% yRuns{iRun}(iBlk).GetDataMatrix();  % data matrix for run iRun, data block iBlk
            for hb = 1:3 % across HbO/HbR/HbT
@@ -85,8 +92,6 @@ for cond = 1:ncond % for each condition
    % get stats
    if isempty(pValues{iBlk})
        for ch = 1:size(MEAN_Hb_peak,2) % channels
            if mlAct(ch) ~=0
                format long
                 for hb = 1:3% HbO/HbR/HbT
                    [h,p,c,stats] = ttest(MEAN_Hb_baseline(:,ch,hb),(MEAN_Hb_peak(:,ch,hb)));
                    pValuesS(hb,ch,cond) = p;
@@ -94,13 +99,13 @@ for cond = 1:ncond % for each condition
                    % 2) Pvalue SHOULD BE CONVERTED TO DATA CLASS IN THE RIGHT DIM AT THE END
                    
                end
            else
                pValuesS(hb,ch,cond) = 'NaN';
            end
        end
    end
end

pValuesS(:,find(mlAct==0),:) = NaN;
   



%% CONDITION vs CONDITION, UNPAIRED T-TEST
@@ -111,18 +116,23 @@ for i = 1:ncond
    lst_stim_all{i} = find(s(:,i)==1);
end

for iBlk = 1:length(nDataBlks)
    for comb_inx = 1:size(cond_2_comb,1) % for each condition
        % get current combin.
        foo = cond_2_comb(comb_inx,:);
        
        for iRun = 1:length(yRuns)
        for iBlk = 1:length(yRuns)
            % get active measuremnt list for each run
            % 1) IS THIS HOW WE EXTRACT MEASLISTACT
            if ~exist('mlActAuto')
                mlActAuto{iBlk} = ones(size(ml,1),1);
            if isempty(mlActRuns{iRun})
                mlActRuns{iRun} = cell(length(nDataBlks),1);
            end
            mlAct = mlActAuto{iBlk};
            ml = yRuns{iRun}(iBlk).GetMeasListSrcDetPairs();
            
            if isempty(mlActRuns{iRun}{iBlk})
                mlActRuns{iRun}{iBlk} = ones(size(ml,1),1);
            end
            mlAct = mlActRuns{iRun}{iBlk}(1:size(ml,1));
            
            % GetDataMatrix() extract data in old homer2 dimensions (time X Hb X channel)
            y = yRuns{iRun}(iBlk).GetDataMatrix();  % data matrix for run iRun, data block iBlk
            for hb = 1:3 % across HbO/HbR/HbT
@@ -154,8 +164,6 @@ for comb_inx = 1:size(cond_2_comb,1) % for each condition
    % get stats
    if ~exist('pValuesS_cond')
        for ch = 1:size(MEAN_Hb_peak,2) % channels
            if mlAct(ch) ~=0
                format long
                for hb = 1:3% HbO/HbR/HbT
                    [h,p,c,stats] = ttest2(MEAN_Hb_peak1(:,ch,hb),(MEAN_Hb_peak2(:,ch,hb)));
                    pValuesS_cond(hb,ch,comb_inx) = p;
@@ -164,9 +172,8 @@ for comb_inx = 1:size(cond_2_comb,1) % for each condition
                    % 2) Pvalue SHOULD BE CONVERTED TO DATA CLASS IN THE RIGHT DIM AT THE END
                    
                end
            else
                pValuesS_cond(hb,ch,comb_inx) = 'NaN';
            end
        end
    end
end
pValuesS_cond(:,find(mlAct==0),:) = NaN;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+2 −10
Original line number Diff line number Diff line
@@ -48,20 +48,16 @@
% rhoSD_ssThresh: 15.0

%% COMMENTS/THOUGHTS/QUESTIONS ALEX
% 1) I think we can remove the original perf_temp_emb_cca.m function (done)
% 2) Output canonical correlation coefficients as quality metric? 
% 3) Output fNIRS signal(s)/Aux regressors for visualization/quality control?
% 4) Add single channel (regressor) feature - flag - how do we provide the individual outputs?
% 5) Implement the variable low/bandpass filter coefficients from previous processing stream
% Q1) why the flagtCCA?
%%

function [Aaux] = hmrR_tCCA(data, aux,  probe, yRuns, flagtCCA, tCCAparams, tCCAaux_inx, tCCArest_inx, rhoSD_ssThresh)
%% flags
flags.pcaf =  [0 0]; % no pca of X or AUX
flags.shrink = true;
% perform regularized (rtcca) (alternatively old approach)
rtccaflag = true;
flag_conc = true; % if 1 CCA inputs are in conc, if 0 CCA inputs are in intensity

%% extract user input
@@ -87,10 +83,6 @@ if flagtCCA
        t = data_y(iBlk).GetTime();
        fq = 1/(t(2)-t(1));
        ml = data_y(iBlk).GetMeasListSrcDetPairs();
        if isempty(mlActAuto{iBlk})
            mlActAuto{iBlk} = ones(size(ml,1),1);
        end
        mlAct = mlActAuto{iBlk};
    end
    
    %% find the list of short and long distance channels
@@ -101,8 +93,8 @@ if flagtCCA
        rhoSD(iML) = sum((SrcPos(ml(lst(iML),1),:) - DetPos(ml(lst(iML),2),:)).^2).^0.5;
        posM(iML,:) = (SrcPos(ml(lst(iML),1),:) + DetPos(ml(lst(iML),2),:)) / 2;
    end
    lstSS = lst(find(rhoSD<=rhoSD_ssThresh & mlAct(lst) == 1));
    lstLS = lst(find(rhoSD>rhoSD_ssThresh & mlAct(lst) == 1));
    lstSS = lst(find(rhoSD<=rhoSD_ssThresh));
    lstLS = lst(find(rhoSD>rhoSD_ssThresh));
    
    
    %% get long and short channels
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ paths = {...
    '/FuncRegistry'; ...
    '/FuncRegistry/UserFunctions'; ...
    '/FuncRegistry/UserFunctions/Archive'; ...
    '/FuncRegistry/UserFunctions/tcca_glm'; ...
    '/MainGUI'; ...
    '/Install'; ...
    '/PlotProbeGUI'; ...

hmrR_tCCA.m

0 → 100644
+0 −0

Empty file added.