function [ successfulMCMC,successfulfreqpval ] = MCMCplotter(SNP, triallength, filename )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

successfulMCMC=0;
successfulfreq=0;
successfulfreqpval=0;

 for j =1:triallength
            
            trial_name1= num2str(j);
            new_filename1 = [filename trial_name1 ];
            
            load (new_filename1)
            
            sorted_TIM= sort(times_in_model,'descend');
            if(times_in_model(SNP)~=0)
            if ( times_in_model(SNP)==sorted_TIM(1)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(2)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(3)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(4)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(5)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(6)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(7)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(8)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(9)) 
                successfulMCMC= successfulMCMC+1;
            elseif ( times_in_model(SNP)==sorted_TIM(10)) 
                successfulMCMC= successfulMCMC+1;
            end
            end
            cases=ones(1000,1);
            controls=zeros(1000,1);
            indextocases=[cases; controls];
            glm_log_pvals=zeros(1,183);
           for l=1:183
               [glm_coeffs,dev,glm_stats]=glmfit(boot(:,l),indextocases,'binomial');
            glm_pvals=glm_stats.p;
            glm_log_pvals(l)=-log10(glm_pvals(2));
           end
           sorted_pvals=sort(glm_log_pvals,'descend');
           
         
            
            if ( glm_log_pvals(SNP)== sorted_pvals(1))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(2))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(3))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(4))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(5))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(6))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(7))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(8))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(9))
                successfulfreqpval=successfulfreqpval+1;
            elseif ( glm_log_pvals(SNP)== sorted_pvals(10))
                successfulfreqpval=successfulfreqpval+1;
            end
 end

end

