Browse Source

gin commit from psy497.lan

Deleted files: 26
Guido Barchiesi 2 years ago
parent
commit
b24af73084
26 changed files with 0 additions and 3677 deletions
  1. BIN
      Stage2_analyses_folder/.DS_Store
  2. 0 39
      Stage2_analyses_folder/Pilot_analysis/GB_gtec_files_concatenation.m
  3. 0 127
      Stage2_analyses_folder/Pilot_analysis/JA_pilot_analysis.R
  4. 0 366
      Stage2_analyses_folder/Pilot_analysis/JA_pilot_analysis_DEF_rep.m
  5. BIN
      Stage2_analyses_folder/Pilot_analysis/final_table_for_R_10-2500_def_o1_rep.xlsx
  6. 0 31
      Stage2_analyses_folder/Pilot_analysis/gb_background_activity.m
  7. 0 38
      Stage2_analyses_folder/Pilot_analysis/gb_cutting_sweeps.m
  8. 0 15
      Stage2_analyses_folder/Pilot_analysis/pilot_functions.rtf
  9. BIN
      Stage2_analyses_folder/Stage2_analysis/.DS_Store
  10. 0 39
      Stage2_analyses_folder/Stage2_analysis/1_JA_fix_splitted_files/GB_gtec_files_concatenation_JA_stage2.m
  11. 0 65
      Stage2_analyses_folder/Stage2_analysis/1_JA_fix_splitted_files/JA_fix_split_files.m
  12. 0 101
      Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_exclusion_criteria.m
  13. 0 88
      Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_exclusion_criteria_CF.m
  14. 0 87
      Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_exclusion_criteria_SBJ.m
  15. 0 115
      Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_exclusion_criteria_table_for_R.m
  16. 0 31
      Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_run_performance_exclusion_criteria_over_subejcts.m
  17. 0 327
      Stage2_analyses_folder/Stage2_analysis/3_JA_run_pre-TMS_Exclusion_Criteria/JA_check_contraction_pre_TMS_padding.m
  18. 0 64
      Stage2_analyses_folder/Stage2_analysis/3_JA_run_pre-TMS_Exclusion_Criteria/JA_run_check_pre_TMS_contraction_padding.m
  19. 0 429
      Stage2_analyses_folder/Stage2_analysis/4_JA_set_MEP_range/JA_set_MEP_range_padfilter.m
  20. BIN
      Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/.DS_Store
  21. 0 467
      Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/JA_MEP_final_analysis_def.m
  22. BIN
      Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/JA_Stage2_analyses_16-Sep-2021.xlsx
  23. 0 113
      Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/JA_run_MEP_analysis.m
  24. 0 1053
      Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/R_statistical_analyses.Rmd
  25. 0 38
      Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/gb_cutting_sweeps.m
  26. 0 44
      Stage2_analyses_folder/Stage2_analysis/analysis_functions_description.rtf

BIN
Stage2_analyses_folder/.DS_Store


+ 0 - 39
Stage2_analyses_folder/Pilot_analysis/GB_gtec_files_concatenation.m

@@ -1,39 +0,0 @@
-function  [alt_y, SR, MetaData] = GB_gtec_files_concatenation(file_tbc)
-
-    % get the last session (final number +1)
-    last_section = size(file_tbc,1);
-    
-    % 
-    alt_y = [];
-    
-    % for each chunk
-    for k = 1:last_section
-        % load the file
-        sect{k} = load(file_tbc(k).name);
-        
-        alt_y = horzcat(alt_y, sect{k}.y);
-        
-    end
-    
-    
-    % time channel is long as the sum of the timings
-    alt_y(1,:) = [1:size(alt_y,2)];
-    
-%     new_file = struct; 
-%     new_file.y = alt_y;
-%     new_file.SR = SR;
-%     
-%     if isfield(sect{end}, 'MetaData')
-%     new_file.MetaData = sect{end}.MetaData;
-%     end
-
-SR = sect{last_section}.SR; 
-
-if isfield(sect{last_section}, 'MetaData')
-    MetaData = sect{last_section}.MetaData;
-else
-    MetaData = '';
-end
-
-end
-

+ 0 - 127
Stage2_analyses_folder/Pilot_analysis/JA_pilot_analysis.R

@@ -1,127 +0,0 @@
-
-rm(list = ls())
-
-
-library(openxlsx)
-library(dplyr) 
-library(ggplot2)
-library(tidyverse)
-library(ez)
-library(plotly)
-library(ggsignif)
-library(cowplot)
-library(multipanelfigure)
-library(ggh4x)
-library(svglite)
-library(BayesFactor)
-
-
-setwd("/Users/b1037210/Desktop/Progetti/JA_Stage1/")
-
-df = read.xlsx("final_table_for_R_10-2500_def_o1_rep.xlsx")
-
-
-df$TMS_timings_rep = as.factor(df$TMS_timings_rep)
-levels(df$TMS_timings_rep) = c("Late TMS","Early TMS")
-df$TMS_timings_rep <- factor(df$TMS_timings_rep, levels = c("Early TMS","Late TMS"))
-
-df$subject = as.factor(df$subject)
-df$CF_colors_order = as.factor(df$CF_colors_order)
-levels(df$CF_colors_order) = c("Lift", "Catch", "Press")
-
-df <- subset(df, CF_colors_order == "Press"| CF_colors_order == "Lift" ) 
-
-df$CF_colors_order = droplevels(df$CF_colors_order)
-
-groups <- group_by(df, CF_colors_order, subject, TMS_timings_rep) 
-
-# summarize by using the medians of each subject --> have a table with a "mean" column for each cell for each participant
-data_avgs <- summarise(groups,
-                       mean = median(ECD_MEP_amplitudes, na.rm=TRUE))
-
-# take a peek
-data_avgs = as.data.frame(data_avgs)
-
-df_final = data_avgs
-
-attach(df_final)
-
-
-## descriptive statistics
-s_alt = ezStats(data=df_final,
-                dv = .(mean),
-                wid = .(subject),
-                within = .(CF_colors_order, TMS_timings_rep))
-
-## plot now
-pd = position_dodge(width=0.0)
-
-# create basic plot with x axis as Cngruendy and y as mean (which is median actually)
-g = ggplot(df_final, aes(x = CF_colors_order, y = mean))
-
-# create Facets, the level of one variable above, the name of the levels of the other on the new line (\n)
-g = g+facet_grid(col = vars(interaction(TMS_timings_rep, sep = "\n",lex.order = TRUE)))
-
-# create bar plot 
-g = g+ geom_bar(aes(fill = CF_colors_order), stat = "summary", fun = "mean")
-
-
-g = g+ geom_line(aes(group = subject)
-                 , stat = "summary"
-                 , fun = "mean" 
-                 ,size= .3
-                 , position = pd)
-
-
-#new filling colors for the bars --> values = c("red","orange","blue","green"))
-g = g+scale_fill_manual(values = c("red","blue","tomato","dodgerblue"))
-
-g = g+theme_classic()
-
-g = g+theme(plot.margin = unit(c(0, 0, 0, 0), "cm")) #top, right, bottom, left
-
-g = g+theme(strip.text.x = element_text(size=20, angle=0, vjust = 0),
-            strip.background = element_rect(colour="white", fill="white"))
-
-g = g + theme(
-  axis.title.x = element_text( size = 20, face = "bold", margin = margin(t = 10, r = 0, b = 0, l = 0)),
-  axis.title.y = element_text(size = 20, face = "bold", margin = margin(t = 0, r = 10, b = 0, l = 0)),
-  
-  axis.text.x = element_text(size = 15),# family = 'Helvetica',
-  axis.text.y = element_text(size = 15))  
-
-g = g+xlab("Cue instruction") + ylab("peak-to-peak amplitude (µV)") #ylab("TMS-evoked pressure (a.u.)") #
-
-g = g+theme(
-  legend.position = "none")
-
-
-file_name = "ECU" #"Pressure (z)"#"ECU(z) - FDS(z)"#"Flexor Digitorum Superficialis (Z-scores)\n"
-g = g+ggtitle(file_name)
-g = g+theme(plot.title = element_text(hjust = 0.5, size = 35, face = "bold"))
-
-
-g
-
-
-## stats
-late_lift = subset(data_avgs, TMS_timings_rep == "Late TMS" & CF_colors_order == "Lift")
-late_press = subset(data_avgs, TMS_timings_rep == "Late TMS" & CF_colors_order == "Press")
-
-early_lift = subset(data_avgs, TMS_timings_rep == "Early TMS" & CF_colors_order == "Lift")
-early_press = subset(data_avgs, TMS_timings_rep == "Early TMS" & CF_colors_order == "Press")
-
-shapiro.test(late_lift$mean)
-shapiro.test(late_press$mean)
-
-shapiro.test(early_lift$mean)
-shapiro.test(early_press$mean)
-
-t.test(early_lift$mean, early_press$mean, paired = TRUE, alternative = "greater")
-t.test(late_lift$mean, late_press$mean, paired = TRUE, alternative = "greater")
-
-
-
-## save
-file_title = paste0(file_name, ".jpg");
-ggsave(file_title,g,width = 10, height = 7, device = "jpg")

+ 0 - 366
Stage2_analyses_folder/Pilot_analysis/JA_pilot_analysis_DEF_rep.m

