From 8697555125c57ae64a0c9b78514b4aac4fd523de Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Tue, 27 Jun 2023 14:50:20 +0200 Subject: Massive formatting and added figcaption --- ...01-03-encoding-binary-data-into-dna-sequence.md | 143 ++++++++++----------- 1 file changed, 70 insertions(+), 73 deletions(-) (limited to 'content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md') diff --git a/content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md b/content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md index a57201f..f0343ae 100644 --- a/content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md +++ b/content/posts/2019-01-03-encoding-binary-data-into-dna-sequence.md @@ -7,64 +7,59 @@ draft: false ## Initial thoughts -Imagine a world where you could go outside and take a leaf from a tree and put -it through your personal DNA sequencer and get data like music, videos or -computer programs from it. Well, this is all possible now. It was not done -on a large scale because it is quite expensive to create DNA strands but it's +Imagine a world where you could go outside and take a leaf from a tree and put +it through your personal DNA sequencer and get data like music, videos or +computer programs from it. Well, this is all possible now. It was not done on a +large scale because it is quite expensive to create DNA strands but it's possible. -Encoding data into DNA sequence is relatively simple process once you understand -the relationship between binary data and nucleotides and scientists have been -making large leaps in this field in order to provide viable long-term storage -solution for our data that would potentially survive our specie if case of -global disaster. We could imprint all the world's knowledge into plants and +Encoding data into DNA sequence is relatively simple process once you understand +the relationship between binary data and nucleotides and scientists have been +making large leaps in this field in order to provide viable long-term storage +solution for our data that would potentially survive our specie if case of +global disaster. We could imprint all the world's knowledge into plants and ensure the survival of our knowledge. -More optimistic usage for this technology would be easier storage of ever -growing data we produce every day. Once machines for sequencing DNA become fast -enough and cheaper this could mean the next evolution of storing data and +More optimistic usage for this technology would be easier storage of ever +growing data we produce every day. Once machines for sequencing DNA become fast +enough and cheaper this could mean the next evolution of storing data and abandoning classical hard and solid state drives in data warehouses. -As we currently stand this is still not viable but it is quite an amazing and +As we currently stand this is still not viable but it is quite an amazing and cool technology. -My interests in this field are purely in encoding processes and experimental -testing mainly because I don't have the access to this expensive machines. My -initial goal was to create a toolkit that can be used by everybody to encode +My interests in this field are purely in encoding processes and experimental +testing mainly because I don't have the access to this expensive machines. My +initial goal was to create a toolkit that can be used by everybody to encode their data into a proper DNA sequence. ## Glossary -**deoxyribose** -A five-carbon sugar molecule with a hydrogen atom rather than a hydroxyl group -in the 2′ position; the sugar component of DNA nucleotides. +**deoxyribose** A five-carbon sugar molecule with a hydrogen atom rather than a +hydroxyl group in the 2′ position; the sugar component of DNA nucleotides. -**double helix** -The molecular shape of DNA in which two strands of nucleotides wind around -each other in a spiral shape. +**double helix** The molecular shape of DNA in which two strands of nucleotides +wind around each other in a spiral shape. -**nitrogenous base** -A nitrogen-containing molecule that acts as a base; often referring to one of -the purine or pyrimidine components of nucleic acids. +**nitrogenous base** A nitrogen-containing molecule that acts as a base; often +referring to one of the purine or pyrimidine components of nucleic acids. -**phosphate group** -A molecular group consisting of a central phosphorus atom bound to four oxygen -atoms. +**phosphate group** A molecular group consisting of a central phosphorus atom +bound to four oxygen atoms. -**RGB** -The RGB color model is an additive color model in which red, green and blue -light are added together in various ways to reproduce a broad array of colors. +**RGB** The RGB color model is an additive color model in which red, green and +blue light are added together in various ways to reproduce a broad array of +colors. -**GCC** -The GNU Compiler Collection is a compiler system produced by the GNU Project -supporting various programming languages. +**GCC** The GNU Compiler Collection is a compiler system produced by the GNU +Project supporting various programming languages. ## Data encoding -**TL;DR:** Encoding involves the use of a code to change original data into a +**TL;DR:** Encoding involves the use of a code to change original data into a form that can be used by an external process. -Encoding is the process of converting data into a format required for a number +Encoding is the process of converting data into a format required for a number of information processing needs, including: - Program compiling and execution @@ -74,7 +69,7 @@ of information processing needs, including: Encoding can have two meanings: - In computer technology, encoding is the process of applying a specific code, - such as letters, symbols and numbers, to data for conversion into an + such as letters, symbols and numbers, to data for conversion into an equivalent cipher. - In electronics, encoding refers to analog to digital conversion. @@ -99,23 +94,25 @@ Encoding can have two meanings: ## What is DNA? -Deoxyribonucleic acid, a self-replicating material which is -**present in nearly all living organisms** as the main constituent of -chromosomes. It is the **carrier of genetic information**. +Deoxyribonucleic acid, a self-replicating material which is **present in nearly +all living organisms** as the main constituent of chromosomes. It is the +**carrier of genetic information**. > The nitrogen in our DNA, the calcium in our teeth, the iron in our blood, > the carbon in our apple pies were made in the interiors of collapsing stars. > We are made of starstuff. > **-- Carl Sagan, Cosmos** -The nucleotide in DNA consists of a sugar (deoxyribose), one of four bases -(cytosine (C), thymine (T), adenine (A), guanine (G)), and a phosphate. -Cytosine and thymine are pyrimidine bases, while adenine and guanine are purine +The nucleotide in DNA consists of a sugar (deoxyribose), one of four bases +(cytosine (C), thymine (T), adenine (A), guanine (G)), and a phosphate. +Cytosine and thymine are pyrimidine bases, while adenine and guanine are purine bases. The sugar and the base together are called a nucleoside. ![DNA](/assets/dna-sequence/dna-basics.jpg) -*DNA (a) forms a double stranded helix, and (b) adenine pairs with thymine and cytosine pairs with guanine. (credit a: modification of work by Jerome Walker, Dennis Myts)* +*DNA (a) forms a double stranded helix, and (b) adenine pairs with thymine and +cytosine pairs with guanine. (credit a: modification of work by Jerome Walker, +Dennis Myts)* ## Encode binary data into DNA sequence @@ -128,18 +125,18 @@ As an input file you can use any file you want: - Database files, - etc. -Note: If you would copy all the bytes from RAM to file or pipe data to file you +Note: If you would copy all the bytes from RAM to file or pipe data to file you could encode also this data as long as you provide file pointer to the encoder. ### Basic Encoding -As already mentioned, the Basic Encoding is based on a simple mapping. Since -DNA is composed of 4 nucleotides (Adenine, Cytosine, Guanine, Thymine; usually +As already mentioned, the Basic Encoding is based on a simple mapping. Since DNA +is composed of 4 nucleotides (Adenine, Cytosine, Guanine, Thymine; usually referred using the first letter). Using this technique we can encode $$ log_2(4) = log_2(2^2) = 2 bits $$ -using a single nucleotide. In this way, we are able to use the 4 bases that +using a single nucleotide. In this way, we are able to use the 4 bases that compose the DNA strand to encode each byte of data. | Two bits | Nucleotides | @@ -149,8 +146,8 @@ compose the DNA strand to encode each byte of data. | 01 | **C** (Cytosine) | | 11 | **T** (Thymine) | -With this in mind we can simply encode any data by using two-bit to -Nucleotides conversion. +With this in mind we can simply encode any data by using two-bit to Nucleotides +conversion. ```python { Algorithm 1: Naive byte array to DNA encode } @@ -173,29 +170,29 @@ begin end ``` -Another encoding would be **Goldman encoding**. Using this encoding helps with -Nonsense mutation (amino acids replaced by a stop codon) that occurs and is -the most problematic during translation because it leads to truncated amino -acid sequences, which in turn results in truncated proteins. +Another encoding would be **Goldman encoding**. Using this encoding helps with +Nonsense mutation (amino acids replaced by a stop codon) that occurs and is the +most problematic during translation because it leads to truncated amino acid +sequences, which in turn results in truncated proteins. [Where to store big data? In DNA: Nick Goldman at TEDxPrague](https://www.youtube.com/watch?v=a4PiGWNsIEU) ### FASTA file format -In bioinformatics, FASTA format is a text-based format for representing either -nucleotide sequences or peptide sequences, in which nucleotides or amino acids -are represented using single-letter codes. The format also allows for sequence -names and comments to precede the sequences. The format originates from the -FASTA software package, but has now become a standard in the field of +In bioinformatics, FASTA format is a text-based format for representing either +nucleotide sequences or peptide sequences, in which nucleotides or amino acids +are represented using single-letter codes. The format also allows for sequence +names and comments to precede the sequences. The format originates from the +FASTA software package, but has now become a standard in the field of bioinformatics. -The first line in a FASTA file started either with a ">" (greater-than) symbol -or, less frequently, a ";" (semicolon) was taken as a comment. Subsequent -lines starting with a semicolon would be ignored by software. Since the only -comment used was the first, it quickly became used to hold a summary -description of the sequence, often starting with a unique library accession -number, and with time it has become commonplace to always use ">" for the first -line and to not use ";" comments (which would otherwise be ignored). +The first line in a FASTA file started either with a ">" (greater-than) symbol +or, less frequently, a ";" (semicolon) was taken as a comment. Subsequent lines +starting with a semicolon would be ignored by software. Since the only comment +used was the first, it quickly became used to hold a summary description of the +sequence, often starting with a unique library accession number, and with time +it has become commonplace to always use ">" for the first line and to not use +";" comments (which would otherwise be ignored). ``` ;LCBO - Prolactin precursor - Bovine @@ -218,7 +215,7 @@ GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX IENY ``` -FASTA format was extended by [FASTQ](https://en.wikipedia.org/wiki/FASTQ_format) +FASTA format was extended by [FASTQ](https://en.wikipedia.org/wiki/FASTQ_format) format from the [Sanger Centre](https://www.sanger.ac.uk/) in Cambridge. ### PNG encoded DNA sequence @@ -230,7 +227,7 @@ format from the [Sanger Centre](https://www.sanger.ac.uk/) in Cambridge. | C ➞ Cytosine | (255,0,0) | Red | | T ➞ Thymine | (255,255,0) | Yellow | -With this in mind we can create a simple algorithm to create PNG representation +With this in mind we can create a simple algorithm to create PNG representation of a DNA sequence. ```python @@ -252,7 +249,7 @@ end ## Encoding text file in practice -In this example we will take a simple text file as our input stream for +In this example we will take a simple text file as our input stream for encoding. This file will have a quote from Niels Bohr and saved as txt file. > How wonderful that we have met with a paradox. Now we have some hope of @@ -306,8 +303,9 @@ After encoding into PNG format this file looks like this. The larger the input stream is the larger the PNG file would be. -Compiled basic Hello World C program with [GCC](https://www.gnu.org/software/gcc/) -would [look like](/assets/dna-sequence/sample.png). +Compiled basic Hello World C program with +[GCC](https://www.gnu.org/software/gcc/) would [look +like](/assets/dna-sequence/sample.png). ```c // gcc -O3 -o sample sample.c @@ -370,7 +368,7 @@ First we generate some binary sample data with dd. dd if=<(openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero) of=1KB.bin bs=1KB count=1 iflag=fullblock ``` -Our freshly generated 1KB file looks something like this (its full of garbage +Our freshly generated 1KB file looks something like this (its full of garbage data as intended). ![Sample binary file 1KB](/assets/dna-sequence/sample-binary-file.png) @@ -410,4 +408,3 @@ gzip -9 < 10MB.fa > 10MB.fa.gz - https://opentextbc.ca/biology/chapter/9-1-the-structure-of-dna/ - https://arxiv.org/abs/1801.04774 - https://en.wikipedia.org/wiki/FASTA_format - -- cgit v1.2.3