Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a quick and easy bit of code to deal with the representation.</p> <pre><code>public static enum Nucleotide { A,B,C,D; } public static int setbit(int val, int pos, boolean on) { if (on) { // set bit return val | (1 &lt;&lt; (8-pos-1)); } else { // unset bit return val &amp; ~(1 &lt;&lt; (8-pos-1)); } } public static int set2bits(int val, int pos, int bits) { // set/unset the first bit val = setbit(val, pos, (bits &amp; 2) &gt; 0); // set/unset the second bit val = setbit(val, pos+1, (bits &amp; 1) &gt; 0); return val; } public static int setNucleotide(int sequence, int pos, Nucleotide tide) { // set both bits based on the ordinal position in the enum return set2bits(sequence, pos*2, tide.ordinal()); } public static void setNucleotide(int [] sequence, int pos, Nucleotide tide) { // figure out which element in the array to work with int intpos = pos/4; // figure out which of the 4 bit pairs to work with. int bitpos = pos%4; sequence[intpos] = setNucleotide(sequence[intpos], bitpos, tide); } public static Nucleotide getNucleotide(int [] sequence, int pos) { int intpos = pos/4; int bitpos = pos%4; int val = sequence[intpos]; // get the bits for the requested on, and shift them // down into the least significant bits so we can // convert batch to the enum. int shift = (8-(bitpos+1)*2); int tide = (val &amp; (3 &lt;&lt; shift)) &gt;&gt; shift; return Nucleotide.values()[tide]; } public static void main(String args[]) { int sequence[] = new int[4]; setNucleotide(sequence, 4, Nucleotide.C); System.out.println(getNucleotide(sequence, 4)); } </code></pre> <p>Obviously there's a lot of bitshifting going on, but the small # of comments should make sense as to what's going on.</p> <p>Of course the downside of this representation is that you are working in groups of 4. If you want say 10 nucleotides, you'll have to keep another variable somewhere with the count so that you know the last 2 nucleotides in the sequence aren't useful.</p> <p>The fuzzy matching can be done with brute force if nothing else. You would take a sequence of N nucleotides in, then, starting at 0, check against nucleotides 0:N-1 and see how many match. Then you go from 1:N then 2:N+1, etc...</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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