Skip to content

Commit f9ddbe8

Browse files
committed
fix: various clippy issues
1 parent 9ddc394 commit f9ddbe8

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

src/bam/record.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ impl Record {
358358

359359
let orig_aux_offset = self.qname_capacity()
360360
+ 4 * self.cigar_len()
361-
+ (self.seq_len() + 1) / 2
361+
+ self.seq_len().div_ceil(2)
362362
+ self.seq_len();
363-
let new_aux_offset = q_len + extranul + cigar_width + (seq.len() + 1) / 2 + qual.len();
363+
let new_aux_offset = q_len + extranul + cigar_width + seq.len().div_ceil(2) + qual.len();
364364
assert!(orig_aux_offset <= self.inner.l_data as usize);
365365
let aux_len = self.inner.l_data as usize - orig_aux_offset;
366366
self.inner_mut().l_data = (new_aux_offset + aux_len) as i32;
@@ -416,7 +416,7 @@ impl Record {
416416
});
417417
}
418418
self.inner_mut().core.l_qseq = seq.len() as i32;
419-
i += (seq.len() + 1) / 2;
419+
i += seq.len().div_ceil(2);
420420
}
421421

422422
// qual
@@ -564,7 +564,7 @@ impl Record {
564564

565565
fn seq_data(&self) -> &[u8] {
566566
let offset = self.qname_capacity() + self.cigar_len() * 4;
567-
&self.data()[offset..][..(self.seq_len() + 1) / 2]
567+
&self.data()[offset..][..self.seq_len().div_ceil(2)]
568568
}
569569

570570
/// Get read sequence. Complexity: O(1).
@@ -579,7 +579,7 @@ impl Record {
579579
/// This does not entail any offsets, hence the qualities can be used directly without
580580
/// e.g. subtracting 33. Complexity: O(1).
581581
pub fn qual(&self) -> &[u8] {
582-
&self.data()[self.qname_capacity() + self.cigar_len() * 4 + (self.seq_len() + 1) / 2..]
582+
&self.data()[self.qname_capacity() + self.cigar_len() * 4 + self.seq_len().div_ceil(2)..]
583583
[..self.seq_len()]
584584
}
585585

@@ -787,7 +787,7 @@ impl Record {
787787
// CIGAR (uint32_t):
788788
+ self.cigar_len() * std::mem::size_of::<u32>()
789789
// Read sequence (4-bit encoded):
790-
+ (self.seq_len() + 1) / 2
790+
+ self.seq_len().div_ceil(2)
791791
// Base qualities (char):
792792
+ self.seq_len()..],
793793
}

src/bcf/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl IndexedReader {
318318
/// # Arguments
319319
///
320320
/// * `rid` - numeric ID of the reference to jump to; use `HeaderView::name2rid` for resolving
321-
/// contig name to ID.
321+
/// contig name to ID.
322322
/// * `start` - `0`-based **inclusive** start coordinate of region on reference.
323323
/// * `end` - Optional `0`-based **inclusive** end coordinate of region on reference. If `None`
324324
/// is given, records are fetched from `start` until the end of the contig.
@@ -605,7 +605,7 @@ pub mod synced {
605605
/// # Arguments
606606
///
607607
/// * `rid` - numeric ID of the reference to jump to; use `HeaderView::name2rid` for resolving
608-
/// contig name to ID.
608+
/// contig name to ID.
609609
/// * `start` - `0`-based start coordinate of region on reference.
610610
/// * `end` - `0`-based end coordinate of region on reference.
611611
pub fn fetch(&mut self, rid: u32, start: u64, end: u64) -> Result<()> {
@@ -835,6 +835,8 @@ fn bcf_open(target: &[u8], mode: &[u8]) -> Result<*mut htslib::htsFile> {
835835

836836
#[cfg(test)]
837837
mod tests {
838+
use tempfile::NamedTempFile;
839+
838840
use super::record::Buffer;
839841
use super::*;
840842
use crate::bcf::header::Id;

src/bcf/record.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ impl Record {
659659
/// # Arguments
660660
///
661661
/// - `genotypes` - a flattened, two-dimensional array of GenotypeAllele,
662-
/// the first dimension contains one array for each sample.
662+
/// the first dimension contains one array for each sample.
663663
///
664664
/// # Errors
665665
///
@@ -841,7 +841,7 @@ impl Record {
841841
///
842842
/// - `tag` - The tag's string.
843843
/// - `data` - a flattened, two-dimensional array, the first dimension contains one array
844-
/// for each sample.
844+
/// for each sample.
845845
///
846846
/// # Errors
847847
///
@@ -856,7 +856,7 @@ impl Record {
856856
///
857857
/// - `tag` - The tag's string.
858858
/// - `data` - a flattened, two-dimensional array, the first dimension contains one array
859-
/// for each sample.
859+
/// for each sample.
860860
///
861861
/// # Errors
862862
///
@@ -893,7 +893,7 @@ impl Record {
893893
///
894894
/// - `tag` - The tag's string.
895895
/// - `data` - a flattened, two-dimensional array, the first dimension contains one array
896-
/// for each sample.
896+
/// for each sample.
897897
///
898898
/// # Errors
899899
///
@@ -934,7 +934,7 @@ impl Record {
934934
///
935935
/// - `tag` - The tag's string.
936936
/// - `data` - a two-dimensional array, the first dimension contains one array
937-
/// for each sample. Must be non-empty.
937+
/// for each sample. Must be non-empty.
938938
///
939939
/// # Errors
940940
///

src/bgzf/mod.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ impl std::io::Read for Reader {
121121
htslib::bgzf_read(self.inner, buf.as_mut_ptr() as *mut libc::c_void, buf.len())
122122
};
123123
if nbytes < 0 {
124-
Err(std::io::Error::new(
125-
std::io::ErrorKind::Other,
126-
"Can not read",
127-
))
124+
Err(std::io::Error::other("Can not read"))
128125
} else {
129126
Ok(nbytes as usize)
130127
}
@@ -268,10 +265,7 @@ impl std::io::Write for Writer {
268265
let nbytes =
269266
unsafe { htslib::bgzf_write(self.inner, buf.as_ptr() as *mut libc::c_void, buf.len()) };
270267
if nbytes < 0 {
271-
Err(std::io::Error::new(
272-
std::io::ErrorKind::Other,
273-
"Can not write",
274-
))
268+
Err(std::io::Error::other("Can not write"))
275269
} else {
276270
Ok(nbytes as usize)
277271
}
@@ -282,10 +276,7 @@ impl std::io::Write for Writer {
282276
if exit_code == 0 {
283277
Ok(())
284278
} else {
285-
Err(std::io::Error::new(
286-
std::io::ErrorKind::Other,
287-
"Can not flush",
288-
))
279+
Err(std::io::Error::other("Can not flush"))
289280
}
290281
}
291282
}

0 commit comments

Comments
 (0)