% This function converts the five text files obtained from Glimmer website 
% to corresponding cell arrays so as to be manipulated within MATLAB. The 
% five text files are:
% f1.txt    (.fna)	genome fasta sequence  (The wole genome)
% f2.txt    (.ffn)	protein coding portions of the genome segments (The set of all
%                   coding regions)
% f3.txt    (.ptt)	protein table
% f4.txt            GeneMark predictions
% f5.txt            Glimmer gene predictions

% In order to use this funtion the original text files have to be renamed
% as above and all saved in the same directory where this fucntion is
% saved.

% The output parameters are:
% DNA   : The whole genome sequence in a cell array.
% AGL   : Actaul Gene Locations
% GGL   : Glimmer Gene Locations
% GMGL  : GeneMark Gene Locations
% HGGL  : Hypothetical Glimmer Gene Locations. i.e. the set of gene predictions 
%         that are not in the Actual Gene Locations (AGL).
% HGMGL : Hypothetical GeneMark Gene Locations. i.e. the set of gene predictions 
%        obtained from GeneMark software that are not in the Actual Gene Locations (AGL). 
% ORFGL : Open Reading Frame Gene Locations. i.e. The set of all possible
%         genes that are more than 99 bases long and have a valid start and stop
%         codons.
% NTGL  : Non-Translated Gene Locations. i.e. the set of ORFs (Open Reading
%         Frames (i.e. ORFGL) that are neither in AGL nor in GGL nor in GMGL.
%         i.e. NTGL = ORFGL - AGL - GGM - GMGL.
% genelocation: the set of all genes locations (start, stop, orientation, ... ) 
%         after locating them in the original DNA sequence.
% genes: The set of gene sequences (Coding region sequences).


function [DNA,AGL,GGL,GMGL,genelocation,genes,HGGL,HGMGL,ORFGL,NTGL] = txt2cell(f1,f2,f3,f4,f5)
% To call this function use the following:
% [DNA,AGL,GGL,GMGL,genelocations,genes,HGGL,HGMGL,ORFGL,NTGL] = txt2cell('f1.txt','f2.txt','f3.txt','f4.txt','f5.txt')
% First rename the following files as
% X.fna.txt = f1.txt
% X.ffn.txt = f2.txt
% X.ptt.txt = f3.txt
% X.GeneMarkHMM-2.6r.txt = f4.txt
% X.Glimmer3.txt = f5.txt

DNA = fna2DNA(f1);
genes = ffn2genes(f2);
AGL = ptt2AGL(f3);
GMGL = GM2GMGL(f4);
GGL = G2GGL(f5);
locategenes;
[HGMGL,HGGL] = Hypothetical(AGL,GGL,GMGL);
ORFGL = ORF(DNA);
NTGL = Nontranslated(AGL,GGL,GMGL,ORFGL);



% save the output variable in a *.mat file