text: user6470: I am trying to write a program that will count the repeats of a given DNA strand:
  I am using a Counter library, something like this code shown below
  from collections import Counter
  
          s="XXXXXAGCCTGCCAAGCAAACTTCACTGGAGXXXXXTGTGCGTAGCATGCTAGTAACTGCAXXXXXTCTGAATCTTTCAGCTGCTTGTXXXXXTGGGCCTCTCACAAGGCAGAGTGTCTTCATGGGACTTTGATATTTATTTTTGTACAACCTAAGAGGAACAAATCCTTTGACACTGACAAATTGGCTTCCATATTTTATACCTTAATCATCTCCATGTTGAATTCATTGATCAACAGTTTAAGAAAAAAAGATGTAAAAATGCTTTTAGAAAGAGAGGCAAAGTTATGCACAATAACTTCTCATGAAGTCACAGTTTGTTAAAAGTTGCCTTAGTTCACAATAAATAATTATGTATGCTCTATAATTTCAGTGA"
  
  
  def chunk_string(s, n):
      return [s[i:i+n] for i in range(len(s)-n+1)]
  
  counter = Counter(chunk_string(s, 5))
  
  Repeat supposed to be "declared" as an identical sequence on the same strand (like XXXXX here that occurs 4 times). However, I can also have this repeat (for ex. XXXXX in this particular test case) on the OPPOSITE strand.
  How am I suppose to intake the opposite strand in case of using .fasta files? As I know for today - fasta is presented only in a single strand way. Or am I completely mixed the terms?
  
  user6628: Yes, you're going to want to take the reverse complement of your string in order to analyze the other strand, that is the standard.
  Also, it is worth pointing out that you may want to use a generator expression instead of a list expression for your chunk_string function:
  def chunk_string(s, n):
      return (s[i:i+n] for i in range(len(s)-n+1))
  
  This will result in a generator that yields kmers as the Counter constructor iterates through them, which means that you don't need to first construct and store the entire list of kmers first and then pass to Counter but instead can feed them directly to it. Not essential for small strings, of course, but a good practice and useful for larger strings. See this SO post for a better explanation.
  You can also use Biopython's reverse_complement function in order to easily obtain the reverse complement.
  
original_text: 6470: <p>I am trying to write a program that will count the repeats of a given DNA strand:</p>
  <p>I am using a Counter library, something like this code shown below</p>
  <pre><code>from collections import Counter
  
          s=&quot;XXXXXAGCCTGCCAAGCAAACTTCACTGGAGXXXXXTGTGCGTAGCATGCTAGTAACTGCAXXXXXTCTGAATCTTTCAGCTGCTTGTXXXXXTGGGCCTCTCACAAGGCAGAGTGTCTTCATGGGACTTTGATATTTATTTTTGTACAACCTAAGAGGAACAAATCCTTTGACACTGACAAATTGGCTTCCATATTTTATACCTTAATCATCTCCATGTTGAATTCATTGATCAACAGTTTAAGAAAAAAAGATGTAAAAATGCTTTTAGAAAGAGAGGCAAAGTTATGCACAATAACTTCTCATGAAGTCACAGTTTGTTAAAAGTTGCCTTAGTTCACAATAAATAATTATGTATGCTCTATAATTTCAGTGA&quot;
  
  
  def chunk_string(s, n):
      return [s[i:i+n] for i in range(len(s)-n+1)]
  
  counter = Counter(chunk_string(s, 5))
  </code></pre>
  <p>Repeat supposed to be &quot;declared&quot; as an identical sequence on the same strand (like <code>XXXXX</code> here that occurs 4 times). However, I can also have this repeat (for ex. <code>XXXXX</code> in this particular test case) on the OPPOSITE strand.</p>
  <p>How am I suppose to intake the opposite strand in case of using <code>.fasta</code> files? As I know for today - fasta is presented only in a single strand way. Or am I completely mixed the terms?</p>
   6628: <p>Yes, you're going to want to take the reverse complement of your string in order to analyze the other strand, that is the standard.</p>
  <p>Also, it is worth pointing out that you may want to use a generator expression instead of a list expression for your <code>chunk_string</code> function:</p>
  <pre><code>def chunk_string(s, n):
      return (s[i:i+n] for i in range(len(s)-n+1))
  </code></pre>
  <p>This will result in a generator that yields kmers as the <code>Counter</code> constructor iterates through them, which means that you don't need to first construct and store the entire list of kmers first and then pass to <code>Counter</code> but instead can feed them directly to it. Not essential for small strings, of course, but a good practice and useful for larger strings. See <a href="https://stackoverflow.com/questions/47789/generator-expressions-vs-list-comprehensions">this SO post</a> for a better explanation.</p>
  <p>You can also use Biopython's <a href="https://biopython.org/wiki/Seq#complement-and-reverse-complement" rel="nofollow noreferrer"><code>reverse_complement</code></a> function in order to easily obtain the reverse complement.</p>
  