This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract bed regions from CRAM files

Hi Everyone,

I have several hundreds of cram files. I need to extract some bed regions from these files. Is there a way to extract bed regions from cram without unwrapping them to BAM? My final output should be BAM file for selected regions for each sample.

bam cram

2 answers

In general the -L option works for CRAM (according to the manual) same as it does for BAM given you indexed them with samtools index.

samtools view --reference ref.fa -L your.bed -o overlaps.bam your.cram
 samtools view -b --reference ref.fa in.cram | bedtools bamtobed -i stdin

Hi Pierre, I am starting with CRAM not BAM.

Hi Peter, I am starting with CRAM not BAM.

fixed

Added -b to your command to avoid unheadered SAM output :)

How is the solution addressing this requirement?

My final output should be BAM file for selected regions for each sample.

Not sure why this gives me error, but @ATpoint's answer works great.

 [an@user]$ samtools view -b --reference /home/all_sequences.fa /40/AD/XX^92XX^0319.cram | bedtools bamtobed -i genes_build37.bed-hg38
    [W::sam_read1] Parse error at line 1
    Failed to open BAM file ades_genes_build37.bed-hg38

Log in to answer this question.