converting multiple BAM files to BED files

479 Views Asked by At

I have BAM files in the external hard drive. Want to convert them into BED. Am using

cd /media/amit/LaCie/mdc_work/chigozie/pool1/bam
for x in *.bam ; do
    echo "print current:$x";
    bedtools bamToBed -i "$x" > "${x%.bam}.bed";
done
echo "done"

it writes the BED files in the directory, but they are all empty. My BEDtools is installed in

/home/amit/miniconda3/bin/bedtools

Can someone tell me where I am going wrong? regards.

1

There are 1 best solutions below

0
On

Empty bed files could be caused by bam files with no reads. The bam files could still have non-zero file size due to headers. Find the number of reads in the bam file using samtools:

samtools view -c input.bam

or sambamba:

sambamba view -c input.bam

This should output into STDIN the number of reads in the bam file. Both of these could be installed using conda, for example like so:

conda create -n my_env_name samtools sambamba