Note that there are some explanatory texts on larger screens.

plurals
  1. PORepresenting the DNA alphabet in C with typedef and enum
    primarykey
    data
    text
    <p>I'm writing a program that processes genetic sequence and I want to store each nucleotide in a byte where each bit represents one of the letters of the genetic alphabet <code>A,C,G,T</code> (only half of the bits will be used evidently).</p> <p>My encoding is the following:</p> <pre><code>A = 0b1000 C = 0b0100 G = 0b0010 T = 0b0001 R = 0b1010 Y = 0b0101 N = 0b0000 </code></pre> <p>Here, <code>R</code> are purines, which can stand for <code>A</code> or <code>G</code>, <code>Y</code> are pyrimidines (<code>C</code> or <code>T</code>), and <code>N</code> could stand for either letter.</p> <p>What is the best way to define this format in C using <code>typedef</code> and <code>enum</code>? I would like to define a type that allows me to assign a letter to a variable by name such as</p> <pre><code>typedef ... nucleotide_t; nucleotide_t x[] = {G, A, T, T, A, C, A}; </code></pre> <p>Edit: Thanks for the input. I definitely have my reason for not wanting strings, but thanks for the suggestion. It's true that logically, <code>N</code> should be <code>0b1111</code> but for my application it does make more sense to represent it as <em>none of the above</em>.</p> <p>Please note that I <em>do</em> have an idea how to make this work, but I don't break out the ol' C too often and I'm rather looking for what the most elegant solution is. I guess if I want to reserve the <code>NUL</code> byte, then I could just add <code>0b10000</code> to my code everywhere.</p> <p>I think the two possible ways to go are either an <code>enum</code> or some <code>#define</code> macros. Yet, enums are <code>int</code> and I need a <code>char</code>, so are macros the better solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload