Skip to content

Commit

Permalink
chore: updates rustfmt to use version = "Two"
Browse files Browse the repository at this point in the history
  • Loading branch information
claymcleod committed Dec 21, 2023
1 parent bfbcd70 commit 50c7dcc
Show file tree
Hide file tree
Showing 18 changed files with 347 additions and 191 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Update Rust
run: rustup update stable && rustup default stable
run: rustup update nightly && rustup defaultnightly
- name: Install rustfmt
run: rustup component add rustfmt
- run: cargo fmt -- --check
Expand All @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Update Rust
run: rustup update stable && rustup default stable
run: rustup update nightly && rustup defaultnightly
- name: Install clippy
run: rustup component add clippy
- run: cargo clippy --all-features -- --deny warnings
Expand All @@ -28,5 +28,5 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Update Rust
run: rustup update stable && rustup default stable
run: rustup update nightly && rustup defaultnightly
- run: cargo test --all-features
10 changes: 5 additions & 5 deletions examples/chain_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.map(BufReader::new)
.map(chain::Reader::new)?;

let machine = liftover::machine::builder::Builder::default().try_build_from(chain)?;
let machine = liftover::machine::builder::Builder.try_build_from(chain)?;

let mut reference = HashMap::new();
for result in fasta::reader::Builder::default()
for result in fasta::reader::Builder
.build_from_path(reference_path)?
.records()
{
Expand All @@ -59,7 +59,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

let mut query = HashMap::new();
for result in fasta::reader::Builder::default()
for result in fasta::reader::Builder
.build_from_path(query_path)?
.records()
{
Expand Down Expand Up @@ -87,8 +87,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for region in results {
let query_sequence = query.get(region.query().contig()).unwrap_or_else(|| {
panic!(
"query fasta did not contain necessary contig: {}. \
Are the FASTA files and chain file correct?",
"query fasta did not contain necessary contig: {}. Are the FASTA files and \
chain file correct?",
region.query().contig()
)
});
Expand Down
2 changes: 1 addition & 1 deletion examples/liftover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.map(BufReader::new)
.map(chain::Reader::new)?;

let machine = liftover::machine::builder::Builder::default().try_build_from(reader)?;
let machine = liftover::machine::builder::Builder.try_build_from(reader)?;
let results = machine.liftover(&interval);

match results {
Expand Down
15 changes: 15 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Unstable settings
condense_wildcard_suffixes = true
format_code_in_doc_comments = true
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
hex_literal_case = "Upper"
imports_granularity = "Item"
newline_style = "Unix"
normalize_comments = true
normalize_doc_attributes = true
reorder_impl_items = true
use_field_init_shorthand = true
wrap_comments = true
version = "Two"
54 changes: 33 additions & 21 deletions src/core/coordinate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! A 0-based location within a genome consisting of a contig, a position, and a strand.
//! A 0-based location within a genome consisting of a contig, a position, and a
//! strand.

use crate::core::Interval;
use crate::core::Strand;
Expand Down Expand Up @@ -46,11 +47,11 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::coordinate::Error;
/// use chain::core::Coordinate;
/// use chain::core::Position;
/// use chain::core::Strand;
/// use chain::core::coordinate::Error;
/// use chainfile as chain;
///
/// // Positive-stranded
///
Expand All @@ -75,7 +76,8 @@ impl Coordinate {
///
/// // Attempting to create negative-bound on positive strand
///
/// let err = Coordinate::try_new("seq0", Position::negative_bound(), Strand::Positive).unwrap_err();
/// let err =
/// Coordinate::try_new("seq0", Position::negative_bound(), Strand::Positive).unwrap_err();
/// assert_eq!(err, Error::NegativeBoundOnNonNegativeStrand);
///
/// # Ok::<(), Box<dyn std::error::Error>>(())
Expand Down Expand Up @@ -107,10 +109,10 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Position;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// let coordinate = Coordinate::negative_bound("seq0");
/// assert_eq!(coordinate.contig().as_str(), "seq0");
Expand All @@ -128,9 +130,9 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// // Zero-based coordinate
///
Expand All @@ -153,10 +155,10 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Position;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// // Zero-based coordinate
///
Expand All @@ -179,9 +181,9 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// // Zero-based coordinate
///
Expand Down Expand Up @@ -211,10 +213,10 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Position;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// // Positive-stranded
///
Expand Down Expand Up @@ -330,10 +332,10 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Position;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// // Positive-stranded
///
Expand Down Expand Up @@ -430,17 +432,19 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Interval;
/// use chain::core::Position;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// // Positive-stranded that falls within interval
///
/// let coordinate = Coordinate::try_new("seq0", 0, Strand::Positive)?;
/// let interval = "seq0:0-1000".parse::<Interval>()?;
/// let result = coordinate.move_forward_checked_bounds(10, &interval).unwrap()?;
/// let result = coordinate
/// .move_forward_checked_bounds(10, &interval)
/// .unwrap()?;
///
/// assert_eq!(result.contig(), &String::from("seq0"));
/// assert_eq!(result.position(), &Position::new(10));
Expand All @@ -450,7 +454,9 @@ impl Coordinate {
///
/// let coordinate = Coordinate::try_new("seq0", 1000, Strand::Negative)?;
/// let interval = "seq0:1000-0".parse::<Interval>()?;
/// let result = coordinate.move_forward_checked_bounds(10, &interval).unwrap()?;
/// let result = coordinate
/// .move_forward_checked_bounds(10, &interval)
/// .unwrap()?;
///
/// assert_eq!(result.contig(), &String::from("seq0"));
/// assert_eq!(result.position(), &Position::new(990));
Expand Down Expand Up @@ -502,17 +508,19 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Interval;
/// use chain::core::Position;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// // Positive-stranded that falls within interval
///
/// let coordinate = Coordinate::try_new("seq0", 500, Strand::Positive)?;
/// let interval = "seq0:0-1000".parse::<Interval>()?;
/// let result = coordinate.move_backward_checked_bounds(10, &interval).unwrap()?;
/// let result = coordinate
/// .move_backward_checked_bounds(10, &interval)
/// .unwrap()?;
///
/// assert_eq!(result.contig(), &String::from("seq0"));
/// assert_eq!(result.position(), &Position::new(490));
Expand All @@ -522,7 +530,9 @@ impl Coordinate {
///
/// let coordinate = Coordinate::try_new("seq0", 500, Strand::Negative)?;
/// let interval = "seq0:1000-0".parse::<Interval>()?;
/// let result = coordinate.move_backward_checked_bounds(10, &interval).unwrap()?;
/// let result = coordinate
/// .move_backward_checked_bounds(10, &interval)
/// .unwrap()?;
///
/// assert_eq!(result.contig(), &String::from("seq0"));
/// assert_eq!(result.position(), &Position::new(510));
Expand All @@ -540,7 +550,9 @@ impl Coordinate {
///
/// let coordinate = Coordinate::negative_bound("seq0");
/// let interval = "seq0:10-$".parse::<Interval>()?;
/// let result = coordinate.move_backward_checked_bounds(11, &interval).unwrap()?;
/// let result = coordinate
/// .move_backward_checked_bounds(11, &interval)
/// .unwrap()?;
///
/// assert_eq!(result.contig(), &String::from("seq0"));
/// assert_eq!(result.position(), &Position::new(10));
Expand Down Expand Up @@ -581,11 +593,11 @@ impl Coordinate {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Coordinate;
/// use chain::core::Interval;
/// use chain::core::Position;
/// use chain::core::Strand;
/// use chainfile as chain;
///
/// // Positive-strand
/// let coordinate = Coordinate::try_new("seq0", 5, Strand::Positive)?;
Expand Down Expand Up @@ -613,16 +625,16 @@ impl Coordinate {
let position = match self.position() {
Position::ZeroBased(position) => position,
Position::NegativeBound => {
return Coordinate::try_new(self.contig(), contig_size, self.strand().clone())
return Coordinate::try_new(self.contig(), contig_size, self.strand().clone());
}
};

let new_position_plus_one = contig_size - position;
if new_position_plus_one == 0 {
match self.strand() {
Strand::Positive => unreachable!(
"it should never be possible to want to return the negative bound \
if the source coordinate is on the positive strand"
"it should never be possible to want to return the negative bound if the \
source coordinate is on the positive strand"
),
Strand::Negative => Ok(Coordinate::negative_bound(self.contig())),
}
Expand Down
11 changes: 3 additions & 8 deletions src/core/coordinate/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ impl std::ops::Sub for &Position {

impl PartialOrd for Position {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
match (self, other) {
(Position::ZeroBased(a), Position::ZeroBased(b)) => a.partial_cmp(b),
(Position::ZeroBased(_), Position::NegativeBound) => Some(std::cmp::Ordering::Greater),
(Position::NegativeBound, Position::ZeroBased(_)) => Some(std::cmp::Ordering::Less),
(Position::NegativeBound, Position::NegativeBound) => Some(std::cmp::Ordering::Equal),
}
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -182,8 +177,8 @@ impl Position {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Position;
/// use chainfile as chain;
///
/// let position = Position::new(0);
/// assert!(matches!(position, Position::ZeroBased(0)));
Expand All @@ -197,8 +192,8 @@ impl Position {
/// # Examples
///
/// ```
/// use chainfile as chain;
/// use chain::core::Position;
/// use chainfile as chain;
///
/// let position = Position::negative_bound();
/// assert!(matches!(position, Position::NegativeBound));
Expand Down

0 comments on commit 50c7dcc

Please sign in to comment.