function [results,A_candidate,list_junction] = BLasso_whole_path_real_shortestpath_TSSPAS(TSS_PASs,tophat_exons,L,L1,N,N1,NN,...
                                                                               read_len,name,p)


m = length(L);
list_junction = [];


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Calculation using the proposed method
%generate the list of junctions
list_junction = [];
junction_threshold = max(max(N1)*5/100,1);
for i = 1:(m-1),
    for j = (i+1):m,
        temp_n = i-1;
        temp_n = (2*(m-1) - temp_n +1)* temp_n/2 + j - i;
        if (N1(temp_n) > junction_threshold)  %The threshold for a exon junction
            list_junction = [list_junction;i j N1(temp_n)];
        end
    end
end

    Adj = zeros(m);%start and end exons are the same.


    for i = 1:size(list_junction,1),
        Adj(list_junction(i,1),list_junction(i,2)) = 1;
    end
    
    
    for i = 1:(m-1),
        if (tophat_exons(i,2)==tophat_exons(i+1,1))
            Adj(i,i+1) = 1;
        end
    end

if m <80   
    %Adj = zeros(m);

    [ paths, num_paths_pairwise, num_paths_per_length] = find_all_graph_paths_original(Adj,'binary',0);
    indexs = [];
    
    indexs = TSS_PASs;

    A_candidate = [];
    for i =1:size(indexs,1),
        A_candidate = [A_candidate;paths{indexs(i,1),indexs(i,2)}];
    end
        
        
else  
    n_TSSPAS = size(TSS_PASs,1);
    A_candidate = [];
    for k=1:n_TSSPAS%iterate over all the start and end exons.
        start_exon=TSS_PASs(k,1);
        end_exon = TSS_PASs(k,2);
        if (end_exon-start_exon == 0)%only single exon to form an isoform
            A_candidate_temp = zeros(1,m);
            A_candidate_temp(start_exon) = 1;
            
            A_candidate = [A_candidate;A_candidate_temp];
        elseif end_exon-start_exon<10 %the number of exons in this isoform is smaller than 10
            Adj_temp = Adj(start_exon:end_exon,start_exon:end_exon);
            [ paths, num_paths_pairwise, num_paths_per_length] = find_all_graph_paths_original(Adj_temp,'binary',0);
            A_candidate = [A_candidate;[zeros(1,start_exon-1) paths{start_exon - start_exon+1,end_exon-start_exon+1} zeros(1,m-end_exon)]];
            
        else
        
            if isempty(list_junction)%if list_junction is empty
                for i = 1:(m-1)
                       if tophat_exons(i,2)==tophat_exons(i+1,1)%only two adjacent exons will connect
                            list_junction = [list_junction;i i+1 0.5];
                       end
                       
                end
            else
                for i = 1:(m-1)
                    if (sum((list_junction(:,1)==i + list_junction(:,2)==(i+1))==2)<1) && (tophat_exons(i,2)==tophat_exons(i+1,1))
                        list_junction = [list_junction;i i+1 0.5];

                    end
                end
            end

            list_junction = [list_junction;m m 0];
            max_weight = max(list_junction(:,3));
            graph_W = max_weight - list_junction(:,3);
            DG=sparse(list_junction(:,1),list_junction(:,2),graph_W);

            [a, shortest_path_result]=graphshortestpath(DG,start_exon,end_exon);
            A_candidate_temp = zeros(1,m);
            A_candidate_temp(shortest_path_result) = 1;
            A_candidate = [A_candidate;A_candidate_temp];
        end
    end
    


 end %%end of the generation of candidate isoforms use simple method
        
A_candidate = unique(A_candidate,'rows');        
A_candidate = A_candidate';



results=isoform_estimation_blasso_no_lock_p(A_candidate, L, L1, N, N1, NN, read_len, name,p);


