What is the standard way to measure contig sequence lengths in a BAM?

My understanding is that the community would use samtools idxstats to compute this information from the corresponding index file.

Are there more precise/standard approaches?


1 Answer 1


Standard approaches would be either samtools idxstats or samtools view -H, both of which will produce the exact same results. In fact, all methods will produce the exact same result, since contig length is set by the reference you align against.

  • 1
    $\begingroup$ Specifically, reference length is not "computed", it is stored. In theory an aligner could store anything in the contig length header records, but generally its the length, in characters, of the FASTA entry for the reference from the genome the reads were aligned to. $\endgroup$ Commented Feb 6, 2018 at 14:49
  • $\begingroup$ @IanSudbery I see your point. Finding the length of characters in the FASTA reference is somewhat of a "computation" though, right? Would "recorded" be a better way to describe it? $\endgroup$
    – EB2127
    Commented Feb 6, 2018 at 17:53

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.