function  Denoise_digest(DataSet,Option)

switch  DataSet
    case 'Sequest'
        load SequestInformation; part = 8;
    case 'yeast' 
        load  YeastInformation.mat; part = 6;
    case 'tal'
        load  TalInformation.mat; part = 8;       
end
p0 = 0.4*1;
%estimation the noies level of the PSMs
[theta] = Split_theta(p0,X,Y,part);



P_Num = length(find(Y==1));
N_Num = length(find(Y==-1));

p1 = 0.1*1;

     p3 = 0.3;% [0 0.0001 0.001:0.003:0.007 0.01:0.01:0.15 0.155 0.16 0.17 0.18 0.19 0.2:0.1:0.9 0.99];
     p = p3;
     n = length(p3);

         [TP, FP, FDR2, TP_Protein, FP_Protein, TP_Label, FP_Label] = Split(p1,p,n,X,Y,protein,digest_index,theta,part);
         [m,n] = size(TP_Label); 
         TP_Full_Label = cell(1,n);
         FP_Full_Label = cell(1,n);
         TP_Half_Label = cell(1,n);
         FP_Half_Label = cell(1,n);
         TP_None_Label = cell(1,n);
         TP_Num = TP; FP_Num = FP;   
         
         TP_Full_Num = zeros(1,n); TP_Half_Num = zeros(1,n);TP_None_Num = zeros(1,n);
                 
         for p = 1:n
             p33 = p3(p);
         
         TP_Full_Label_temp = find(digest_index(TP_Label{1,p}) == 3);
         TP_Full_Label{1,p} = TP_Label{1,p}(TP_Full_Label_temp);
         TP_Full_Num(1,p) = length(TP_Full_Label_temp);
         TP_Half_Label_temp = find(digest_index(TP_Label{1,p}) == 1|digest_index(TP_Label{1,p}) == 2);
         TP_Half_Label{1,p} = TP_Label{1,p}(TP_Half_Label_temp);
         TP_Half_Num(1,p) = length(TP_Half_Label_temp);
         TP_None_Label_temp = find(digest_index(TP_Label{1,p}) == 0);
         TP_None_Label{1,p} = TP_Label{1,p}(TP_None_Label_temp);
         TP_None_Num(1,p) = length(TP_None_Label_temp);
         
         
         FP_Full_Label_temp = digest_index(FP_Label{1,p}) == 3;
         FP_Full_Label{1,p} = FP_Label{1,p}(FP_Full_Label_temp);
         FP_Half_Label_temp = digest_index(FP_Label{1,p}) == 1|digest_index(FP_Label{1,p}) == 2;
         FP_Half_Label{1,p} = FP_Label{1,p}(FP_Half_Label_temp);
         name = sprintf('%s%s%s%s%s%s%.4f.xls','E:\bioinfo\document\',DataSet,'\',Option,'\','MKp1_',p33);
         TP_temp = length(TP_Label{1,p});
         TP = cell(TP_temp,8);
             for ii = 1:TP_temp
                 TP{ii,1} = TP_Label{1,p}(ii);
                 for jj = 1:3
                    TP{ii,jj} = textdata{TP_Label{1,p}(ii),jj}; 
                 end
                 for kk = 4:8
                     TP{ii,kk} = X(TP_Label{1,p}(ii),kk-3);
                 end
             end
         xlswrite(name,TP,'TP');
         FP_temp = length(FP_Label{1,p});
         FP = cell(FP_temp,8);
         for ii = 1:FP_temp
                 FP{ii,1} = FP_Label{1,p}(ii);
                 for jj = 1:3
                    FP{ii,jj} = textdata{FP_Label{1,p}(ii),jj}; 
                 end
                 for kk = 4:8
                     FP{ii,kk} = X(FP_Label{1,p}(ii),kk-3);
                 end
         end
             if cellfun(@isempty, FP) == 0  
                 xlswrite(name,FP,'FP'); 
             end
         TP_Full_temp = length(TP_Full_Label{1,p});
         TP_Full = cell(TP_Full_temp,8);
             for ii = 1:TP_Full_temp
                 TP_Full{ii,1} = TP_Full_Label{1,p}(ii);
                 for jj = 1:3
                    TP_Full{ii,jj} = textdata{TP_Full_Label{1,p}(ii),jj}; 
                 end
                 for kk = 4:8
                     TP_Full{ii,kk} = X(TP_Full_Label{1,p}(ii),kk-3);
                 end
             end
             if cellfun(@isempty, TP_Full)==0  
                 xlswrite(name,TP_Full,'TP_Full'); 
             end
         FP_Full_temp = length(FP_Full_Label{1,p});   
         FP_Full = cell(FP_Full_temp,8);
            for ii = 1:FP_Full_temp
                 FP_Full{ii,1} = FP_Full_Label{1,p}(ii);
                 for jj = 1:3
                    FP_Full{ii,jj} = textdata{FP_Full_Label{1,p}(ii),jj}; 
                 end
                 for kk = 4:8
                     FP_Full{ii,kk} = X(FP_Full_Label{1,p}(ii),kk-3);
                 end
             end
        if cellfun(@isempty, FP_Full)==0  
                 xlswrite(name,FP_Full,'FP_Full'); 
        end
TP_Half_temp = length(TP_Half_Label{1,p});      
TP_Half = cell(TP_Half_temp,8);
             for ii = 1:TP_Half_temp
                 TP_Half{ii,1} = TP_Half_Label{1,p}(ii);
                 for jj = 1:3
                    TP_Half{ii,jj} = textdata{TP_Half_Label{1,p}(ii),jj}; 
                 end
                 for kk = 4:8
                     TP_Half{ii,kk} = X(TP_Half_Label{1,p}(ii),kk-3);
                 end
             end
              if cellfun(@isempty, TP_Half)==0  
                 xlswrite(name,TP_Half,'TP_Half'); 
              end
              
TP_Half_temp = length(TP_Half_Label{1,p});      
TP_Half = cell(TP_Half_temp,8);
             for ii = 1:TP_Half_temp
                 TP_Half{ii,1} = TP_Half_Label{1,p}(ii);
                 for jj = 1:3
                    TP_Half{ii,jj} = textdata{TP_Half_Label{1,p}(ii),jj}; 
                 end
                 for kk = 4:8
                     TP_Half{ii,kk} = X(TP_Half_Label{1,p}(ii),kk-3);
                 end
             end
              if cellfun(@isempty, TP_Half)==0  
                 xlswrite(name,TP_Half,'TP_Half'); 
              end
FP_Half_temp = length(FP_Half_Label{1,p});      
FP_Half = cell(FP_Half_temp,8);
             for ii = 1:FP_Half_temp
                 FP_Half{ii,1} = FP_Half_Label{1,p}(ii);
                 for jj = 1:3
                    FP_Half{ii,jj} = textdata{FP_Half_Label{1,p}(ii),jj}; 
                 end
                 for kk = 4:8
                     FP_Half{ii,kk} = X(FP_Half_Label{1,p}(ii),kk-3);
                 end
             end
              if cellfun(@isempty, FP_Half)==0  
                 xlswrite(name,FP_Half,'FP_Half'); 
              end
TP_None_temp = length(TP_None_Label{1,p});      
TP_None = cell(TP_None_temp,8);         
            for ii = 1:TP_None_temp
                 TP_None{ii,1} = TP_None_Label{1,p}(ii);
                 for jj = 1:3
                    TP_None{ii,jj} = textdata{TP_None_Label{1,p}(ii),jj}; 
                 end
                 for kk = 4:8
                     TP_None{ii,kk} = X(TP_None_Label{1,p}(ii),kk-3);
                 end
             end
         if cellfun(@isempty, TP_None)==0  
                 xlswrite(name,TP_None,'TP_None'); 
         end         

         end
         
   TP_Full = zeros(1,n);
   TP_Half = zeros(1,n);

 for ii = 1:n 
     
     TP_Full(1,ii) = length(TP_Full_Label{1,ii});
     TP_Half(1,ii) = length(TP_Half_Label{1,ii});
     
end

Digest_Nondigest = (TP_Full + TP_Half)./(TP_Num - TP_Full - TP_Half);


FP_TP = FP_Num./TP_Num;
TPR = TP_Num./P_Num;
FPR = FP_Num./N_Num;
FDR =  2*FP_Num./(TP_Num+FP_Num);
A = [TP_Num;FP_Num;FDR;FP_TP;TPR;FPR;FDR2;TP_Protein;FP_Protein;TP_Full_Num;TP_Half_Num;Digest_Nondigest];
results = sprintf('%s%s%s%s%s%s.xls','E:\bioinfo\document\',DataSet,'\',Option,'\','Results');
xlswrite(results,A,'Results');


