|
| 1 | +function NPS_region_vals = plugin_extract_local_nps_region_vals(second_level_DAT_object, my_region) |
| 2 | +%% Helper function to extract local NPS region values from DAT object |
| 3 | +% |
| 4 | +% |
| 5 | +% This program is free software: you can redistribute it and/or modify |
| 6 | +% it under the terms of the GNU General Public License as published by |
| 7 | +% the Free Software Foundation, either version 3 of the License, or |
| 8 | +% (at your option) any later version. |
| 9 | +% |
| 10 | +% This program is distributed in the hope that it will be useful, |
| 11 | +% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +% GNU General Public License for more details. |
| 14 | +% |
| 15 | +% You should have received a copy of the GNU General Public License |
| 16 | +% along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +% .. |
| 18 | +% |
| 19 | +% :Usage: |
| 20 | +% :: |
| 21 | +% **NOTE**: This script and it's counterpart, |
| 22 | +% plugin_plot_local_nps_region_vals.m, ONLY pertain to the CANlab 2nd level |
| 23 | +% script system. They are not for general use. The input data object |
| 24 | +% for this script is a DAT object, which is specific to the 2nd level |
| 25 | +% script system, and other data objects may not work as intended with |
| 26 | +% this function. |
| 27 | +% |
| 28 | +% |
| 29 | +% NPS_region_vals = extract_local_nps_region_vals(second_level_DAT_object, nps_region_of_interest) |
| 30 | +% |
| 31 | +% |
| 32 | +% :Inputs: |
| 33 | +% 1.) An CANlab 2nd level batch script DAT object: This is most likely created by using the |
| 34 | +% canlab 2nd level scripts, which can create a DAT object with the |
| 35 | +% property NPSsubregions. This function will use this property to extract |
| 36 | +% relevant data. |
| 37 | +% |
| 38 | +% 2.) An NPS region of interest: This can be any of the positive or |
| 39 | +% negative regions of the NPS, which include: |
| 40 | +% |
| 41 | +% posnames: {'vermis' 'rIns' 'rV1' 'rThal' 'lIns' 'rdpInsDATA_STRUCT' 'rS2_Op' 'dACC'} |
| 42 | +% negnames: {'rLOC' 'lLOC' 'rpLOC' 'pgACC' 'lSTS' 'rIPL' 'PCC'} |
| 43 | +% |
| 44 | +% :Outputs: |
| 45 | +% 1.) NPS_region_vals: A data structure with the following properties |
| 46 | +% A.) Region: This is the NPS region from which the function is extracting data |
| 47 | +% B.) condition_data: Values from input fmri_data_object |
| 48 | +% (usually DAT from 2nd level analysis) that correspond to NPS activation |
| 49 | +% in input my_region. Values grouped by conditions in input fmri_data_object. |
| 50 | +% This function pulls from fmri_data_object.NPSsubregions |
| 51 | +% C.) condition_names: Names of conditions from |
| 52 | +% fmri_data_object (usually DAT from 2nd level analysis) that |
| 53 | +% describe the condition_data groups. This function pulls from input |
| 54 | +% fmri_data_object.conditions |
| 55 | +% D.) contrast_data: Values from input fmri_data_object |
| 56 | +% (usually DAT from 2nd level analysis) that correspond to NPS activation |
| 57 | +% in input my_region. Values grouped by contrasts in input fmri_data_object. |
| 58 | +% This function pulls from fmri_data_object.NPSsubregions |
| 59 | +% E.) contrast_names: Names of contrasts from fmri_data_object |
| 60 | +% (usually DAT from 2nd level analysis) that describe the |
| 61 | +% contrast_data groups. This function pulls from input |
| 62 | +% fmri_data_object.contrastnames |
| 63 | +% F.) colors: Colors pulled from input fmri_data_object for plotting |
| 64 | +% by conditions |
| 65 | +% G.) contrast_colors: Colors pulled from input fmri_data_object for |
| 66 | +% plotting by contrasts |
| 67 | +% :Examples: |
| 68 | +% (1) NPS_region_vals = extract_local_nps_region_vals(DAT, 'dACC') %saves dACC |
| 69 | +% values to new variable NPS_region_vals |
| 70 | +% |
| 71 | +% (2)To load in a CANlab second-level analysis session, extract an NPS subregion, and |
| 72 | +% then plot it by condition/contrast: |
| 73 | +% |
| 74 | +% %reload second level analysis objects |
| 75 | +% addpath(genpath('/path/to/data/files')); |
| 76 | +% a_set_up_paths_always_run_first; |
| 77 | +% b_reload_saved_matfiles |
| 78 | +% |
| 79 | +% %Example to extract dACC from DAT |
| 80 | +% NPS_local_dACC = extract_local_nps_region_vals(DAT, 'dACC') |
| 81 | +% |
| 82 | +% %Example to plot newly extrated dACC object |
| 83 | +% plot_local_nps_region_vals(NPS_local_dACC) |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +% Get INPUTS |
| 89 | +region = my_region; |
| 90 | +in_DAT = second_level_DAT_object; |
| 91 | + |
| 92 | +% check input region and designate pos or neg NPS |
| 93 | +if sum(strcmp(in_DAT.NPSsubregions.posnames, region)) == 1 |
| 94 | + pos_or_neg_field = 'npspos_by_region'; % set flag field to positive |
| 95 | + wh_region = strcmp(in_DAT.NPSsubregions.posnames, region); % find index of input region |
| 96 | + sprintf('Input region %s is an NPS Pos region.', region) |
| 97 | + |
| 98 | +elseif sum(strcmp(in_DAT.NPSsubregions.negnames, region)) == 1 |
| 99 | + pos_or_neg_field = 'npsneg_by_region'; % set flag field to negative |
| 100 | + wh_region = strcmp(in_DAT.NPSsubregions.negnames, region); % find index of input region |
| 101 | + sprintf('Input region %s is an NPS Neg region.', region) |
| 102 | + |
| 103 | +else |
| 104 | + error('Bad Region Name') |
| 105 | +end |
| 106 | + |
| 107 | +% Check input data for specified region for each condition |
| 108 | +region_index = find(wh_region); |
| 109 | +for i = 1:length(in_DAT.NPSsubregions.(pos_or_neg_field)) |
| 110 | + if size(in_DAT.NPSsubregions.npspos_by_region{i}, 2) < region_index |
| 111 | + warning('Input object does not have NPS Data for specified region for every condition') |
| 112 | + end |
| 113 | + |
| 114 | + |
| 115 | +NPS_region_vals = []; |
| 116 | +NPS_region_vals.region = region; |
| 117 | + |
| 118 | +k = length(in_DAT.conditions); |
| 119 | +kc = length(in_DAT.contrastnames); |
| 120 | + |
| 121 | +% check for problems |
| 122 | +if sum(wh_region) > 1 || sum(wh_region) == 0, error('Bad region name'); end |
| 123 | + |
| 124 | +% get the condition data |
| 125 | +NPS_region_vals.condition_data = cell(1, k); |
| 126 | +NPS_region_vals.conditions = in_DAT.conditions; |
| 127 | + |
| 128 | +for i = 1:k |
| 129 | + NPS_region_vals.condition_data{i} = in_DAT.NPSsubregions.(pos_or_neg_field){i}(:, wh_region); |
| 130 | +end |
| 131 | + |
| 132 | +% get the contrast data |
| 133 | +NPS_region_vals.contrastnames = in_DAT.contrastnames; |
| 134 | + |
| 135 | +myfield = [pos_or_neg_field '_contrasts']; |
| 136 | + |
| 137 | +for i = 1:kc |
| 138 | + NPS_region_vals.contrast_data{i} = in_DAT.NPSsubregions.(myfield){i}(:, wh_region); |
| 139 | +end |
| 140 | + |
| 141 | +% Copy colors for use later in plotting |
| 142 | +NPS_region_vals.colors = in_DAT.colors; |
| 143 | +NPS_region_vals.contrastcolors = in_DAT.contrastcolors; |
| 144 | + |
| 145 | +end |
0 commit comments