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