Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-23T02:56:06.017Z
Answers.LastActivityDate: 2021-04-23T02:56:06.017Z
Answers.UserDisplayName: Throckmorton
Answers.Body: <p>What's going to be simplest is to generate the reverse complement of your short search sequence, and search for that too.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-29T09:05:22.143Z
Answers.Text: Hi @swbarnes2, this looks like the start of a good answer; any chance you could expand on this approach?
Answers.UserDisplayName: gringer
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-22T23:01:45.737Z
Answers.LastActivityDate: 2021-04-22T23:01:45.737Z
Answers.UserDisplayName: swbarnes2
Body: <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>
  
Tags: <python><fasta>
Title: How to input the opposite strand of DNA?
ThreadText: # How to input the opposite strand of DNA?
  
  (Asked by: username_0 on 2021-04-22)
  
  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?
  
  **Tags:** python, fasta
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-04-23. Score: 1 | Accepted answer
  
  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](https://stackoverflow.com/questions/47789/generator-expressions-vs-list-comprehensions) for a better explanation.
  
  You can also use Biopython's [`reverse_complement`](https://biopython.org/wiki/Seq#complement-and-reverse-complement) function in order to easily obtain the reverse complement.
  
  
  ---
  
  ### Answer by username_2 on 2021-04-22. Score: 0
  
  What's going to be simplest is to generate the reverse complement of your short search sequence, and search for that too.
  
  > **Comments:**
  > **username_3**: Hi @username_2, this looks like the start of a good answer; any chance you could expand on this approach?  
  
  ---
  
  