-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_load_plot_export_m2_simulations.m
133 lines (121 loc) · 5.25 KB
/
example_load_plot_export_m2_simulations.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function sweep_data = example_load_plot_export_m2_simulations(W, SweepName, options)
%EXAMPLE_LOAD_PLOT_EXPORT_M2_SIMULATIONS Shows how to load/plot/export the NEURON simulations
arguments
W (:,3) = [30, 30, 30; 50 30 10; 20 50 20; 10 30 50];
SweepName (1,:) string = ["Constant", "Decreasing", "Up-Down", "Increasing"];
options.CloseExisting (1,1) logical = true;
options.ClearCommandWindow (1,1) logical = true;
options.SaveFolder {mustBeTextScalar} = 'export/NEURON';
options.DeckName {mustBeTextScalar} = 'M2-Modulation';
end
if size(W,1) < numel(SweepName)
error("Not enough qualitative labels in SweepName for each combination (row) of weights (W)!");
end
if options.CloseExisting
close all force;
end
if options.ClearCommandWindow
clc;
end
% % % Powerpoint Deck exporter % % %
pptx = exportToPPTX('', ...
'Dimensions',[10, 7.5], ...
'Title','M2-Modulation MOTONEURON Simulations', ...
'Author','Max Murphy (MATLAB Auto-gen)', ...
'Subject','M2-Modulation MOTONEURON Simulations', ...
'Comments','Frequency-vs-Rate sweeps for pre- vs post-synaptic APs under different modulation conditions.');
pptx.addSlide();
pptx.addTextbox('M2-Modulation (NEURON Simulated)', ...
'Position',[0 3.5 10 1.5], ...
'FontName', 'Tahoma', ...
'HorizontalAlignment', 'center', ...
'FontSize', 36);
sweep_data = [];
[~,deck_name,~] = fileparts(options.DeckName);
for ii = 1:size(W,1)
% 1. Load simulation data for "constant" sweep (all 3 pulses in sets of 3 stimuli have same weight)
% (Assumes you've:
% 1. Installed NEURON simulator
% 2. From `~/NEURON/MotorNeuron`, in a terminal run `mknrndll`
% 3. From `~/NEURON/MotorNeuron`, in a terminal run `nrniv main.hoc`
% 4. Waited until the NEURON GUI goes away (i.e. it's done simulating)
% )
%
% SEE ALSO: run_neuron_simulation('main_m2_freq_sweep.hoc');
% |
% |-> Runs the NEURON simulation sweep from MATLAB!
W1 = W(ii,1);
W2 = W(ii,2);
W3 = W(ii,3);
simdata = load_simulated_data(W1, W2, W3);
% 2. Plot figures.
[fig, tmp] = plot_simulations(simdata);
sweep_data = [sweep_data; tmp]; %#ok<AGROW>
% 3. Create sweep "section-header" slide.
slideId = pptx.addSlide();
pptx.addTextbox(sprintf('W1 = %5.2f | W2 = %5.2f | W3 = %5.2f',W1,W2,W3), ...
'Position',[0 3.5 10 1.5], ...
'FontName', 'Tahoma', ...
'HorizontalAlignment', 'center', ...
'FontSize', 36);
pptx.addTextbox(sprintf('"%s" Sweep', SweepName(ii)), ...
'Position',[0 5 10 1], ...
'HorizontalAlignment', 'center', ...
'FontSize', 16);
pptx.addTextbox(num2str(slideId), ...
'Position',[9.5 7 0.5 0.5], ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','right', ...
'FontSize', 10);
% 4. Iterate over figures, saving to Powerpoint.
for iFig = 1:numel(fig)
slideId = pptx.addSlide();
pptx.addTextbox(num2str(slideId), ...
'Position',[9.5 7 0.5 0.5], ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','right', ...
'FontSize', 10, ...
'FontName', 'Consolas');
pptx.addTextbox('Black Solid = membrane voltage at soma', ...
'Position',[0 6.5 4.5 0.5], ...
'VerticalAlignment','middle', ...
'HorizontalAlignment','left', ...
'FontName', 'Tahoma', ...
'FontWeight','bold', ...
'Color', [0 0 0], ...
'FontSize', 10);
pptx.addTextbox('Red Dashed = synaptic EPSP onset (stimuli)', ...
'Position',[0 7.0 4.5 0.5], ...
'VerticalAlignment','middle', ...
'HorizontalAlignment','left', ...
'FontName', 'Tahoma', ...
'FontWeight', 'bold', ...
'Color', [1 0 0], ...
'FontSize', 10);
pptx.addTextbox(sprintf('"%s" Sweep', SweepName(ii)), ...
'Position',[5.0 6.5 2.5 1.0], ...
'VerticalAlignment','middle', ...
'HorizontalAlignment','center', ...
'FontName', 'Tahoma', ...
'FontAngle','italic', ...
'Color', [0.65 0.65 0.65], ...
'FontSize', 10);
pptx.addPicture(fig(iFig),'Position',[0.5 0 9 6.5]);
utils.save_figure(fig(iFig),sprintf('%s/%s',options.SaveFolder,deck_name), ...
sprintf("Recruitment_Vsoma_%ggl_%gm2_%s",fig(iFig).UserData.Leak, fig(iFig).UserData.M2_Level, SweepName(ii)));
end
end
% 5. Plot the collected sweep pre- vs post-synaptic frequency curves
fig = plot_simulation_sweeps(sweep_data, 'SubSweepOrder', SweepName);
slideId = pptx.addSlide();
pptx.addTextbox(num2str(slideId), ...
'Position',[9.5 7 0.5 0.5], ...
'VerticalAlignment','bottom', ...
'HorizontalAlignment','right', ...
'FontSize', 10);
pptx.addPicture(fig,...
'Position',[0 0 10 6]);
utils.save_figure(fig, options.SaveFolder, sprintf('%s_Pre-vs-Post_Synaptic_Frequency_Curves', deck_name));
% 6. Save Powerpoint slide deck for viewing figures.
pptx.save(fullfile(options.SaveFolder, deck_name));
end