4
$\begingroup$

When I tried to use samtools to split a bam file based on different chromosomes, I used this command:

samtools view input.bam -b chr21 | chr21.bam

However, I get error messages like this:

-bash: chr21.bam: command not found
[W::hts_idx_load3] The index file is older than the data file: input.bam.bai

How could I solve this problem? Thanks in advance~~~

The version I am using is:

Program: samtools (Tools for alignments in the SAM format)
Version: 1.10 (using htslib 1.10.2)
$\endgroup$

1 Answer 1

5
$\begingroup$

Try re-indexing your bam file:

samtools index input.bam

Or update the timestamp via touch index.bam.bai but I think re-indexing is safer. You might want to save any original index file first, e.g. via mv input.bam.bai old_input.bam.bai or similar

Also I think you meant > chr21.bam instead of piping via | chr21.bam if you want to save the output file

$\endgroup$
1
  • $\begingroup$ Cool! I think the problem is because I use | chr21.bam. $\endgroup$
    – Scott XU
    Commented Feb 28, 2022 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.