In [40]:
import os
import glob
import shutil
In [41]:
in_path = '/data1/auto_qc/sample_data/adhd200_qc_niak'
out_path = '/data1/auto_qc/sample_data/adhd200_qc_niak/test'
if not os.path.isdir(out_path):
os.makedirs(out_path)
In [42]:
list_subjects = ['X1538046', 'X1517240', 'X1561488']
In [43]:
temp_anat = 'summary_{}_anat.jpg'
temp_func = 'summary_{}_func.jpg'
In [44]:
out_csv = 'sub_id,image1,image2'
for sub_id in list_subjects:
anat_path = glob.glob(os.path.join(in_path, temp_anat.format(sub_id)))[0]
func_path = glob.glob(os.path.join(in_path, temp_func.format(sub_id)))[0]
out_csv = '{}\n{},{},{}'.format(out_csv,sub_id,temp_anat.format(sub_id),temp_func.format(sub_id))
# Copy the files over to the new path
anat_new = os.path.join(out_path, temp_anat.format(sub_id))
func_new = os.path.join(out_path, temp_func.format(sub_id))
shutil.copy(anat_path, anat_new)
shutil.copy(func_path, func_new)
In [45]:
out_csv
Out[45]:
In [46]:
with open(os.path.join(out_path, 'test.csv'), 'w') as out:
out.write(out_csv)
In [ ]: