clc
clear
close all
%%%%%%%%%%%%%%%排序理化特征%%%%%%%%%%%%%%%%%
load aaindex2.mat
load Positive.mat;
load Negative.mat;
% % window=7;
% label=[];
% for i=1:size(positive,1)
%     label=[label;1];
% end
% for i=1:size(negative,1)
%     label=[label;-1];
% end
% % sample=[positive(:,(16-window):(16+window));negative(:,(16-window):(16+window))];
% sample=[positive;negative];
% num=size(sample,1);
% D=size(sample,2);
% letter=['A','R','N','D','C','Q','E','G','H','I','L','K','M','F','P','S','T','W','Y','V'];
% n=size(aaindex1,1);
% fitness=[];
% for i=1:n
%     aar=[];
%     for j=1:num
%         temp=[];
%         for k=1:D
%             index=find(letter(1,:)==sample(j,k));
%             if ~isempty(index)
%                 temp=[temp aaindex1(i,index)];
%             else
%                 temp=[temp 0];
%             end
%         end
%         aar=[aar;temp];
%     end
%     aar=zscore(aar);
%     auc = plotrocs(label, aar ,'-v 10');
%     fitness=[fitness auc];
% end
% [result index]=sort(fitness,'descend');
% phy=index;
% save('phyindex.mat','phy');
% save('label.mat','label');
% %%%%%%%%%%%%%%%%%样本的理化属性提取%%%%%%%%%%%%
% num=size(positive,1);
% m=size(negative,1);
% D=size(positive,2);
% threod=20;
% letter=['A','R','N','D','C','Q','E','G','H','I','L','K','M','F','P','S','T','W','Y','V'];
% phychemical=[];
% for i=1:threod
%     aar=[];
%     for j=1:num
%         temp=[];
%         for k=1:D
%             index=find(letter(1,:)==positive(j,k));
%             if ~isempty(index)
%                 temp=[temp aaindex1(phy(1,i),index)];
%             else
%                 temp=[temp 0];
%             end
%         end
%         aar=[aar;temp];
%     end
%     for j=1:m
%         temp=[];
%         for k=1:D
%             index=find(letter(1,:)==negative(j,k));
%             if ~isempty(index)
%                 temp=[temp aaindex1(phy(1,i),index)];
%             else
%                 temp=[temp 0];
%             end
%         end
%         aar=[aar;temp];
%     end
%     phychemical(:,:,i)=aar;
% end
% save('phychemical.mat','phychemical');
%%%%%%%%%%%%
load phychemical.mat;
load phychedata.mat;
load phyindex.mat;
% strchar=[];
% strchar(1).name='QIAN'
%%%%%%%%%%%%%%phyplot%%%%%%%%%%%%%%%%%%%%
threod=20;
window=15;
n=size(positive,1);
m=size(negative,1);
D=size(positive,2);
total=size(phychemical,1);
% position=[0.02 1/3 1/3 1/3;1/3+0.02 1/3 1/3 1/3;2/3 1/3 1/3 1/3;0.02   2/3  1/3  1/3;1/3 2/3  1/3  1/3;2/3 2/3  1/3  1/3;0.02   3/3  1/3  1/3;1/3 3/3  1/3  1/3;2/3 3/3  1/3  1/3]
% position=[0.02 1/3 1/3 1/3;1/3 1/3 1/3 1/3;2/3 1/3 1/3 1/3;0   2/3  1/3  1/3;1/3 2/3  1/3  1/3;2/3 2/3  1/3  1/3;0   3/3  1/3  1/3;1/3 3/3  1/3  1/3;2/3 3/3  1/3  1/3]
%  figure;
sub_row = 3; % 子图行数
sub_col = 3; % 子图列数
order=[];
k=1;
 for i_row = 1 : sub_row
      for j_col = 1 : sub_col
           order = (i_row-1)*sub_col+j_col; % 子图的顺序
            Psm=zeros(1,D);
    Nsm=zeros(1,D);
    for i=1:D
        for j=1:n
          Psm(1,i)=Psm(1,i)+phychemical(j,i,k);
        end
    end
    Psm=Psm./n;
    for i=1:D
        for j=(n+1):total
          Nsm(1,i)=Nsm(1,i)+phychemical(j,i,k);
        end
    end
    Nsm=Nsm./m;
    subplot(sub_row, sub_col, order);
    x1=(-window):-1;
    x2=1:window;
    plot(x1,Psm(1:window),'ro-','MarkerFaceColor','r','LineWidth',1);
    box off;
    hold on
    plot(x1,Nsm(1:window),'ks-','MarkerFaceColor','k','LineWidth',1);
     box off;
    hold off
    hold on
    plot(x2,Psm((window+2):end),'ro-','MarkerFaceColor','r','LineWidth',1);
     box off;
    hold off
    hold on
    plot(x2,Nsm((window+2):end),'ks-','MarkerFaceColor','k','LineWidth',1);
     box off;
    xlabel('Site');
    ylabel('Mean');
    title(phychedata(phy(1,k)).name);
    str={'Glycation' 'Non-glycation'};
    legend(str);
    hold off
     RemoveSubplotWhiteArea(gca, sub_row, sub_col, i_row, j_col); % 去除空白部分
      end
 end
for k=1:9%threod
    Psm=zeros(1,D);
    Nsm=zeros(1,D);
    for i=1:D
        for j=1:n
          Psm(1,i)=Psm(1,i)+phychemical(j,i,k);
        end
    end
    Psm=Psm./n;
    for i=1:D
        for j=(n+1):total
          Nsm(1,i)=Nsm(1,i)+phychemical(j,i,k);
        end
    end
    Nsm=Nsm./m;
%     figure;
%     subplot(3,3,k);
%     subplot('position',position(k,:));
    subplot(3, 3, order(k));
    x1=(-window):-1;
    x2=1:window;
    plot(x1,Psm(1:window),'ro-','MarkerFaceColor','r','LineWidth',1);
    box off;
    hold on
    plot(x1,Nsm(1:window),'ks-','MarkerFaceColor','k','LineWidth',1);
     box off;
    hold off
    hold on
    plot(x2,Psm((window+2):end),'ro-','MarkerFaceColor','r','LineWidth',1);
     box off;
    hold off
    hold on
    plot(x2,Nsm((window+2):end),'ks-','MarkerFaceColor','k','LineWidth',1);
     box off;
    xlabel('Site');
    ylabel('Mean');
    title(phychedata(phy(1,k)).name);
    str={'Glycation' 'Non-glycation'};
    legend(str);
    hold off
    RemoveSubplotWhiteArea(gca, 3, 3, i_row, j_col); % 去除空白部分
end
% str=[];
% for i=1:threod
%     str=[str;phychedata(phy(1,i)).name];
% end