diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2019-01-10 02:42:24 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2019-01-10 02:42:24 +0100 |
| commit | a2243ed7cae795057a5d8624d15212a0eb15f376 (patch) | |
| tree | 34a19a2d68cfe92b643112aea92059a8fa409be7 /_posts/2019-01-03-encoding-binary-data-into-dna-sequence.md | |
| parent | 3e50d7f7bff5980754a34d803733306b2c9e5a63 (diff) | |
| download | mitjafelicijan.com-a2243ed7cae795057a5d8624d15212a0eb15f376.tar.gz | |
added algorithm for dna to png
Diffstat (limited to '_posts/2019-01-03-encoding-binary-data-into-dna-sequence.md')
| -rw-r--r-- | _posts/2019-01-03-encoding-binary-data-into-dna-sequence.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/_posts/2019-01-03-encoding-binary-data-into-dna-sequence.md b/_posts/2019-01-03-encoding-binary-data-into-dna-sequence.md index b9a5754..0371359 100644 --- a/_posts/2019-01-03-encoding-binary-data-into-dna-sequence.md +++ b/_posts/2019-01-03-encoding-binary-data-into-dna-sequence.md | |||
| @@ -196,6 +196,25 @@ FASTA format was extended by [FASTQ](https://en.wikipedia.org/wiki/FASTQ_format) | |||
| 196 | | C (Cytosine) | (255,0,0) | Red | | 196 | | C (Cytosine) | (255,0,0) | Red | |
| 197 | | T (Thymine) | (255,255,0) | Yellow | | 197 | | T (Thymine) | (255,255,0) | Yellow | |
| 198 | 198 | ||
| 199 | With this in mind we can create a simple algorithm to create PNG representation of a DNA sequence. | ||
| 200 | |||
| 201 | ```pascal | ||
| 202 | { Algorithm 2: Naive DNA to PNG encode from FASTA file } | ||
| 203 | procedure EncodeDNASequenceToPNG(f) | ||
| 204 | begin | ||
| 205 | i image | ||
| 206 | while not eof(f) do | ||
| 207 | c char := buffer[0] { Read 1 char from buffer } | ||
| 208 | case c of | ||
| 209 | 'A': color := RGB{0, 0, 255} { Blue } | ||
| 210 | 'G': color := RGB{0, 100, 0} { Green } | ||
| 211 | 'C': color := RGB{255, 0, 0} { Red } | ||
| 212 | 'T': color := RGB{255, 255, 0} { Yellow } | ||
| 213 | drawRect(i, x, y, x_offset, y_offset, color) | ||
| 214 | save(i) { Save PNG image } | ||
| 215 | end | ||
| 216 | ``` | ||
| 217 | |||
| 199 | ## Encoding text file in practice | 218 | ## Encoding text file in practice |
| 200 | 219 | ||
| 201 | 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. | 220 | 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. |
