-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_lists_healty_patients.py
66 lines (52 loc) · 1.76 KB
/
create_lists_healty_patients.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# coding: utf-8
#Crea due liste, una per i pazienti e una per i controlli sani da passare poi a Matlab
#Da lanciare dopo unfold_and_rename [aggiungere chiamata a questo script da unfold_and_rename]
import os
import pandas as pd
import glob
df = pd.read_csv('Directories.txt',sep='\t',index_col='Index')
global prefix
global datadir
global codedir
global windatadir
prefix = df.loc['PREFIX','value']
datadir = df.loc['Data directory','value']
codedir = df.loc['Code directory','value']
windatadir=df.loc['Windows Data Directory','value'] #se ubuntu usare path di ubuntu
with open(datadir+'subjectlist.txt') as f:
lines=f.readlines()
f.close()
adnimerge=pd.read_excel('/home/sbombieri/DATA/UNIQUE_FILE.xlsx')
listHealty=[]
listPatients=[]
for line in lines:
tmp=line.split('/')
tmp=tmp[len(tmp)-1].split('_')
tmp=tmp[len(tmp)-1] #these are now the RIDS of subjectlist
#for every rid create the appropriate list
tmp=tmp.strip()
# print(tmp)
subj=adnimerge[adnimerge['RID']==int(tmp)]['ADNIMERGE'].values[0]
#print(tmp+" -> "+subj)
if subj in ['CN','SMC']: #controls
listHealty.append(line)
#for every list create appropriate subjectlist.txt for healty
else:
#for every list create appropriate subjectlist.txt for patients
listPatients.append(line)
#save lists:
with open(datadir+'subjectlist_PATIENTS.txt', 'w') as fp:
for item in listPatients:
# write each item on a new line
fp.write("%s" % item)
print('Done PATIENTS')
fp.close()
ctrls=datadir+'subjectlist_CONTROLS.txt'
with open(ctrls, 'w') as fp:
for item in listHealty:
# write each item on a new line
fp.write("%s" % item)
print('Done CONTROLS')
fp.close()
print("Done all.")