Samtools view pipe and position
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
• 4,050 views
•
link
2 answers
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.
• 0 views
•
link
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
• 0 views
•
link
Log in to answer this question.