text: user4039: Suppose I have a short chain string of oligos, and I want to rate them from 0 to 1 based on how clustered the "A"s are in respect to the chain. For example:
  "AAAAACCCCC" #should score as 1 for being as clustered as it possibly could
  "ACACACACAC" #should be scored as 0 for being as thinly distributed as it could
  
  Current idea is to strip both ends of A's, then remove first and last characters, then 
  gaps = ''.join(str(x) for x in deck).split("A")
  listofCs = [x for x in gaps if x] 
  
  to join it all together as a list of how big the gaps are (i.e. the "C"s), and simply count the average size 
  average = sum(map(len,listofCs))/len(listofCs)
  
  But I feel like there should be a much more elegant solution to this. It feels messy. How can I improve the scoring?
  
  user3828: You could count the number of transitions between an A and a 'not A', and divide this number by the total number of As.  You might also need to scale by the sequence length, if you have different length sequences that you want to compare.
  Edit: also, there might be a correction to make if one or both ends of the sequence are an A
  
original_text: 4039: <p>Suppose I have a short chain string of oligos, and I want to rate them from 0 to 1 based on how clustered the "A"s are in respect to the chain. For example:</p>
  
  <pre><code>"AAAAACCCCC" #should score as 1 for being as clustered as it possibly could
  "ACACACACAC" #should be scored as 0 for being as thinly distributed as it could
  </code></pre>
  
  <p>Current idea is to strip both ends of A's, then remove first and last characters, then </p>
  
  <pre><code>gaps = ''.join(str(x) for x in deck).split("A")
  listofCs = [x for x in gaps if x] 
  </code></pre>
  
  <p>to join it all together as a list of how big the gaps are (i.e. the "C"s), and simply count the average size </p>
  
  <pre><code>average = sum(map(len,listofCs))/len(listofCs)
  </code></pre>
  
  <p>But I feel like there should be a much more elegant solution to this. It feels messy. How can I improve the scoring?</p>
   3828: <p>You could count the number of transitions between an A and a 'not A', and divide this number by the total number of As.  You might also need to scale by the sequence length, if you have different length sequences that you want to compare.</p>
  
  <p>Edit: also, there might be a correction to make if one or both ends of the sequence are an A</p>
  