function [all_p] = SurvivalAnalysis()
clc;
clear all;
all_value=[];

plotDir=pwd;
%plotDirAllP= '../../Results/survival/4star/subtype/P/BL/'
%mkdir(plotDirAllP);
plotDirAllH= '../../Results/survival/tumor_denorm/'
mkdir(plotDirAllH);

[data1, str1] = xlsread('../../data/surv_denorm.xlsx', 'Denorm');
[data_cl, str_cl] = xlsread('../../data/denorm_STAD_survival_data.xlsx', 'Clinical');
[n d]=size(data1);
points=data1;
%mirnaTemp=str1(:,1);
%points=(2.^data1)-1;
mirnaTemp=str1(1,:)';
mirnas=mirnaTemp(2:d+1,1);
points_all=zeros(n,1);
fid = fopen('../../Results/survival/tumor_denorm/p-values-tumor.csv', 'w' );
  for i=1:d-1
    i
    % h = figure; 
    points_all = points(:,i);
    colmn_median = median(points_all);
    inx_down=find(points_all >= colmn_median);
    inx_up=find(points_all < colmn_median);
    
    low_risk=data_cl(inx_up,:);
    high_risk=data_cl(inx_down,:);

    low_exp=points_all(inx_up,:);
    high_exp=points_all(inx_down,:);
    exp_all=[low_exp;high_exp];

    % Days=[high_risk(:,2);low_risk(:,2)];
    % status=[high_risk(:,3);low_risk(:,3)];
    % [b,logL,H,stats] = coxphfit(log2(exp_all(:,1)),Days,'Censoring',status);
    % cox_coeff=stats.beta;
    % cox_pvalue=stats.p;
    % cox_data=[cox_coeff,cox_pvalue];
    % miRNA=source_files(l).name;
    strs = char(mirnas(i));
    [HR,p,h]=logrank(high_risk(:,2:3),low_risk(:,2:3));
    all_p(i,:)=p;
    all_HR(i,:)=HR;
    fprintf( fid, '%s,%d,%d\n', strs,p,HR );
    
    %list = strcat(num2str(p),'|',num2str(strs));
    %dlmwrite('p-values.txt',list,'delimiter',',','-append');
    %[Y,I] = sort(all_p);

    % imageFile = strcat(plotDirAll,num2str(p),'-',num2str(strs),'.pdf');
    % eval(['print -dpdf ' imageFile]);
    % eval(['print -depsc2 -painters ' num2str(strs) '.eps']);
    % imageFile = strcat(num2str(strs),'.jpeg');
    % print(h, '-depsc', imageFile);
    close(h);
  end
 fclose(fid);

[YP,I] = sort(all_p);
% for i=1:d-1
%     % h = figure; 
%     points_all = points(:,I(i));
%     colmn_median = median(points_all);
%     inx_down=find(points_all >= colmn_median);
%     inx_up=find(points_all < colmn_median);
%     
%     low_risk=data_cl(inx_up,:);
%     high_risk=data_cl(inx_down,:);
% 
%     low_exp=points_all(inx_up,:);
%     high_exp=points_all(inx_down,:);
%     exp_all=[low_exp;high_exp];
% 
%     % Days=[high_risk(:,2);low_risk(:,2)];
%     % status=[high_risk(:,3);low_risk(:,3)];
%     % [b,logL,H,stats] = coxphfit(log2(exp_all(:,1)),Days,'Censoring',status);
%     % cox_coeff=stats.beta;
%     % cox_pvalue=stats.p;
%     % cox_data=[cox_coeff,cox_pvalue];
%     % miRNA=source_files(l).name;
%     strs = char(mirnas(I(i)))
%     [rHR,rp,h]=logrank(high_risk(:,2:3),low_risk(:,2:3));
% 
%     %list = strcat(num2str(p),'|',num2str(strs));
%     %dlmwrite('p-values.txt',list,'delimiter',',','-append');
%     %[Y,I] = sort(all_p);
% 
%     imageFile = strcat(plotDirAllP,num2str(i),'-',num2str(rp),'-',num2str(rHR),'-',num2str(strs),'.pdf');
%     % eval(['print -dpdf ' imageFile]);
%     % eval(['print -depsc2 -painters ' num2str(strs) '.eps']);
%     % imageFile = strcat(num2str(strs),'.jpeg');
%     % print(h, '-depsc', imageFile);
%     close(h);
% end

  
[YH,H] = sort(all_HR,'descend');
for i=1:d-1
    i
    % h = figure; 
    points_all = points(:,H(i));
    colmn_median = median(points_all);
    inx_down=find(points_all >= colmn_median);
    inx_up=find(points_all < colmn_median);
    
    low_risk=data_cl(inx_up,:);
    high_risk=data_cl(inx_down,:);

    low_exp=points_all(inx_up,:);
    high_exp=points_all(inx_down,:);
    exp_all=[low_exp;high_exp];

    % Days=[high_risk(:,2);low_risk(:,2)];
    % status=[high_risk(:,3);low_risk(:,3)];
    % [b,logL,H,stats] = coxphfit(log2(exp_all(:,1)),Days,'Censoring',status);
    % cox_coeff=stats.beta;
    % cox_pvalue=stats.p;
    % cox_data=[cox_coeff,cox_pvalue];
    % miRNA=source_files(l).name;
    strs = char(mirnas(H(i)))
    [rHR,rp,h]=logrank(low_risk(:,2:3),high_risk(:,2:3));
    %fprintf( fid, '%s,%d,%d\n', strs, rp,rHR );
    %list = strcat(num2str(p),'|',num2str(strs));
    %dlmwrite('p-values.txt',list,'delimiter',',','-append');
    %[Y,I] = sort(all_p);

    imageFile = strcat(plotDirAllH,num2str(i),'-',num2str(YH(i)),'-',num2str(rp),'-',num2str(strs));
    %imageFile = strcat(plotDirAllH, num2str(strs));
    eval(['print -dpdf -painters ' imageFile '.pdf']);
    eval(['print -depsc2 -painters ' imageFile '.eps']);
    % imageFile = strcat(num2str(strs),'.jpeg');
    % print(h, '-depsc', imageFile);
    close(h);
end
  %fclose(fid);
end