Unverified Commit 10832b7e authored by Christian Arthur's avatar Christian Arthur Committed by GitHub
Browse files

CSV Stim Tools (#58)



* Updated DesignNotes.ppt

* Update 1
Added Zoom and Pan functionality to axesSDG (probe display) on the MainGUI with additional buttons in the GUI

* Update 1.1
Minor Zoom adjustments

* prevented ArgClass Extract from indexing into empty list

* FuncCallClass GetInputs and GetOutputs convenience function for returning strings

* GetProcInputs method returns all properties of ProcInputClass for use with proc stream checking

* Processing stream is only run if Check returns zero, else an error msg is raised

* Changed uses of properties to propnames in ProcInputClass GetProcInputs

* Added removal and addition of stim data columns and interface in StimEditGUI; added dialog box for setting amp, duration, and values for new stims

* Added rename column interface

* GUI updates: column interface changed, rename condition moved to menubar -> tools

* Tooltip to manual edit, exit condition for value entry prompt

* Callback Added for CSV Read/Write

* Script Addition
- CSV Write to StimEditGUI
- CSV Read from StimEditGUI

* Stim CSV Reader and Write Update
- Integrated into StimEditGUI.fig

* StimEditGUI.fig Update
- Added StimCSV_Read and StimCSV_Write to the Menu Bar

* StimEditGUI.fig Update
- Normalized objects (with two errors(?))

* Added sample .csv file for stims

* Session level GLM

Adding hmrS_GLM which gets all run level data from a single subject and concatenates them. The new design matrix has HRF regressors common to all runs but have separate regressors for the rest of the model (e.g. drift, short separation).

* Update hmrS_GLM.m

Fix on contrast estimation from the concatenated GLM.

* Update hmrS_GLM.m

Updating the help of the function

* tstats for iRML

Adding tstats per condition and per contrast for the iterative restricted maximum likelihood method from Barker, BOE, 2013.

* Stim GUI interface changes (#47)

* prevented ArgClass Extract from indexing into empty list

* FuncCallClass GetInputs and GetOutputs convenience function for returning strings

* GetProcInputs method returns all properties of ProcInputClass for use with proc stream checking

* Processing stream is only run if Check returns zero, else an error msg is raised

* Changed uses of properties to propnames in ProcInputClass GetProcInputs

* Added removal and addition of stim data columns and interface in StimEditGUI; added dialog box for setting amp, duration, and values for new stims

* Added rename column interface

* GUI updates: column interface changed, rename condition moved to menubar -> tools

* Tooltip to manual edit, exit condition for value entry prompt

* Generate filters with butter interface, error checking

* Logic to prevent button presses when no conditions are present

* Removed rename cond and add/delete/rename column GUI options because they result in undefined behavior

* User function improvements (#53)

* prevented ArgClass Extract from indexing into empty list

* FuncCallClass GetInputs and GetOutputs convenience function for returning strings

* GetProcInputs method returns all properties of ProcInputClass for use with proc stream checking

* Processing stream is only run if Check returns zero, else an error msg is raised

* Changed uses of properties to propnames in ProcInputClass GetProcInputs

* tCCAaux_inx is a list again as variable length parameters are supported

* Standardized tIncMan, mlActAuto in code

* Properly generate the tIncCh matrix if it is not provided

* Include mlActAuto and tIncAuto in PCA motion correction

* recurse updated to work with new function inputs

* mlActMan and mlActAuto both used for wavelet correction

* OD2Conc wavelength restriction removed

* Phase out old GLM for new stim GLM, suppress a line in errchk

* Prevent stim amps getter from crashing on empty data

* Removed registry from PR

* Synced the Stim CSV Reader and Writer
- Added menu button for saving and loading CSV files

* Re-Update
- Added CSV Stim Read and Write tools to StimEdit GUI

* Clean Up
- Adjusted SubjClass.m, hmrR_GLM.m to sync with the development branch
- Deleted the previously pulled hmrS_GLM.m (from a reverted merge)

Co-authored-by: default avatarsstucker <sstucker@bu.edu>
Co-authored-by: default avatarMeryem Ayse Yucel <49535526+mayucel@users.noreply.github.com>
parent a6798fa1
Loading
Loading
Loading
Loading

Docs/ex_stimCSV.csv

0 → 100644
+29 −0
Original line number Diff line number Diff line
Stim 1 Name,,,,
Onset,Duration,Amplitude,Extra1,Extra2
31.1984,10,1,5,20
61.1969,10,1,10,40
91.1953,10,1,15,60
121.1938,10,1,20,80
151.1923,10,1,25,100
181.1907,10,1,30,120
211.1892,10,1,35,140
241.1877,10,1,40,160
271.1861,10,1,45,180
300.1846,10,1,50,200
331.1831,10,1,55,220
361.1815,10,1,60,240
,,,,
Stim 2 Name,,,,
Onset,Duration,Amplitude,Extra1,Extra2
40,10,1,20,5
70,10,1,40,10
100,10,1,60,15
130,10,1,80,20
160,10,1,100,25
190,10,1,120,30
220,10,1,140,35
250,10,1,160,40
280,10,1,180,45
310,10,1,200,50
340,10,1,220,55
370,10,1,240,60
−13.7 KiB (50.6 KiB)

File changed.

No diff preview for this file type.

+41 −1
Original line number Diff line number Diff line
@@ -1025,7 +1025,6 @@ end

labels = stimEdit.dataTreeHandle.currElem.GetStimDataLabels(icond);
stimdata = stimEdit.dataTreeHandle.currElem.GetStimData(icond);

if ~isempty(stimdata)
    [tpts, idx] = sort(stimdata(:,1));
    stimdata_sorted = stimdata(idx,:);
@@ -1313,3 +1312,44 @@ stimEdit.dataTreeHandle.currElem.AddStimColumn(name, value);
Display(handles);



% --------------------------------------------------------------------
function StimCSV_Read_Callback(hObject, eventdata, handles)
% hObject    handle to StimCSV_Read (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global stimEdit
[conds,labels,stimData] = StimCSV_Reader();
for j = 1:length(labels{1})
    stimEdit.dataTreeHandle.currElem.AddStimColumn(labels{1}{j},1);
end
for i = 1:length(stimData)
    onsets = str2double(stimData{i}(:,1));
    dur = str2double(stimData{i}(:,2));
    amp = str2double(stimData{i}(:,3));
    if size(stimData{i},2) > 3
        other = str2double(stimData{i}(:,4:end));
    else
        other = [];
    end
    for k = 1:size(stimData{i},1)
        stimEdit.dataTreeHandle.currElem.AddStims(onsets(k), conds{i}{1}, dur(k), amp(k), other(k,:));
    end
end
iG = stimEdit.locDataTree.GetCurrElemIndexID();
stimEdit.locDataTree.groups(iG).SetConditions();
Display(handles);


% --------------------------------------------------------------------
function StimCSV_Write_Callback(hObject, eventdata, handles)
% hObject    handle to CSV_Write (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global stimEdit
conds = stimEdit.dataTreeHandle.currElem.GetConditions();
for i = 1:length(conds)
    stimData{:,i} = stimEdit.dataTreeHandle.currElem.GetStimData(i);
    stimLabels{:,i} = stimEdit.dataTreeHandle.currElem.GetStimDataLabels(i);
end
StimCSV_Write(conds,stimLabels,stimData);

Utils/StimCSV_Reader.m

0 → 100644
+61 −0
Original line number Diff line number Diff line
function [conds,labels,stimData] = StimCSV_Reader()
    %Open File
%     filename = "StimCSV_Sample_Error.csv";
    [file,path,~] = uigetfile({'*.csv','CSV File (*.csv)'});
    filename = [path file];
    stimFileID = fopen(filename);
    
    %Initial Variables
    i = 1;
    stimNameIndicator = true;
    stimLabelIndicator = true;
    labels = cell(1,1);
    data = [];
    stimData = cell(1,1);
    
    %Get Line
    linestr = fgetl(stimFileID);
    
    while(linestr ~= -1)
        strCell = strsplit(linestr,',');
        strCell = strCell(~cellfun(@isempty,strCell));
        if isempty(strCell) %Update Stim (Finalize)
            try
                stimData{:,i} = data;
            catch
                errordlg('Invalid Stim CSV Syntax. Please check reference file for guidance');
                return;
            end
            i = i+1;
            stimNameIndicator = true;
            stimLabelIndicator = true;
            data = [];
        elseif stimNameIndicator %Update Stim Name
            try
                conds{i} = strCell(1);
            catch
                errordlg('Invalid Stim CSV Syntax. Please check reference file for guidance');
                return;
            end
            stimNameIndicator = false;
        elseif stimLabelIndicator %Update Stim Label
            labels{i} = strCell;
            stimLabelIndicator = false;
        else %Update Stim Data
            try
                data = [data; strCell];
            catch
                errordlg('Invalid Stim CSV Syntax. Please check reference file for guidance');
                return;
            end
        end
        %Read Next Line
        linestr = fgetl(stimFileID);
    end
    
    %Final Stim Update
    stimData{:,i} = data;
    
    %Close File
    fclose(stimFileID);
end
 No newline at end of file

Utils/StimCSV_Write.m

0 → 100644
+46 −0
Original line number Diff line number Diff line
function StimCSV_Write(conds,stimLabels,stimData)
%     filename = 'test.csv';
%     stimvar = importStim;
    [file,path,~] = uiputfile({'*.csv','CSV File (*.csv)'});
    filename = [path file];
    
    fid = fopen(filename,'w');
    
    for i = 1:length(conds)
        for j = 1:size(stimData{i},1)+2
            linestr = [];
            for k = 1:size(stimLabels{i},2)
                if j == 1
                    if k == 1
                        linestr = sprintf('%s,', conds{i});
                        linediv = sprintf(',');
                    elseif k == size(stimLabels{i},2)
                        % Done
                        linediv = sprintf('%s\n', linediv);
                    else
                        linestr = sprintf('%s,', linestr);
                        linediv = sprintf('%s,', linediv);
                    end
                elseif j == 2
                    if k == size(stimLabels{i},2)
                        linestr = sprintf('%s%s', linestr, stimLabels{i}{k});
                    else
                        linestr = sprintf('%s%s,', linestr, stimLabels{i}{k});
                    end
                else
                    if k == size(stimLabels{i},2)
                        linestr = sprintf('%s%f', linestr, stimData{i}(j-2,k));
                    else
                        linestr = sprintf('%s%f,', linestr, stimData{i}(j-2,k));
                    end
                end
            end
            linestr = sprintf('%s\n', linestr);
            fprintf(fid,linestr);
        end
        fprintf(fid,linediv);
    end
    
    fclose(fid);

end