PCA_creator.m 5.12 KB
Newer Older
Michaela Olson's avatar
Michaela Olson committed
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
152
153
154
155
156
157
158
159
160
161
162
163
%% PCA Analysis with user prompts for workspace, number of variable, and drug selection
% DESCRIPTION:
%     Prompts users to obtain the following variables
%         - numvar
%         - chosen_workspaces
%         - chosen_drugs
%         - drugs_to_apply
% 
%     Having declared these variables, runs the following scripts in this
%     order:
%         - load_workspaces
%         - PCA_analysis
%
% PREREQUISITES: none
% 
% OUTPUT: ~fill this out~

%% Clear workspace before start
%~~ Comment out to disable this feature ~~%
%clear

%% Add Paths
add_all_paths 


%% Prompt for figure workspace

%figure_folder_path = inputdlg("Folder to save figures in:", "Figure Path", [1 35], "./figures/");

figure_folder_path = "./figures/";
%% Prompt for PCA_analysis settings

% Scripts like get_existing_feature_set set these variables, and we want
% them to be respected in the gui selection. If they're no set there
% though, they still need a default value.
if ~exist('do_feature_reduction','var')
    do_feature_reduction = true;
end

if ~exist('remove_extra_controls','var')
    remove_extra_controls = true;
end

disp('bad treated = IMI, Dau, Nig, Nal');
variables_to_create = {'disc', 'do_feature_reduction', 'include_DMSO', 'show_clustergram', 'show_pca', 'plot_3', 'plot_3_DMSO', 'plot_before_tvn', 'remove_INH_control', 'remove_extra_controls', 'remove_bad_treated', 'prompt_for_one_dose', 'use_medians_only'};
default_values =      [true,   do_feature_reduction,      false,            false,            true,       false,    false,       false,            true,                 remove_extra_controls,     true,               false,                  false];

target_values = checkboxList("Select PCA_analysis Settings", variables_to_create, default_values);

initialize_variables %Initialize variables_to_create as target_values

if use_medians_only
    numvar = 25;
    
end 

%% make this global to make it accessible inside ver_figsave()
global chosen_workspaces

%% Select number of variables to use

if do_feature_reduction
    prompt = {'Enter number of variables:'};
    dlgtitle = 'Variable Number';
    dims = [1 35];
    definput = {'94'};
    numvar = inputdlg(prompt,dlgtitle,dims,definput);
    numvar = str2num(numvar{1});
else
    if exist('pca_whitened_table','var')
        numvar =  sum(varfun(@isnumeric,pca_whitened_table,'OutputFormat', 'uniform'));
    else
        
    end 
end 
%% Find list of workspaces, prompt user for choice, and load chosen
if ~exist('workspace_directory', 'var')
    workspace_directory = './workspaces';
    disp("Defaulted workspace_directory to './workspaces' in load_workspaces")
end

workspace_list = get_workspaces(workspace_directory);
if isempty(workspace_list)
    error(strcat("No workspaces found in ", workspace_directory))
end
% If we are operating from an existing feature set, automatically select
% the workspaces that were used to calculate that set
if exist('overall_vars', 'var')
    try
        default_selection = find(ismember(workspace_list, overall_vars.WORKSPACE));
    catch
        disp("Note: overall_vars does not have a WORKSPACE field")
        default_selection = [];
    end 
else
    default_selection = [];
end

% prompt the user to select 
[indexes_chosen, any_chosen_tf] = listdlg('ListString',workspace_list,...
    'Name',"Select workspace",'ListSize',[380 380],...
    'InitialValue', default_selection);

% if the user did not select anything, exit (there is a catch for this in load_workspaces too)
if ~any_chosen_tf
    return
end

% use the index to get the list of user-selected workspaces
chosen_workspaces = workspace_list(indexes_chosen);

%% run the script to load the workspaces
load_workspaces

%% From the list of drugs, prompt user to select which drugs to use and apply

% If we are operating from an existing feature set, automatically select
% the variables that were used to calculate that set
if exist('overall_vars', 'var')
    default_selection = find(ismember(choice_variable, overall_vars.DRUGS));
else
    default_selection = [];
end

suggestion = {'Mer','Amp','Ctax','INH','EMB','ETA','IMI','Van','Cyc','Del',...
'Lev','Mox','Clz','MIT','Olf','Kan','Amk','Cam','Cla','Dox','Gent',...
'Strep','Tet','Lin','Pre','CCCP','Cer','Mon','Nig','Thi','RifT','BDQ',... 
'RIF','THL','water','Untreated'};

if exist('suggestion','var')
    default_selection = find(ismember(choice_variable,suggestion));
    
end 

% For extra_resolution_confusion
if prompt_for_one_dose
    select_one_dose
end

% Prompt user to select a list of drugs
[indexes_chosen, any_chosen_tf] = listdlg('ListString',choice_variable,...
    'Name',"Select Drugs",'ListSize',[220 380],'PromptString',"Select Drugs",...
    'InitialValue', default_selection); 

% if the user did not select anything, exit
if ~any_chosen_tf
    return
end

% Get a list of the drugs chosen
chosen_drugs = choice_variable(indexes_chosen);

%prompt the user to select drugs to apply if they want to 
[indexes_chosen, any_chosen_tf] = listdlg('ListString',choice_variable,'Name',"Select Drugs to apply",'ListSize',[220 380],...
    'CancelString','No Selection'); 

% Get a list of drugs to apply

drugs_to_apply = choice_variable(indexes_chosen);

%% Run PCA Analysis

PCA_analysis