55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
import glob
|
|
import csv
|
|
|
|
directories = {}
|
|
directories['patient'] = []
|
|
directories['year'] = []
|
|
directories['t2'] = []
|
|
directories['adc'] = []
|
|
directories['high_b'] = []
|
|
|
|
# for patient in patients:
|
|
# for year in mri_d:
|
|
# x = glob.glob('/data/pca-rad/dataset/datasets/anonymized_mri/only_nii_directory/{patient}/{year}/')
|
|
|
|
path = '../../../datasets/anonymized_mri/only_nii_directory/*/*'
|
|
x = glob.glob('../../../datasets/anonymized_mri/only_nii_directory/*/*')
|
|
|
|
for patient_year in sorted(x):
|
|
directories['patient'].append(patient_year.split('/')[-2])
|
|
directories['year'].append(patient_year.split('/')[-1])
|
|
for string in sorted(glob.glob(f'../../../datasets/anonymized_mri/only_nii_directory/{patient_year.split("/")[-2]}/{patient_year.split("/")[-1]}/*/*')):
|
|
if 'T2' in string or 't2' in string:
|
|
if ('tra' in string):
|
|
if not ('seg' in string):
|
|
directories['t2'].append(string)
|
|
# input(string)
|
|
# input(patient_year)
|
|
|
|
for string in sorted(glob.glob(f'../../../datasets/anonymized_mri/only_nii_directory/{patient_year.split("/")[-2]}/{patient_year.split("/")[-1]}/*')):
|
|
if 'manual_adc' in string:
|
|
directories['adc'].append(string)
|
|
if 'manual_b-1400' in string:
|
|
directories['high_b'].append(string)
|
|
|
|
|
|
print(len(x))
|
|
print(len(directories['t2']))
|
|
print(len(directories['adc']))
|
|
print(len(directories['high_b']))
|
|
|
|
print(directories)
|
|
with open('test.csv', 'w') as f:
|
|
for key in directories.keys():
|
|
f.write("%s,%s\n"%(key,directories[key]))
|
|
# with open('dict.csv', 'w') as csv_file:
|
|
# writer = csv.writer(csv_file)
|
|
# for key, value in directories.items():
|
|
# writer.writerow([key, value])
|
|
# break
|
|
# with open('Names.csv', 'w', newline='') as csvfile:
|
|
# writer = csv.DictWriter(csvfile, fieldnames=['patient','year','t2','adc','high_b'], delimiter=';')
|
|
# writer.writeheader()
|
|
# writer.writerows(directories)
|
|
|
|
# give patients with incomplete exam |