This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Looping bedtools multicov on paired bam and bed files

Hi guys, I would like to run bedtools multicov on paired (by name) .bam files and .bed files. In other words the situation is the following:

bedtools multicov -bams 1265_29_S1_L001_R1_001.sorted_PCRDuped.bam -bed 1265_29_S1_L001_R1_001_q0.001broad_peaks.bed > 1265_29_S1_L001_R1_001_q0.001_Counts.bed
bedtools multicov -bams 1265_30_S1_L001_R1_001.sorted_PCRDuped.bam -bed 1265_30_S1_L001_R1_001_q0.001broad_peaks.bed > 1265_30_S1_L001_R1_001_q0.001_Counts.bed
bedtools multicov -bams 1265_31_S1_L001_R1_001.sorted_PCRDuped.bam -bed 1265_31_S1_L001_R1_001_q0.001broad_peaks.bed > 1265_31_S1_L001_R1_001_q0.001_Counts.bed
  

I have many paired .bam/.bed files. Is there a way to run bedtools multicov by looping over paired .bam/.bed files by matching names? Thank you in advance!

chip-seq bedtools

1 answer

for i in *.sorted_PCRDuped.bam
  do
  Basename=$(echo $i | awk -F ".sorted_PCRDuped.bam" '{print $1}')
  bedtools multicov \
  -bams ${Basename}.sorted_PCRDuped.bam \
  -bed ${Basename}_q0.001broad_peaks.bed \
  > ${Basename}_q0.001_Counts.bed
  done

Thank you very much!

Log in to answer this question.