Samtools Depth Stdin ?
2
1
Entering edit mode
11.5 years ago
Mike Axtell ▴ 250

Hi all,

I would like to use samtools depth in a pipeline to grab strand-specific coverage from a given interval, where the bam comes from STDIN. I thought that all of the samtools tools accepted STDIN data with the "-" switch. But, the following code fails with message "open: No such file or directory":

samtools view -u -f 0x10 example.bam chr1:1234-4567 | samtools depth -

As a counter-example, it works fine if mpileup is used in the pipeline, like follows:

samtools view -u -f 0x10 example.bam chr1:1234-4567 | samtools mpileup -

I know I could just write a temporary bam file, and the read it with samtools depth, but a pipe would be nicer...

samtools version 0.1.19-44428cd

samtools depth-of-coverage • 6.2k views
ADD COMMENT
6
Entering edit mode
11.5 years ago
matted 7.8k

Just use /dev/stdin instead of -.

It won't work for cases where the tool tries to look for .bai index files based on the name (which in this case would only happen if you try to analyze a specific region with the -r flag), but it will work for the example you've given.

ADD COMMENT
0
Entering edit mode

great, works like a champ! Analysis of a specific region is easily accomplished from the upstream samtools view call, so no need to use the depth option -r

ADD REPLY
0
Entering edit mode
11.5 years ago

in https://github.com/lh3/samtools/blob/master/

in the C code 'bam2depth.c" the bam is open using:

    data[i]->fp = bam_open(argv[optind+i], "r"); // open BAM

you can try to replace this line with:

    data[i]->fp = strcmp(argv[optind+i], "-")? bam_open(argv[optind+i], "r") : bam_dopen(fileno(stdin), "r");

and recompile bam2depth using 'make' (not tested)

BUT this hack won't work if there is more than one BAM and if the BAM needs a random-access.

ADD COMMENT

Login before adding your answer.

Traffic: 2396 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