Question: Samtools Depth Stdin ?
1
gravatar for Mike Axtell
5.9 years ago by
Mike Axtell240
Penn State University
Mike Axtell240 wrote:

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

depth-of-coverage samtools • 3.4k views
ADD COMMENTlink modified 5.9 years ago by matted7.0k • written 5.9 years ago by Mike Axtell240
6
gravatar for matted
5.9 years ago by
matted7.0k
Boston, United States
matted7.0k wrote:

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 COMMENTlink written 5.9 years ago by matted7.0k

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 REPLYlink written 5.9 years ago by Mike Axtell240
0
gravatar for Pierre Lindenbaum
5.9 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum120k wrote:

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 COMMENTlink written 5.9 years ago by Pierre Lindenbaum120k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1007 users visited in the last hour