Answers.Body: <p>Related question: <a href="https://bioinformatics.stackexchange.com/questions/7401/access-base-aligned-to-particular-reference-position">Access base aligned to particular reference position</a></p>
  <p>After an initial effort posted here, I ended up rewriting this and testing it a little, and posted the script <a href="https://github.com/maximilianpress/teaching_code/blob/master/variant_cooccurrence.py" rel="nofollow noreferrer">here</a>. It still has some drawbacks (handling indels intelligently) but now it more or less works.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-29T00:39:22.003Z
Answers.LastActivityDate: 2021-08-29T22:20:38.900Z
Answers.LastEditDate: 2021-08-29T22:20:38.900Z
Answers.UserDisplayName: Maximilian Press
Body: <p>I need some help getting started on this project.</p>
  <p>To simplify we want to be able to quantify the occurrence of 3 variants on each sequencing read in an alignment file as a proxy measurement for recombination.</p>
  <p>The possible combinations we have are A, B or AB.</p>
  <p>For example, variant A is at position 100 and variant B is at position 300 of the reference and AB would have both.</p>
  <p>We have alignment files against a reference sequence, and then I get stuck. I could technically look by eye in tablet or IGV for example but is there a way to extract each read then query by expected base at the reference position then bin these reads into the categories; A, B, AB and unclassified then calculate the total occurrences of each?</p>
  <p>Thanks for your time and suggestions!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-04T15:27:46.647Z
Comments.Text: You'll need to write something to do this, using pysam or a similar package.
Comments.UserDisplayName: Devon Ryan
Tags: <sam><samtools><mutations><variants>
Title: Counting the co-occurrence of variants A and B in an aligned sequencing read
ThreadText: # Counting the co-occurrence of variants A and B in an aligned sequencing read
  
  (Asked by: username_0 on 2021-08-03)
  
  I need some help getting started on this project.
  
  To simplify we want to be able to quantify the occurrence of 3 variants on each sequencing read in an alignment file as a proxy measurement for recombination.
  
  The possible combinations we have are A, B or AB.
  
  For example, variant A is at position 100 and variant B is at position 300 of the reference and AB would have both.
  
  We have alignment files against a reference sequence, and then I get stuck. I could technically look by eye in tablet or IGV for example but is there a way to extract each read then query by expected base at the reference position then bin these reads into the categories; A, B, AB and unclassified then calculate the total occurrences of each?
  
  Thanks for your time and suggestions!
  
  **Tags:** sam, samtools, mutations, variants
  
  > **Comments:**
  > **username_1**: You'll need to write something to do this, using pysam or a similar package.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-08-29. Score: 1
  
  Related question: [Access base aligned to particular reference position](https://bioinformatics.stackexchange.com/questions/7401/access-base-aligned-to-particular-reference-position)
  
  After an initial effort posted here, I ended up rewriting this and testing it a little, and posted the script [here](https://github.com/username_2/teaching_code/blob/master/variant_cooccurrence.py). It still has some drawbacks (handling indels intelligently) but now it more or less works.
  
  
  ---
  
  