count and generate count files for multiple bam files
1
0
Entering edit mode
4.7 years ago
najim3 • 0

Hello guys. Can you please help out?

I have a directory with multiple sub-directories that contain bam files. I try to count the number of reads for the different bam files recursively and generate count files with the unique bam file names using the command below:

for i in */*bam; do bedtools multicov -bams $i /data/reference/bedfiles/bed1.bed > /data/results/test/${i}; done

I get:

-bash: /data/results/test/sample1/sample1.txt: No such file or directory

-bash: /data/results/test/sample1/sample2.txt: No such file or directory
...

What am I missing?

Your help is appreciated

NGS • 1.5k views
ADD COMMENT
4
Entering edit mode
4.7 years ago
shawn.w.foley ★ 1.3k

The error is saying that the output file or directory does not exist. This is likely due to how you're calling the filenames. In your for loop you're using two wildcards, one for the directory and one for the filename. Therefore, in your out file when you specify ${i} your computer is again seeing both the directory and filename.

I assume you want your output file to be: /data/results/test/sample1.txt, but ${i} corresponds to sample1/sample1.txt, so it's trying to make a file called /data/results/test/sample1/sample1.txt, which I'm guessing corresponds to a directory that doesn't exist.

Instead I would name your outfile: /data/results/test/$(basename $i). Using the basename function will remove the directory name from the variable $i.

ADD COMMENT
0
Entering edit mode

Thanks, Shawn. It works.

ADD REPLY

Login before adding your answer.

Traffic: 2802 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6