diff options
Diffstat (limited to 'public/what-would-dna-sound-if-synthesized.html')
| -rwxr-xr-x | public/what-would-dna-sound-if-synthesized.html | 204 |
1 files changed, 0 insertions, 204 deletions
diff --git a/public/what-would-dna-sound-if-synthesized.html b/public/what-would-dna-sound-if-synthesized.html deleted file mode 100755 index 17209a7..0000000 --- a/public/what-would-dna-sound-if-synthesized.html +++ /dev/null | |||
| @@ -1,204 +0,0 @@ | |||
| 1 | <!doctype html><html lang=en-us><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL69vf8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv76+/8LBwQkAAAAAAAAAAAAAAAC+vb3/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL+9vf/Bv78JAAAAAAAAAAAAAAAAu7q6/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC7ubr/vr29CAAAAAAAAAAAy8nJAZ6foP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnqGj/6GipAoAAAAAHLjU/xcXHf/BwsL/I8XY/yPK3v8XGiD/IbjL/yPF2f8XGiD/Fxkf/yLF2f8gnK3/Fxog/62ztv8fwNf/FRcd/x271v8mz93/GRsi/xkXHf8p097/GiIp/xobIv8p0t3/KdPe/xocIv8fYmr/KNPe/xoZH/8aHCL/J87c/xy81/8VFxz/IsPZ/8zS0/8XGiD/Ir/R/yPH2/8XGiD/Fxkf/yPH2/8dd4T/GBog/yPJ3f8jyNr/uru9/xcUGv8cudb/EhITDKi5vRKlvMP/RUpOERwcHRAdOj4QHTk8EBwdHRAdNTgQHTo/EBwcHRAcHB0QSGduEKW4vf+koqQfHzg+EBqz0ewSFRv7EyMr/xq51vsTERb7ExUb+xq41fsau9j7ExUb+xiPp/sZudb7ExUb+xMVG/sZuNX/GKvI/BIUGfMdvdn/IrfL/xcaIP8n1eb/J9Dh/xkcIf8ZGR7/J8/f/xxCSv8ZGyH/J9Dg/ybQ4P8ZHCL/FSQs/yPK3/8UExj/GE1b/ybS5P8ZGB7/Ghwj/ynW5P8p2Ob/Ghwi/yWrtv8p1eH/Ghwi/xocIv8p1uT/J8XT/xkcIv8m1un/Hb7d/xUYH/8hzOr/HtHu/xcaIf8XGB//I8vi/xgxOv8XGSD/I8rg/yPK4P8XGiD/GUFL/yPP6f8SERj/Fhkh/x3A4f8AAAAAJ2f9/ydr//8mZPH/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlYu38J2v//ydo/f8AAAAAAAAAAAd8/fkFqf//Iob8sAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMY39awWr//8FfP3/AAAAAAAAAAAFm/7/SfD//wR+/f8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOB/f9B7v//BaX+/wAAAAAAAAAAQ878SAyZ/v9n1v4KAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADu9v8DDJb+/z3N/XgAAAAA3/sAAN/7AADf+wAA3/sAAAAAAAAAAAAAAAAAAN/7AAAAAAAAAAAAAAAAAAAAAAAAj/EAAI/5AACP8QAA3/sAAA==" rel=icon type=image/x-icon><title>What would DNA sound if synthesized to an audio file</title><meta name=description content="IntroductionLately, I have been thinking a lot about the nature of life, what are thefoundation blocks of life and things like that."><link rel=alternate type=application/rss+xml title="Mitja Felicijan's posts" href=https://mitjafelicijan.com/index.xml><link rel=alternate type=application/rss+xml title="Mitja Felicijan's notes" href=https://mitjafelicijan.com/notes.xml><style>body{padding:1rem;max-width:760px;background:#fff;font-family:times new roman,Times,serif;line-height:1.35rem}hr{margin-block-start:1.5rem}h1,h2,h3{line-height:initial}footer{margin-block-start:3rem}table{max-width:100%;border-collapse:separate;border-spacing:2px;border:1px solid #000;border-left:1px solid #999;border-top:1px solid #999}blockquote{font-style:italic}table thead{background:#eee}td,th{border:1px solid #000;padding:4px;border-right:1px solid #999;border-bottom:1px solid #999;text-align:left}pre{text-wrap:nowrap;overflow-x:auto;margin-block-start:1.5rem;margin-block-end:1.5rem;padding:.5rem 0;border-top:1px solid #000;border-bottom:1px solid #000}pre code{line-height:1.3em}pre,code,pre *,code *{font-family:monospace;font-size:initial!important}img,video,audio{max-width:100%}header{display:flex;flex-direction:row;gap:3rem}nav{display:flex;gap:.75rem}.pstatus-orange{background:gold}.pstatus-green{background:#9acd32}.pstatus-red{background:#cd5c5c}@media only screen and (max-width:600px){header{flex-direction:column;gap:1rem}a{word-wrap:break-word}}</style><header><nav class=main><a href=/>Home</a> | ||
| 2 | <a href=https://git.mitjafelicijan.com/ target=_blank>Git</a> | ||
| 3 | <a href=https://files.mitjafelicijan.com/ target=_blank>Files</a> | ||
| 4 | <a href=/mitjafelicijan.pgp.pub.txt target=_blank>PGP</a> | ||
| 5 | <a href=/curriculum-vitae.html>CV</a> | ||
| 6 | <a href=/index.xml target=_blank>RSS</a></nav></header><main><div><h1>What would DNA sound if synthesized to an audio file</h1><p>Jul 5, 2022<div><h2 id=introduction>Introduction</h2><p>Lately, I have been thinking a lot about the nature of life, what are the | ||
| 7 | foundation blocks of life and things like that. It's remarkable how complex and | ||
| 8 | on the other hand simple the creation is when you look at it. The miracle of | ||
| 9 | life keeps us grounded when our imagination goes wild. If the DNA are the blocks | ||
| 10 | of life, you could consider them to be an API nature provided us to better | ||
| 11 | understand all of this chaos masquerading as order.<p>I have been reading a lot about superintelligence and our somehow misguided path | ||
| 12 | to create general artificial intelligence. What would the building blocks or our | ||
| 13 | creation look like? Is the compression really the ultimate storage of | ||
| 14 | information? Will our creation also ponder this questions when creating new | ||
| 15 | worlds for themselves, or will we just disappear into the vastness of | ||
| 16 | possibilities? It is a little offensive that we are playing God whilst being | ||
| 17 | completely ignorant of our own reality. Who knows! Like many other | ||
| 18 | breakthroughs, this one will also come at a cost not known to us when it finally | ||
| 19 | happens.<p>To keep things a bit lighter, I decided to convert some popular DNA sequences | ||
| 20 | into an audio files for us to listen to. I am not the first one, nor I will be | ||
| 21 | the last one to do this. But it is an interesting exercise in better | ||
| 22 | understanding the relationship between art and science. Maybe listening to DNA | ||
| 23 | instead of parsing it will find a way into better understanding, or at least | ||
| 24 | enjoying the creation and cryptic nature of life.<h2 id=dna-encoding-and-primer-example>DNA encoding and primer example</h2><p>I have been exploring DNA in the past in my post from about 3 years ago in | ||
| 25 | <a href=/encoding-binary-data-into-dna-sequence.html>Encoding binary data into DNA | ||
| 26 | sequence</a> where I have been | ||
| 27 | converting all sorts of data into DNA sequences.<p>This will be a similar exercise but instead of converting to DNA, I will be | ||
| 28 | generating tones from Nucleotides.<table><thead><tr><th>Nucleotides<th>Note<th>Frequency<tbody><tr><td><strong>A</strong> (Adenine)<td>A<td>440 Hz<tr><td><strong>C</strong> (Cytosine)<td>C<td>783.99 Hz<tr><td><strong>G</strong> (Guanine)<td>G<td>523.25 Hz<tr><td><strong>T</strong> (Thymine)<td>D<td>587.33 Hz</table><p>Since we do not have T in equal-tempered scale, I choose D to represent T note.<p>You can check <a href=https://pages.mtu.edu/~suits/notefreqs.html>Frequencies for equal-tempered scale, A4 = 440 | ||
| 29 | Hz</a>. For this tuning, we also | ||
| 30 | choose <code>Speed of Sound = 345 m/s = 1130 ft/s = 770 miles/hr</code>.<p>Now that we have this out of the way, we can also brush up on the DNA sequencing | ||
| 31 | a bit. This is a famous quote I also used for the encoding tests, and it goes | ||
| 32 | like this.<blockquote><p>How wonderful that we have met with a paradox. Now we have some hope of | ||
| 33 | making progress. | ||
| 34 | ― Niels Bohr</blockquote><pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span>>SEQ1 | ||
| 35 | </span></span><span style=display:flex><span>GACAGCTTGTGTACAAGTGTGCTTGCTCGCGAGCGGGTACGCGCGTGGGCTAACAAGTGA | ||
| 36 | </span></span><span style=display:flex><span>GCCAGCAGGTGAACAAGTGTGCGGACAAGCCAGCAGGTGCGCGGACAAGCTGGCGGGTGA | ||
| 37 | </span></span><span style=display:flex><span>ACAAGTGTGCCGGTGAGCCAACAAGCAGACAAGTAAGCAGGTACGCAGGCGAGCTTGTCA | ||
| 38 | </span></span><span style=display:flex><span>ACTCACAAGATCGCTTGTGTACAAGTGTGCGGACAAGCCAGCAGGTGCGCGGACAAGTAT | ||
| 39 | </span></span><span style=display:flex><span>GCTTGCTGGCGGACAAGCCAGCTTGTAAGCGGACAAGCTTGCGCACAAGCTGGCAGGCCT | ||
| 40 | </span></span><span style=display:flex><span>GCCGGCTCGCGTACAAATTCACAAGTAAGTACGCTTGCGTGTACGCGGGTATGTATACTC | ||
| 41 | </span></span><span style=display:flex><span>AACCTCACCAAACGGGACAAGATCGCCGGCGGGCTAGTATACAAGAACGCTTGCCAGTAC | ||
| 42 | </span></span><span style=display:flex><span>AACC | ||
| 43 | </span></span></code></pre><p>This is what we gonna work with to get things rolling forward, when creating | ||
| 44 | parser and waveform generator.<h2 id=parsing-dna-data>Parsing DNA data</h2><p>This step is rather simple one. All we need to do is parse input DNA sequence in | ||
| 45 | <a href=https://en.wikipedia.org/wiki/FASTA_format>FASTA format</a> well known in | ||
| 46 | <a href=https://en.wikipedia.org/wiki/Bioinformatics>Bioinformatics</a> to extract single | ||
| 47 | Nucleotides that will be converted into separate tones based on equal-tempered | ||
| 48 | scale explained above.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span>nucleotide_tone_map = { | ||
| 49 | </span></span><span style=display:flex><span> <span style=color:#a31515>'A'</span>: 440, | ||
| 50 | </span></span><span style=display:flex><span> <span style=color:#a31515>'C'</span>: 523.25, | ||
| 51 | </span></span><span style=display:flex><span> <span style=color:#a31515>'G'</span>: 783.99, | ||
| 52 | </span></span><span style=display:flex><span> <span style=color:#a31515>'T'</span>: 587.33, <span style=color:green># converted to D</span> | ||
| 53 | </span></span><span style=display:flex><span>} | ||
| 54 | </span></span><span style=display:flex><span> | ||
| 55 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> split(word): | ||
| 56 | </span></span><span style=display:flex><span> <span style=color:#00f>return</span> [char <span style=color:#00f>for</span> char <span style=color:#00f>in</span> word] | ||
| 57 | </span></span><span style=display:flex><span> | ||
| 58 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> generate_from_dna_sequence(sequence): | ||
| 59 | </span></span><span style=display:flex><span> <span style=color:#00f>for</span> nucleotide <span style=color:#00f>in</span> split(sequence): | ||
| 60 | </span></span><span style=display:flex><span> print(nucleotide, nucleotide_tone_map[nucleotide]) | ||
| 61 | </span></span></code></pre><h2 id=generating-sine-wave>Generating sine wave</h2><p>Because we are essentially creating a long stream of notes we will be appending | ||
| 62 | sine notes to a global array we will later use for creating a WAV file out of | ||
| 63 | it.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span><span style=color:#00f>import</span> math | ||
| 64 | </span></span><span style=display:flex><span> | ||
| 65 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> append_sinewave(freq=440.0, duration_milliseconds=500, volume=1.0): | ||
| 66 | </span></span><span style=display:flex><span> <span style=color:#00f>global</span> audio | ||
| 67 | </span></span><span style=display:flex><span> | ||
| 68 | </span></span><span style=display:flex><span> num_samples = duration_milliseconds * (sample_rate / 1000.0) | ||
| 69 | </span></span><span style=display:flex><span> | ||
| 70 | </span></span><span style=display:flex><span> <span style=color:#00f>for</span> x <span style=color:#00f>in</span> range(int(num_samples)): | ||
| 71 | </span></span><span style=display:flex><span> audio.append(volume * math.sin(2 * math.pi * freq * (x / sample_rate))) | ||
| 72 | </span></span><span style=display:flex><span> | ||
| 73 | </span></span><span style=display:flex><span> <span style=color:#00f>return</span> | ||
| 74 | </span></span></code></pre><p>The sine wave generated here is the standard beep. If you want something more | ||
| 75 | aggressive, you could try a square or saw tooth waveform.<h2 id=generating-a-wav-file-from-accumulated-sine-waves>Generating a WAV file from accumulated sine waves</h2><pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span><span style=color:#00f>import</span> wave | ||
| 76 | </span></span><span style=display:flex><span><span style=color:#00f>import</span> struct | ||
| 77 | </span></span><span style=display:flex><span> | ||
| 78 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> save_wav(file_name): | ||
| 79 | </span></span><span style=display:flex><span> wav_file = wave.open(file_name, <span style=color:#a31515>'w'</span>) | ||
| 80 | </span></span><span style=display:flex><span> nchannels = 1 | ||
| 81 | </span></span><span style=display:flex><span> sampwidth = 2 | ||
| 82 | </span></span><span style=display:flex><span> | ||
| 83 | </span></span><span style=display:flex><span> nframes = len(audio) | ||
| 84 | </span></span><span style=display:flex><span> comptype = <span style=color:#a31515>'NONE'</span> | ||
| 85 | </span></span><span style=display:flex><span> compname = <span style=color:#a31515>'not compressed'</span> | ||
| 86 | </span></span><span style=display:flex><span> wav_file.setparams((nchannels, sampwidth, sample_rate, nframes, comptype, compname)) | ||
| 87 | </span></span><span style=display:flex><span> | ||
| 88 | </span></span><span style=display:flex><span> <span style=color:#00f>for</span> sample <span style=color:#00f>in</span> audio: | ||
| 89 | </span></span><span style=display:flex><span> wav_file.writeframes(struct.pack(<span style=color:#a31515>'h'</span>, int(sample * 32767.0))) | ||
| 90 | </span></span><span style=display:flex><span> | ||
| 91 | </span></span><span style=display:flex><span> wav_file.close() | ||
| 92 | </span></span></code></pre><p>44100 is the industry standard sample rate - CD quality. If you need to save on | ||
| 93 | file size, you can adjust it downwards. The standard for low quality is, 8000 or | ||
| 94 | 8kHz.<p>WAV files here are using short, 16 bit, signed integers for the sample size. | ||
| 95 | So, we multiply the floating-point data we have by 32767, the maximum value for | ||
| 96 | a short integer.<blockquote><p>It is theoretically possible to use the floating point -1.0 to 1.0 data | ||
| 97 | directly in a WAV file, but not obvious how to do that using the wave module | ||
| 98 | in Python.</blockquote><h2 id=generating-spectograms>Generating Spectograms</h2><p>I have tried two methods of doing this and both were just fine. I however opted | ||
| 99 | out to use the <a href=https://linux.die.net/man/1/sox>SoX - Sound eXchange, the Swiss Army knife of audio | ||
| 100 | manipulation</a> one because it didn't require | ||
| 101 | anything else.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span>sox output.wav -n spectrogram -o spectrogram.png | ||
| 102 | </span></span></code></pre><p>An example spectrogram of Ludwig van Beethoven Symphony No. 6 First movement.</p><audio controls><source src=/assets/dna-synthesized/symphony-no6-1st-movement.mp3 type=audio/mpeg></audio><p><img src=/assets/dna-synthesized/symphony-no6-1st-movement.png alt="Ludwig van Beethoven Symphony No. 6 First movement"><p>The other option could also be in combination with | ||
| 103 | <a href=http://www.gnuplot.info/>gnuplot</a>. This would require an intermediary step, | ||
| 104 | however.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span>sox output.wav audio.dat | ||
| 105 | </span></span><span style=display:flex><span>tail -n+3 audio.dat > audio_only.dat | ||
| 106 | </span></span><span style=display:flex><span>gnuplot audio.gpi | ||
| 107 | </span></span></code></pre><p>And input file <code>audio.gpi</code> that would be passed to gnuplot looks something like | ||
| 108 | this.<pre><code># set output format and size | ||
| 109 | set term png size 1000,280 | ||
| 110 | |||
| 111 | # set output file | ||
| 112 | set output "audio.png" | ||
| 113 | |||
| 114 | # set y range | ||
| 115 | set yr [-1:1] | ||
| 116 | |||
| 117 | # we want just the data | ||
| 118 | unset key | ||
| 119 | unset tics | ||
| 120 | unset border | ||
| 121 | set lmargin 0 | ||
| 122 | set rmargin 0 | ||
| 123 | set tmargin 0 | ||
| 124 | set bmargin 0 | ||
| 125 | |||
| 126 | # draw rectangle to change background color | ||
| 127 | set obj 1 rectangle behind from screen 0,0 to screen 1,1 | ||
| 128 | set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "#ffffff" | ||
| 129 | |||
| 130 | # draw data with foreground color | ||
| 131 | plot "audio_only.dat" with lines lt rgb 'red' | ||
| 132 | </code></pre><h2 id=pre-generated-sequences>Pre-generated sequences</h2><p>What I did was take interesting parts from an animal's genome and feed it to a | ||
| 133 | tone generator script. This then generated a WAV file and I converted those to | ||
| 134 | MP3, so they can be played in a browser. The last step was creating a | ||
| 135 | spectrogram based on a WAV file.<h3 id=niels-bohr-quote>Niels Bohr quote</h3><audio controls><source src=/assets/dna-synthesized/quote/out.mp3 type=audio/mpeg></audio><p><img src=/assets/dna-synthesized/quote/spectogram.png alt=Spectogram><h3 id=mouse>Mouse</h3><p>This is part of a mouse genome <code>Mus_musculus.GRCm39.dna.nonchromosomal</code>. You | ||
| 136 | can get <a href=http://ftp.ensembl.org/pub/release-106/fasta/mus_musculus/dna/>genom data | ||
| 137 | here</a>.</p><audio controls><source src=/assets/dna-synthesized/mouse/out.mp3 type=audio/mpeg></audio><p><img src=/assets/dna-synthesized/mouse/spectogram.png alt=Spectogram><h3 id=bison>Bison</h3><p>This is part of a bison genome <code>Bison_bison_bison.Bison_UMD1.0.cdna</code>. You can | ||
| 138 | get <a href=http://ftp.ensembl.org/pub/release-106/fasta/bison_bison_bison/cdna/>genom data | ||
| 139 | here</a>.</p><audio controls><source src=/assets/dna-synthesized/bison/out.mp3 type=audio/mpeg></audio><p><img src=/assets/dna-synthesized/bison/spectogram.png alt=Spectogram><h3 id=taurus>Taurus</h3><p>This is part of a taurus genome <code>Bos_taurus.ARS-UCD1.2.cdna</code>. You can get | ||
| 140 | <a href=http://ftp.ensembl.org/pub/release-106/fasta/bos_taurus/cdna/>genom data | ||
| 141 | here</a>.</p><audio controls><source src=/assets/dna-synthesized/taurus/out.mp3 type=audio/mpeg></audio><p><img src=/assets/dna-synthesized/taurus/spectogram.png alt=Spectogram><h2 id=making-a-drummer-out-of-a-dna-sequence>Making a drummer out of a DNA sequence</h2><p>To make things even more interesting, I decided to send this data via MIDI to my | ||
| 142 | <a href=https://www.elektron.se/en/model-samples>Elektron Model:Samples</a>. This is a | ||
| 143 | really cool piece of equipment that supports MIDI in via USB and 3.5 mm audio | ||
| 144 | jack.<p>Elektron is connected to my MacBook via USB cable and audio out is patched to a | ||
| 145 | Sony Bluetooth speaker I have that supports 3.5 mm audio in. Elektron doesn't | ||
| 146 | have internal speakers.<p><img src=/assets/dna-synthesized/elektron/IMG_0619.jpg alt><p><img src=/assets/dna-synthesized/elektron/IMG_0620.jpg alt><p><img src=/assets/dna-synthesized/elektron/IMG_0622.jpg alt><p>For communicating with Elektron, I choose <code>pygame</code> Python module that has MIDI | ||
| 147 | built in. With this, it was rather simple to send notes to the device. All I did | ||
| 148 | was map MIDI notes to the actual Nucleotides.<p>Before all of this I also checked Audio MIDI Setup app under MacOS and checked | ||
| 149 | MIDI Studio by pressing ⌘-2.<p><img src=/assets/dna-synthesized/elektron/midi-studio.jpg alt><p>The whole script that parses and send notes to the Elektron looks like this.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span><span style=color:#00f>import</span> pygame.midi | ||
| 150 | </span></span><span style=display:flex><span><span style=color:#00f>import</span> time | ||
| 151 | </span></span><span style=display:flex><span> | ||
| 152 | </span></span><span style=display:flex><span>pygame.midi.init() | ||
| 153 | </span></span><span style=display:flex><span> | ||
| 154 | </span></span><span style=display:flex><span>print(pygame.midi.get_default_output_id()) | ||
| 155 | </span></span><span style=display:flex><span>print(pygame.midi.get_device_info(0)) | ||
| 156 | </span></span><span style=display:flex><span> | ||
| 157 | </span></span><span style=display:flex><span>player = pygame.midi.Output(1) | ||
| 158 | </span></span><span style=display:flex><span>player.set_instrument(2) | ||
| 159 | </span></span><span style=display:flex><span> | ||
| 160 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> send_note(note, velocity): | ||
| 161 | </span></span><span style=display:flex><span> <span style=color:#00f>global</span> player | ||
| 162 | </span></span><span style=display:flex><span> player.note_on(note, velocity) | ||
| 163 | </span></span><span style=display:flex><span> time.sleep(0.3) | ||
| 164 | </span></span><span style=display:flex><span> player.note_off(note, velocity) | ||
| 165 | </span></span><span style=display:flex><span> | ||
| 166 | </span></span><span style=display:flex><span> | ||
| 167 | </span></span><span style=display:flex><span>nucleotide_midi_map = { | ||
| 168 | </span></span><span style=display:flex><span> <span style=color:#a31515>'A'</span>: 60, | ||
| 169 | </span></span><span style=display:flex><span> <span style=color:#a31515>'C'</span>: 90, | ||
| 170 | </span></span><span style=display:flex><span> <span style=color:#a31515>'G'</span>: 160, | ||
| 171 | </span></span><span style=display:flex><span> <span style=color:#a31515>'T'</span>: 180, <span style=color:green># is D</span> | ||
| 172 | </span></span><span style=display:flex><span>} | ||
| 173 | </span></span><span style=display:flex><span> | ||
| 174 | </span></span><span style=display:flex><span><span style=color:#00f>with</span> open(<span style=color:#a31515>"quote.fa"</span>) <span style=color:#00f>as</span> f: | ||
| 175 | </span></span><span style=display:flex><span> sequence = f.read().replace(<span style=color:#a31515>'</span><span style=color:#a31515>\n</span><span style=color:#a31515>'</span>, <span style=color:#a31515>''</span>) | ||
| 176 | </span></span><span style=display:flex><span> | ||
| 177 | </span></span><span style=display:flex><span><span style=color:#00f>for</span> nucleotide <span style=color:#00f>in</span> [char <span style=color:#00f>for</span> char <span style=color:#00f>in</span> sequence]: | ||
| 178 | </span></span><span style=display:flex><span> print(<span style=color:#a31515>"Playing nucleotide </span><span style=color:#a31515>{}</span><span style=color:#a31515> with MIDI note </span><span style=color:#a31515>{}</span><span style=color:#a31515>"</span>.format( | ||
| 179 | </span></span><span style=display:flex><span> nucleotide, nucleotide_midi_map[nucleotide])) | ||
| 180 | </span></span><span style=display:flex><span> send_note(nucleotide_midi_map[nucleotide], 127) | ||
| 181 | </span></span><span style=display:flex><span> | ||
| 182 | </span></span><span style=display:flex><span><span style=color:#00f>del</span> player | ||
| 183 | </span></span><span style=display:flex><span>pygame.midi.quit() | ||
| 184 | </span></span></code></pre><p><video src=/assets/dna-synthesized/elektron/elektron.mp4 controls></video><p>All of this could be made much more interesting if I choose different | ||
| 185 | instruments for different Nucleotides, or doing more funky stuff with Elektron. | ||
| 186 | But for now, this should be enough. It is just a proof of concept. Something to | ||
| 187 | play around with.<h2 id=going-even-further>Going even further</h2><p>As you probably notice, the end results are quite similar to each other. This is | ||
| 188 | to be expected because we are operating only with 4 notes essentially. What | ||
| 189 | could make this more interesting is using something like | ||
| 190 | <a href=https://supercollider.github.io/>Supercollider</a> to create more interesting | ||
| 191 | sounds. By transposing notes or using effects based on repeated data in a | ||
| 192 | sequence. Possibilities are endless.<p>It is really astonishing what can be achieved with a little bit of code and an | ||
| 193 | idea. I could see this becoming an interesting background soundscape instrument | ||
| 194 | if done properly. It could replace random note generator with something more | ||
| 195 | intriguing, biological, natural.<p>I actually find the results fascinating. I took some time and listened to this | ||
| 196 | music of nature. Even though it's quite the same, it's also quite different. | ||
| 197 | The subtle differences on repeat kind of creates music on its own. Makes you | ||
| 198 | wonder. It kind of puts Occam’s Razor in its place. Nature for sure loves to | ||
| 199 | make things as energy efficient as possible.</div></div></main><footer><hr><div><h3>Want to comment or have something to add?</h3>You can write me an email at | ||
| 200 | <a href=mailto:m@mitjafelicijan.com>m@mitjafelicijan.com</a> or catch up | ||
| 201 | with me | ||
| 202 | <a href=https://telegram.me/mitjafelicijan target=_blank>on Telegram</a>.</div><hr><p>This website does not track you. Content is made available under | ||
| 203 | the <a href=https://creativecommons.org/licenses/by/4.0/ target=_blank rel=noreferrer>CC BY 4.0 license</a> unless specified | ||
| 204 | otherwise. Blog feed is available as <a href=/index.xml target=_blank>RSS feed</a>.</footer><script src=https://cdn.usefathom.com/script.js data-site=XHQARKXP defer></script> \ No newline at end of file | ||
