Last active
January 9, 2020 09:53
-
-
Save ilkayisik/09d08db65ef0ba1bfbe32e2a4d0178c4 to your computer and use it in GitHub Desktop.
remove files based on expression in the file name and create text files with those files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from glob import glob | |
sub_exc = [0, 1, 2, 15, 18] | |
sub_list = ['sub-{:02d}'.format(s+1) for s in sub_exc] | |
files1 = [i for i in files1 if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
files2 = [i for i in files2 if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
files3 = [i for i in files3 if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
files = [files1, files2, files3] | |
for c_idx, c in enumerate(copes): | |
with open('/path/files{}.txt'.format(c_idx+1), 'w') as f: | |
for item in c: | |
f.write("%s\n" % item) | |
root='/Users/ilkay.isik/project_folder_temp/fc_content/MRI_data/lscp_data/' | |
rh_cope1_files = sorted(glob(root + 'derivatives/analysis/sub-*/video/betaseries/level_2.gfeat/cope1.feat/stats/fs/rh*.cope1_fsaverage.mgh')) | |
lh_cope1_files = sorted(glob(root + 'derivatives/analysis/sub-*/video/betaseries/level_2.gfeat/cope1.feat/stats/fs/lh*.cope1_fsaverage.mgh')) | |
rh_cope2_files = sorted(glob(root + 'derivatives/analysis/sub-*/video/betaseries/level_2.gfeat/cope1.feat/stats/fs/rh*.cope2_fsaverage.mgh')) | |
lh_cope2_files = sorted(glob(root + 'derivatives/analysis/sub-*/video/betaseries/level_2.gfeat/cope1.feat/stats/fs/lh*.cope2_fsaverage.mgh')) | |
rh_cope3_files = sorted(glob(root + 'derivatives/analysis/sub-*/video/betaseries/level_2.gfeat/cope1.feat/stats/fs/rh*.cope3_fsaverage.mgh')) | |
lh_cope3_files = sorted(glob(root + 'derivatives/analysis/sub-*/video/betaseries/level_2.gfeat/cope1.feat/stats/fs/lh*.cope3_fsaverage.mgh')) | |
sub_exc = [0, 1, 2, 15, 18] | |
sub_list = ['sub-{:02d}'.format(s+1) for s in sub_exc] | |
rh_cope1_files = [i for i in rh_cope1_files if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
lh_cope1_files = [i for i in lh_cope1_files if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
rh_cope2_files = [i for i in rh_cope2_files if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
lh_cope2_files = [i for i in lh_cope2_files if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
rh_cope3_files = [i for i in rh_cope3_files if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
lh_cope3_files = [i for i in lh_cope3_files if i.rsplit('analysis/',1 )[1].split('/')[0] not in sub_list] | |
# write out subject paths | |
copes = [rh_cope1_files, lh_cope1_files, rh_cope2_files, lh_cope2_files, rh_cope3_files, lh_cope3_files] | |
for c_idx, c in enumerate(copes): | |
# Assign even odd to right left hemisphere | |
if c_idx%2==0: | |
prefix_hemi = "rh" | |
else: | |
prefix_hemi = "lh" | |
# Assign COPE1, COPE2, COPE3 | |
prefix_cope_type = int(np.ceil((c_idx+1) / 2.)) | |
# Write text files | |
in_file = '{}/derivatives/analysis/video/betaseries/surface/{}_cope{}_files.txt'.format( | |
root, prefix_hemi, prefix_cope_type) | |
with open(in_file, 'w') as f: | |
for item in c: | |
f.write("%s\n" % item) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment