-
Notifications
You must be signed in to change notification settings - Fork 1
/
createTableMixedModel.m
154 lines (141 loc) · 5.73 KB
/
createTableMixedModel.m
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
clear;
%create full table for mixed model from individual powerspectrum tables
%created in createPSForMixedModel.m
%all drugs for mixed model
% meds=["Risperidone", "Olanzapine", "Quetiapine", "Aripiprazole", "Ziprasidone", "Haloperidol", ...
% "Cariprazine", "Asenapine", "Benperidol", "Bromperidol", "Chlorprotixene", "Flupentixole", ...
% "Fluphenazine", "Fluspirilene", "Levomepromazine", "Melperone", "Perazin", "Perphenazine",...
% "Pimozide", "Pipamperon", "Prothipendyl", "Sertindole", "Sulpiride", "Thioridazine",...
% "Zuclopenthixol", "Clozapin", ...
% "Citalopram", "Escitalopram", "Sertraline", "Paroxetine", "Fluoxetine", "Bupropion", "Venlafaxine", "Mirtazapine", ...
% "Trazodone", "Agomelatin", "Amitriptyline", "Clomipramin", "Doxepin", "Duloxetin", "Imipramin", ...
% "Maprotilin", "Mianserin", "Milnacipran", "Moclobemid", "Nortriptylin", "Reboxetin",...
% "Tranylcypromin", "Trimipramin",...
% "Lithium"];
%all drugs where we found data
meds=["Risperidone", "Olanzapine", "Quetiapine", "Aripiprazole", "Ziprasidone", "Haloperidol", ...
"Fluphenazine", "Perphenazine",...
"Clozapin", ...
"Citalopram", "Escitalopram", "Sertraline", "Paroxetine", "Fluoxetine", "Bupropion", "Venlafaxine", "Mirtazapine", ...
"Trazodone", "Amitriptyline", "Clomipramin", "Doxepin", "Duloxetin", ...
"Nortriptylin"];
dataAll = [];
drive="D:/";
%put together powerspectrum tables for individual drugs
for i=1:length(meds)
%get drug table
medicine = strcat(meds(i));
disp(medicine);
savefile = strcat(drive, 'Results\MixedModel\Powerspectrum\', medicine, '_powerspectrumMixedModel.xls');
dataDrug = readtable(savefile);
%add drug names as headers
for j=1:length(meds)
if meds{j}==medicine
%set current drug to 1
dataDrug.(meds{j})=ones(size(dataDrug,1),1);
else
dataDrug.(meds{j})=zeros(size(dataDrug,1),1);
end
end
if isempty(dataAll)
dataAll=dataDrug;
else
%add data
PatientNr={0};
SessionNr={0};
FileNr={0};
previous=table(PatientNr,SessionNr,FileNr);
for j=1:size(dataDrug,1)
entry=dataDrug(j,{'PatientNr' 'SessionNr', 'FileNr'});
key=strcat(entry.PatientNr{1},entry.SessionNr{1},entry.FileNr{1});
key2=strcat(previous.PatientNr{1},previous.SessionNr{1},previous.FileNr{1});
%next file
if ~strcmp(key,key2)
%is this patient already in dataAll table?
index = find(ismember(dataAll(:,{'PatientNr' 'SessionNr', 'FileNr'}),entry));
%if entry is not in dataAll
if isempty(index)
%find all corresponding entries in dataDrug
index = find(ismember(dataDrug(:,{'PatientNr' 'SessionNr', 'FileNr'}),entry));
%add entry in dataAll
dataAll = [dataAll; dataDrug(index,:)];
else %if entry is already in dataAll
%set drug to 1 into same entry in dataAll
dataAll(index, medicine) = array2table(ones(size(index,1),1));
end
previous=entry;
end
end
end
end
dataAll.Power = num2str(dataAll.Power);
%save file
savefile =strcat(drive, "Results\FullTableMixedModelWOReceptorProperties.csv");
writetable(dataAll, savefile);
disp("Receptor properties");
%calculate total drug properties
%add headers for drug groups
dataAll.Antidepressant=zeros(size(dataAll,1),1);
dataAll.Antipsychotic=zeros(size(dataAll,1),1);
%add headers for categories
dataAll.SGA=zeros(size(dataAll,1),1);
dataAll.FGA=zeros(size(dataAll,1),1);
%add headers for receptor properties
receptorPropertiesFile="D:/Results/DrugReceptorProperties.xlsx";
fileReceptor = readtable(receptorPropertiesFile);
header = fileReceptor.Properties.VariableNames;
for j=4:length(header)
dataAll.(header{j})=zeros(size(dataAll,1),1);
end
for j=1:length(meds)
medicine=meds(j);
disp(medicine);
%find all indexes where drug is 1
index = find(ismember(dataAll.(medicine),1));
%get receptor propeties for drug
index2 = find(ismember(fileReceptor.DrugName, medicine));
row = fileReceptor(index2,:);
row = fillmissing(row,'constant',0, 'DataVariables', @isnumeric);
properties=row;
%update receptor profile
%drug groups
if strcmp(properties.DrugGroup, "AP")
dataAll.Antipsychotic(index)=1;
elseif strcmp(properties.DrugGroup, "AD")
dataAll.Antidepressant(index)=1;
end
%categories
if strcmp(properties.Category, "SGA")
dataAll.SGA(index)=1;
elseif strcmp(properties.Category, "FGA")
dataAll.FGA(index)=1;
end
%für jede Zeile von dataAll(index)
for k=1:length(index)
%für jeden Eintrag in properties
n=9+length(meds);%number of entry where receptor properties start
for i=4:size(properties,2)
if dataAll{index(k),i+n}==0
dataAll{index(k),i+n}=properties{1,i};
elseif dataAll{index(k),i+n}==-1
if properties{1,i}==0 || properties{1,i}==-1
dataAll{index(k),i+n}=-1;
else
dataAll{index(k),i+n}=2;
end
elseif dataAll{index(k),i+n}==1
if properties{1,i}==0 || properties{1,i}==1
dataAll{index(k),i+n}=1;
else
dataAll{index(k),i+n}=2;
end
%if dataAll==2: it stays the same
end
end
end
savefile =strcat(drive, "Results\FullTableMixedModel.csv");
writetable(dataAll, savefile);
end
%save file
%savefile =strcat(drive, "Results\FullTableMixedModel.csv");
%writetable(dataAll, savefile);