Skip to content

Commit

Permalink
Note positions are 1-based, inclusive
Browse files Browse the repository at this point in the history
noodles uses the 1-based coordinate system with closed intervals. All
positions are 1-based, inclusive.

Closes #226 and closes #281.
  • Loading branch information
zaeleus committed Jul 16, 2024
1 parent 1a1a322 commit b9ed7ef
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions noodles-bam/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ impl Record {

/// Returns the alignment start.
///
/// This position is 1-based, inclusive.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -102,6 +104,8 @@ impl Record {

/// Returns the mate alignment start.
///
/// This position is 1-based, inclusive.
///
/// # Examples
///
/// ```
Expand Down
5 changes: 2 additions & 3 deletions noodles-bcf/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ impl Record {

/// Returns the variant start position.
///
/// Despite the BCF format using 0-based positions, this normalizes the value as a 1-based
/// position.
/// This position is 1-based, inclusive.
///
/// # Examples
///
Expand All @@ -113,7 +112,7 @@ impl Record {

/// Returns the end position of this record.
///
/// This value is 1-based.
/// This position is 1-based, inclusive.
///
/// # Examples
///
Expand Down
4 changes: 4 additions & 0 deletions noodles-cram/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ impl Record {
}

/// Returns the alignment start.
///
/// This position is 1-based, inclusive.
pub fn alignment_start(&self) -> Option<Position> {
self.alignment_start
}
Expand All @@ -109,6 +111,8 @@ impl Record {
}

/// Returns the alignment end.
///
/// This position is 1-based, inclusive.
pub fn alignment_end(&self) -> Option<Position> {
self.alignment_start().and_then(|alignment_start| {
let end = usize::from(alignment_start) + self.alignment_span() - 1;
Expand Down
4 changes: 2 additions & 2 deletions noodles-gff/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Record {

/// Returns the start position of the record.
///
/// This value is 1-based.
/// This position is 1-based, inclusive.
///
/// # Examples
///
Expand All @@ -107,7 +107,7 @@ impl Record {

/// Returns the end position of the record.
///
/// This value is 1-based.
/// This position is 1-based, inclusive.
///
/// # Examples
///
Expand Down
4 changes: 2 additions & 2 deletions noodles-gtf/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Record {

/// Returns the start position.
///
/// This value is 1-based.
/// This position is 1-based, inclusive.
///
/// # Examples
///
Expand All @@ -101,7 +101,7 @@ impl Record {

/// Returns the end position.
///
/// This value is 1-based.
/// This position is 1-based, inclusive.
///
/// # Examples
///
Expand Down
6 changes: 6 additions & 0 deletions noodles-sam/src/alignment/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub trait Record {
-> Option<io::Result<usize>>;

/// Returns the alignment start.
///
/// This position is 1-based, inclusive.
fn alignment_start(&self) -> Option<io::Result<core::Position>>;

/// Returns the mapping quality.
Expand All @@ -53,6 +55,8 @@ pub trait Record {
) -> Option<io::Result<usize>>;

/// Returns the mate alignment start.
///
/// This position is 1-based, inclusive.
fn mate_alignment_start(&self) -> Option<io::Result<core::Position>>;

/// Returns the template length.
Expand Down Expand Up @@ -102,6 +106,8 @@ pub trait Record {
}

/// Calculates the end position.
///
/// This position is 1-based, inclusive.
fn alignment_end(&self) -> Option<io::Result<core::Position>> {
let start = match self.alignment_start().transpose() {
Ok(position) => position?,
Expand Down
8 changes: 8 additions & 0 deletions noodles-sam/src/alignment/record_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ impl RecordBuf {

/// Returns the alignment start.
///
/// This position is 1-based, inclusive.
///
/// # Examples
///
/// ```
Expand All @@ -158,6 +160,8 @@ impl RecordBuf {

/// Returns a mutable reference to the alignment start.
///
/// This position is 1-based, inclusive.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -264,6 +268,8 @@ impl RecordBuf {

/// Returns the mate alignment start.
///
/// This position is 1-based, inclusive.
///
/// # Examples
///
/// ```
Expand All @@ -277,6 +283,8 @@ impl RecordBuf {

/// Returns a mutable reference to the mate alignment start.
///
/// This position is 1-based, inclusive.
///
/// # Examples
///
/// ```
Expand Down
4 changes: 4 additions & 0 deletions noodles-sam/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ impl Record {

/// Returns the alignment start.
///
/// This position is 1-based, inclusive.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -163,6 +165,8 @@ impl Record {

/// Returns the mate alignment start.
///
/// This position is 1-based, inclusive.
///
/// # Examples
///
/// ```
Expand Down
4 changes: 4 additions & 0 deletions noodles-vcf/src/variant/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub trait Record {
fn reference_sequence_name<'a, 'h: 'a>(&'a self, header: &'h Header) -> io::Result<&'a str>;

/// Returns the variant start position.
///
/// This position is 1-based, inclusive.
fn variant_start(&self) -> Option<io::Result<Position>>;

/// Returns the IDs.
Expand Down Expand Up @@ -58,6 +60,8 @@ pub trait Record {
/// If available, this returns the value of the `END` INFO field. Otherwise, it is calculated
/// using the [variant start position] and [reference bases length].
///
/// This position is 1-based, inclusive.
///
/// [variant start position]: `Self::variant_start`
/// [reference bases length]: `ReferenceBases::len`
fn variant_end(&self, header: &Header) -> io::Result<Position> {
Expand Down
6 changes: 4 additions & 2 deletions noodles-vcf/src/variant/record_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ impl RecordBuf {

/// Returns the variant start position.
///
/// If the record represents the start of a telomeric breakend, this returns `None`.
/// This position is 1-based, inclusive. If the record represents the start of a telomeric
/// breakend, this returns `None`.
///
/// # Examples
///
Expand All @@ -103,7 +104,8 @@ impl RecordBuf {

/// Returns a mutable reference to the variant start position.
///
/// If the record represents the start of a telomeric breakend, this returns `None`.
/// This position is 1-based, inclusive. If the record represents the start of a telomeric
/// breakend, this returns `None`.
///
/// # Examples
///
Expand Down

0 comments on commit b9ed7ef

Please sign in to comment.