-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCA_graph.m
78 lines (58 loc) · 2.53 KB
/
PCA_graph.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
% This script plots the PCA scatter plot for the different metabolic
% scenarios
%% Load abundance and expression data
abundanceTable_FileName = 'out/abundanceTable.mat';
expressionTable_FileName = 'out/expressionTable.mat';
load(abundanceTable_FileName, 'abundanceTable');
load(expressionTable_FileName, 'expressionTable');
abundanceTable_pa = abundanceTable(:, 1:6); % Only take palmitate
expressionTable_pa = expressionTable(:, 1:6); % Only take palmitate
% Make a single table
omicDataTable = [abundanceTable_pa, expressionTable_pa];
omicData = table2array(omicDataTable);
% Set -1 values to NaN (This is the meaning in cobratoolbox)
omicData(omicData == -1) = NaN;
NaN_mask = any(~isnan(omicData), 2);
% Normalize omic data
omicDataNormalized = normalize(omicData(NaN_mask, :));
writematrix(omicDataNormalized, "out/omicDataNormalized.xlsx")
% Get the principal components
[coeff,pca_scores,latent,tsquared,explained,mu] = pca(omicDataNormalized);
scatter(pca_scores(:,1),pca_scores(:,2),"filled")
axis equal
xlabel('1st Principal Component')
ylabel('2nd Principal Component')
hold on
%% ##########################
%% Graph tibolone
%% ##########################
abundanceTable_tib = abundanceTable(:, 7:12); % Only take tibolone
expressionTable_tib = expressionTable(:, 1:6); % Only take palmitate
% Make a single table
omicDataTable = [abundanceTable_tib, expressionTable_tib];
omicData = table2array(omicDataTable);
% Set -1 values to NaN (This is the meaning in cobratoolbox)
omicData(omicData == -1) = NaN;
NaN_mask = any(~isnan(omicData), 2);
% Normalize omic data
omicDataNormalized = normalize(omicData(NaN_mask, :));
% Get the principal components
[coeff,pca_scores,latent,tsquared,explained,mu] = pca(omicDataNormalized);
scatter(pca_scores(:,1),pca_scores(:,2),"filled", "MarkerFaceColor", 'r')
%% ##########################
%% Graph controls
%% ##########################
abundanceTable_ctl = abundanceTable(:, 13:); % Only take control
expressionTable_ctl = expressionTable(:, 1:6); % Only take palmitate
% Make a single table
omicDataTable = [abundanceTable_ctl, expressionTable_ctl];
omicData = table2array(omicDataTable);
% Set -1 values to NaN (This is the meaning in cobratoolbox)
omicData(omicData == -1) = NaN;
NaN_mask = any(~isnan(omicData), 2);
% Normalize omic data
omicDataNormalized = normalize(omicData(NaN_mask, :));
% Get the principal components
[coeff,pca_scores,latent,tsquared,explained,mu] = pca(omicDataNormalized);
scatter(pca_scores(:,1),pca_scores(:,2), "x", "MarkerFaceColor", 'g')
legend('Palmitate', 'Tibolone', 'Control')