%SUMMARY
%- ABSTRACT
%- INTRODUCTION
%# BASICS
%- \acs{DNA} STRUCTURE
%- DATA TYPES
% - BAM/FASTQ
% - NON STANDARD
%- COMPRESSION APPROACHES
% - SAVING DIFFERENCES WITH GIVEN BASE \acs{DNA}
% - HUFFMAN ENCODING
% - PROBABILITY APPROACHES (WITH BASE?)
%
%# COMPARING TOOLS
%- 
%# POSSIBLE IMPROVEMENT
%- \acs{DNA}S STOCHASTICAL ATTRIBUTES 
%- IMPACT ON COMPRESSION

\chapter{Compression aproaches}
% begin with entropy encoding/shannons source coding theorem

The process of compressing data serves the goal to generate an output, that is smaller than its input. In many cases, like in gene compressing, the compression is idealy lossless. This means it is possible with any compressed data, to receive the full information that were available in the origin data, by decompressing it. Lossy compression on the other hand, might excludes parts of data in the compression process, in order to increase the compression rate. The excluded parts are typicaly not necessary to transmit the origin information. This works with certain audio and pictures files or with network protocols which are used to transmit video/audio streams live.\\
For storing \acs{DNA} a lossless compression is needed. To be preceice a lossy compression is not possible, because there is no unnecessary data. Every nucleotide and its exact position is needed for the sequence to be complete and usefull.\\

\section{Arithmetic coding}
Arithmetic coding is an approach to solve the problem of waste of memory, due to the overhead which is created by encoding certain lenghts of alphabets in binary. Encoding a three-letter alphabet requires at least two bit per letter. Since there are four possilbe combinations with two bits, one combination is left unused. So the full potential is not exhausted. Looking at it from another perspective, less storage would be required, if it would be possible to encode two letters with one bit and the other one with a combination of two bits. This approache is not possible because the letters would not be clearly distinguishable. The two bit letter could be interpreted as two one bit letters rather than the letter it should represent.
% check this wording 'simulating' with sources 
% this is called subdividing
Arithmetic coding works by simulating a n-letter binary encoding for a n-letter alphabet. This is possible by projecting the input text on a floatingpoint number. Every character in the alphabet is represented by an interval between two floating point numbers between 0.0 and 1.0 (exclusively). This interval is determined by its distribution in the input text (interval start) and the the start of the next character (interval end).\\
To encode a sequence of characters, the interval start of the first character is noted, its interval is split into smaller intervals, mapping the ratios of the initial intervals between 0.0 and 1.0. In this smaller distribution the interval representing the second character is choosen. This process is repeated for until a interval for the last character is determined.\\
% explain abstract ussage to show the goal of splitting intervals
To encode in binary, the floating point representation of a number inside the interval, for the last character is calculated. This is done by using a similar process to the one described above, called subdividing.
% its finite subdividing because processors bottleneck floatingpoints 

\section{Huffman encoding}
% list of algos and the tools that use them
The well known Huffman coding, is used in several Tools for genome compression. This subsection should give the reader a general impression how this algorithm works, without going into to much details. To use Huffman coding one must first define an alphabet, in our case a four letter alphabet, containing \texttt{A, C, G and T} is sufficient. The basic structure is symbolized as a tree. With that, a few simple rules apply to the structure:
% binary view for alphabet
% length n of sequence to compromize
% greedy algo
\begin{itemize}
  \item every symbol of the alphabet is one leaf.
  \item the right branch from every node is marked as a 1, the left one is marked as a 0.
  \item every symbol got a weight, the weight is defined by the frequency the symbol occours in the input text just like in the section Arithmetic coding.
  \item the less weight a node has, the higher the probability is, that this node is read next in the symbol sequence.
\end{itemize}
The process of compressing starts with the nodes that has the lowest weight and stepwise builds up to the hightest. Each step adds nodes to a tree where the most left branch should be the shortest and the most right the longest. The most left branch ends with the symbol that has the highest weight, therefore occours the most in the input data.\\
Following one path results in the binary representation for one symbol. For an alphabet like the one described above, the binary representation encoded in \ac{ascii} is shown here \texttt{A -> 01000001, C -> 01000011, G -> 01010100, T -> 00001010}. An imaginary sequence, that contains a distribution of characters like the following \texttt{A -> 10, C -> 8, G -> 4, T -> 2}. From this information a weighting would be calculated for each character by dividing one by the characters occurence. With a corresponding tree, build from the weights, the binary data for each symbol would change to this \texttt{A -> 0, C -> 11, T -> 100, G -> 101}.\\
Besides the compressed data, the information contained in the tree msut be saved for the decompression process.

% (genomic squeeze <- official | inofficial -> GDC, GRS). Further \ac{ANS} or rANS ... TBD.
\subsection{LZ77}
\ac{LZ77} basically works, by removing all repetition of a string or substring and replacing them with information where to find the first occurence and how long it is. Typically it is stored in two bytes, whereby more than one one byte can be used to point to the first occurence because usually less than one byte is required to store the length.

\section{DEFLATE}
% mix of huffman and lz77
The DEFLATE compression algorithm combines \ac{lz77} and huffman coding. It is used in well known tools like gzip.
