This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error message when using samtools view

Hi, every one.

I ran the following command.

samtools view input.bam scaffold_list > subset_reads.sam

I then received the following error message.

[main_samview] region "scaffold_list" specifies an invalid region or unknown reference. Continue anyway.

The contents of "scaffold_list" are as follows.

scaffold_71345
scaffold_71293
scaffold_71300
scaffold_71309
scaffold_71272
scaffold_71267
scaffold_71292
scaffold_71262
scaffold_71282

I ran the following command to check the scaffold name and found no mistakes.

samtools view -H input.bam

I would like to know how to resolve this error.

Thank you.

samtools

2 answers

You cannot give a file as an coordinate argument. It must ne a coordinate like "chr1:22344-678344"

Otherwise you can use the options -L and -M. See the manual.

Thank you for always replying to my questions! I will refer to your advice.

cat scaffold_list | xargs samtools view -o out.bam in.bam

Output only contains alignments on those scaffolds.

Thank you for your reply. It is very helpful.

Log in to answer this question.