diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-10-29 14:41:39 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-10-29 14:41:39 +0100 |
| commit | 2836163e54e3b94342113314e70ee564c456c43e (patch) | |
| tree | 59b82fc69e83cc6d92846a8e9f510b0bb865cf3b /public/what-would-dna-sound-if-synthesized.html | |
| parent | d50ea4053ea04abb3a455606d4591a8283af0677 (diff) | |
| download | mitjafelicijan.com-2836163e54e3b94342113314e70ee564c456c43e.tar.gz | |
Added public folder to git so it get get deployed on vercel
Diffstat (limited to 'public/what-would-dna-sound-if-synthesized.html')
| -rwxr-xr-x | public/what-would-dna-sound-if-synthesized.html | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/public/what-would-dna-sound-if-synthesized.html b/public/what-would-dna-sound-if-synthesized.html new file mode 100755 index 0000000..d729046 --- /dev/null +++ b/public/what-would-dna-sound-if-synthesized.html | |||
| @@ -0,0 +1,218 @@ | |||
| 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:sans-serif;line-height:1.35rem;font-size:16px;margin:0 auto}hr{margin-block-start:1.5rem}h1,h2,h3{line-height:initial}h1{font-size:xx-large}footer{margin-block-start:2rem}cap{text-transform:capitalize}table{max-width:100%;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}ul.list li{padding:.2em 0}ul{line-height:1.4em}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;padding:0 1em;border:1px solid #dcdcdc}code{padding:0 3px;font-size:14px;border:0}pre code{line-height:1.3em}pre,code,pre *,code *{font-family:monospace}figure{margin-inline-start:0;margin-inline-end:0}figcaption{text-align:center}figcaption p{margin:.3em 0 0}img,video,audio{max-width:100%}header{display:flex;flex-direction:row;gap:3rem}nav{display:flex;gap:.75rem}nav.main{flex-grow:1}.pstatus-orange{background:gold}.pstatus-green{background:#9acd32}.pstatus-red{background:#cd5c5c}@media only screen and (max-width:600px){body{padding:15px}header{flex-direction:column;gap:1rem}a{word-wrap:break-word}}</style><header><nav class=main itemscope itemtype=http://schema.org/SiteNavigationElement role=toolbar><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=/radio.pls target=_blank>Radio</a> | ||
| 5 | <a href=/mitjafelicijan.pgp.pub.txt target=_blank>PGP</a> | ||
| 6 | <a href=/curriculum-vitae.html>CV</a> | ||
| 7 | <a href=/index.xml target=_blank>RSS</a></nav></header><main role=main><article itemtype=http://schema.org/Article><h1 itemtype=headline>What would DNA sound if synthesized to an audio file</h1><p><cap>post</cap>, Jul 5, 2022 on <a href=https://mitjafelicijan.com>Mitja Felicijan's blog</a><div><h2 id=introduction>Introduction</h2><p>Lately, I have been thinking a lot about the nature of life, what are the | ||
| 8 | foundation blocks of life and things like that. It's remarkable how complex and | ||
| 9 | on the other hand simple the creation is when you look at it. The miracle of | ||
| 10 | life keeps us grounded when our imagination goes wild. If the DNA are the blocks | ||
| 11 | of life, you could consider them to be an API nature provided us to better | ||
| 12 | understand all of this chaos masquerading as order.<p>I have been reading a lot about superintelligence and our somehow misguided path | ||
| 13 | to create general artificial intelligence. What would the building blocks or our | ||
| 14 | creation look like? Is the compression really the ultimate storage of | ||
| 15 | information? Will our creation also ponder this questions when creating new | ||
| 16 | worlds for themselves, or will we just disappear into the vastness of | ||
| 17 | possibilities? It is a little offensive that we are playing God whilst being | ||
| 18 | completely ignorant of our own reality. Who knows! Like many other | ||
| 19 | breakthroughs, this one will also come at a cost not known to us when it finally | ||
| 20 | happens.<p>To keep things a bit lighter, I decided to convert some popular DNA sequences | ||
| 21 | into an audio files for us to listen to. I am not the first one, nor I will be | ||
| 22 | the last one to do this. But it is an interesting exercise in better | ||
| 23 | understanding the relationship between art and science. Maybe listening to DNA | ||
| 24 | instead of parsing it will find a way into better understanding, or at least | ||
| 25 | 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 | ||
| 26 | <a href=/encoding-binary-data-into-dna-sequence.html>Encoding binary data into DNA | ||
| 27 | sequence</a> where I have been | ||
| 28 | converting all sorts of data into DNA sequences.<p>This will be a similar exercise but instead of converting to DNA, I will be | ||
| 29 | 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 | ||
| 30 | Hz</a>. For this tuning, we also | ||
| 31 | 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 | ||
| 32 | a bit. This is a famous quote I also used for the encoding tests, and it goes | ||
| 33 | like this.<blockquote><p>How wonderful that we have met with a paradox. Now we have some hope of | ||
| 34 | making progress. | ||
| 35 | ― Niels Bohr</blockquote><pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span>>SEQ1 | ||
| 36 | </span></span><span style=display:flex><span>GACAGCTTGTGTACAAGTGTGCTTGCTCGCGAGCGGGTACGCGCGTGGGCTAACAAGTGA | ||
| 37 | </span></span><span style=display:flex><span>GCCAGCAGGTGAACAAGTGTGCGGACAAGCCAGCAGGTGCGCGGACAAGCTGGCGGGTGA | ||
| 38 | </span></span><span style=display:flex><span>ACAAGTGTGCCGGTGAGCCAACAAGCAGACAAGTAAGCAGGTACGCAGGCGAGCTTGTCA | ||
| 39 | </span></span><span style=display:flex><span>ACTCACAAGATCGCTTGTGTACAAGTGTGCGGACAAGCCAGCAGGTGCGCGGACAAGTAT | ||
| 40 | </span></span><span style=display:flex><span>GCTTGCTGGCGGACAAGCCAGCTTGTAAGCGGACAAGCTTGCGCACAAGCTGGCAGGCCT | ||
| 41 | </span></span><span style=display:flex><span>GCCGGCTCGCGTACAAATTCACAAGTAAGTACGCTTGCGTGTACGCGGGTATGTATACTC | ||
| 42 | </span></span><span style=display:flex><span>AACCTCACCAAACGGGACAAGATCGCCGGCGGGCTAGTATACAAGAACGCTTGCCAGTAC | ||
| 43 | </span></span><span style=display:flex><span>AACC | ||
| 44 | </span></span></code></pre><p>This is what we gonna work with to get things rolling forward, when creating | ||
| 45 | 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 | ||
| 46 | <a href=https://en.wikipedia.org/wiki/FASTA_format>FASTA format</a> well known in | ||
| 47 | <a href=https://en.wikipedia.org/wiki/Bioinformatics>Bioinformatics</a> to extract single | ||
| 48 | Nucleotides that will be converted into separate tones based on equal-tempered | ||
| 49 | scale explained above.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span>nucleotide_tone_map = { | ||
| 50 | </span></span><span style=display:flex><span> <span style=color:#a31515>'A'</span>: 440, | ||
| 51 | </span></span><span style=display:flex><span> <span style=color:#a31515>'C'</span>: 523.25, | ||
| 52 | </span></span><span style=display:flex><span> <span style=color:#a31515>'G'</span>: 783.99, | ||
| 53 | </span></span><span style=display:flex><span> <span style=color:#a31515>'T'</span>: 587.33, <span style=color:green># converted to D</span> | ||
| 54 | </span></span><span style=display:flex><span>} | ||
| 55 | </span></span><span style=display:flex><span> | ||
| 56 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> split(word): | ||
| 57 | </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] | ||
| 58 | </span></span><span style=display:flex><span> | ||
| 59 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> generate_from_dna_sequence(sequence): | ||
| 60 | </span></span><span style=display:flex><span> <span style=color:#00f>for</span> nucleotide <span style=color:#00f>in</span> split(sequence): | ||
| 61 | </span></span><span style=display:flex><span> print(nucleotide, nucleotide_tone_map[nucleotide]) | ||
| 62 | </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 | ||
| 63 | sine notes to a global array we will later use for creating a WAV file out of | ||
| 64 | it.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span><span style=color:#00f>import</span> math | ||
| 65 | </span></span><span style=display:flex><span> | ||
| 66 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> append_sinewave(freq=440.0, duration_milliseconds=500, volume=1.0): | ||
| 67 | </span></span><span style=display:flex><span> <span style=color:#00f>global</span> audio | ||
| 68 | </span></span><span style=display:flex><span> | ||
| 69 | </span></span><span style=display:flex><span> num_samples = duration_milliseconds * (sample_rate / 1000.0) | ||
| 70 | </span></span><span style=display:flex><span> | ||
| 71 | </span></span><span style=display:flex><span> <span style=color:#00f>for</span> x <span style=color:#00f>in</span> range(int(num_samples)): | ||
| 72 | </span></span><span style=display:flex><span> audio.append(volume * math.sin(2 * math.pi * freq * (x / sample_rate))) | ||
| 73 | </span></span><span style=display:flex><span> | ||
| 74 | </span></span><span style=display:flex><span> <span style=color:#00f>return</span> | ||
| 75 | </span></span></code></pre><p>The sine wave generated here is the standard beep. If you want something more | ||
| 76 | 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 | ||
| 77 | </span></span><span style=display:flex><span><span style=color:#00f>import</span> struct | ||
| 78 | </span></span><span style=display:flex><span> | ||
| 79 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> save_wav(file_name): | ||
| 80 | </span></span><span style=display:flex><span> wav_file = wave.open(file_name, <span style=color:#a31515>'w'</span>) | ||
| 81 | </span></span><span style=display:flex><span> nchannels = 1 | ||
| 82 | </span></span><span style=display:flex><span> sampwidth = 2 | ||
| 83 | </span></span><span style=display:flex><span> | ||
| 84 | </span></span><span style=display:flex><span> nframes = len(audio) | ||
| 85 | </span></span><span style=display:flex><span> comptype = <span style=color:#a31515>'NONE'</span> | ||
| 86 | </span></span><span style=display:flex><span> compname = <span style=color:#a31515>'not compressed'</span> | ||
| 87 | </span></span><span style=display:flex><span> wav_file.setparams((nchannels, sampwidth, sample_rate, nframes, comptype, compname)) | ||
| 88 | </span></span><span style=display:flex><span> | ||
| 89 | </span></span><span style=display:flex><span> <span style=color:#00f>for</span> sample <span style=color:#00f>in</span> audio: | ||
| 90 | </span></span><span style=display:flex><span> wav_file.writeframes(struct.pack(<span style=color:#a31515>'h'</span>, int(sample * 32767.0))) | ||
| 91 | </span></span><span style=display:flex><span> | ||
| 92 | </span></span><span style=display:flex><span> wav_file.close() | ||
| 93 | </span></span></code></pre><p>44100 is the industry standard sample rate - CD quality. If you need to save on | ||
| 94 | file size, you can adjust it downwards. The standard for low quality is, 8000 or | ||
| 95 | 8kHz.<p>WAV files here are using short, 16 bit, signed integers for the sample size. | ||
| 96 | So, we multiply the floating-point data we have by 32767, the maximum value for | ||
| 97 | a short integer.<blockquote><p>It is theoretically possible to use the floating point -1.0 to 1.0 data | ||
| 98 | directly in a WAV file, but not obvious how to do that using the wave module | ||
| 99 | 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 | ||
| 100 | out to use the <a href=https://linux.die.net/man/1/sox>SoX - Sound eXchange, the Swiss Army knife of audio | ||
| 101 | manipulation</a> one because it didn't require | ||
| 102 | anything else.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span>sox output.wav -n spectrogram -o spectrogram.png | ||
| 103 | </span></span></code></pre><p>An example spectrogram of Ludwig van Beethoven Symphony No. 6 First movement.</p><audio controls><source src=/posts/dna-synthesized/symphony-no6-1st-movement.mp3 type=audio/mpeg></audio><figure><img src=/posts/dna-synthesized/symphony-no6-1st-movement.png alt="Ludwig van Beethoven Symphony No. 6 First movement"></figure><p>The other option could also be in combination with | ||
| 104 | <a href=http://www.gnuplot.info/>gnuplot</a>. This would require an intermediary step, | ||
| 105 | however.<pre tabindex=0 style=background-color:#fff><code><span style=display:flex><span>sox output.wav audio.dat | ||
| 106 | </span></span><span style=display:flex><span>tail -n+3 audio.dat > audio_only.dat | ||
| 107 | </span></span><span style=display:flex><span>gnuplot audio.gpi | ||
| 108 | </span></span></code></pre><p>And input file <code>audio.gpi</code> that would be passed to gnuplot looks something like | ||
| 109 | this.<pre><code># set output format and size | ||
| 110 | set term png size 1000,280 | ||
| 111 | |||
| 112 | # set output file | ||
| 113 | set output "audio.png" | ||
| 114 | |||
| 115 | # set y range | ||
| 116 | set yr [-1:1] | ||
| 117 | |||
| 118 | # we want just the data | ||
| 119 | unset key | ||
| 120 | unset tics | ||
| 121 | unset border | ||
| 122 | set lmargin 0 | ||
| 123 | set rmargin 0 | ||
| 124 | set tmargin 0 | ||
| 125 | set bmargin 0 | ||
| 126 | |||
| 127 | # draw rectangle to change background color | ||
| 128 | set obj 1 rectangle behind from screen 0,0 to screen 1,1 | ||
| 129 | set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "#ffffff" | ||
| 130 | |||
| 131 | # draw data with foreground color | ||
| 132 | plot "audio_only.dat" with lines lt rgb 'red' | ||
| 133 | </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 | ||
| 134 | tone generator script. This then generated a WAV file and I converted those to | ||
| 135 | MP3, so they can be played in a browser. The last step was creating a | ||
| 136 | spectrogram based on a WAV file.<h3 id=niels-bohr-quote>Niels Bohr quote</h3><audio controls><source src=/posts/dna-synthesized/quote/out.mp3 type=audio/mpeg></audio><figure><img src=/posts/dna-synthesized/quote/spectogram.png alt=Spectogram></figure><h3 id=mouse>Mouse</h3><p>This is part of a mouse genome <code>Mus_musculus.GRCm39.dna.nonchromosomal</code>. You | ||
| 137 | can get <a href=http://ftp.ensembl.org/pub/release-106/fasta/mus_musculus/dna/>genom data | ||
| 138 | here</a>.</p><audio controls><source src=/posts/dna-synthesized/mouse/out.mp3 type=audio/mpeg></audio><figure><img src=/posts/dna-synthesized/mouse/spectogram.png alt=Spectogram></figure><h3 id=bison>Bison</h3><p>This is part of a bison genome <code>Bison_bison_bison.Bison_UMD1.0.cdna</code>. You can | ||
| 139 | get <a href=http://ftp.ensembl.org/pub/release-106/fasta/bison_bison_bison/cdna/>genom data | ||
| 140 | here</a>.</p><audio controls><source src=/posts/dna-synthesized/bison/out.mp3 type=audio/mpeg></audio><figure><img src=/posts/dna-synthesized/bison/spectogram.png alt=Spectogram></figure><h3 id=taurus>Taurus</h3><p>This is part of a taurus genome <code>Bos_taurus.ARS-UCD1.2.cdna</code>. You can get | ||
| 141 | <a href=http://ftp.ensembl.org/pub/release-106/fasta/bos_taurus/cdna/>genom data | ||
| 142 | here</a>.</p><audio controls><source src=/posts/dna-synthesized/taurus/out.mp3 type=audio/mpeg></audio><figure><img src=/posts/dna-synthesized/taurus/spectogram.png alt=Spectogram></figure><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 | ||
| 143 | <a href=https://www.elektron.se/en/model-samples>Elektron Model:Samples</a>. This is a | ||
| 144 | really cool piece of equipment that supports MIDI in via USB and 3.5 mm audio | ||
| 145 | jack.<p>Elektron is connected to my MacBook via USB cable and audio out is patched to a | ||
| 146 | Sony Bluetooth speaker I have that supports 3.5 mm audio in. Elektron doesn't | ||
| 147 | have internal speakers.<figure><img src=/posts/dna-synthesized/elektron/IMG_0619.jpg alt></figure><figure><img src=/posts/dna-synthesized/elektron/IMG_0620.jpg alt></figure><figure><img src=/posts/dna-synthesized/elektron/IMG_0622.jpg alt></figure><p>For communicating with Elektron, I choose <code>pygame</code> Python module that has MIDI | ||
| 148 | built in. With this, it was rather simple to send notes to the device. All I did | ||
| 149 | was map MIDI notes to the actual Nucleotides.<p>Before all of this I also checked Audio MIDI Setup app under MacOS and checked | ||
| 150 | MIDI Studio by pressing ⌘-2.<figure><img src=/posts/dna-synthesized/elektron/midi-studio.jpg alt></figure><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 | ||
| 151 | </span></span><span style=display:flex><span><span style=color:#00f>import</span> time | ||
| 152 | </span></span><span style=display:flex><span> | ||
| 153 | </span></span><span style=display:flex><span>pygame.midi.init() | ||
| 154 | </span></span><span style=display:flex><span> | ||
| 155 | </span></span><span style=display:flex><span>print(pygame.midi.get_default_output_id()) | ||
| 156 | </span></span><span style=display:flex><span>print(pygame.midi.get_device_info(0)) | ||
| 157 | </span></span><span style=display:flex><span> | ||
| 158 | </span></span><span style=display:flex><span>player = pygame.midi.Output(1) | ||
| 159 | </span></span><span style=display:flex><span>player.set_instrument(2) | ||
| 160 | </span></span><span style=display:flex><span> | ||
| 161 | </span></span><span style=display:flex><span><span style=color:#00f>def</span> send_note(note, velocity): | ||
| 162 | </span></span><span style=display:flex><span> <span style=color:#00f>global</span> player | ||
| 163 | </span></span><span style=display:flex><span> player.note_on(note, velocity) | ||
| 164 | </span></span><span style=display:flex><span> time.sleep(0.3) | ||
| 165 | </span></span><span style=display:flex><span> player.note_off(note, velocity) | ||
| 166 | </span></span><span style=display:flex><span> | ||
| 167 | </span></span><span style=display:flex><span> | ||
| 168 | </span></span><span style=display:flex><span>nucleotide_midi_map = { | ||
| 169 | </span></span><span style=display:flex><span> <span style=color:#a31515>'A'</span>: 60, | ||
| 170 | </span></span><span style=display:flex><span> <span style=color:#a31515>'C'</span>: 90, | ||
| 171 | </span></span><span style=display:flex><span> <span style=color:#a31515>'G'</span>: 160, | ||
| 172 | </span></span><span style=display:flex><span> <span style=color:#a31515>'T'</span>: 180, <span style=color:green># is D</span> | ||
| 173 | </span></span><span style=display:flex><span>} | ||
| 174 | </span></span><span style=display:flex><span> | ||
| 175 | </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: | ||
| 176 | </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>) | ||
| 177 | </span></span><span style=display:flex><span> | ||
| 178 | </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]: | ||
| 179 | </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( | ||
| 180 | </span></span><span style=display:flex><span> nucleotide, nucleotide_midi_map[nucleotide])) | ||
| 181 | </span></span><span style=display:flex><span> send_note(nucleotide_midi_map[nucleotide], 127) | ||
| 182 | </span></span><span style=display:flex><span> | ||
| 183 | </span></span><span style=display:flex><span><span style=color:#00f>del</span> player | ||
| 184 | </span></span><span style=display:flex><span>pygame.midi.quit() | ||
| 185 | </span></span></code></pre><p><video src=/posts/dna-synthesized/elektron/elektron.mp4 controls></video><p>All of this could be made much more interesting if I choose different | ||
| 186 | instruments for different Nucleotides, or doing more funky stuff with Elektron. | ||
| 187 | But for now, this should be enough. It is just a proof of concept. Something to | ||
| 188 | 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 | ||
| 189 | to be expected because we are operating only with 4 notes essentially. What | ||
| 190 | could make this more interesting is using something like | ||
| 191 | <a href=https://supercollider.github.io/>Supercollider</a> to create more interesting | ||
| 192 | sounds. By transposing notes or using effects based on repeated data in a | ||
| 193 | sequence. Possibilities are endless.<p>It is really astonishing what can be achieved with a little bit of code and an | ||
| 194 | idea. I could see this becoming an interesting background soundscape instrument | ||
| 195 | if done properly. It could replace random note generator with something more | ||
| 196 | intriguing, biological, natural.<p>I actually find the results fascinating. I took some time and listened to this | ||
| 197 | music of nature. Even though it's quite the same, it's also quite different. | ||
| 198 | The subtle differences on repeat kind of creates music on its own. Makes you | ||
| 199 | wonder. It kind of puts Occam’s Razor in its place. Nature for sure loves to | ||
| 200 | make things as energy efficient as possible.</div></article></main><section><hr><h2>Posts from blogs I follow around the net</h2><ul><li><a href=https://chotrin.org/writing/2023-10-20.html target=_blank rel=noopener>OpenBSD upgrade and fall things.</a><div>Been AFK for a bit. It's autumn and I upgraded this server to OpenBSD 7.4! — <a href=https://chotrin.org>chötrin's wiki.</a><li><a href=https://mirzapandzo.com/next-image-url-parameter-is-valid-but-upstream-response-is-invalid target=_blank rel=noopener>Next/Image "url" parameter is valid but upstream response is invalid</a><div>Getting "url" parameter is valid but upstream response is invalid error with Next/Image on WSL2 — <a href=https://mirzapandzo.com/>Mirza Pandzo's Blog</a><li><a href=https://drewdevault.com/2023/10/13/Going-off-script.html target=_blank rel=noopener>Going off-script</a><div>There is a phenomenon in society which I find quite bizarre. Upon our entry to | ||
| 201 | this mortal coil, we are endowed with self-awareness, agency, and free will. | ||
| 202 | Each of th… — <a href=https://drewdevault.com>Drew DeVault's blog</a><li><a href=https://solar.lowtechmagazine.com/2023/10/workshop-in-rotterdam-how-to-build-a-bike-generator/ target=_blank rel=noopener>Workshop in Rotterdam: How to Build a Bike Generator</a><div>Afbeelding: Low-tech Magazine workshop in Rotterdam, the Netherlands. Poster: Marie Verdeil. Image: Sara Vercauteren | ||
| 203 | The workshop takes place on behalf of the “Hou… — <a href=https://solar.lowtechmagazine.com/posts/>LOW←TECH MAGAZINE English</a><li><a href="http://offbeatpursuit.com:80/blog/?id=24" target=_blank rel=noopener>Printf debugging</a><div>tags: | ||
| 204 | plan9 | ||
| 205 | There’s no shame in that. Yes, there is documentation, code to be | ||
| 206 | read, and debuggers to be used. But sometimes you just need to “see” | ||
| 207 | what is happening. | ||
| 208 | So… — <a href=http://offbeatpursuit.com:80/blog/>WLOG - blog</a><li><a href=https://neil.computer/notes/chart-of-accounts-for-startups-and-saas-companies/ target=_blank rel=noopener>Chart of Accounts for Startups and SaaS Companies</a><div>Accounting is fundamental to starting a business. You need to have a basic understanding of accounting principles and essential bookkeeping. I had to learn it. Ther… — <a href=https://neil.computer/>Neil Panchal</a><li><a href=https://journal.valeriansaliou.name/deploy-a-nomad-cluster-on-alpine-linux-with-vultr/ target=_blank rel=noopener>Deploy a Nomad Cluster on Alpine Linux with Vultr</a><div>After spending countless hours trying to understand how to deploy my apps on Kubernetes for the first time to host Mirage, an AI API service that I run, I ended up … — <a href=https://journal.valeriansaliou.name/>Valerian Saliou</a><li><a href=https://jcs.org/2023/10/17/wikipedia target=_blank rel=noopener>Wikipedia Reader 1.0 Released</a><div>Wikipedia Reader | ||
| 209 | 1.0 has been released: | ||
| 210 | wikipedia-1.0.sit | ||
| 211 | (StuffIt 3 archive, includes | ||
| 212 | source code | ||
| 213 | and THINK C 5 project file) | ||
| 214 | SHA256: 360e12d064f6579695f1e627ce34cb2f0… — <a href=https://jcs.org/>joshua stein</a></ul><p><a href=https://git.sr.ht/~sircmpwn/openring>Generated with openring.</a></section><footer><hr><p><big><strong>Want to comment or have something to add?</strong></big><p>You can write me an email | ||
| 215 | at <a href=mailto:m@mitjafelicijan.com>m@mitjafelicijan.com</a> or | ||
| 216 | catch up with me <a href=https://telegram.me/mitjafelicijan target=_blank>on Telegram</a>.<hr><p>This website does not track you. Content is made available under | ||
| 217 | the <a href=https://creativecommons.org/licenses/by/4.0/ target=_blank rel=noreferrer>CC BY 4.0 license</a> unless specified | ||
| 218 | otherwise. Blog is also available as <a href=/index.xml target=_blank>RSS feed</a>.</footer> \ No newline at end of file | ||
