@@ -0,0 +1,2842 @@
+import argparse%0Aimport glob%0Aimport re%0Aimport os%0Aimport scipy.io%0A%0A%0Adef parser_annotation(root_dir):%0A    file_list = glob.glob(root_dir + '/*_segments.txt')%0A    file_list.sort(key=lambda var: %5Bint(x) if x.isdigit() else x for x in re.findall(r'%5B%5E0-9%5D%7C%5B0-9%5D+', var)%5D)%0A%0A    file_index_all = %5B%5D%0A    trial_index_all = %5B%5D%0A    action_all = %5B%5D%0A    start_time_sec_all = %5B%5D%0A    start_time_msec_all = %5B%5D%0A    end_time_sec_all = %5B%5D%0A    end_time_msec_all = %5B%5D%0A%0A    for file in file_list:%0A        filename_split = file.split('/')%5B-1%5D.split('_success_')%0A        file_index1 = %5Bs for s in filename_split%5B0%5D.split('_') if s.isdigit()%5D%0A        file_index2 = %5Bs for s in filename_split%5B0%5D.split('palm') if s.isdigit()%5D%0A        trial_index = %5Bint(s) for s in filename_split%5B0%5D.split('_') if s.isdigit()%5D%0A        assert(len(file_index1) == 1)%0A        assert(0 %3C= len(file_index2) %3C= 1)%0A        assert(len(trial_index) == 1)%0A        file_index = str(file_index1) + '.' + str(file_index2)%0A%0A        # load file%0A        lines = %5Bline.rstrip('%5Cn') for line in open(file)%5D%0A        for line in lines:%0A            # comment%0A            if line.startswith('---'):%0A                continue%0A            # empty line%0A            elif not line.rstrip().lstrip():%0A                continue%0A            else:%0A                action, end_time_sec, end_time_msec = line.rstrip().lstrip().split(',')%0A                if action == 'start':%0A                    start_time_sec = end_time_sec%0A                    start_time_msec = end_time_msec%0A                    continue%0A%0A                file_index_all.append(file_index.rstrip('.'))%0A                trial_index_all.append(trial_index)%0A                action_all.append(action)%0A                start_time_sec_all.append(start_time_sec)%0A                start_time_msec_all.append(start_time_msec)%0A                end_time_sec_all.append(end_time_sec)%0A                end_time_msec_all.append(end_time_msec)%0A%0A                start_time_sec = end_time_sec%0A                start_time_msec = end_time_msec%0A    scipy.io.savemat('annotation.mat',%0A                     mdict=%7B'file_index': file_index_all,%0A                            'trial_index': trial_index_all,%0A                            'action': action_all,%0A                            'start_time_sec': start_time_sec_all,%0A                            'start_time_msec': start_time_msec_all,%0A                            'end_time_sec': end_time_sec_all,%0A                            'end_time_msec': end_time_msec_all%7D)%0A%0A%0Adef main():%0A    # parse input%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument('-i', '--input_dir')%0A    parser.add_argument('-o', '--output')%0A    args = parser.parse_args()%0A%0A    root_dir = args.input_dir%0A    assert (os.path.exists(root_dir))%0A    assert (os.path.isdir(root_dir))%0A%0A    parser_annotation(root_dir)%0A%0A%0Aif __name__ == '__main__':%0A    main()

add annotation2mat python script