aboutsummaryrefslogtreecommitdiff
path: root/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md')
-rw-r--r--content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md134
1 files changed, 102 insertions, 32 deletions
diff --git a/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md b/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md
index 002eb5d..15bbf2b 100644
--- a/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md
+++ b/content/posts/2022-07-05-what-would-dna-sound-if-synthesized.md
@@ -1,23 +1,44 @@
1--- 1---
2title: What would DNA sound if synthesized to an audio file 2title: What would DNA sound if synthesized to an audio file
3url: what-would-dna-sound-if-synthesized.html 3url: what-would-dna-sound-if-synthesized.html
4date: 2022-07-05 4date: 2022-07-05T12:00:00+02:00
5draft: false 5draft: false
6--- 6---
7 7
8## Introduction 8## Introduction
9 9
10Lately, I have been thinking a lot about the nature of life, what are the foundation blocks of life and things like that. It's remarkable how complex and on the other hand simple the creation is when you look at it. The miracle of life keeps us grounded when our imagination goes wild. If the DNA are the blocks of life, you could consider them to be an API nature provided us to better understand all of this chaos masquerading as order. 10Lately, I have been thinking a lot about the nature of life, what are the
11 11foundation blocks of life and things like that. It's remarkable how complex
12I have been reading a lot about superintelligence and our somehow misguided path to create general artificial intelligence. What would the building blocks or our creation look like? Is the compression really the ultimate storage of information? Will our creation also ponder this questions when creating new worlds for themselves, or will we just disappear into the vastness of possibilities? It is a little offensive that we are playing God whilst being completely ignorant of our own reality. Who knows! Like many other breakthroughs, this one will also come at a cost not known to us when it finally happens. 12and on the other hand simple the creation is when you look at it. The miracle
13 13of life keeps us grounded when our imagination goes wild. If the DNA are the
14To keep things a bit lighter, I decided to convert some popular DNA sequences into an audio files for us to listen to. I am not the first one, nor I will be the last one to do this. But it is an interesting exercise in better understanding the relationship between art and science. Maybe listening to DNA instead of parsing it will find a way into better understanding, or at least enjoying the creation and cryptic nature of life. 14blocks of life, you could consider them to be an API nature provided us to
15better understand all of this chaos masquerading as order.
16
17I have been reading a lot about superintelligence and our somehow misguided
18path to create general artificial intelligence. What would the building blocks
19or our creation look like? Is the compression really the ultimate storage of
20information? Will our creation also ponder this questions when creating new
21worlds for themselves, or will we just disappear into the vastness of
22possibilities? It is a little offensive that we are playing God whilst being
23completely ignorant of our own reality. Who knows! Like many other
24breakthroughs, this one will also come at a cost not known to us when it
25finally happens.
26
27To keep things a bit lighter, I decided to convert some popular DNA sequences
28into an audio files for us to listen to. I am not the first one, nor I will be
29the last one to do this. But it is an interesting exercise in better
30understanding the relationship between art and science. Maybe listening to DNA
31instead of parsing it will find a way into better understanding, or at least
32enjoying the creation and cryptic nature of life.
15 33
16## DNA encoding and primer example 34## DNA encoding and primer example
17 35
18I have been exploring DNA in the past in my post from about 3 years ago in [Encoding binary data into DNA sequence](/encoding-binary-data-into-dna-sequence.html) where I have been converting all sorts of data into DNA sequences. 36I have been exploring DNA in the past in my post from about 3 years ago in
37[Encoding binary data into DNA sequence](/encoding-binary-data-into-dna-sequence.html)
38where I have been converting all sorts of data into DNA sequences.
19 39
20This will be a similar exercise but instead of converting to DNA, I will be generating tones from Nucleotides. 40This will be a similar exercise but instead of converting to DNA, I will be
41generating tones from Nucleotides.
21 42
22| Nucleotides | Note | Frequency | 43| Nucleotides | Note | Frequency |
23| ---------------- | ---- | --------- | 44| ---------------- | ---- | --------- |
@@ -28,11 +49,15 @@ This will be a similar exercise but instead of converting to DNA, I will be gene
28 49
29Since we do not have T in equal-tempered scale, I choose D to represent T note. 50Since we do not have T in equal-tempered scale, I choose D to represent T note.
30 51
31You can check [Frequencies for equal-tempered scale, A4 = 440 Hz](https://pages.mtu.edu/~suits/notefreqs.html). For this tuning, we also choose `Speed of Sound = 345 m/s = 1130 ft/s = 770 miles/hr`. 52You can check [Frequencies for equal-tempered scale, A4 = 440 Hz](https://pages.mtu.edu/~suits/notefreqs.html).
53For this tuning, we also choose `Speed of Sound = 345 m/s = 1130 ft/s = 770 miles/hr`.
32 54
33Now that we have this out of the way, we can also brush up on the DNA sequencing a bit. This is a famous quote I also used for the encoding tests, and it goes like this. 55Now that we have this out of the way, we can also brush up on the DNA
56sequencing a bit. This is a famous quote I also used for the encoding tests,
57and it goes like this.
34 58
35> How wonderful that we have met with a paradox. Now we have some hope of making progress. 59> How wonderful that we have met with a paradox. Now we have some hope of
60> making progress.
36> ― Niels Bohr 61> ― Niels Bohr
37 62
38```shell 63```shell
@@ -47,11 +72,16 @@ AACCTCACCAAACGGGACAAGATCGCCGGCGGGCTAGTATACAAGAACGCTTGCCAGTAC
47AACC 72AACC
48``` 73```
49 74
50This is what we gonna work with to get things rolling forward, when creating parser and waveform generator. 75This is what we gonna work with to get things rolling forward, when creating
76parser and waveform generator.
51 77
52## Parsing DNA data 78## Parsing DNA data
53 79
54This step is rather simple one. All we need to do is parse input DNA sequence in [FASTA format](https://en.wikipedia.org/wiki/FASTA_format) well known in [Bioinformatics](https://en.wikipedia.org/wiki/Bioinformatics) to extract single Nucleotides that will be converted into separate tones based on equal-tempered scale explained above. 80This step is rather simple one. All we need to do is parse input DNA sequence in
81[FASTA format](https://en.wikipedia.org/wiki/FASTA_format) well known
82in [Bioinformatics](https://en.wikipedia.org/wiki/Bioinformatics) to extract
83single Nucleotides that will be converted into separate tones based on
84equal-tempered scale explained above.
55 85
56```python 86```python
57nucleotide_tone_map = { 87nucleotide_tone_map = {
@@ -71,7 +101,8 @@ def generate_from_dna_sequence(sequence):
71 101
72## Generating sine wave 102## Generating sine wave
73 103
74Because we are essentially creating a long stream of notes we will be appending sine notes to a global array we will later use for creating a WAV file out of it. 104Because we are essentially creating a long stream of notes we will be appending
105sine notes to a global array we will later use for creating a WAV file out of it.
75 106
76```python 107```python
77import math 108import math
@@ -87,7 +118,8 @@ def append_sinewave(freq=440.0, duration_milliseconds=500, volume=1.0):
87 return 118 return
88``` 119```
89 120
90The sine wave generated here is the standard beep. If you want something more aggressive, you could try a square or saw tooth waveform. 121The sine wave generated here is the standard beep. If you want something more
122aggressive, you could try a square or saw tooth waveform.
91 123
92## Generating a WAV file from accumulated sine waves 124## Generating a WAV file from accumulated sine waves
93 125
@@ -112,15 +144,23 @@ def save_wav(file_name):
112 wav_file.close() 144 wav_file.close()
113``` 145```
114 146
11544100 is the industry standard sample rate - CD quality. If you need to save on file size, you can adjust it downwards. The standard for low quality is, 8000 or 8kHz. 14744100 is the industry standard sample rate - CD quality. If you need to save
148on file size, you can adjust it downwards. The standard for low quality is,
1498000 or 8kHz.
116 150
117WAV files here are using short, 16 bit, signed integers for the sample size. So, we multiply the floating-point data we have by 32767, the maximum value for a short integer. 151WAV files here are using short, 16 bit, signed integers for the sample size.
152So, we multiply the floating-point data we have by 32767, the maximum value
153for a short integer.
118 154
119> It is theoretically possible to use the floating point -1.0 to 1.0 data directly in a WAV file, but not obvious how to do that using the wave module in Python. 155> It is theoretically possible to use the floating point -1.0 to 1.0 data
156> directly in a WAV file, but not obvious how to do that using the wave module
157> in Python.
120 158
121## Generating Spectograms 159## Generating Spectograms
122 160
123I have tried two methods of doing this and both were just fine. I however opted out to use the [SoX - Sound eXchange, the Swiss Army knife of audio manipulation](https://linux.die.net/man/1/sox) one because it didn't require anything else. 161I have tried two methods of doing this and both were just fine. I however opted
162out to use the [SoX - Sound eXchange, the Swiss Army knife of audio manipulation](https://linux.die.net/man/1/sox)
163one because it didn't require anything else.
124 164
125```shell 165```shell
126sox output.wav -n spectrogram -o spectrogram.png 166sox output.wav -n spectrogram -o spectrogram.png
@@ -134,7 +174,8 @@ An example spectrogram of Ludwig van Beethoven Symphony No. 6 First movement.
134 174
135![Ludwig van Beethoven Symphony No. 6 First movement](/assets/dna-synthesized/symphony-no6-1st-movement.png) 175![Ludwig van Beethoven Symphony No. 6 First movement](/assets/dna-synthesized/symphony-no6-1st-movement.png)
136 176
137The other option could also be in combination with [gnuplot](http://www.gnuplot.info/). This would require an intermediary step, however. 177The other option could also be in combination with [gnuplot](http://www.gnuplot.info/).
178This would require an intermediary step, however.
138 179
139```shell 180```shell
140sox output.wav audio.dat 181sox output.wav audio.dat
@@ -173,7 +214,10 @@ plot "audio_only.dat" with lines lt rgb 'red'
173 214
174## Pre-generated sequences 215## Pre-generated sequences
175 216
176What I did was take interesting parts from an animal's genome and feed it to a tone generator script. This then generated a WAV file and I converted those to MP3, so they can be played in a browser. The last step was creating a spectrogram based on a WAV file. 217What I did was take interesting parts from an animal's genome and feed it to a
218tone generator script. This then generated a WAV file and I converted those to
219MP3, so they can be played in a browser. The last step was creating a
220spectrogram based on a WAV file.
177 221
178### Niels Bohr quote 222### Niels Bohr quote
179 223
@@ -185,7 +229,8 @@ What I did was take interesting parts from an animal's genome and feed it to a t
185 229
186### Mouse 230### Mouse
187 231
188This is part of a mouse genome `Mus_musculus.GRCm39.dna.nonchromosomal`. You can get [genom data here](http://ftp.ensembl.org/pub/release-106/fasta/mus_musculus/dna/). 232This is part of a mouse genome `Mus_musculus.GRCm39.dna.nonchromosomal`.
233You can get [genom data here](http://ftp.ensembl.org/pub/release-106/fasta/mus_musculus/dna/).
189 234
190<audio controls> 235<audio controls>
191 <source src="/assets/dna-synthesized/mouse/out.mp3" type="audio/mpeg"> 236 <source src="/assets/dna-synthesized/mouse/out.mp3" type="audio/mpeg">
@@ -195,7 +240,8 @@ This is part of a mouse genome `Mus_musculus.GRCm39.dna.nonchromosomal`. You can
195 240
196### Bison 241### Bison
197 242
198This is part of a bison genome `Bison_bison_bison.Bison_UMD1.0.cdna`. You can get [genom data here](http://ftp.ensembl.org/pub/release-106/fasta/bison_bison_bison/cdna/). 243This is part of a bison genome `Bison_bison_bison.Bison_UMD1.0.cdna`.
244You can get [genom data here](http://ftp.ensembl.org/pub/release-106/fasta/bison_bison_bison/cdna/).
199 245
200<audio controls> 246<audio controls>
201 <source src="/assets/dna-synthesized/bison/out.mp3" type="audio/mpeg"> 247 <source src="/assets/dna-synthesized/bison/out.mp3" type="audio/mpeg">
@@ -205,7 +251,8 @@ This is part of a bison genome `Bison_bison_bison.Bison_UMD1.0.cdna`. You can ge
205 251
206### Taurus 252### Taurus
207 253
208This is part of a taurus genome `Bos_taurus.ARS-UCD1.2.cdna`. You can get [genom data here](http://ftp.ensembl.org/pub/release-106/fasta/bos_taurus/cdna/). 254This is part of a taurus genome `Bos_taurus.ARS-UCD1.2.cdna`.
255You can get [genom data here](http://ftp.ensembl.org/pub/release-106/fasta/bos_taurus/cdna/).
209 256
210<audio controls> 257<audio controls>
211 <source src="/assets/dna-synthesized/taurus/out.mp3" type="audio/mpeg"> 258 <source src="/assets/dna-synthesized/taurus/out.mp3" type="audio/mpeg">
@@ -215,9 +262,14 @@ This is part of a taurus genome `Bos_taurus.ARS-UCD1.2.cdna`. You can get [genom
215 262
216## Making a drummer out of a DNA sequence 263## Making a drummer out of a DNA sequence
217 264
218To make things even more interesting, I decided to send this data via MIDI to my [Elektron Model:Samples](https://www.elektron.se/en/model-samples). This is a really cool piece of equipment that supports MIDI in via USB and 3.5 mm audio jack. 265To make things even more interesting, I decided to send this data via MIDI to
266my [Elektron Model:Samples](https://www.elektron.se/en/model-samples). This is
267a really cool piece of equipment that supports MIDI in via USB and 3.5 mm
268audio jack.
219 269
220Elektron is connected to my MacBook via USB cable and audio out is patched to a Sony Bluetooth speaker I have that supports 3.5 mm audio in. Elektron doesn't have internal speakers. 270Elektron is connected to my MacBook via USB cable and audio out is patched to
271a Sony Bluetooth speaker I have that supports 3.5 mm audio in. Elektron
272doesn't have internal speakers.
221 273
222![](/assets/dna-synthesized/elektron/IMG_0619.jpg) 274![](/assets/dna-synthesized/elektron/IMG_0619.jpg)
223 275
@@ -225,9 +277,12 @@ Elektron is connected to my MacBook via USB cable and audio out is patched to a
225 277
226![](/assets/dna-synthesized/elektron/IMG_0622.jpg) 278![](/assets/dna-synthesized/elektron/IMG_0622.jpg)
227 279
228For communicating with Elektron, I choose `pygame` Python module that has MIDI built in. With this, it was rather simple to send notes to the device. All I did was map MIDI notes to the actual Nucleotides. 280For communicating with Elektron, I choose `pygame` Python module that has MIDI
281built in. With this, it was rather simple to send notes to the device. All I
282did was map MIDI notes to the actual Nucleotides.
229 283
230Before all of this I also checked Audio MIDI Setup app under MacOS and checked MIDI Studio by pressing ⌘-2. 284Before all of this I also checked Audio MIDI Setup app under MacOS and checked
285MIDI Studio by pressing ⌘-2.
231 286
232![](/assets/dna-synthesized/elektron/midi-studio.jpg) 287![](/assets/dna-synthesized/elektron/midi-studio.jpg)
233 288
@@ -273,12 +328,27 @@ pygame.midi.quit()
273 328
274<video src="/assets/dna-synthesized/elektron/elektron.mp4" controls></video> 329<video src="/assets/dna-synthesized/elektron/elektron.mp4" controls></video>
275 330
276All of this could be made much more interesting if I choose different instruments for different Nucleotides, or doing more funky stuff with Elektron. But for now, this should be enough. It is just a proof of concept. Something to play around with. 331All of this could be made much more interesting if I choose different
332instruments for different Nucleotides, or doing more funky stuff with Elektron.
333But for now, this should be enough. It is just a proof of concept. Something
334to play around with.
277 335
278## Going even further 336## Going even further
279 337
280As you probably notice, the end results are quite similar to each other. This is to be expected because we are operating only with 4 notes essentially. What could make this more interesting is using something like [Supercollider](https://supercollider.github.io/) to create more interesting sounds. By transposing notes or using effects based on repeated data in a sequence. Possibilities are endless. 338As you probably notice, the end results are quite similar to each other. This
339is to be expected because we are operating only with 4 notes essentially. What
340could make this more interesting is using something like [Supercollider](https://supercollider.github.io/)
341to create more interesting sounds. By transposing notes or using effects based
342on repeated data in a sequence. Possibilities are endless.
343
344It is really astonishing what can be achieved with a little bit of code and an
345idea. I could see this becoming an interesting background soundscape instrument
346if done properly. It could replace random note generator with something more
347intriguing, biological, natural.
281 348
282It is really astonishing what can be achieved with a little bit of code and an idea. I could see this becoming an interesting background soundscape instrument if done properly. It could replace random note generator with something more intriguing, biological, natural. 349I actually find the results fascinating. I took some time and listened to this
350music of nature. Even though it's quite the same, it's also quite different.
351The subtle differences on repeat kind of creates music on its own. Makes you
352wonder. It kind of puts Occam’s Razor in its place. Nature for sure loves to
353make things as energy efficient as possible.
283 354
284I actually find the results fascinating. I took some time and listened to this music of nature. Even though it's quite the same, it's also quite different. The subtle differences on repeat kind of creates music on its own. Makes you wonder. It kind of puts Occam’s Razor in its place. Nature for sure loves to make things as energy efficient as possible.