-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMDS_19F_NMR.txt
169 lines (153 loc) · 5.19 KB
/
MDS_19F_NMR.txt
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
164
165
166
167
168
169
Multidimensional scaling Matlab script
%Depends on rbnmr.m to read in Bruker data directly
close all
clearvars
clc
addpath . %This should help with finding the file pathway name
%% Set up information
labels={"Apo", "chemical 1", "chemical 2"};%% Set up information
%% Read data with rbnmr
foldername = 'example_foldername';
A = rbnmr([foldername,'./'])
exptnum = length(labels)
z=cell2mat(A);
DataNum=length(A);
X=[z(1:DataNum).Data]; %Makes a matrix suitable for MDS and PCA
%%
xmin = -123
xmax = -128
X_axis = A{1,1}.XAxis
abs_diff_xmin = abs(X_axis-xmin)
abs_diff_xmax = abs(X_axis-xmax)
[q,d]=min(abs_diff_xmin)
[r,c]= min(abs_diff_xmax)
%%
Xx=X(d:c,:); %Extracts subset of data
XminPPM=A{1}.XAxis(d:c,:); %Extracts the ppm range
Xxx=(Xx(:,1))-(Xx); %Subtracts the control from other spectra
W=Xxx(:,2:exptnum); %delete zero
clear Xxx
clear DataNum
clear z
%%
% Creating a new folder for figures
figFolder = [foldername, '_figures'];
if ~exist(figFolder, 'dir')
mkdir(figFolder);
end
%% Plot Overlay of all real raw data
figure (1)
subplot(1,3,1)
set (gca, 'xdir', 'reverse')
hold on
for i=1:length(A)
plot(A{i}.XAxis, A{i}.Data,'LineWidth', 2)
end
%Note: The x-axis needs to be flipped in Matlab
title('Full Spectra')
ylabel('Intensity', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlabel(['^1^9F (ppm)'], 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlim([(A{1,1}.Procs.ABSF2) (A{1,1}.Procs.ABSF1)])
legend(labels(1,:))
%Note: The above sets the limits in ppm based on the first spectrum
hold off
subplot(1,3,2)
set ( gca, 'xdir', 'reverse' )
hold on
for i=1:length(A)
plot(XminPPM, Xx(:,i),'LineWidth', 2)
end
%Note: The x-axis needs to be flipped in Matlab
title('Spectral Region for Analysis')
ylabel('Intensity', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlabel(['^1^9F (ppm)'], 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlim([min(XminPPM) max(XminPPM)])
%Note: The above sets the limits in ppm based on the first spectrum
legend(labels(1,:))
hold off
subplot(1,3,3)
set ( gca, 'xdir', 'reverse' )
hold on
for i=1:length(A)-1
plot(XminPPM, W(:,i),'LineWidth', 2)
end
%Note: The x-axis needs to be flipped in Matlab
title('Difference Spectra for Analysis')
ylabel('Intensity', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlabel(['^1^9F (ppm)'], 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlim([min(XminPPM) max(XminPPM)])
legend(labels(1,:))
%Note: The above sets the limits in ppm based on the first spectrum
hold off
clear i
%Note: The imaginary data is located in: for i=1:length(A)
figure(1);
% ... (your plotting code here) ...
saveas(gcf, fullfile(figFolder, 'Figure1.pdf')); % Saving the figure
%Dissimilarity matrix generation for MDS preparation
Wmds1 = pdist(W.'); %This computes the Euclidean distance
%Note: a tranpose of W required
%classic MDS
[Y1,eigvals1]=cmdscale(Wmds1);
%% MDS
% mdscale(dissimilarities,2,'criterion','metricsstress');
[Y1a,stress1]=mdscale(Wmds1,2);
stress1;
%% Plot the cMDS values
figure (3)
subplot(1,2,1)
title('Full Spectra')
plot(Y1(:,1), Y1(:,2),'ok', 'MarkerFaceColor', 'red')
text(Y1(:,1), Y1(:,2), labels(2:end))
ylabel('cMDS2', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlabel(['cMDS1'], 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
subplot(1,2,2)
bar(eigvals1, 'red')
ylabel('Eigenvalue number', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlabel('Eigenvalue', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
figure(3);
% ... (your plotting code here) ...
saveas(gcf, fullfile(figFolder, 'Figure3.pdf')); % Saving the figure
%% Plot the cMDS values based on different pdiff functions
figure (4)
plot(Y1(:,1), Y1(:,2),'ok', 'MarkerFaceColor', 'red','MarkerSize',9)
text(Y1(:,1), Y1(:,2),labels(2:end))
ylabel('cMDS2', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlabel(['cMDS1'], 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
title('Euclidean')
figure(4);
% ... (your plotting code here) ...
saveas(gcf, fullfile(figFolder, 'Figure4.pdf')); % Saving the figure
%% Goodness of cMDS
figure (5)
bar(eigvals1, 'red')
ylabel('Eigenvalue number', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlabel('Eigenvalue', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
title('Euclidean')
figure(5);
% ... (your plotting code here) ...
saveas(gcf, fullfile(figFolder, 'Figure5.pdf')); % Saving the figure
%% Plot the cMDS values based on different pdiff functions
figure (6)
plot(Y1a(:,1), Y1a(:,2),'ok', 'MarkerFaceColor', 'red','MarkerSize',9)
text(Y1a(:,1), Y1a(:,2), labels(2:end))
ylabel('MDS2', 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
xlabel(['MDS1'], 'Interpreter', 'tex', ...
'FontName', 'Arial','Fontsize',18)
title('Euclidean')
saveas(gcf, fullfile(figFolder, 'Figure6.pdf')); % Saving the figure