<p>Standard approaches would be either <code>samtools idxstats</code> or <code>samtools view -H</code>, 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.</p>

CC BY-SA 3.0
2018-02-06T14:49:49.453Z
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.
Ian Sudbery
CC BY-SA 3.0
2018-02-06T17:53:46.963Z
@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?
EB2127
CC BY-SA 3.0
2018-02-06T11:18:04.657Z
2018-02-06T11:18:04.657Z
Devon Ryan
<p>What is the standard way to measure contig sequence lengths in a BAM? </p>

<p>My understanding is that the community would use <code>samtools idxstats</code> to compute this information from the corresponding index file. </p>

<p>Are there more precise/standard approaches? </p>

<samtools>
What is the standard way to measure contig sequence lengths in a BAM?
# What is the standard way to measure contig sequence lengths in a BAM?

(Asked by: username_0 on 2018-02-06)

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?

**Tags:** samtools

---

## 1 answers

### Answer by username_1 on 2018-02-06. Score: 4 | Accepted answer

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.

> **Comments:**
> **username_2**: 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.  
> **username_0**: @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?  

---

