%mMasterParser_original.m
motifs={'marismortui_1850_1881'};

for mot=1:length(motifs)

    Filename = strcat(motifs{mot},'.mat');

    % if exist(Filename,'file') > 0,            % load previous work, if it exists
    %   load(Filename);
    %   k = k + 1;                              % go to next sequence
    %   fprintf('Loaded previous computations\n');
    % else                                      % define model, load sequences

    % -----------------------------------------
    clear Node
    %Nodes_23S_1850_1881
    eval(['Nodes_',motifs{mot}])
    mpErrorCheck
    %     FastaPath='C:\AliRes\_MatlabWork\MATLAB programs\Alignment_Analysis\_TripleAlignmentAnalysis\Alignment_Parser\16S_Sequences\FastaExtracts\';
    %     FastaFilename=strcat(FastaPath,'16SelectedABEAllEc_',motifs{mot},'.fasta');
    FastaPath='C:\AliRes\_MatlabWork\MATLAB programs\Alignment_Analysis\FASTA_alignments\';
    FastaFilename=strcat(FastaPath,'23S_ABE_2004_UNIQUE.mat_extract_Archaea_Haloarcula_',motifs{mot},'.fasta');
    clear Sequence
    Sequence = pReadFASTA(FastaFilename);
    % -----------------------------------------

    k = 1;
    % end

    numtodo = 100;

    for j=k:min(length(Sequence),(k+numtodo-1)),
        [Node,Sequence] = pParseSequences(Node,Sequence,j,j);
        k = j;
        drawnow
        %   if mod(j,10) == 0,
        %     pDisplayMultipleAlignment(1,Node,Sequence);
        %     save(Filename,'Node','Sequence','k');
        %   end
    end

    ind= findstr('.',FastaFilename);
    RealignedFastaFilename = strcat(FastaFilename(1:ind(length(ind))-1),'_Realigned.fasta');
    fidOUT = fopen(RealignedFastaFilename,'w+');
    mpDisplayMultipleAlignment(fidOUT,Node,Sequence);%%%Ali, this will print all at once and only once
    save(Filename,'Node','Sequence','k');
    fclose(fidOUT);
    % save(Filename,'Node','Sequence','k');

    return

    for j=1:length(Sequence),
        %   fprintf('%s %s\n', Sequence(j).Fasta(6206:6311),Sequence(j).Organism);
        fprintf('%s %s\n', Sequence(j).Fasta,Sequence(j).Organism);
    end

end
