This is a test version of Biostars. For the public version, visit https://www.biostars.org.
extract region.txt from bam file

Hi,

I am extracting some regions(in txt file) from bam file using following command

      cat ref.txt | xargs samtools view -b in.bam -o out.bam

But it doesn't return whole list of reference instead miss few from the end. My question is:

  1. is there any limit on extracting references from bam file?
  2. is there any other way to do the same job

Replies on few posts suggested to use region in bed format, I couldn't figure out how to convert .txt file into .bed file.

Any lead would be appreciated :)

TIA

alignment assembly rna-seq

Hi,

There should be no limit on extracting reads from bam file and you may find other ways to do the same job here.

The BED are presented in the form of columns separated by tabs or tab. The obligatory columns are chrom, chromStart e chromEnd. Depending on the format of your data you could use awk or even sed replacing ":" or "-" by "\t" to convert txt to bed format.

Thank you for your response.

I think I can't use method involving bed file as I am using it in a pipeline so generating some extra files will give me overhead in terms of time.

The link you shared mostly refer to this samtools view -b -h input.bam "Chr10:18000-45500" > output.bam

But I have say Chr number in txt file separated by new lines. Does samtools accept "Chr10:18000-45500" in text file using any flag? I couldn't figure that out from their manual page.

I did it using intersectbed from BED file. Thank you for your guidance.

0 answers

No answers yet.

Log in to answer this question.