k4_algorithms.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. %SUMMARY
  2. %- ABSTRACT
  3. %- INTRODUCTION
  4. %# BASICS
  5. %- \acs{DNA} STRUCTURE
  6. %- DATA TYPES
  7. % - BAM/FASTQ
  8. % - NON STANDARD
  9. %- COMPRESSION APPROACHES
  10. % - SAVING DIFFERENCES WITH GIVEN BASE \acs{DNA}
  11. % - HUFFMAN ENCODING
  12. % - PROBABILITY APPROACHES (WITH BASE?)
  13. %
  14. %# COMPARING TOOLS
  15. %-
  16. %# POSSIBLE IMPROVEMENT
  17. %- \acs{DNA}S STOCHASTICAL ATTRIBUTES
  18. %- IMPACT ON COMPRESSION
  19. \newcommand{\mycomment}[1]{}
  20. % entropie fim doku grundlagen2
  21. % dna nucleotide zu einem kapitel -> structure of dna. auch kapitel wegstreichen (zu generisch)
  22. % file structure/format <-> datatypes. länger beschreiben: e.g. File formats to store dna
  23. % 3.2.1 raus
  24. \section{Compression aproaches}
  25. The process of compressing data serves the goal to generate an output that is smaller than its input data. In many cases, like in gene compressing, the compression is idealy lossless. This means it is possible for every 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 network protocols that are used to transmit video/audio streams live.
  26. For \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 position is needed for the sequenced \acs{DNA} to be complete. For lossless compression two mayor approaches are known: the dictionary coding and the entropy coding. Both are described in detail below.\\
  27. \subsection{Dictionary coding}
  28. Dictionary coding, as the name suggest, uses a dictionary to eliminate redundand occurences of strings. Strings are a chain of characters representing a full word or just a part of it. This is explained shortly for a better understanding of dictionary coding but is of no great relevance to the focus of this work:
  29. % exkurs
  30. Looking at the string 'stationary' it might be smart to store 'station' and 'ary' as seperate dictionary enties. Which way is more efficient depents on the text that should get compressed.
  31. % end exkurs
  32. The dictionary should only store strings that occour in the input data. Also storing a dictionary in addition to the (compressed) input data, would be a waste of resources. Therefore the dicitonary is made out of the input data. Each first occourence is left uncompressed. Every occurence of a string, after the first one, points to its first occurence. Since this 'pointer' needs less space than the string it points to, a decrease in the size is created.\\
  33. Unfortunally, known implementations like the ones out of LZ Family, do not use probabilities to compress and are therefore out of scope for this work. Since finding repetations and their location might also be improved, this chapter will remain.
  34. % unuseable due to the lack of probability
  35. \mycomment{
  36. % - known algo
  37. \subsubsection{The LZ Family}
  38. The computer scientist Abraham Lempel and the electrical engineere Jacob Ziv created multiple algorithms that are based on dictionary coding. They can be recognized by the substring \texttt{LZ} in its name, like \texttt{LZ77 and LZ78} which are short for Lempel Ziv 1977 and 1978. The number at the end indictates when the algorithm was published. Today LZ78 is widely used in unix compression solutions like gzip and bz2. Those tools are also used in compressing \ac{DNA}.\\
  39. \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.\\
  40. % example
  41. }
  42. \subsection{Shannons Entropy}
  43. The founder of information theory Claude Elwood Shannon described entropy and published it in 1948 \autocite{Shannon_1948}. In this work he focused on transmitting information. His theorem is applicable to almost any form of communication signal. His findings are not only usefull for forms of information transmition.
  44. % todo insert Fig. 1 shannon_1948
  45. Altering this figure shows how it can be used for other technology like compression.\\
  46. The Information source and destination are left unchanged, one has to keep in mind, that it is possible that both are represented by the same phyiscal actor.
  47. transmitter and receiver are changed to compression/encoding and decompression/decoding and inbetween ther is no signal but any period of time \autocite{Shannon_1948}.\\
  48. Shannons Entropy provides a formular to determine the 'uncertainty of a probability distribution' in a finite field.
  49. %H(X) \defd \Sum{x\in X, prob(x)\neq0}{}{prob(x) * log_2(frac{1}{prob(x)})} \equiv - \Sum { x\in X, prob(x)\neq0 } {} {prob(x) * log_2 (prob(x))}.
  50. \begin{figure}[H]
  51. \centering
  52. \includegraphics[width=12cm]{k4/shannon_entropy.png}
  53. \caption{Shannons definition of entropy.}
  54. \label{k4:entropy}
  55. \end{figure}
  56. He defined entropy as shown in figure \ref{k4:entropy}. Let X be a finite probability space. Then x in X are possible final states of an probability experimen over X. Every state that actually occours, while executing the experiment generates infromation which is meassured in \textit{Bits} with the part of the formular displayed in \ref{k4:info-in-bits}\autocite{delfs_knebl,Shannon_1948}:
  57. %\bein{math}
  58. % log_2(frac{1}{prob(x)}) \equiv - log_2(prob(x)).
  59. %\end{math}
  60. \begin{figure}[H]
  61. \centering
  62. \includegraphics[width=8cm]{k4/information_bits.png}
  63. \caption{The amount of information measured in bits, in case x is the end state of a probability experiment.}
  64. \label{k4:info-in-bits}
  65. \end{figure}
  66. %todo explain 2.2 second bulletpoint of delfs_knebl. Maybe read gumbl book
  67. %This can be used to find the maximum amount of bits needed to store information.\\
  68. % alphabet, chain of symbols, kurz entropy erklären
  69. \subsection{Arithmetic coding}
  70. Arithmetic coding is an approach to solve the problem of wasting memeory 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 not used, so the full potential is not exhausted. Looking at it from another perspective, less storage would be required, if there would be a possibility to encode two letters in the alphabet with one bit and the other one with a two byte combination. This approache is not possible because the letters would not be clearly distinguishable. The two bit letter could be interpreted either as the letter it should represent or as two one bit letters.
  71. % check this wording 'simulating' with sources
  72. % this is called subdividing
  73. Arithmetic coding works by translating a n-letter alphabet into a n-letter binary encoding. This is possible by projecting the input text on a floatingpoint number. Every character in the alphabet is represented by an intervall between two floating point numbers in the space between 0.0 and 1.0 (exclusively). This intervall is determined by its distribution in the input text (intervall start) and the the start of the next character (intervall end). To encode a sequence of characters subdividing is used.
  74. % exkurs on subdividing?
  75. This means the intervall start of the character is noted, its intervall is split into smaller intervalls with the ratios of the initial intervalls between 0.0 and 1.0. With this, the second character is choosen. This process is repeated for until a intervall for the last character is choosen.\\
  76. To encode in binary, the binary floating point representation of a number inside the intervall, for the last character is calculated, by using a similar process, described above, called subdividing.
  77. % its finite subdividing because processors bottleneck floatingpoints
  78. % (genomic squeeze <- official | inofficial -> GDC, GRS). Further \ac{ANS} or rANS ... TBD.
  79. \subsection{\ac{LZ77}}
  80. \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.
  81. \subsection{Huffman encoding}
  82. % list of algos and the tools that use them
  83. 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 detail. 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:
  84. % binary view for alphabet
  85. % length n of sequence to compromize
  86. % greedy algo
  87. \begin{itemize}
  88. \item every symbol of the alphabet is one leaf
  89. \item the right branch from every not is marked as a 1, the left one is marked as a 0
  90. \item every symbol got a weight, the weight is defined by the frequency the symbol occours in the input text
  91. \item the less weight a node has, the higher the probability is, that this node is read next in the symbol sequence
  92. \end{itemize}
  93. The process of compressing starts with the nodes with the lowest weight and buids 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 with the highest weight, therefore occours the most in the input data.
  94. Following one path results in the binary representation for one symbol. For an alphabet like the one described above, the binary representation encoded in ASCI is shown here \texttt{A -> 01000001, C -> 01000011, G -> 01010100, T -> 00001010}. An imaginary sequence, that has this distribution of characters \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, created from with 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.
  95. \section{DEFLATE}
  96. % mix of huffman and lz77
  97. The DEFLATE compression algorithm combines \ac{lz77} and huffman coding. It is used in well known tools like gzip.
  98. \subsubsection{misc}
  99. %check if (small) text coding is done with this:
  100. Arithmetic Asymmetric numeral systems ?
  101. Modified -> used in cram
  102. \section{Implementations in Relevant Tools}
  103. \subsection{} % geco
  104. \subsection{} % genie
  105. \subsection{} % samtools
  106. \mycomment{
  107. \subsection{\ac{CABAC}}
  108. % a form of entropy coding
  109. % https://en.wikipedia.org/wiki/Context-adaptive_binary_arithmetic_coding
  110. \section{Implementations}
  111. % SAM - LZ4 src: https://github.com/lz4/lz4/blob/dev/doc/lz4_Block_format.md
  112. % GeCo - arithmetic coding
  113. % Genie - CABAC
  114. % following text is irelevant. Just describe used algorithms in comparison chapter and refere to their base algo
  115. % mix of Huffman and lz77
  116. The DEFLATE compression algorithm combines \ac{LZ77} and Huffman coding. To get more specific, the raw data is compressed with \ac{LZ77} and remaining data is shortened by using Huffman coding.
  117. % huffman - little endian
  118. % lz77 compressed - big endian (least significant byte first/most left)
  119. }