@@ -1,366 +0,0 @@
-%%
-clear
-general_directory = '/Users/b1037210/Desktop/Progetti/JA_Stage1/'
-cd(general_directory)
-addpath(general_directory)
-%%
-addpath(genpath('/Users/b1037210/Documents/MATLAB/fieldtrip-20161117'))
-
-ft_defaults
-%%
-
-subjects = ...
-    {'S01_pilot',...
-    'S02_pilot',...
-    'S03_pilot',...
-    'S04_pilot',...
-    'S05_pilot',...
-    'S06_pilot',...
-    'S07_pilot',...
-    'S08_pilot',...
-    'S09_pilot',...
-    'S10_pilot',...
-    'S11_pilot',...
-    'S12_pilot'}
-
-
-threshold = {[0.018 0.032],...
-    [0.016 0.035],...
-    [0.018 0.040],...
-    [0.019 0.039],...
-    [0.017 0.037],...
-    [0.016 0.036],...
-    [0.019 0.042],...
-    [0.018 0.039],...
-    [0.016 0.035],...
-    [0.015 0.035],...
-    [0.02 0.03],...
-    [0.02 0.04]}
-
-
-
-TMS_timings = {'-0.05', '0.0'};
-final_table = table;
-%%
-for s = 1:length(subjects)
-    
-    %% cd directory
-    cd([general_directory,subjects{s}])
-    
-    %% ...for each tms timing 
-    for t = 1:length(TMS_timings)
-        
-        %% file loading
-        file_tmp = (dir(strcat(subjects{s},'_', TMS_timings{t},'_TMS*')))
-        
-        
-        if size(file_tmp,1)>1
-        
-        disp(strcat('concatenate ',file_tmp(1).name))
-        [y SR MetaData] = GB_gtec_files_concatenation(file_tmp);
-        
-        else
-        
-        disp(strcat('loading ', file_tmp.name)) 
-        load(file_tmp.name)
-
-        end
-        
-        clear file_tmp
-        %% name the trigger channel and time channel, then erase time from y
-        
-        % select trigger row and time row
-        trigger = y(end,:); % trigger channel for glove touch detection
-        time = y(1,:); % time-series in seconds
-        
-        % new data without time, so channels in the gtect settings and data
-        % analysis have the same nnumber
-        y = y(2:end,:);
-        
-        %% get triggers and sample points at which each event of interest happens
-        
-        % get were variations happen within trigger channel
-        diff_trigger = diff(trigger);
-        
-        % get trigger codes wihtin trgger line
-        trigger_numbers = unique(trigger);
-        
-        % find were the wash_out ends
-        end_wash_out = find(diff_trigger == 1)+1;
-        end_wash_out = end_wash_out(1);
-        
-        % for each code present, get the sample were the rising triggers are present
-        for x = 1:length(trigger_numbers)
-            
-            % find rising triggers and add 1 sampling point (due to diff which removes one)
-            tmp = find(diff_trigger == trigger_numbers(x))+1;
-            
-            % based on the code --> assign the tmp numbers to the correct variable
-            switch trigger_numbers(x)
-                
-%                 case 14 % color press CF
-%                     sp_slow_id = tmp(tmp>end_wash_out);
-%                     
-%                 case 15 % color press CF
-%                     sp_fast_id = tmp(tmp>end_wash_out);
-                
-                case 16 % color press CF
-                    sp_out_slow_id = tmp(tmp>end_wash_out);
-                
-                case 17 % color press CF
-                    sp_out_fast_id = tmp(tmp>end_wash_out);
-                    
-%                 case 18 % color press CF
-%                     sp_out_ok_catch_id = tmp(tmp>end_wash_out);
-%                      
-%                 case 19 % color press CF
-%                     sp_out_failed_catch_id = tmp(tmp>end_wash_out);
-%                 
-                    
-                    
-                    
-                    
-                case 20 % color press CF
-                    sp_color_CF_press = tmp(tmp>end_wash_out);
-                    
-                case 21 % color lift CF
-                    sp_color_CF_lift = tmp(tmp>end_wash_out);
-                    
-                case 22 % color catch CF
-                    sp_color_CF_catch = tmp(tmp>end_wash_out);
-                    
-                case 30 % color press SBJ
-                    sp_color_SBJ_press = tmp(tmp>end_wash_out);
-                    
-                case 31 % color_lift SBJ
-                    sp_color_SBJ_lift = tmp(tmp>end_wash_out);
-                    
-                case 40 % CF hitting
-                    sp_CF_hitting = tmp(tmp>end_wash_out);
-                    
-                case 41 % SBJ hitting
-                    sp_SBJ_hitting = tmp(tmp>end_wash_out);
-                    
-                case 128 % TMS pulse
-                    sp_TMS = tmp(tmp>end_wash_out);
-            end
-            
-        end
-        
-        %%
-        
-        % check dimensions
-        size(sp_color_CF_press)
-        size(sp_color_CF_lift)
-        size(sp_color_CF_catch)
-        size(sp_TMS)
-        
-        %
-        [CF_colors_idx] = sortrows(vertcat(sp_color_CF_press',sp_color_CF_lift',sp_color_CF_catch'));
-        CF_colors_order = CF_colors_idx;
-        
-        % assign codes to sample points corresponding to press lift and catch
-        CF_colors_order(ismember(CF_colors_idx, sp_color_CF_press)) = 1;
-        CF_colors_order(ismember(CF_colors_idx, sp_color_CF_lift)) = -1;
-        CF_colors_order(ismember(CF_colors_idx, sp_color_CF_catch)) = 0;
-        
-        %%
-        
-
-        size(sp_out_slow_id)
-        size(sp_out_fast_id)
-
-         
-  [trials_idx] = sortrows(vertcat(sp_out_slow_id',sp_out_fast_id'))
-
- 
-         
-       %%
-       for ex = 1:length(trials_idx)
-          
-           [v_abs(ex) p_abs(ex)] = min(abs(CF_colors_idx - trials_idx(ex)))
-          ddd = CF_colors_idx - trials_idx(ex);
-           exclude(ex) = p_abs(ex);
-           is_exclude_positive(ex) = ddd(exclude(ex))
-       end
-       
-       clear v_abs
-       clear ddd
-       clear is_exclude_positive
-       
-       
-        
-        %% EMG preprocessing
-        
-        ECD_right = y(2,:);
-        FDS_right = y(4,:);
-        ECD_response = y(6,:);
-        
-        
-        
-        Fsample = SR;
-        hp_filter = 10
-        lp_filter = 2500
-        
-   
-        ECD_right_filt = ft_preproc_highpassfilter(ECD_right, Fsample, hp_filter,1);
-        FDS_right_filt = ft_preproc_highpassfilter(FDS_right, Fsample, hp_filter,1);
-        
-        ECD_right_filt = ft_preproc_lowpassfilter(ECD_right_filt, Fsample, lp_filter,1);
-        FDS_right_filt = ft_preproc_lowpassfilter(FDS_right_filt, Fsample, lp_filter,1);
-        
-        
-        ECD_right_filt = ft_preproc_dftfilter(ECD_right_filt, Fsample);
-        FDS_right_filt = ft_preproc_dftfilter(FDS_right_filt, Fsample);
-        
-        
- %% take away the decay from MEPs
-        
-cfg = [];
-cfg.start_time = 0.005;
-cfg.end_time = 0.15;
-cfg.SR = SR;
-cfg.sp_trigger = sp_TMS;
-
-[ECD_sweep_cuts_tmp, ECD_sweep_time, ECD_sample_points] = gb_cutting_sweeps(cfg, ECD_right_filt);
-[FDS_sweep_cuts_tmp, FDS_sweep_time, FDS_sample_points] = gb_cutting_sweeps(cfg, FDS_right_filt);
-
-
-
-
-        %% get MEPs p2p amplitudes
-        cfg = [];
-        cfg.start_time = threshold{s}(1);
-        cfg.end_time = threshold{s}(2);
-        cfg.SR = SR;
-        cfg.sp_trigger = sp_TMS;
-        
-        [ECD_MEP_amplitudes] = gb_MEP_p2p(cfg, ECD_right_filt);
-        [FDS_MEP_amplitudes] = gb_MEP_p2p(cfg, FDS_right_filt);
-        
-        
-%% fit the decay and remove it
-
-cfg = [];
-cfg.start_time = -0.15;
-cfg.end_time = -0.002;
-cfg.SR = SR;
-cfg.sp_trigger = sp_TMS;
-
-[ECD_sweep_cuts_bkgrnd_tmp, ECD_sweep_time_bkgrnd, ECD_sample_points_bkgrnd] = gb_cutting_sweeps(cfg, ECD_right_filt)
-
-[FDS_sweep_cuts_bkgrnd_tmp, FDS_sweep_time_bkgrnd, FDS_sample_points_bkgrnd] = gb_cutting_sweeps(cfg, FDS_right_filt)
-
-%%
-for x = 1:length(ECD_sweep_cuts_bkgrnd_tmp)
-[~, ~, resECD{x}] = fit(ECD_sweep_time_bkgrnd',ECD_sweep_cuts_bkgrnd_tmp{x}','poly3'); % time in ms
-ECD_sweep_cuts_bkgrnd{x} =resECD{x}.residuals';
-
-[~, ~, resFDS{x}] = fit(FDS_sweep_time_bkgrnd',FDS_sweep_cuts_bkgrnd_tmp{x}','poly3'); % time in ms
-FDS_sweep_cuts_bkgrnd{x} =resFDS{x}.residuals';
-
-end
-clear resECD resFDS
-
-%%
-for x = 1:length(ECD_sample_points_bkgrnd)
-    
-ECD_right_filt(ECD_sample_points_bkgrnd{x}) = ECD_sweep_cuts_bkgrnd{x};
-FDS_right_filt(FDS_sample_points_bkgrnd{x}) = FDS_sweep_cuts_bkgrnd{x};
-
-end
-
-
-        %% any contraction befor TMS?
-        
-        cfg = [];
-        cfg.start_time = -0.05;
-        cfg.end_time = -0.002;
-        cfg.SR = SR;
-        cfg.sp_trigger = sp_TMS;
-        cfg.analysis = 'p2p';
-        
-        [ECD_MEP_bkgrnd] = gb_background_activity(cfg, ECD_right_filt)
-        [FDS_MEP_bkgrnd] = gb_background_activity(cfg, FDS_right_filt)
-        
-        
-        %% muscle contraction before TMS?
-        
-        MEP_excl_ECD_idx = find(ECD_MEP_bkgrnd>200) % microvolt
-        MEP_excl_FDS_idx = find(FDS_MEP_bkgrnd>200) % microvolt
-        
-        
-        %% EXCLUDE MEP<50 p2p microVolts
-        
-        MEP_excl2_ECD_idx = find(ECD_MEP_amplitudes<50) % microvolt
-       
-        
-         %% EXCLUDE out slow and out fast trials
-        
-      ECD_MEP_amplitudes(exclude) = nan;
-     
-        
-        %% exclude trials with background contraction
-        
-        ECD_MEP_amplitudes(union(MEP_excl_ECD_idx, MEP_excl_FDS_idx)) = nan;
-    
-        
-        ECD_MEP_amplitudes(MEP_excl2_ECD_idx) = nan;
-    
- 
-        %% median amplitude based on color trigger         
-        summary.ECD_press{s,t} = nanmedian((ECD_MEP_amplitudes(CF_colors_order == 1)));
-        summary.ECD_lift{s,t} = nanmedian((ECD_MEP_amplitudes(CF_colors_order == -1)));
-        %%
-              
-cfg = [];
-cfg.start_time = -0.015;
-cfg.end_time = 0.15;
-cfg.SR = SR;
-cfg.sp_trigger = sp_TMS;
-
-[bbb.ECD_sweep_PLOT_CHECKS, bbb.ECD_sweep_time_PLOT_CHECKS, bbb.ECD_sample_points_PLOT_CHECKS] = gb_cutting_sweeps(cfg, ECD_right_filt);
-    
-        %%
-        
-        trial = (1:length(CF_colors_order))';
-        subject_rep = repmat(subjects(s), [length(CF_colors_order),1]);
-        TMS_timings_rep = repmat(TMS_timings(t), [length(CF_colors_order),1]);
-        
-        subject_table{t} = table(subject_rep,trial, ECD_MEP_amplitudes,...
-            ECD_MEP_bkgrnd,...
-            FDS_MEP_bkgrnd,...
-            TMS_timings_rep,...
-            CF_colors_order)
-        
-        
-        
-        
-        
-        
-        clearvars -except s t subjects TMS_timings threshold subject_table general_directory final_table summary
-        
-        %%
-       
-    end
-    
-    final_subject_table = vertcat(subject_table{:})
-    
-    
-     output_filename = strcat('final_subject_table_',subjects{s},'_' , '.mat');
-     save(output_filename,'final_subject_table')
-     
-     
-     final_table = vertcat(final_table, final_subject_table)
-     
-     clearvars -except s t subjects TMS_timings threshold general_directory final_table summary
-     
-     
-end
-
-
-%%
-cd(general_directory)
-filename = 'final_table_for_R_10-2500_def_o1_rep.xlsx';
-writetable(final_table,filename,'Sheet',1)
-

BIN
Stage2_analyses_folder/Pilot_analysis/final_table_for_R_10-2500_def_o1_rep.xlsx


+ 0 - 31
Stage2_analyses_folder/Pilot_analysis/gb_background_activity.m

@@ -1,31 +0,0 @@
-function [amplitudes, sweep_cut] = gb_background_activity(cfg, data)
-
-sweep_start = round(cfg.start_time*cfg.SR);
-sweep_end = round(cfg.end_time*cfg.SR);
-
-for x = 1:length(cfg.sp_trigger)
-   
-   sweep_points{x} = sweep_start+cfg.sp_trigger(x):cfg.sp_trigger(x)+sweep_end;
-    
-   sweep_cut{x} = data(sweep_points{x});
-   
-    %plot(sweep_cut{x})
-   switch  cfg.analysis
-       case 'p2p'
-   MEP_max{x} = max(sweep_cut{x});
-   MEP_min{x} = min(sweep_cut{x});
-   
-   amplitudes(x,1) = MEP_max{x} - MEP_min{x};
-   
-       case 'mean'
-         amplitudes(x,1) = mean(sweep_cut{x});  
-         
-       case 'median'
-         amplitudes(x,1) = median(sweep_cut{x});  
-         
-       case 'sum'
-         amplitudes(x,1) = sum(sweep_cut{x});   
-         
-   end
-
-end

+ 0 - 38
Stage2_analyses_folder/Pilot_analysis/gb_cutting_sweeps.m

@@ -1,38 +0,0 @@
-function [sweep_cut, sweep_time,sweep_points] = gb_cutting_sweeps(cfg, data)
-
-sweep_start = round(cfg.start_time*cfg.SR);
-sweep_end = round(cfg.end_time*cfg.SR);
-
-
-for x = 1:length(cfg.sp_trigger)
-   
-   sweep_points{x} = sweep_start+cfg.sp_trigger(x):cfg.sp_trigger(x)+sweep_end;
-    
-   sweep_cut{x} = data(sweep_points{x});
-   
-   if isfield(cfg, 'baseline_rectify')
-       
-    % rectify epoch   
-    sweep_cut{x} =  abs(sweep_cut{x});
-    
-    
-      bs_start = round(cfg.baseline_rectify(1)*cfg.SR);
-    bs_end = round(cfg.baseline_rectify(2)*cfg.SR);
-    
-      bs_points{x} = bs_start+cfg.sp_trigger(x):cfg.sp_trigger(x)+bs_end;
-    
-   bs_cut{x} = abs(data(bs_points{x}));
-  
-    
-  
-    
-    % identify mean of the baselined period
-    baselined_chunk = mean(bs_cut{x},2);   
-    
-    % subtract the mean from the baselined period from the rectified epoch
-    sweep_cut{x} =  sweep_cut{x} - baselined_chunk;
-   end
-
-end
-
- sweep_time = linspace(cfg.start_time,cfg.end_time, length(sweep_points{1})) ; 

+ 0 - 15
Stage2_analyses_folder/Pilot_analysis/pilot_functions.rtf

@@ -1,15 +0,0 @@
-{\rtf1\ansi\ansicpg1252\cocoartf2636
-\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
-{\colortbl;\red255\green255\blue255;}
-{\*\expandedcolortbl;;}
-\paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
-\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
-
-\f0\fs24 \cf0 The folder contains the functions used to preprocess and analyse the pilot data\
-\
-JA_pilot_analysis_DEF_rep.m contains all the other functions\
-\
-JA_pilot_analysis.R was used to perform statistical analysis of pilot data\
-\
-\
-final_table_for_R_10-2500_def_o1_rep.xlsx contains the preprocessed data as a table which is used a s input fro the R script}

BIN
Stage2_analyses_folder/Stage2_analysis/.DS_Store


+ 0 - 39
Stage2_analyses_folder/Stage2_analysis/1_JA_fix_splitted_files/GB_gtec_files_concatenation_JA_stage2.m

@@ -1,39 +0,0 @@
-function  [alt_y, SR, MetaData] = GB_gtec_files_concatenation(file_tbc)
-
-    % get the last session (final number +1)
-    last_section = size(file_tbc,1);
-    
-    % 
-    alt_y = [];
-    
-    % for each chunk
-    for k = 1:last_section
-        % load the file
-        sect{k} = load(file_tbc(k).name);
-        
-        alt_y = horzcat(alt_y, sect{k}.y);
-        
-    end
-    
-    
-    % time channel is long as the sum of the timings
-    alt_y(1,:) = [1:size(alt_y,2)];
-    
-%     new_file = struct; 
-%     new_file.y = alt_y;
-%     new_file.SR = SR;
-%     
-%     if isfield(sect{end}, 'MetaData')
-%     new_file.MetaData = sect{end}.MetaData;
-%     end
-
-SR = sect{last_section}.SR; 
-
-if isfield(sect{last_section}, 'MetaData')
-    MetaData = sect{last_section}.MetaData;
-else
-    MetaData = '';
-end
-
-end
-

+ 0 - 65
Stage2_analyses_folder/Stage2_analysis/1_JA_fix_splitted_files/JA_fix_split_files.m

@@ -1,65 +0,0 @@
-function [] = JA_fix_split_files(subject)
-
-%%
-% concatenate files
-
-general_directory = '/Volumes/SAMSUNG/Ja_Stage_2'%'/Users/b1037210/Desktop/Progetti/JA_Stage2/';
-function_directory = '/Users/b1037210/Desktop/Progetti/JA_Stage1/';
-cd(general_directory)
-addpath(function_directory)
-
-%% cd directory
-cd(fullfile(general_directory,subject)) % subject as string
-
-%% check if there are exceedings files
-file_tmp_split = (dir('TMSSession*0001.mat'));
-
-
-% if there are split files
-if ~isempty(file_tmp_split)
-    
-    % for each file being split (having chunks)
-    for f = 1:length(file_tmp_split)
-        
-        % keep the core name string of the file
-        str_tmp = strsplit(file_tmp_split(f).name, '_0001.mat');
-        
-        
-        % specifies how many chunks are there to be concatenated for the
-        % file
-        file_tmp = dir(strcat(str_tmp{1}, '*.mat'));
-        
-        
-        % do the concatenation
-        disp(strcat('concatenation of ',file_tmp(1).name))
-        
-        [y SR MetaData] = GB_gtec_files_concatenation_JA_stage2(file_tmp);
-        
-        
-        % rename chunks so that thay will be not further analysed
-        for c = 1:length(file_tmp)
-            
-            movefile(file_tmp(c).name, strcat('concatenated_', file_tmp(c).name));
-            
-        end
-        
-        % save the new file as a unique file as name_date_.0000.mat
-        save(file_tmp(1).name, 'y', 'SR', 'MetaData')
-        
-        % clear variables
-        clear 'y' 'SR' 'MetaData';
-        clear str_tmp file_tmp;
-        
-    end
-    
-    
-    
-end
-
-
-
-
-
-
-
-end

+ 0 - 101
Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_exclusion_criteria.m

@@ -1,101 +0,0 @@
-function [exclusion_criteria] = JA_exclusion_criteria(PTB_file, exclusion_criteria)
-
-    
-   load(PTB_file);
-    
-    if strcmp(relationship,'warming_up') 
-        
-        [~, ~, ~, ~,...
-            right_turn_abs_number_wrong_responses_last_three_game,...
-            right_turn_wrong_response_last_three_games_percentage]= JA_exclusion_criteria_SBJ(Par);
-        
-        
-        [~, ~, ~, ~,...
-            left_turn_abs_number_wrong_responses_last_three_game,...
-            left_turn_wrong_response_last_three_games_percentage]= JA_exclusion_criteria_CF(Par);
-        
-        last_three_games_wrong_total_responses_percentage =...
-            mean([right_turn_wrong_response_last_three_games_percentage, left_turn_wrong_response_last_three_games_percentage]);
-        
-        exclusion_criteria.(relationship).last_three_games_wrong_total_responses_percentage = last_three_games_wrong_total_responses_percentage;
-        
-        if  exclusion_criteria.(relationship).last_three_games_wrong_total_responses_percentage > 30
-            
-             exclusion_criteria.OUT = 1;
-             exclusion_criteria.(relationship).OUT = 1;
-            
-        end
-        
-        
-    end
-    
-    
-    
-    if strcmp(relationship,'training') 
-        
-        
-         [right_abs_number_of_out_of_range,...
-            right_out_time_range_percentage,...
-            right_abs_number_wrong_catch,...
-            right_wrong_catch_percentage]= JA_exclusion_criteria_CF(Par);
-        
-         [left_abs_number_of_out_of_range,...
-            left_out_time_range_percentage,...
-            left_abs_number_wrong_catch,...
-            left_wrong_catch_percentage]= JA_exclusion_criteria_SBJ(Par);
-        
-        
-        exclusion_criteria.(relationship).out_time_range_percentage = mean([left_out_time_range_percentage, right_out_time_range_percentage]);
-        exclusion_criteria.(relationship).wrong_catch_percentage = mean([left_wrong_catch_percentage, right_wrong_catch_percentage]);
-        
-        if (exclusion_criteria.(relationship).out_time_range_percentage > 30) ||...
-                (exclusion_criteria.(relationship).wrong_catch_percentage > 50)
-            
-            exclusion_criteria.OUT = 1;
-            exclusion_criteria.(relationship).OUT = 1;
-            
-        end
-         
-        
-        
-    end
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    if strcmp(relationship,'joint') ||...
-            strcmp(relationship,'parallel') ||...
-            strcmp(relationship,'competitive') ||...
-            strcmp(relationship,'imagery')
-        
-        
-        [abs_number_of_out_of_range,...
-            out_time_range_percentage,...
-            abs_number_wrong_catch,...
-            wrong_catch_percentage]= JA_exclusion_criteria_SBJ(Par);
-        
-        
-        exclusion_criteria.(relationship).out_time_range_percentage = out_time_range_percentage;
-        exclusion_criteria.(relationship).wrong_catch_percentage = wrong_catch_percentage;
-        
-        if (exclusion_criteria.(relationship).out_time_range_percentage > 30) ||...
-                (exclusion_criteria.(relationship).wrong_catch_percentage > 50)
-            
-            exclusion_criteria.OUT = 1;
-            exclusion_criteria.(relationship).OUT = 1;
-            
-        end
-        
-    end
-    
-  
-  
-end
-
-
-

+ 0 - 88
Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_exclusion_criteria_CF.m

@@ -1,88 +0,0 @@
-function [abs_number_of_out_of_range,...
-    out_time_range_percentage,...
-    abs_number_wrong_catch,...
-    wrong_catch_percentage,...
-    abs_number_wrong_responses_last_three_game,...  
-wrong_response_last_three_games_percentage]= JA_exclusion_criteria_CF(Par)
-
-% 
-% 
-% nt_idx = cat(1,find(strcmp(Par.final_design.Type, 'fast_tr')),...
-%     find(strcmp(Par.final_design.Type, 'slow_tr')));
-
-
-
-    
-%% TABLE WITH rtS AND CLASSIFICATIONS
-
-summary_table = table; 
-
-
-summary_table.Games = Par.final_design.Games;
-
-
-
-summary_table.Type = Par.final_design.Type;
-summary_table.CF_colors = Par.final_design.CF_colors;
-summary_table.CF_classification = Par.CF_classification';
-summary_table.CF_RT_tmp = cell2mat(Par.CF_RT_tmp)';
-
-%% get only from trial 12 (first of the Game 2), without the washout
-
-nt_idx_tmp = 12:size(summary_table,1)
-
-
-catch_idx_tmp =  cat(1,find(strcmp(summary_table.Type, 'ok_catch')),...
-    find(strcmp(summary_table.Type, 'failed_catch')))
-
-% get only from the 12 games leave the washout out
-catch_idx  = catch_idx_tmp(catch_idx_tmp>=12); 
-
-
-
-%% out of time range 
-
-% get only  notrmal trials
-nt_idx = setdiff(nt_idx_tmp, catch_idx)
-
-RTs = summary_table.CF_RT_tmp(nt_idx);
-
-% we do not car if the response was right or wrong
-out_time_range = [find(RTs<0.45); find(RTs>1.3)]
-
-
-abs_number_of_out_of_range = length(out_time_range);
-
-out_time_range_percentage = 100*(abs_number_of_out_of_range/length(nt_idx))
-
-%% get Catch trials
-
-CTs = summary_table.CF_RT_tmp(catch_idx);
-
-wrong_catch = [find(CTs<1.3)];
-
-
-abs_number_wrong_catch = length(wrong_catch);
-
-wrong_catch_percentage = 100*(abs_number_wrong_catch/length(catch_idx))
-
-%% get wrong responses in the last three blocks (in warming and training blocks)
-
-% get last three games
-warming_last_three_idx_tmp = find(cell2mat(summary_table.Games)>=11);
-
-% get idx normal tirals in the last three games
-warming_last_three_idx = intersect(nt_idx, warming_last_three_idx_tmp);
-
-wrong_responses_last_three_games = (find(strcmp(summary_table.CF_classification(warming_last_three_idx), 'wrong_response')))
-% intersect(find(summary_table.CF_RT_tmp(warming_last_three_idx)>=0.45); find(RTs.summary_table(warming_last_three_idx)<=1.3))
-abs_number_wrong_responses_last_three_game = length(wrong_responses_last_three_games);
-
-
-wrong_response_last_three_games_percentage = 100*(abs_number_wrong_responses_last_three_game/length(warming_last_three_idx))
-
-
-
-
-
-end

+ 0 - 87
Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_exclusion_criteria_SBJ.m

@@ -1,87 +0,0 @@
-function [abs_number_of_out_of_range,...
-    out_time_range_percentage,...
-    abs_number_wrong_catch,...
-    wrong_catch_percentage,...
-    abs_number_wrong_responses_last_three_game,...  
-wrong_response_last_three_games_percentage]= JA_exclusion_criteria_SBJ(Par)
-
-% 
-% 
-% nt_idx = cat(1,find(strcmp(Par.final_design.Type, 'fast_tr')),...
-%     find(strcmp(Par.final_design.Type, 'slow_tr')));
-
-
-
-    
-%% TABLE WITH rtS AND CLASSIFICATIONS
-
-summary_table = table; 
-
-
-summary_table.Games = Par.final_design.Games;
-
-
-
-summary_table.Type = Par.final_design.Type;
-summary_table.SBJ_colors = Par.final_design.SBJ_colors;
-summary_table.SBJ_classification = Par.SBJ_classification';
-summary_table.SBJ_RT_tmp = cell2mat(Par.SBJ_RT_tmp)';
-
-%% get only 12 gmaes , without the washout
-
-nt_idx_tmp = 12:size(summary_table,1)
-
-
-catch_idx_tmp =  cat(1,find(strcmp(summary_table.Type, 'ok_catch')),...
-    find(strcmp(summary_table.Type, 'failed_catch')))
-
-% get only from the 12 games leave the washout out
-catch_idx  = catch_idx_tmp(catch_idx_tmp>=12); 
-
-
-
-%% out of time range 
-
-% get only  notrmal trials
-nt_idx = setdiff(nt_idx_tmp, catch_idx)
-
-RTs = summary_table.SBJ_RT_tmp(nt_idx);
-
-% we do not car if the response was right or wrong
-out_time_range = [find(RTs<0.45); find(RTs>1.3)]
-
-abs_number_of_out_of_range = length(out_time_range);
-
-out_time_range_percentage = 100*(abs_number_of_out_of_range/length(nt_idx))
-
-%% get Catch trials
-
-CTs = summary_table.SBJ_RT_tmp(catch_idx);
-
-wrong_catch = [find(CTs<1.3)];
-
-
-abs_number_wrong_catch = length(wrong_catch);
-
-wrong_catch_percentage = 100*(abs_number_wrong_catch/length(catch_idx))
-
-%% get wrong responses in the last three blocks
-
-% get last three games
-warming_last_three_idx_tmp = find(cell2mat(summary_table.Games)>=11);
-
-% get idx normal tirals in the last three games
-warming_last_three_idx = intersect(nt_idx, warming_last_three_idx_tmp);
-
-wrong_responses_last_three_games = (find(strcmp(summary_table.SBJ_classification(warming_last_three_idx), 'wrong_response')))
-% intersect(find(summary_table.CF_RT_tmp(warming_last_three_idx)>=0.45); find(RTs.summary_table(warming_last_three_idx)<=1.3))
-abs_number_wrong_responses_last_three_game = length(wrong_responses_last_three_games);
-
-
-wrong_response_last_three_games_percentage = 100*(abs_number_wrong_responses_last_three_game/length(warming_last_three_idx))
-
-
-
-
-
-end

+ 0 - 115
Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_exclusion_criteria_table_for_R.m

@@ -1,115 +0,0 @@
-
-general_directory ='/Volumes/SAMSUNG/Ja_Stage_2'% '/Users/b1037210/Desktop/Progetti/JA_Stage2/';%
-function_directory = '/Users/b1037210/Desktop/Progetti/JA_Stage1/';
-function_directory2 = '/Users/b1037210/Desktop/Progetti/JA_Stage2/';
-addpath(general_directory);
-addpath(function_directory);
-addpath(genpath(function_directory2));
-%%
-addpath(genpath('/Users/b1037210/Documents/MATLAB/fieldtrip-20161117'))
-
-ft_defaults
-%%
-list_subjects = {...
-    'S01',...
-    'S02',...
-    'S03',...
-    'S04',...
-    'S05',...
-    'S06',...
-    'S07',...
-    'S08',...
-    'S09',...
-    'S10',...
-    'S11',...
-    'S12',...
-    'S13',...
-    'S14',...
-    'S15',...
-    'S16',...
-    'S17',...
-    'S18',...
-    'S19',...
-    'S20',...
-    'S21',...
-    'S22',...
-    'S23',...
-    'S24',...
-    'S25',...
-    'S26',...
-    'S27',...
-    'S28',...
-    'S29',...
-    'S30',...
-    'S31',...
-    'S32',...
-    'S33',...
-    'S34',...
-    'S35',...
-    'S36',...
-    'S37',...
-    'S38',...
-    'S39',...
-    'S40',...
-    'S41',...
-    'S42'}'
-
-%%
-tab_for_R = table;
-
-for s = 1:length(list_subjects)
-    
-    
-    
-%     
-%     % cd directory
-%     cd(fullfile(general_directory,list_subjects{s}));
-%     
-%     % file list
-%     file_list_tmp = dir(strcat(list_subjects{s}, '*'))
-%     
-%     for f = 1:length(file_list_tmp)
-%         
-%         clear relationship
-%         
-%         load(file_list_tmp(f).name, 'relationship');
-%         
-%         
-%         
-%         matfile = file_list_tmp(f).name;
-%             
-%     
-    % cd directory
-    cd(fullfile(general_directory,list_subjects{s}));
-    
-    % file list
-    file_list_tmp = dir(strcat(list_subjects{s}, '*'))
-    
-    for f = 1:length(file_list_tmp)
-        
-            %disp(strcat('loading____', file_list_tmp(f).name))
-            matfile = file_list_tmp(f).name;
-
-      
-       %from PTB files  
-       [tab] = JA_RT_final_analysis(list_subjects{s}, matfile, f)
-      
-       % from gtec files
-       %[info, tab] = JA_final_table(list_subjects{s}, matfile, f)   
- 
-        tab_for_R = vertcat(tab_for_R, tab);
-        
-        clear tab 
-           end
-    
-end
-
-
-%%
-cd(function_directory2)
-a = clock;
-filename = strcat('JA_Stage2_RT_analyses_',date,'_', num2str(a(3:5)),  '.xlsx');
-writetable(tab_for_R,filename,'Sheet',1)
-
-save(strcat('tab_for_R_REACTION_TIMES',date,  '.mat'), 'tab_for_R') 
-

+ 0 - 31
Stage2_analyses_folder/Stage2_analysis/2_JA_run_OnLine_and_Performance_Exclusion_Criteria/JA_run_performance_exclusion_criteria_over_subejcts.m

@@ -1,31 +0,0 @@
-
-addpath(genpath('/Users/b1037210/Desktop/Progetti/JA_stage2'))
-%cd('/Users/b1037210/Desktop/Progetti/JA_stage2')
-cd('/Volumes/SAMSUNG/Ja_Stage_2')
-
-%subject_list = 
-subject_list  = dir('S*')
-ex = [];
-for s = 1:length(subject_list)
-clear a
-
-cd('/Volumes/SAMSUNG/Ja_Stage_2')
-cd(subject_list(s).name)
-
-a = dir(strcat(subject_list(s).name, '*'));
-
-exclusion_criteria = [];
-
-
-for n_cond = 1:length(a);
-    
-    [exclusion_criteria] = JA_exclusion_criteria(a(n_cond).name, exclusion_criteria);
-    
-    
-end
-
-ex.(subject_list(s).name).exclusion_criteria = exclusion_criteria;
-
-end
-    
-

+ 0 - 327
Stage2_analyses_folder/Stage2_analysis/3_JA_run_pre-TMS_Exclusion_Criteria/JA_check_contraction_pre_TMS_padding.m

@@ -1,327 +0,0 @@
-function [out_of_criteria, pre_TMS_contraction] = JA_check_contraction_pre_TMS_padding(subject)
-
-% check all the 
-
-% check pre TMS_contractions on
-
-general_directory = '/Volumes/SAMSUNG/Ja_Stage_2'%'/Users/b1037210/Desktop/Progetti/JA_Stage2/';%
-function_directory = '/Users/b1037210/Desktop/Progetti/JA_Stage1/';
-cd(general_directory);
-addpath(function_directory);
-
-% cd directory
-cd(fullfile(general_directory,subject));
-
-% file list
-file_list_tmp = dir('TMSSession*')
-
-%% file loading (load only block with TMS)
-for f = 1:length(file_list_tmp)
-    
-clearvars -except...
-    subject...
-    f...
-    file_list_tmp...
-    cl_sp_TMS...
-    relationship...
-    ECU_pre_TMS_sweep...
-    FDS_pre_TMS_sweep...
-    ECU_pre_TMS_sweep_time...
-    ECU_pre_TMS_sample_points...
-    ECU_MEP_sweep...
-    FDS_MEP_sweep...
-    ECU_MEP_sweep_time...
-    ECU_MEP_sample_points...
-    pre_TMS_contraction
-    
-    
-load(file_list_tmp(f).name, 'MetaData');
-condition_code = strsplit(MetaData.GeneralInfo, '_');
-
-
-if  strcmp(condition_code{2}, 'TR') || strcmp(condition_code{2}, 'WARM');
-    
-    disp('behavioral block --> exit');
-    continue
-    
-else
-    disp(strcat('loading____', file_list_tmp(f).name))
-    load(file_list_tmp(f).name);
-    
-end
-
-
-
-
-%% name the trigger channel and time channel, then erase time from y
-
-% select trigger row and time row
-trigger = y(end,:); % trigger channel 
-time = y(1,:); % time-series in seconds
-
-%% get triggers and sample points at which each event of interest happens after the washout
-
-% get were variations happen within trigger channel
-diff_trigger = diff(trigger);
-
-% get trigger codes wihtin trgger line
-trigger_numbers = unique(trigger);
-
-% find were the wash_out ends
-end_wash_out = find(diff_trigger == 1)+1;
-end_wash_out = end_wash_out(1);
-
-% for each code present, get the sample were the rising triggers are present
-for x = 1:length(trigger_numbers)
-    
-    % find rising triggers and add 1 sampling point (due to diff which removes one)
-    tmp = find(diff_trigger == trigger_numbers(x))+1;
-    
-    % based on the code --> assign the tmp numbers to the correct variable
-    switch trigger_numbers(x)
-        
-        %                 case 14 % color press CF
-        %                     sp_slow_id = tmp(tmp>end_wash_out);
-        %
-        %                 case 15 % color press CF
-        %                     sp_fast_id = tmp(tmp>end_wash_out);
-        
-        case 16
-            sp_out_slow_id = tmp(tmp>end_wash_out);
-            
-        case 17
-            sp_out_fast_id = tmp(tmp>end_wash_out);
-            
-            %                 case 18 % color press CF
-            %                     sp_out_ok_catch_id = tmp(tmp>end_wash_out);
-            %
-            %                 case 19 % color press CF
-            %                     sp_out_failed_catch_id = tmp(tmp>end_wash_out);
-            %
-            
-            
-            
-            
-        case 20 % color press CF
-            sp_color_CF_press = tmp(tmp>end_wash_out);
-            
-        case 21 % color lift CF
-            sp_color_CF_lift = tmp(tmp>end_wash_out);
-            
-        case 22 % color catch CF
-            sp_color_CF_catch = tmp(tmp>end_wash_out);
-            
-        case 30 % color press SBJ
-            sp_color_SBJ_press = tmp(tmp>end_wash_out);
-            
-        case 31 % color_lift SBJ
-            sp_color_SBJ_lift = tmp(tmp>end_wash_out);
-            
-        case 40 % CF hitting
-            sp_CF_hitting = tmp(tmp>end_wash_out);
-            
-        case 41 % SBJ hitting
-            sp_SBJ_hitting = tmp(tmp>end_wash_out);
-            
-        case 128 % TMS pulse
-            sp_TMS = tmp(tmp>end_wash_out);
-            
-            
-            
-            
-       % get the condition     
-        case 122
-            relationship{f} = 'warming_up'
-           % continue
-            
-        case 123
-            relationship{f} = 'training'
-          %  continue
-            
-            
-        case 124
-            relationship{f} = 'joint'
-        case 125
-            relationship{f} = 'parallel'
-        case 126
-            relationship{f} = 'competitive'
-        case 127
-            relationship = 'motor_imagery'
-    end
-    
-end
-
-%% organize color appearence
-
-if strcmp(subject, 'S38') && strcmp(relationship{f}, 'competitive')
-    
- sp_color_CF_press   = cat(2,sp_color_CF_press(1:8), 1340263 ,sp_color_CF_press(9:end));
-    
-sp_out_slow_id = sp_out_slow_id(2:end)
-    
-end
-
-% put all the sampling points related to CF color appearence in temporal
-% order
-[CF_colors_idx] = sortrows(vertcat(sp_color_CF_press',sp_color_CF_lift',sp_color_CF_catch'));
-CF_colors_order = CF_colors_idx;
-
-% assign codes to sample points corresponding to press lift and catch
-% 1 --> press (red dot)
-% -1 --> lift (yellow dot)
-% 0 --> catch trial
-% !!!! fast/slow out trials are still inside
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_press)) = 1;
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_lift)) = -1;
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_catch)) = 0;
-
-
-% get color appearence2TMS delay in seconds
-color_TMS_delay =  (sp_TMS' - CF_colors_idx)./SR;
-
-%% find fast/slow out trials
-
-[out_sp] = sortrows(vertcat(sp_out_slow_id',sp_out_fast_id'));
-
-
-% exclude out_fast and out_slow
-for ex = 1:length(out_sp)
-    
-    [v_abs(ex) p_abs(ex)] = min(abs(CF_colors_idx - out_sp(ex)));
-    ddd = CF_colors_idx - out_sp(ex);
-    exclude_fast_slow(ex) = p_abs(ex);
-    is_exclude_positive(ex) = ddd(exclude_fast_slow(ex));
-    
-end
-
-clear v_abs ddd is_exclude_positive
-
-% in alcuni p_abs sono 7 in alcuni 8 i alcuni 6??  --> perche' alcuni
-% sono sul wash-out
-
-%% create a clean sample (other than excluding washout trials, also fast/slow trials, and catch_trials are excluded)
-
-catch_trials_idx = find(CF_colors_order == 0);
-total_idx_tb_excluded = cat(1,catch_trials_idx, exclude_fast_slow');
-
-
-total_idx_to_keep = setdiff(1:length(sp_TMS),total_idx_tb_excluded);
-
-
-cl_CF_colors_idx = CF_colors_idx(total_idx_to_keep);
-cl_CF_colors_order = CF_colors_order(total_idx_to_keep);
-cl_color_TMS_delay = color_TMS_delay(total_idx_to_keep);
-cl_sp_TMS{f} = sp_TMS(total_idx_to_keep);
-
-%% epoch to pre_TMS time-window, filter, peak extraction
-
-
-% select channels
-ECU_right = y(3,:);
-FDS_right = y(5,:);
-
-% select window --> epoch
-cfg = [];
-cfg.start_time = -0.05;
-cfg.end_time = -0.002;%0.1;
-cfg.SR = SR;
-cfg.sp_trigger = cl_sp_TMS{f};
-
-[ECU_pre_TMS_sweep{f}, ECU_pre_TMS_sweep_time{f}, ECU_pre_TMS_sample_points{f}] = gb_cutting_sweeps(cfg, ECU_right);
-[FDS_pre_TMS_sweep{f}, FDS_pre_TMS_sweep_time{f}, FDS_pre_TMS_sample_points{f}] = gb_cutting_sweeps(cfg, FDS_right);
-
-
-
-
-% filter the pre_TMS epochs 
-Fsample = SR;
-hp_filter = 10;
-lp_filter = 2500;
-padding_length = SR*0.3;
-
-% for each epoch
-for k = 1:length(ECU_pre_TMS_sweep{f})
-
-% padding 
-ECU_pre_TMS_sweep{f}{k} = ft_preproc_padding(ECU_pre_TMS_sweep{f}{k}, 'mean', padding_length);    
-FDS_pre_TMS_sweep{f}{k} = ft_preproc_padding(FDS_pre_TMS_sweep{f}{k}, 'mean', padding_length);    
-     
-    
-% highpass filter >10 Hz
-ECU_pre_TMS_sweep{f}{k} = ft_preproc_highpassfilter(ECU_pre_TMS_sweep{f}{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-FDS_pre_TMS_sweep{f}{k} = ft_preproc_highpassfilter(FDS_pre_TMS_sweep{f}{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-
-% lowpass filter <2500 Hz
-ECU_pre_TMS_sweep{f}{k} = ft_preproc_lowpassfilter(ECU_pre_TMS_sweep{f}{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-FDS_pre_TMS_sweep{f}{k} = ft_preproc_lowpassfilter(FDS_pre_TMS_sweep{f}{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-
-% notch filter 50 Hz
-ECU_pre_TMS_sweep{f}{k} = ft_preproc_dftfilter(ECU_pre_TMS_sweep{f}{k}, Fsample,50);
-FDS_pre_TMS_sweep{f}{k} = ft_preproc_dftfilter(FDS_pre_TMS_sweep{f}{k}, Fsample,50);
-
-ECU_pre_TMS_sweep{f}{k} = ECU_pre_TMS_sweep{f}{k}(padding_length+1:length(ECU_pre_TMS_sweep_time{f})+padding_length);
-FDS_pre_TMS_sweep{f}{k} = FDS_pre_TMS_sweep{f}{k}(padding_length+1:length(FDS_pre_TMS_sweep_time{f})+padding_length);
-end
-
-%% take a look
-% 
-% cfg = []
-% cfg.maxmin = 'yes';
-% cfg.hold = 'no';
-% sweep_peeking(cfg,ECU_pre_TMS_sweep{f}, ECU_pre_TMS_sweep_time{f});
-
-
-%%
-% max-min peaks extraction
-for k = 1:length(ECU_pre_TMS_sweep{f})
-
-   [ECU_bkgrnd_max(k,1) ECU_bkgrnd_x_max(k,1)] = max(ECU_pre_TMS_sweep{f}{k});
-   [ECU_bkgrnd_min(k,1) ECU_bkgrnd_x_min(k,1)] = min(ECU_pre_TMS_sweep{f}{k});
-   
-   ECU_bkgrnd(k,1) = ECU_bkgrnd_max(k,1)- ECU_bkgrnd_min(k,1);
-   
-   
-   
-   
-   
-   [FDS_bkgrnd_max(k,1) FDS_bkgrnd_x_max(k,1)] = max(FDS_pre_TMS_sweep{f}{k});
-   [FDS_bkgrnd_min(k,1) FDS_bkgrnd_x_min(k,1)] = min(FDS_pre_TMS_sweep{f}{k});
-   FDS_bkgrnd(k,1) = FDS_bkgrnd_max(k,1)- FDS_bkgrnd_min(k,1);
-   
-end
-
-% find the trial number in which the excessive contraction (> +/- 100 microV)
-excl_ECU_idx = find(ECU_bkgrnd>200);
-excl_FDS_idx = find(FDS_bkgrnd>200);
-
-% get trials and total number from both recorded muscles
-pre_TMS_contraction{f}.idx = union(excl_ECU_idx, excl_FDS_idx);
-pre_TMS_contraction{f}.number = length(pre_TMS_contraction{f}.idx);
-
-% valid TMS trials should be 100. if >30% are excluded due to
-% background contration --> exclude the participant
-if (pre_TMS_contraction{f}.number/length(cl_sp_TMS{f})) > (30/length(cl_sp_TMS{f}));
-    pre_TMS_contraction{f}.exclusion = 1;
-else
-    pre_TMS_contraction{f}.exclusion = 0;
-end
-
-
-
-
-
-
-end
-
-
-%% check pre_TMS_contraction criteria
-for b = 1:length(file_list_tmp)
-    if isfield(pre_TMS_contraction{b}, 'exclusion')
-out_of_criteria_blocks(b) = pre_TMS_contraction{b}.exclusion
-    end
-
-end
-
-out_of_criteria = sum(out_of_criteria_blocks)
-%%
-

+ 0 - 64
Stage2_analyses_folder/Stage2_analysis/3_JA_run_pre-TMS_Exclusion_Criteria/JA_run_check_pre_TMS_contraction_padding.m

@@ -1,64 +0,0 @@
-
-general_directory ='/Volumes/SAMSUNG/Ja_Stage_2'% '/Users/b1037210/Desktop/Progetti/JA_Stage2/';%
-function_directory = '/Users/b1037210/Desktop/Progetti/JA_Stage1/';
-addpath(general_directory);
-addpath(function_directory);
-%%
-addpath(genpath('/Users/b1037210/Documents/MATLAB/fieldtrip-20161117'))
-
-ft_defaults
-%%
-list_subjects = {...
-     'S01',...
-     'S02',...
-     'S03',...
-     'S04',...
-     'S05',...
-     'S06',...
-     'S07',...
-     'S08',...
-     'S09',...
-    'S10',...
-    'S11',...
-    'S12',...
-    'S13',...
-    'S14',...
-    'S15',...
-    'S16',...
-    'S17',...
-    'S18',...
-    'S19',...
-    'S20',...
-    'S21',...
-    'S22',...
-    'S23',...
-    'S24',...
-    'S25',...
-    'S26',...
-    'S27',...
-    'S28',...
-    'S29',...
-    'S30',...
-    'S31',...
-    'S32',...
-    'S33',...
-    'S34',...
-    'S35',...
-    'S36',...
-    'S37',...
-    'S38',...
-    'S39',...
-    'S40',...
-    'S41'}'
-
-%%
-
-for s = 1:length(list_subjects)
-    
-    [out_of_criteria{s}, pre_TMS_contraction{s}] = JA_check_contraction_pre_TMS_padding(list_subjects{s})
-    
-   % [out_of_criteria{s}, pre_TMS_contraction{s}] = JA_check_pre_TMS_contraction(list_subjects{s})
-end
-
-
-sum(cell2mat(out_of_criteria))

+ 0 - 429
Stage2_analyses_folder/Stage2_analysis/4_JA_set_MEP_range/JA_set_MEP_range_padfilter.m

@@ -1,429 +0,0 @@
-addpath(genpath('/Users/b1037210/Documents/MATLAB/fieldtrip-20161117'))
-
-ft_defaults
-%%
-
-subject = 'S01'
-
-% check all the 
-
-% check pre TMS_contractions on
-
-general_directory = '/Volumes/SAMSUNG/Ja_Stage_2'%'/Users/b1037210/Desktop/Progetti/JA_Stage2/';
-function_directory = '/Users/b1037210/Desktop/Progetti/JA_Stage1/';
-cd(general_directory);
-addpath(function_directory);
-
-% cd directory
-cd(fullfile(general_directory,subject));
-
-% file list
-file_list_tmp = dir('TMSSession*')
-
-%% file loading (load only block with TMS)
-for f = 1:length(file_list_tmp)
-    
-clearvars -except...
-    subject...
-    f...
-    file_list_tmp...
-    cl_sp_TMS...
-    relationship...
-    ECU_pre_TMS_sweep...
-    FDS_pre_TMS_sweep...
-    ECU_pre_TMS_sweep_time...
-    ECU_pre_TMS_sample_points...
-    ECU_MEP_sweep...
-    FDS_MEP_sweep...
-    ECU_MEP_sweep_time...
-    ECU_MEP_sample_points...
-    pre_TMS_contraction
-    
-    
-load(file_list_tmp(f).name, 'MetaData');
-condition_code = strsplit(MetaData.GeneralInfo, '_');
-
-
-if  strcmp(condition_code{2}, 'TR') || strcmp(condition_code{2}, 'WARM');
-    
-    disp('behavioral block --> exit');
-    continue
-    
-else
-    disp(strcat('loading____', file_list_tmp(f).name))
-    load(file_list_tmp(f).name);
-    
-end
-
-
-
-
-%% name the trigger channel and time channel, then erase time from y
-
-% select trigger row and time row
-trigger = y(end,:); % trigger channel 
-time = y(1,:); % time-series in seconds
-
-%% get triggers and sample points at which each event of interest happens after the washout
-
-% get were variations happen within trigger channel
-diff_trigger = diff(trigger);
-
-% get trigger codes wihtin trgger line
-trigger_numbers = unique(trigger);
-
-% find were the wash_out ends
-end_wash_out = find(diff_trigger == 1)+1;
-end_wash_out = end_wash_out(1);
-
-% for each code present, get the sample were the rising triggers are present
-for x = 1:length(trigger_numbers)
-    
-    % find rising triggers and add 1 sampling point (due to diff which removes one)
-    tmp = find(diff_trigger == trigger_numbers(x))+1;
-    
-    % based on the code --> assign the tmp numbers to the correct variable
-    switch trigger_numbers(x)
-        
-        %                 case 14 % color press CF
-        %                     sp_slow_id = tmp(tmp>end_wash_out);
-        %
-        %                 case 15 % color press CF
-        %                     sp_fast_id = tmp(tmp>end_wash_out);
-        
-        case 16
-            sp_out_slow_id = tmp(tmp>end_wash_out);
-            
-        case 17
-            sp_out_fast_id = tmp(tmp>end_wash_out);
-            
-            %                 case 18 % color press CF
-            %                     sp_out_ok_catch_id = tmp(tmp>end_wash_out);
-            %
-            %                 case 19 % color press CF
-            %                     sp_out_failed_catch_id = tmp(tmp>end_wash_out);
-            %
-            
-            
-            
-            
-        case 20 % color press CF
-            sp_color_CF_press = tmp(tmp>end_wash_out);
-            
-        case 21 % color lift CF
-            sp_color_CF_lift = tmp(tmp>end_wash_out);
-            
-        case 22 % color catch CF
-            sp_color_CF_catch = tmp(tmp>end_wash_out);
-            
-        case 30 % color press SBJ
-            sp_color_SBJ_press = tmp(tmp>end_wash_out);
-            
-        case 31 % color_lift SBJ
-            sp_color_SBJ_lift = tmp(tmp>end_wash_out);
-            
-        case 40 % CF hitting
-            sp_CF_hitting = tmp(tmp>end_wash_out);
-            
-        case 41 % SBJ hitting
-            sp_SBJ_hitting = tmp(tmp>end_wash_out);
-            
-        case 128 % TMS pulse
-            sp_TMS = tmp(tmp>end_wash_out);
-            
-            
-            
-            
-       % get the condition     
-        case 122
-            relationship{f} = 'warming_up'
-           % continue
-            
-        case 123
-            relationship{f} = 'training'
-          %  continue
-            
-            
-        case 124
-            relationship{f} = 'joint'
-        case 125
-            relationship{f} = 'parallel'
-        case 126
-            relationship{f} = 'competitive'
-        case 127
-            relationship{f} = 'motor_imagery'
-    end
-    
-end
-
-%% organize color appearence
-
-if strcmp(subject, 'S38') && strcmp(relationship{f}, 'competitive')
-    
- sp_color_CF_press   = cat(2,sp_color_CF_press(1:8), 1340263 ,sp_color_CF_press(9:end));
-    
-sp_out_slow_id = sp_out_slow_id(2:end)
-    
-end
-
-
-
-
-% put all the sampling points related to CF color appearence in temporal
-% order
-[CF_colors_idx] = sortrows(vertcat(sp_color_CF_press',sp_color_CF_lift',sp_color_CF_catch'));
-CF_colors_order = CF_colors_idx;
-
-
-
-
-% assign codes to sample points corresponding to press lift and catch
-% 1 --> press (red dot)
-% -1 --> lift (yellow dot)
-% 0 --> catch trial
-% !!!! fast/slow out trials are still inside
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_press)) = 1;
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_lift)) = -1;
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_catch)) = 0;
-%%
-
-
-
-% get color appearence2TMS delay in seconds
-color_TMS_delay =  (sp_TMS' - CF_colors_idx)./SR;
-
-%% find fast/slow out trials
-
-[out_sp] = sortrows(vertcat(sp_out_slow_id',sp_out_fast_id'));
-
-
-% exclude out_fast and out_slow
-for ex = 1:length(out_sp)
-    
-    [v_abs(ex) p_abs(ex)] = min(abs(CF_colors_idx - out_sp(ex)));
-    ddd = CF_colors_idx - out_sp(ex);
-    exclude_fast_slow(ex) = p_abs(ex);
-    is_exclude_positive(ex) = ddd(exclude_fast_slow(ex));
-    
-end
-
-clear v_abs ddd is_exclude_positive
-
-% in alcuni p_abs sono 7 in alcuni 8 i alcuni 6??  --> perche' alcuni
-% sono sul wash-out
-
-%% create a clean sample (other than excluding washout trials, also fast/slow trials, and catch_trials are excluded)
-
-catch_trials_idx = find(CF_colors_order == 0);
-total_idx_tb_excluded = cat(1,catch_trials_idx, exclude_fast_slow');
-
-
-total_idx_to_keep = setdiff(1:length(sp_TMS),total_idx_tb_excluded);
-
-
-cl_CF_colors_idx = CF_colors_idx(total_idx_to_keep);
-cl_CF_colors_order = CF_colors_order(total_idx_to_keep);
-cl_color_TMS_delay = color_TMS_delay(total_idx_to_keep);
-cl_sp_TMS{f} = sp_TMS(total_idx_to_keep);
-
-%% epoch to pre_TMS time-window, filter, peak extraction
-
-
-% select channels
-ECU_right = y(3,:);
-FDS_right = y(5,:);
-
-% select window --> epoch
-cfg = [];
-cfg.start_time = -0.05;
-cfg.end_time = -0.002;%0.1;
-cfg.SR = SR;
-cfg.sp_trigger = cl_sp_TMS{f};
-
-[ECU_pre_TMS_sweep{f}, ECU_pre_TMS_sweep_time{f}, ECU_pre_TMS_sample_points{f}] = gb_cutting_sweeps(cfg, ECU_right);
-[FDS_pre_TMS_sweep{f}, FDS_pre_TMS_sweep_time{f}, FDS_pre_TMS_sample_points{f}] = gb_cutting_sweeps(cfg, FDS_right);
-
-
-
-
-% filter the pre_TMS epochs 
-Fsample = SR;
-hp_filter = 10;
-lp_filter = 2500;
-padding_length = SR*0.3;
-
-% for each epoch
-for k = 1:length(ECU_pre_TMS_sweep{f})
-
-% padding 
-ECU_pre_TMS_sweep{f}{k} = ft_preproc_padding(ECU_pre_TMS_sweep{f}{k}, 'mean', padding_length);    
-FDS_pre_TMS_sweep{f}{k} = ft_preproc_padding(FDS_pre_TMS_sweep{f}{k}, 'mean', padding_length);    
-     
-    
-% highpass filter >10 Hz
-ECU_pre_TMS_sweep{f}{k} = ft_preproc_highpassfilter(ECU_pre_TMS_sweep{f}{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-FDS_pre_TMS_sweep{f}{k} = ft_preproc_highpassfilter(FDS_pre_TMS_sweep{f}{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-
-% lowpass filter <2500 Hz
-ECU_pre_TMS_sweep{f}{k} = ft_preproc_lowpassfilter(ECU_pre_TMS_sweep{f}{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-FDS_pre_TMS_sweep{f}{k} = ft_preproc_lowpassfilter(FDS_pre_TMS_sweep{f}{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-
-% notch filter 50 Hz
-ECU_pre_TMS_sweep{f}{k} = ft_preproc_dftfilter(ECU_pre_TMS_sweep{f}{k}, Fsample,50);
-FDS_pre_TMS_sweep{f}{k} = ft_preproc_dftfilter(FDS_pre_TMS_sweep{f}{k}, Fsample,50);
-
-ECU_pre_TMS_sweep{f}{k} = ECU_pre_TMS_sweep{f}{k}(padding_length+1:length(ECU_pre_TMS_sweep_time{f})+padding_length);
-FDS_pre_TMS_sweep{f}{k} = FDS_pre_TMS_sweep{f}{k}(padding_length+1:length(FDS_pre_TMS_sweep_time{f})+padding_length);
-end
-
-%% take a look
-% 
-% cfg = []
-% cfg.maxmin = 'yes';
-% cfg.hold = 'no';
-% sweep_peeking(cfg,ECU_pre_TMS_sweep{f}, ECU_pre_TMS_sweep_time{f});
-
-
-%%
-% max-min peaks extraction
-for k = 1:length(ECU_pre_TMS_sweep{f})
-
-   [ECU_bkgrnd_max(k,1) ECU_bkgrnd_x_max(k,1)] = max(ECU_pre_TMS_sweep{f}{k});
-   [ECU_bkgrnd_min(k,1) ECU_bkgrnd_x_min(k,1)] = min(ECU_pre_TMS_sweep{f}{k});
-   
-   ECU_bkgrnd(k,1) = ECU_bkgrnd_max(k,1)- ECU_bkgrnd_min(k,1);
-   
-   
-   
-   
-   
-   [FDS_bkgrnd_max(k,1) FDS_bkgrnd_x_max(k,1)] = max(FDS_pre_TMS_sweep{f}{k});
-   [FDS_bkgrnd_min(k,1) FDS_bkgrnd_x_min(k,1)] = min(FDS_pre_TMS_sweep{f}{k});
-   FDS_bkgrnd(k,1) = FDS_bkgrnd_max(k,1)- FDS_bkgrnd_min(k,1);
-   
-end
-
-% find the trial number in which the excessive contraction (> +/- 100 microV)
-excl_ECU_idx = find(ECU_bkgrnd>200);
-excl_FDS_idx = find(FDS_bkgrnd>200);
-
-% get trials and total number from both recorded muscles
-pre_TMS_contraction{f}.idx = union(excl_ECU_idx, excl_FDS_idx);
-pre_TMS_contraction{f}.number = length(pre_TMS_contraction{f}.idx);
-
-% valid TMS trials should be 100. if >30% are excluded due to
-% background contration --> exclude the participant
-if (pre_TMS_contraction{f}.number/length(cl_sp_TMS{f})) > (30/length(cl_sp_TMS{f}));
-    pre_TMS_contraction{f}.exclusion = 1;
-else
-    pre_TMS_contraction{f}.exclusion = 0;
-end
-
-
-
-
-%% epoch to MEP time-window then filter
-
-
-% select window --> epoch in the MEP window
-cfg = [];
-cfg.start_time = 0.01; % 10 ms
-cfg.end_time = 0.05;%...to 50 ms
-cfg.SR = SR;
-cfg.sp_trigger = cl_sp_TMS{f};
-
-[ECU_MEP_sweep{f}, ECU_MEP_sweep_time{f}, ECU_MEP_sample_points{f}] = gb_cutting_sweeps(cfg, ECU_right);
-[FDS_MEP_sweep{f}, FDS_MEP_sweep_time{f}, FDS_MEP_sample_points{f}] = gb_cutting_sweeps(cfg, FDS_right);
-
-
-
-% filter for each epoch (same filters as above)
-for k = 1:length(ECU_MEP_sweep{f})
-
-% padding 
-ECU_MEP_sweep{f}{k} = ft_preproc_padding(ECU_MEP_sweep{f}{k}, 'mean', padding_length);    
-FDS_MEP_sweep{f}{k} = ft_preproc_padding(FDS_MEP_sweep{f}{k}, 'mean', padding_length);    
-     
-    
-% highpass filter >10 Hz
-ECU_MEP_sweep{f}{k} = ft_preproc_highpassfilter(ECU_MEP_sweep{f}{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-FDS_MEP_sweep{f}{k} = ft_preproc_highpassfilter(FDS_MEP_sweep{f}{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-
-% lowpass filter <2500 Hz
-ECU_MEP_sweep{f}{k} = ft_preproc_lowpassfilter(ECU_MEP_sweep{f}{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-FDS_MEP_sweep{f}{k} = ft_preproc_lowpassfilter(FDS_MEP_sweep{f}{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-
-% notch filter 50 Hz
-ECU_MEP_sweep{f}{k} = ft_preproc_dftfilter(ECU_MEP_sweep{f}{k}, Fsample,50);
-FDS_MEP_sweep{f}{k} = ft_preproc_dftfilter(FDS_MEP_sweep{f}{k}, Fsample,50);
-
-ECU_MEP_sweep{f}{k} = ECU_MEP_sweep{f}{k}(padding_length+1:length(ECU_MEP_sweep_time{f})+padding_length);
-FDS_MEP_sweep{f}{k} = FDS_MEP_sweep{f}{k}(padding_length+1:length(FDS_MEP_sweep_time{f})+padding_length);
-end
-
-
-%% nan trials with pre_TMS_contraction
-  
-for k = 1:length(ECU_MEP_sweep{f})
-    if ismember(k, pre_TMS_contraction{f}.idx)
-    ECU_MEP_sweep{f}{k}(:) = nan;
-    FDS_MEP_sweep{f}{k}(:) = nan;
-    end
-end
-
-end
-
-
-%% check pre_TMS_contraction criteria
-for b = 1:length(file_list_tmp)
-    if isfield(pre_TMS_contraction{b}, 'exclusion')
-out_of_criteria_blocks(b) = pre_TMS_contraction{b}.exclusion
-    end
-
-end
-
-out_of_criteria = sum(out_of_criteria_blocks)
-%% concatenate all the conditions
-ECU_sweep_cuts_total = cat(2, ECU_MEP_sweep{:});
-FDS_sweep_cuts_total = cat(2, FDS_MEP_sweep{:});
-
-ECU_sweep_time_total = ECU_MEP_sweep_time{f};
-ECU_sample_points_total = ECU_MEP_sample_points{f};
-%%
-sweep_sp_length = length(ECU_sweep_cuts_total{1});
-
-ECU_sweep_cuts_mat = [];
-FDS_sweep_cuts_mat = [];
-
-for k = 1:length(ECU_MEP_sweep)
-ECU_sweep_cuts_mat(k,1:sweep_sp_length) = ECU_sweep_cuts_total{k};
-FDS_sweep_cuts_mat(k,1:sweep_sp_length) = FDS_sweep_cuts_total{k};
-end
-
-%%
-plot(ECU_sweep_time_total, nanmean(ECU_sweep_cuts_mat,1))
-hold on
-plot(ECU_sweep_time_total, nanmean(abs(ECU_sweep_cuts_mat),1))
-
-plot(ECU_sweep_time_total, nanmean(FDS_sweep_cuts_mat,1))
-hold on
-plot(ECU_sweep_time_total, nanmean(abs(FDS_sweep_cuts_mat),1))
-%%
-
-cfg = []
-cfg.maxmin = 'yes';
-cfg.hold = 'no';
-sweep_peeking(cfg,ECU_sweep_cuts_total, ECU_sweep_time_total);
-%sweep_peeking(cfg,ECU_pre_TMS_sweep{f}, ECU_pre_TMS_sweep_time{f});
-
-    %%
-sweep_peeking(cfg,FDS_sweep_cuts_total, ECU_sweep_time_total);
-
-%%
-
-MEP_range.win=[0.018 0.045];
-MEP_range.subject = subject;
-save('MEP_range.mat', 'MEP_range')
-
-
-

BIN
Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/.DS_Store


+ 0 - 467
Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/JA_MEP_final_analysis_def.m

@@ -1,467 +0,0 @@
-function [info, tab] = JA_MEP_final_analysis_def(subject, matfile, f)
-
-load(matfile)
-
-load MEP_range
-
-%% name the trigger channel and time channel, then erase time from y
-
-% select trigger row and time row
-trigger = y(end,:); % trigger channel 
-time = y(1,:); % time-series in seconds
-
-%% get triggers and sample points at which each event of interest happens after the washout
-
-% get were variations happen within trigger channel
-diff_trigger = diff(trigger);
-
-% get trigger codes wihtin trgger line
-trigger_numbers = unique(trigger);
-
-% for each code present, get the sample were the rising triggers are present
-for x = 1:length(trigger_numbers)
-    
-    % find rising triggers and add 1 sampling point (due to diff which removes one)
-    tmp = find(diff_trigger == trigger_numbers(x))+1;
-    
-    % based on the code --> assign the tmp numbers to the correct variable
-    switch trigger_numbers(x)
-        
-        case 16
-            sp_out_slow_id = tmp;
-            
-        case 17
-            sp_out_fast_id = tmp;
-            
-        case 20 % color press CF
-            sp_color_CF_press = tmp;
-            
-        case 21 % color lift CF
-            sp_color_CF_lift = tmp;
-            
-        case 22 % color catch CF
-            sp_color_CF_catch = tmp;
-            
-        case 30 % color press SBJ
-            sp_color_SBJ_press = tmp;
-            
-        case 31 % color_lift SBJ
-            sp_color_SBJ_lift = tmp;
-            
-        case 40 % CF hitting
-            sp_CF_hitting = tmp;
-            
-        case 41 % SBJ hitting
-            sp_SBJ_hitting = tmp;
-            
-        case 128 % TMS pulse
-            sp_TMS = tmp;
-            
-            
-            
-            
-       % get the condition     
-        case 122
-            relationship = 'warming_up'
-        case 123
-            relationship = 'training'
-        case 124
-            relationship = 'joint'
-        case 125
-            relationship = 'parallel'
-        case 126
-            relationship = 'competitive'
-        case 127
-            relationship = 'motor_imagery'
-    end
-    
-end
-
-
-info.relationship = relationship
-
-%% organize color appearence
-
-
-% bug on this ptp in the competitive block
-if strcmp(subject, 'S38') && strcmp(relationship, 'competitive')
-    
- sp_color_CF_press   = sort(cat(2,sp_color_CF_press(1:21), 1340263 ,sp_color_CF_press(22:end)));
-    
-sp_out_slow_id = sp_out_slow_id(2:end)
-    
-end
-
-% bug on this ptp in the competitive block
-if strcmp(subject, 'S42') && strcmp(relationship, 'joint')
-    
- sp_color_CF_press   = sort(cat(2,sp_color_CF_press(1:30), 2334159 ,sp_color_CF_press(31:end)));
-    
-sp_out_slow_id = sp_out_slow_id(2:end);
-    
-end
-
-
-% put all the sampling points related to CF color in temporal
-% order
-[CF_colors_idx] = sortrows(vertcat(sp_color_CF_press',sp_color_CF_lift',sp_color_CF_catch'));
-CF_colors_order = CF_colors_idx;
-
-
-
-% assign codes to sample points corresponding to press lift and catch
-% 1 --> press (red dot)
-% -1 --> lift (yellow dot)
-% 0 --> catch trial
-% !!!! fast/slow out trials are still inside
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_press)) = 1;
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_lift)) = -1;
-CF_colors_order(ismember(CF_colors_idx, sp_color_CF_catch)) = 0;
-
-for k = 1:length(CF_colors_order)
-    
-    switch CF_colors_order(k)
-        case 1
-    CF_colors_label{k} = 'press';
-        case -1
-    CF_colors_label{k} = 'lift';   
-        case 0
-    CF_colors_label{k} = 'catch';  
-    end
-end
-%% get color appearence to TMS delay in seconds
-
-color_TMS_delay =  (sp_TMS' - CF_colors_idx)./SR;
-
-
-info.color_TMS_delay = color_TMS_delay;
-
-%% find fast/slow out trials
-
-[out_sp] = sortrows(vertcat(sp_out_slow_id',sp_out_fast_id'));
-
-
-% exclude out_fast and out_slow
-for ex = 1:length(out_sp)
-    
-    [v_abs(ex) p_abs(ex)] = min(abs(CF_colors_idx - out_sp(ex)));
-    ddd = CF_colors_idx - out_sp(ex);
-    exclude_fast_slow(ex) = p_abs(ex);
-    is_exclude_positive(ex) = ddd(exclude_fast_slow(ex));
-    
-end
-
-
-info.out_sp = out_sp;
-info.out_idx = exclude_fast_slow;
-
-
-
-%% create a clean sample (other than excluding washout trials, also fast/slow trials, and catch_trials are excluded)
-
-wash_out_trials = [1:11]'; % exclude first game
-
-catch_trials_idx = find(CF_colors_order == 0); % all cathc trials
-
-
-
-idx_tb_excluded = cat(1,catch_trials_idx, exclude_fast_slow', wash_out_trials);
-
-idx_to_keep = setdiff(1:length(sp_TMS),idx_tb_excluded);
-
-
-
-info.wash_out_trials = wash_out_trials;
-info.catch_trials_idx = catch_trials_idx;
-info.idx_tb_excluded = idx_tb_excluded;
-info.idx_to_keep = idx_to_keep;
-%%
-
-for k = 1:length(CF_colors_order)
-    
-    % if it is a washout
-    if ~isempty(find(ismember(wash_out_trials, k)))
-        
-        trial_category{k} = 'wash_out';
-        
-    % else if it is an out_slow or out_fast    
-    else if ~isempty(find(ismember(exclude_fast_slow, k)))
-            
-            trial_category{k} = 'out_fast_slow';
-            
-        else % in any other case color_label
-            trial_category{k} = CF_colors_label{k};
-        end
-    end
-    
-    
-end
-
-
-
-%% epoch to pre_TMS time-window, filter, peak extraction
-
-% select channels
-ECU_right = y(3,:);
-FDS_right = y(5,:);
-
-% select window --> epoch
-cfg = [];
-cfg.start_time = -0.05;
-cfg.end_time = -0.002;
-cfg.SR = SR;
-cfg.sp_trigger = sp_TMS;
-
-[ECU_pre_TMS_sweep, ECU_pre_TMS_sweep_time, ECU_pre_TMS_sample_points] = gb_cutting_sweeps(cfg, ECU_right);
-[FDS_pre_TMS_sweep, FDS_pre_TMS_sweep_time, FDS_pre_TMS_sample_points] = gb_cutting_sweeps(cfg, FDS_right);
-
-
-
-
-% filter the pre_TMS epochs 
-Fsample = SR;
-hp_filter = 10;
-lp_filter = 2500;
-padding_length = SR*0.3;
-
-% for each epoch
-for k = 1:length(ECU_pre_TMS_sweep)
-
-% padding 
-ECU_pre_TMS_sweep{k} = ft_preproc_padding(ECU_pre_TMS_sweep{k}, 'mean', padding_length);    
-FDS_pre_TMS_sweep{k} = ft_preproc_padding(FDS_pre_TMS_sweep{k}, 'mean', padding_length);    
-     
-    
-% highpass filter >10 Hz
-ECU_pre_TMS_sweep{k} = ft_preproc_highpassfilter(ECU_pre_TMS_sweep{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-FDS_pre_TMS_sweep{k} = ft_preproc_highpassfilter(FDS_pre_TMS_sweep{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-
-% lowpass filter <2500 Hz
-ECU_pre_TMS_sweep{k} = ft_preproc_lowpassfilter(ECU_pre_TMS_sweep{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-FDS_pre_TMS_sweep{k} = ft_preproc_lowpassfilter(FDS_pre_TMS_sweep{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-
-% notch filter 50 Hz
-ECU_pre_TMS_sweep{k} = ft_preproc_dftfilter(ECU_pre_TMS_sweep{k}, Fsample,50);
-FDS_pre_TMS_sweep{k} = ft_preproc_dftfilter(FDS_pre_TMS_sweep{k}, Fsample,50);
-
-ECU_pre_TMS_sweep{k} = ECU_pre_TMS_sweep{k}(padding_length+1:length(ECU_pre_TMS_sweep_time)+padding_length);
-FDS_pre_TMS_sweep{k} = FDS_pre_TMS_sweep{k}(padding_length+1:length(FDS_pre_TMS_sweep_time)+padding_length);
-end
-
-
-
-
-info.hp_filter = hp_filter;
-info.lp_filter = lp_filter;
-info.padding = padding_length/SR;
-
-
-%%
-% max-min peaks extraction
-for k = 1:length(ECU_pre_TMS_sweep)
-
-   [ECU_bkgrnd_max(k,1) ECU_bkgrnd_x_max(k,1)] = max(ECU_pre_TMS_sweep{k});
-   [ECU_bkgrnd_min(k,1) ECU_bkgrnd_x_min(k,1)] = min(ECU_pre_TMS_sweep{k});
-   
-   ECU_bkgrnd(k,1) = ECU_bkgrnd_max(k,1)- ECU_bkgrnd_min(k,1);
-   
-   
-   
-   
-   
-   [FDS_bkgrnd_max(k,1) FDS_bkgrnd_x_max(k,1)] = max(FDS_pre_TMS_sweep{k});
-   [FDS_bkgrnd_min(k,1) FDS_bkgrnd_x_min(k,1)] = min(FDS_pre_TMS_sweep{k});
-   FDS_bkgrnd(k,1) = FDS_bkgrnd_max(k,1)- FDS_bkgrnd_min(k,1);
-   
-end
-
-original_ECU_bkgrnd = ECU_bkgrnd;
-original_FDS_bkgrnd = FDS_bkgrnd;
-
-% nan all the trials not to be analysed
-ECU_bkgrnd(idx_tb_excluded) = nan;
-FDS_bkgrnd(idx_tb_excluded) = nan;
-
-% find the trial number in which the excessive contraction (> +/- 100 microV)
-excl_ECU_idx = find(ECU_bkgrnd>200);
-excl_FDS_idx = find(FDS_bkgrnd>200);
-
-% get trials and total number from both recorded muscles
-pre_TMS_contraction.idx = union(excl_ECU_idx, excl_FDS_idx);
-pre_TMS_contraction.number = length(pre_TMS_contraction.idx);
-
-% if >30% are excluded due to background contration --> exclude the participant
-if (pre_TMS_contraction.number/length(sp_TMS(idx_to_keep))) > (30/length(sp_TMS(idx_to_keep)));
-    pre_TMS_contraction.exclusion = 1;
-else
-    pre_TMS_contraction.exclusion = 0;
-end
-
-idx_contraction_tb_excluded = pre_TMS_contraction.idx;
-
-
-info.pre_TMS_contraction = pre_TMS_contraction;
-info.ECU_bkgrnd = ECU_bkgrnd;
-info.FDS_bkgrnd = FDS_bkgrnd;
-info.excl_ECU_idx = excl_ECU_idx;
-info.excl_FDS_idx = excl_FDS_idx;
-
-info.idx_contraction_tb_excluded = idx_contraction_tb_excluded;
-
-
-%% epoch to MEP time-window then filter
-
-MEP_stating_time = 0.01;
-% select window --> epoch in the MEP window
-cfg = [];
-cfg.start_time = MEP_stating_time; % from 10 ms
-cfg.end_time = 0.055;%...to 55 ms
-cfg.SR = SR;
-cfg.sp_trigger = sp_TMS;
-
-[ECU_MEP_sweep, ECU_MEP_sweep_time, ECU_MEP_sample_points] = gb_cutting_sweeps(cfg, ECU_right);
-[FDS_MEP_sweep, FDS_MEP_sweep_time, FDS_MEP_sample_points] = gb_cutting_sweeps(cfg, FDS_right);
-
-
-
-% filter for each epoch (same filters as above)
-for k = 1:length(ECU_MEP_sweep)
-
-% padding 
-ECU_MEP_sweep{k} = ft_preproc_padding(ECU_MEP_sweep{k}, 'mean', padding_length);    
-FDS_MEP_sweep{k} = ft_preproc_padding(FDS_MEP_sweep{k}, 'mean', padding_length);    
-     
-    
-% highpass filter >10 Hz
-ECU_MEP_sweep{k} = ft_preproc_highpassfilter(ECU_MEP_sweep{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-FDS_MEP_sweep{k} = ft_preproc_highpassfilter(FDS_MEP_sweep{k}, Fsample, hp_filter,1, 'but');%,'onepass-reverse');
-
-% lowpass filter <2500 Hz
-ECU_MEP_sweep{k} = ft_preproc_lowpassfilter(ECU_MEP_sweep{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-FDS_MEP_sweep{k} = ft_preproc_lowpassfilter(FDS_MEP_sweep{k}, Fsample, lp_filter,1, 'but');%,'onepass-reverse');
-
-% notch filter 50 Hz
-ECU_MEP_sweep{k} = ft_preproc_dftfilter(ECU_MEP_sweep{k}, Fsample,50);
-FDS_MEP_sweep{k} = ft_preproc_dftfilter(FDS_MEP_sweep{k}, Fsample,50);
-
-ECU_MEP_sweep{k} = ECU_MEP_sweep{k}(padding_length+1:length(ECU_MEP_sweep_time)+padding_length);
-FDS_MEP_sweep{k} = FDS_MEP_sweep{k}(padding_length+1:length(FDS_MEP_sweep_time)+padding_length);
-
-end
-
-
-
-info.ECU_MEP_sweep = ECU_MEP_sweep;
-info.FDS_MEP_sweep = FDS_MEP_sweep;
-
-%%
-
-MEP_win_onset_sp = find(ECU_MEP_sweep_time <= (MEP_range.win(1)), 1,'last');
-MEP_win_end_sp = find(ECU_MEP_sweep_time >= (MEP_range.win(2)), 1,'first');
-
-% max-min MEP peaks extraction
-for k = 1:length(ECU_MEP_sweep)
-
-   [ECU_MEP_max(k,1) ECU_MEP_x_max(k,1)] = max(ECU_MEP_sweep{k}(MEP_win_onset_sp:MEP_win_end_sp));
-   [ECU_MEP_min(k,1) ECU_MEP_x_min(k,1)] = min(ECU_MEP_sweep{k}(MEP_win_onset_sp:MEP_win_end_sp));
-   
-   ECU_MEP(k,1) = ECU_MEP_max(k,1)- ECU_MEP_min(k,1);
-   
-   
-   
-   
-   
-   [FDS_MEP_max(k,1) FDS_MEP_x_max(k,1)] = max(FDS_MEP_sweep{k}(MEP_win_onset_sp:MEP_win_end_sp));
-   [FDS_MEP_min(k,1) FDS_MEP_x_min(k,1)] = min(FDS_MEP_sweep{k}(MEP_win_onset_sp:MEP_win_end_sp));
-   FDS_MEP(k,1) = FDS_MEP_max(k,1)- FDS_MEP_min(k,1);
-   
-end
-
-info.ECU_MEP = ECU_MEP;
-info.FDS_MEP = FDS_MEP;
-
-%%
-original_ECU_MEP = ECU_MEP;
-original_FDS_MEP = FDS_MEP;
-
-ECU_MEP(idx_tb_excluded) = nan;
-FDS_MEP(idx_tb_excluded) = nan;
-
-ECU_MEP(idx_contraction_tb_excluded) = nan;
-FDS_MEP(idx_contraction_tb_excluded) = nan;
-
-% find the trial number in which the excessive contraction (> +/- 100 microVolt)
-excl_ECU_MEP_idx = find(ECU_MEP<50);
-excl_FDS_MEP_idx = find(FDS_MEP<50);
-
-
-% nan those trials in which the MEPs are < 50 microVolt
-ECU_MEP(excl_ECU_MEP_idx) = nan;
-FDS_MEP(excl_FDS_MEP_idx) = nan;
-
-% get trials and total number from both recorded muscles
-info.noECU_MEP_idx = excl_ECU_MEP_idx;
-info.noECU_MEP_number = length(excl_ECU_MEP_idx);
-
-info.noFDS_MEP_idx = excl_FDS_MEP_idx;
-info.noFDS_MEP_number = length(excl_FDS_MEP_idx);
-
-
-%% get the medians for the color conditions
-
-press_trials = find(CF_colors_order == 1); % press
-
-lift_trials = find(CF_colors_order == -1); % lift
-
-
-% get the medians for each color observed
-ECU_MEP_press = nanmedian(ECU_MEP(press_trials));
-ECU_MEP_lift = nanmedian(ECU_MEP(lift_trials));
-
-FDS_MEP_press = nanmedian(FDS_MEP(press_trials));
-FDS_MEP_lift = nanmedian(FDS_MEP(lift_trials));
-
-
-info.analysable_press_trials_number = length(find(~isnan(ECU_MEP(press_trials))))
-info.analysable_lift_trials_number = length(find(~isnan(ECU_MEP(lift_trials))))
-
-
-info.ECU_MEP_press = ECU_MEP_press;
-info.ECU_MEP_lift = ECU_MEP_lift;
-
-info.FDS_MEP_press = FDS_MEP_press;
-info.FDS_MEP_lift = FDS_MEP_lift;
-
-%%
-subject_name = repmat(subject, [length(CF_colors_order),1]);
-condition = repmat(cellstr(relationship), [length(CF_colors_order),1]);
-trial  = 1:length(CF_colors_order);
-CF_colors_label  = CF_colors_label';
-trial_category = trial_category';
-trial = trial';
-order = repmat(f-2, [length(CF_colors_order),1]);
-
-
-tab = table(subject_name, ...
-condition,...
-order,...  
-CF_colors_label,...    
-trial_category,...
-ECU_bkgrnd,...
-FDS_bkgrnd,...
-original_ECU_bkgrnd,...
-original_FDS_bkgrnd,...
-ECU_MEP,...
-FDS_MEP,...
-original_ECU_MEP,...
-original_FDS_MEP,...
-color_TMS_delay,...
-trial)
-
-
-
-end
-
-
-
-

BIN
Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/JA_Stage2_analyses_16-Sep-2021.xlsx


+ 0 - 113
Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/JA_run_MEP_analysis.m

@@ -1,113 +0,0 @@
-
-general_directory ='/Volumes/SAMSUNG/Ja_Stage_2'
-function_directory = '/Users/b1037210/Desktop/Progetti/JA_Stage1/';
-function_directory2 = '/Users/b1037210/Desktop/Progetti/JA_Stage2/';
-addpath(general_directory);
-addpath(function_directory);
-addpath(function_directory2);
-%%
-addpath(genpath('/Users/b1037210/Documents/MATLAB/fieldtrip-20161117'))
-
-ft_defaults
-%%
-list_subjects = {...
-    'S01',...
-    'S02',...
-    'S03',...
-    'S04',...
-    'S05',...
-    'S06',...
-    'S07',...
-    'S08',...
-    'S09',...
-    'S10',...
-    'S11',...
-    'S12',...
-    'S13',...
-    'S14',...
-    'S15',...
-    'S16',...
-    'S17',...
-    'S18',...
-    'S19',...
-    'S20',...
-    'S21',...
-    'S22',...
-    'S23',...
-    'S24',...
-    'S25',...
-    'S26',...
-    'S27',...
-    'S28',...
-    'S29',...
-    'S30',...
-    'S31',...
-    'S32',...
-    'S33',...
-    'S34',...
-    'S35',...
-    'S36',...
-    'S37',...
-    'S38',...
-    'S39',...
-    'S40',...
-    'S41',...
-    'S42'}'
-
-%%
-tab_for_R = table;
-
-for s = 1:length(list_subjects)
-    
-    
-    
-    
-    % cd directory
-    cd(fullfile(general_directory,list_subjects{s}));
-    
-    % file list
-    file_list_tmp = dir('TMSSession*')
-    
-    for f = 1:length(file_list_tmp)
-        
-        clear MetaData condition_code matfile
-        
-        load(file_list_tmp(f).name, 'MetaData');
-        condition_code = strsplit(MetaData.GeneralInfo, '_');
-        condition_code  = strtrim(condition_code)
-        
-        if  strcmp(condition_code{2}, 'TR') || strcmp(condition_code{2}, 'WARM');
-            
-            disp('behavioral block --> exit');
-            continue
-            
-        else
-           
-            matfile = file_list_tmp(f).name;
-            
-        end
-       
-         
-        [info_tmp tab] = JA_MEP_final_analysis_def(list_subjects{s}, matfile, f)
-%        [info_tmp tab] = JA_MEP_final_analysis_alt(list_subjects{s}, matfile, f)
-  
-         info.(list_subjects{s}).(condition_code{2})= info_tmp;
-
-        tab_for_R = vertcat(tab_for_R, tab);
-        
-        clear info_tmp tab info_for_R
-           end
-    
-end
-
-
-%%
-cd(function_directory2)
-
-filename = strcat('JA_Stage2_analyses_',date, '.xlsx');
-writetable(tab_for_R,filename,'Sheet',1)
-
-
-save(strcat('tab_for_R_',date,  '.mat'), 'tab_for_R') 
-
-save('JA_Stage_2_info.mat', 'info')

File diff suppressed because it is too large
+ 0 - 1053
Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/R_statistical_analyses.Rmd


+ 0 - 38
Stage2_analyses_folder/Stage2_analysis/5_JA_Analyses/gb_cutting_sweeps.m

@@ -1,38 +0,0 @@
-function [sweep_cut, sweep_time,sweep_points] = gb_cutting_sweeps(cfg, data)
-
-sweep_start = round(cfg.start_time*cfg.SR);
-sweep_end = round(cfg.end_time*cfg.SR);
-
-
-for x = 1:length(cfg.sp_trigger)
-   
-   sweep_points{x} = sweep_start+cfg.sp_trigger(x):cfg.sp_trigger(x)+sweep_end;
-    
-   sweep_cut{x} = data(sweep_points{x});
-   
-   if isfield(cfg, 'baseline_rectify')
-       
-    % rectify epoch   
-    sweep_cut{x} =  abs(sweep_cut{x});
-    
-    
-      bs_start = round(cfg.baseline_rectify(1)*cfg.SR);
-    bs_end = round(cfg.baseline_rectify(2)*cfg.SR);
-    
-      bs_points{x} = bs_start+cfg.sp_trigger(x):cfg.sp_trigger(x)+bs_end;
-    
-   bs_cut{x} = abs(data(bs_points{x}));
-  
-    
-  
-    
-    % identify mean of the baselined period
-    baselined_chunk = mean(bs_cut{x},2);   
-    
-    % subtract the mean from the baselined period from the rectified epoch
-    sweep_cut{x} =  sweep_cut{x} - baselined_chunk;
-   end
-
-end
-
- sweep_time = linspace(cfg.start_time,cfg.end_time, length(sweep_points{1})) ; 

+ 0 - 44
Stage2_analyses_folder/Stage2_analysis/analysis_functions_description.rtf

@@ -1,44 +0,0 @@
-{\rtf1\ansi\ansicpg1252\cocoartf2636
-\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fmodern\fcharset0 Courier;}
-{\colortbl;\red255\green255\blue255;}
-{\*\expandedcolortbl;;}
-\paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
-\deftab720
-\pard\pardeftab720\partightenfactor0
-
-\f0\fs24 \cf0 \
-## Analysis: preprocessing performance data collected from psychtoolbox stimuli presentation scripts\
-\
-# it checks (offline) that PTP performance was not within the exclusion criteria\
-JA_run_performance_exclusion_criteria_over_subejcts.m\
-	it uses \
-JA_exclusion_criteria.m \
-JA_exclusion_criteria_SBJ.m \
-JA_exclusion_criteria_CF.m\
-\
-\
-## EMG (MEP) recordings preprocessing (they require Fieldtrip for filtering traces)\
-\
-# it checks how many trials show above threshold contraction before TMS \
-JA_run_check_pre_TMS_contraction_padding.m\
-	it uses\
-JA_check_contraction_pre_TMS_padding.m\
-\
-\
-# It Sets ranges in which looking for MEP peaks. It outputs a .mat file containing for each PTP the MEP time window\
-JA_set_MEP_range_padfilter.m\
-\
-\
-# Actual computation of peak to peak MEP amplitudes. It outputs a table which is saved as \'93.xlsx\'94 Excel file to read from and .R script (see R statistical analysis).\
-\
-JA_run_MEP_analysis.m\
-	it uses\
-JA_MEP_final_analysis_alt.m\
-\
-\
-# statistical analysis in R (packages required are listed at the beginning of the each analyises within the .Rmd file. the packages are actually the same for all the analyses).\
-\
-R_statistical_analyses.Rmd\
-\
-\
-}