text: user180: I have a series of 15bp DNA sequences from single-cell barcodes and I would like to encode them into a shorter than 15 digits number so that each unique 15bp DNA sequence will create a unique numeric value. What's the best way of achieving this?
  
  user6322: What you are asking is called a "hash" (wiki).
  In python, get your oligo as a string and use the standard library method hash(oligo), this is a number that gets used for a lot of operations. It is however always a 18+1 digit number in decimal, so a different solution is needed.
  There are four nucleobases, so binary conversion from scratch is easy and best option and each solution will be unique and small. Each base takes up 2 bits and you concatenate these and convert them to hex or decimal —the length should be 10 decimal digits. One issue is when you have a oligo of a different length which start with adenosine or not.
  One issue with this is the order. I am not sure where it comes from but the bases are nearly often expressed in the order ATGC. So...
  mapping = {'A': '00', 'T': '01', 'G': '10', 'C': '11'}
  
  It is satisfying how the first digit is the W/S, while the second is R/Y.
  Now simply covert and add them compressed = functools.reduce(lambda acc,base : acc+mapping[base], oligo, '') and covert the string to decimal like so int(compressed, 2).
  
original_text: 180: <p>I have a series of 15bp DNA sequences from single-cell barcodes and I would like to encode them into a shorter than 15 digits number so that each unique 15bp DNA sequence will create a unique numeric value. What's the best way of achieving this?</p>
   6322: <p>What you are asking is called a &quot;hash&quot; (<a href="https://en.wikipedia.org/wiki/Hash_function" rel="nofollow noreferrer">wiki</a>).</p>
  <p>In python, get your oligo as a string and use the standard library method <code>hash(oligo)</code>, this is a number that gets used for a lot of operations. It is however always a 18+1 digit number in decimal, so a different solution is needed.</p>
  <p>There are four nucleobases, so binary conversion from scratch is easy and best option and each solution will be unique and small. Each base takes up 2 bits and you concatenate these and convert them to hex or decimal —the length should be 10 decimal digits. One issue is when you have a oligo of a different length which start with adenosine or not.</p>
  <p>One issue with this is the order. I am not sure where it comes from but the bases are nearly often expressed in the order ATGC. So...</p>
  <pre><code>mapping = {'A': '00', 'T': '01', 'G': '10', 'C': '11'}
  </code></pre>
  <p>It is satisfying how the first digit is the W/S, while the second is R/Y.</p>
  <p>Now simply covert and add them <code>compressed = functools.reduce(lambda acc,base : acc+mapping[base], oligo, '')</code> and covert the string to decimal like so <code>int(compressed, 2)</code>.</p>
  