function assigns_text = textify_assigns_TCR_Mus(assigns, V, D, J, genV, genD, genJ, Sequence)

% Now to display the details of the leading assignments
% particular assignments; start with highest proba
assigns_text = cell(assigns.n_assignments,1);
[B,IX] = sort(assigns.proba,'descend');
disp(Sequence);
for i = 1:assigns.n_assignments
    index = IX(i);   % We want to display results in order of proba.
    
    % There has to be a better way to create the following struct
    proba = assigns.proba(index);
    VDJ = assigns.VDJ (index,:);
    % Where did this variable go ...
    %algn_inds = assigns.algn_inds(index,:);  % This just tells me where I am in the alignment
    x = fieldnames(assigns);
    pVdelV = assigns.pVdelV(index,:);
    pDldelDl = assigns.pDldelDl(index,:);
    pDrdelDr = assigns.pDrdelDr(index,:);
    pJdelJ = assigns.pJdelJ(index,:);
    insVD = assigns.insVD(index,:);
    insDJ = assigns.insDJ(index,:);
    if find(ismember(x,'dinucleotideVD'))~=0
        dinucVD = assigns.dinucleotideVD(index,:);
        dinucDJ = assigns.dinucleotideDJ(index,:);
    elseif find(ismember(x,'nucleotideVD'))~=0
        dinucVD = assigns.nucleotideVD(index,:);
        dinucDJ = assigns.nucleotideDJ(index,:);
    end
    
    % Now capture the particular alignment index for this assignment
%     v = algn_inds(1);
%     d = algn_inds(2);
%     j = algn_inds(3);
    
    v = assigns.v_alignment_index(index);
    j = assigns.j_alignment_index(index);
    n_d_alignment = assigns.d_alignment_index(index,1);
    d = assigns.d_alignment_index(index,2);
    
    
    % Here are the raw alignment lengths
    v_len = V.align_length(v);
    d_len = D.align_length(n_d_alignment, d);
    j_len = J.align_length(j);
    
    % Here are the min deletions for this alignment
    minVdel = V.min_deletions(v);
%     minDdel_l = D.min_deletions_left(d);
%     minDdel_r = D.min_deletions_right(d);
    minDdel_l = D.deletions_left(n_d_alignment, d);    % These two lines may be wrong
    minDdel_r = D.deletions_right(n_d_alignment, d);
    minJdel = J.min_deletions(j);
    
    % Here are the insertions for this alignment assignment
    vd_ins = insVD -1;  % for convenience these indices were shifted by one
    dj_ins = insDJ -1;
    
    % Here are the palindrome counts for this alignment assignment
    v_pal = pVdelV(1) - 1; % half-length of any palindromes
    j_pal = pJdelJ(1) - 1;
    dl_pal = pDldelDl(1) -1;
    dr_pal = pDrdelDr(1) -1;
        
    v_del = (pVdelV(2) - 1);
    j_del = (pJdelJ(2) - 1);
    dl_del = (pDldelDl(2) -1);
    dr_del = (pDrdelDr(2) -1);

    % How much have the minimum alignments been chewed away
    
    
    v_excess_del = (pVdelV(2) - 1) - minVdel;
    j_excess_del = (pJdelJ(2) - 1) - minJdel;
    
    if d_len>0
        dl_excess_del = (pDldelDl(2) -1) - minDdel_l;
        dr_excess_del = (pDrdelDr(2) -1) - minDdel_r;
        VJ_overlap = 0;
    else
        dl_excess_del = 0;
        dr_excess_del = 0;
        VJ_overlap = max(0,v_len - v_excess_del + j_len  - j_excess_del - 60);
    end        
    
    checksum = (v_len - v_excess_del) + v_pal + vd_ins + dl_pal + (d_len - dl_excess_del - dr_excess_del) ...
        + dr_pal + dj_ins + j_pal + (j_len - j_excess_del) - VJ_overlap;
    
    assigns_text{i} = [repmat('V',1,v_len-v_excess_del-VJ_overlap) repmat('O',1,VJ_overlap) repmat('P',1,v_pal) repmat('I',1,vd_ins) ...
       repmat('P',1,dl_pal) repmat('D',1,d_len-dl_excess_del - dr_excess_del) repmat('P',1,dr_pal) ...
       repmat('I',1,dj_ins) repmat('P',1,j_pal) repmat('J',1,j_len-j_excess_del-VJ_overlap) ' ' genV(VDJ(1)).gene ' ' genD(VDJ(2)).gene ' ' genJ(VDJ(3)).gene ...
       ' | ' num2str(v_del,'%02d') ' ' num2str(dl_del,'%02d') ' ' num2str(dr_del,'%02d') ' ' num2str(j_del,'%02d') ' | ' ...
       num2str(vd_ins,'%02d') ' ' num2str(dj_ins,'%02d') ' | ' num2str(v_pal,'%02d') ' ' num2str(dl_pal,'%02d') ' ' num2str(dr_pal,'%02d') ' ' num2str(j_pal,'%02d')...
       ' | ' num2str(proba,'%6.4e') ' ' num2str(VJ_overlap,'%02d')];
  %comment out the following if you are not concerned with dinucleotides  
   assigns_text{i} = [repmat('V',1,v_len-v_excess_del-VJ_overlap) repmat('O',1,VJ_overlap) repmat('P',1,v_pal) repmat('I',1,vd_ins) ...
       repmat('P',1,dl_pal) repmat('D',1,d_len-dl_excess_del - dr_excess_del) repmat('P',1,dr_pal) ...
       repmat('I',1,dj_ins) repmat('P',1,j_pal) repmat('J',1,j_len-j_excess_del-VJ_overlap)  ...
       ' |' num2str(vd_ins,'%02d') ' ' num2str(dj_ins,'%02d') ' |' num2str(dinucVD,'%d') '| ' num2str(proba,'%6.4e') ];
  
    if (checksum~=60) 
        disp(['checksum failure:' num2str(checksum) ' at assign number ' num2str(i)]);
        X = [length(genD(VDJ(2)).seq) , d_len, dl_del, dr_del, dl_excess_del, dr_excess_del];
        disp(X);
%         v_len
%         j_len
%         d_len
%         v_del
%         j_del
%         dl_del
%         dr_del
%         v_excess_del
%         j_excess_del
%         dl_excess_del
%         dr_excess_del
%         v_pal
%         dl_pal
%         dr_pal
%         j_pal       
%         VJ_overlap
        %break
    end;
   
    % if all is well, we want to display the whole thing visually:
    %assert(checksum==60)
    disp([assigns_text{i} ' ' num2str(checksum) ]);
%      X = [length(genD(VDJ(2)).seq) , d_len, dl_del, dr_del];
%         disp(X);
     
end




