Skip to main content
Commonmark migration
Source Link

I have a text file 'qnames.txt' with QNAMEs in the following format:

EXAMPLE:QNAME1
EXAMPLE:QNAME2
EXAMPLE:QNAME3
EXAMPLE:QNAME4
EXAMPLE:QNAME5

I would like to subset my BAM file.bam via all of these QNAMEs into a new SAM.

Naturally, I can do this individually, e.g.

samtools view file.bam | grep 'EXAMPLE:QNAME1' > subset.bam

But I'm unsure how to do this for a list of QNAMES:

  1. How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

    How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

    I could write a for loop that creates n SAM files, and then cats them…

  2. Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?

  3. How do I keep the BAM header?

I could write a for loop that creates n SAM files, and then cats them…

  1. Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?

  2. How do I keep the BAM header?

I have a text file 'qnames.txt' with QNAMEs in the following format:

EXAMPLE:QNAME1
EXAMPLE:QNAME2
EXAMPLE:QNAME3
EXAMPLE:QNAME4
EXAMPLE:QNAME5

I would like to subset my BAM file.bam via all of these QNAMEs into a new SAM.

Naturally, I can do this individually, e.g.

samtools view file.bam | grep 'EXAMPLE:QNAME1' > subset.bam

But I'm unsure how to do this for a list of QNAMES:

  1. How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

I could write a for loop that creates n SAM files, and then cats them…

  1. Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?

  2. How do I keep the BAM header?

I have a text file 'qnames.txt' with QNAMEs in the following format:

EXAMPLE:QNAME1
EXAMPLE:QNAME2
EXAMPLE:QNAME3
EXAMPLE:QNAME4
EXAMPLE:QNAME5

I would like to subset my BAM file.bam via all of these QNAMEs into a new SAM.

Naturally, I can do this individually, e.g.

samtools view file.bam | grep 'EXAMPLE:QNAME1' > subset.bam

But I'm unsure how to do this for a list of QNAMES:

  1. How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

    I could write a for loop that creates n SAM files, and then cats them…

  2. Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?

  3. How do I keep the BAM header?

formatting
Source Link
Konrad Rudolph
  • 4.9k
  • 16
  • 45

I have a text file 'qnames.txt' with QNAMEs in the following format:

EXAMPLE:QNAME1
EXAMPLE:QNAME2
EXAMPLE:QNAME3
EXAMPLE:QNAME4
EXAMPLE:QNAME5

I would like to subset my BAM file.bam via all of these QNAMEs into a new SAMESAM.

Naturally, I can do this individually, e.g.

samtools view file.bam | grep 'EXAMPLE:QNAME1' > subset.bam

But I'm unsure how to do this for a list of QNAMES:

(1) How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

  1. How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

I could write a forfor loop that creates N number ofn SAM files, and then cats them...

(2) Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?cats them…

(3) How do I keep the BAM header?

  1. Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?

  2. How do I keep the BAM header?

I have a text file 'qnames.txt' with QNAMEs in the following format:

EXAMPLE:QNAME1
EXAMPLE:QNAME2
EXAMPLE:QNAME3
EXAMPLE:QNAME4
EXAMPLE:QNAME5

I would like to subset my BAM file.bam via all of these QNAMEs into a new SAME

Naturally, I can do this individually, e.g.

samtools view file.bam | grep 'EXAMPLE:QNAME1' > subset.bam

But I'm unsure how to do this for a list of QNAMES:

(1) How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

I could write a for loop that creates N number of SAM files, and then cats them...

(2) Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?

(3) How do I keep the BAM header?

I have a text file 'qnames.txt' with QNAMEs in the following format:

EXAMPLE:QNAME1
EXAMPLE:QNAME2
EXAMPLE:QNAME3
EXAMPLE:QNAME4
EXAMPLE:QNAME5

I would like to subset my BAM file.bam via all of these QNAMEs into a new SAM.

Naturally, I can do this individually, e.g.

samtools view file.bam | grep 'EXAMPLE:QNAME1' > subset.bam

But I'm unsure how to do this for a list of QNAMES:

  1. How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

I could write a for loop that creates n SAM files, and then cats them…

  1. Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?

  2. How do I keep the BAM header?

Source Link
EB2127
  • 1.4k
  • 2
  • 12
  • 25

How to subset a BAM by a list of QNAMEs?

I have a text file 'qnames.txt' with QNAMEs in the following format:

EXAMPLE:QNAME1
EXAMPLE:QNAME2
EXAMPLE:QNAME3
EXAMPLE:QNAME4
EXAMPLE:QNAME5

I would like to subset my BAM file.bam via all of these QNAMEs into a new SAME

Naturally, I can do this individually, e.g.

samtools view file.bam | grep 'EXAMPLE:QNAME1' > subset.bam

But I'm unsure how to do this for a list of QNAMES:

(1) How do I write a for loop that will do all of these queries, outputting the correct SAM needed?

I could write a for loop that creates N number of SAM files, and then cats them...

(2) Is there a way to specifically grep by QNAME? The above may grep reads that may not be associated with the correct QNAME?

(3) How do I keep the BAM header?