Samtools view pipe and position
2
0
Entering edit mode
8.6 years ago

Hi,

following gives the error

samtools merge -u -b all_files.list - | samtools view -u -q 20 -F 0x704 - '1:1-10000' > /dev/null</pre>
[main_samview] random alignment retrieval only works for indexed BAM or CRAM files.

Without the position it works. So I guess, samtools takes the position as input. Is this a bug?

Version: 1.2 (using htslib 1.2.1)

Thanks,
Alexander

pipe samtools • 3.3k views
ADD COMMENT
0
Entering edit mode
8.6 years ago
thackl ★ 3.0k

This is not a bug. As the error suggests, you can only access regions from a file, not a piped stream. You will need to merge into file, which you than index to be able to access its regions.

ADD COMMENT
0
Entering edit mode
8.6 years ago
matted 7.8k

You could view the subregions you want first, then merge them. Depending on what you're trying to do, this would be more or less efficient than simply merging to one file (and indexing it) first.

This terrible one-liner should work:

cat <(samtools view -H first_bam.bam) <(cat all_files.list | xargs -n 1 -I {} samtools view -u -q 20 -F 0x704 {} 1:1-10000) | samtools view -bS - | samtools sort -o - - > /dev/null
ADD COMMENT

Login before adding your answer.

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