Answers.Body: <p>If need to get msa between every read and ref in the specific region , 
  you can try this <a href="https://github.com/orangeSi/bam2msa.git" rel="nofollow noreferrer">https://github.com/orangeSi/bam2msa.git</a></p>
  
  <pre><code>bam2sam ref.fa input.bam --regions chr1:200-300
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-29T09:50:06.543Z
Answers.LastActivityDate: 2020-05-29T09:50:06.543Z
Answers.UserDisplayName: orange
Body: <p>I am working with paired end NGS miseq data from a viral genome with multiple timepoints.  I have filtered and trimmed this data for quality and adapter sequences.  I have then merged the filtered paired end reads and mapped them to a reference genome using bowtie2.  I then used samtools to filter for mapping quality and visualized the resulting filtered bam file on IGV.</p>
  <p>My goal is to now scan along the genome using various window sizes (e.g. 300 nt) across the reads that have mapped to the reference. I will then chop up the genome and build phylogenetic trees based on each window.</p>
  <p>How can I extract a multiple sequence alignment of these 300 nt windows from a sam or bam file using the coordinates of a reference viral genome?  I have tried using <code>samtools view</code> but this does not actually provide the subsection or alignment within the window but rather all reads that overlap the window in some way.</p>
  <p>The virus is HIV1 and the immediate goal is to get an alignment of all reads that completely span a user specified coordinate range eg. 1-300 based on some reference sequence. Ideally reads that fit this criteria would be extracted and aligned. After ragged edges are removed, the resulting alignments subjected to phylogenetic analyses.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-31T04:11:03.273Z
Comments.Text: this seems a little "chaotic". I would consider doing variant calling and then trying some approach?
Comments.UserDisplayName: Colin D
Tags: <sam><samtools><covid-19><sars-cov-2><bowtie2>
Title: How to get a MSA fasta from BAM/SAM?
ThreadText: # How to get a MSA fasta from BAM/SAM?
  
  (Asked by: username_0 on 2019-07-19)
  
  I am working with paired end NGS miseq data from a viral genome with multiple timepoints. I have filtered and trimmed this data for quality and adapter sequences. I have then merged the filtered paired end reads and mapped them to a reference genome using bowtie2. I then used samtools to filter for mapping quality and visualized the resulting filtered bam file on IGV.
  
  My goal is to now scan along the genome using various window sizes (e.g. 300 nt) across the reads that have mapped to the reference. I will then chop up the genome and build phylogenetic trees based on each window.
  
  How can I extract a multiple sequence alignment of these 300 nt windows from a sam or bam file using the coordinates of a reference viral genome? I have tried using `samtools view` but this does not actually provide the subsection or alignment within the window but rather all reads that overlap the window in some way.
  
  The virus is HIV1 and the immediate goal is to get an alignment of all reads that completely span a user specified coordinate range eg. 1-300 based on some reference sequence. Ideally reads that fit this criteria would be extracted and aligned. After ragged edges are removed, the resulting alignments subjected to phylogenetic analyses.
  
  **Tags:** sam, samtools, covid-19, sars-cov-2, bowtie2
  
  > **Comments:**
  > **username_1**: this seems a little "chaotic". I would consider doing variant calling and then trying some approach?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-05-29. Score: 2
  
  If need to get msa between every read and ref in the specific region ,
  you can try this <https://github.com/orangeSi/bam2msa.git>
  
  ```
  bam2sam ref.fa input.bam --regions chr1:200-300
  
  ```
  
  
  ---
  
  