Skip to content

Commit 8ae3d41

Browse files
cargo fmt
1 parent 5f5973b commit 8ae3d41

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

gtars/src/common/utils.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub fn get_dynamic_reader(path: &Path) -> Result<BufReader<Box<dyn Read>>> {
3939
///
4040
/// - file_path: path to the file to read, or '-' for stdin
4141
///
42-
/// # Returns
43-
///
42+
/// # Returns
43+
///
4444
/// A `BufReader` object for a given file path or stdin.
4545
pub fn get_dynamic_reader_w_stdin(file_path_str: &str) -> Result<BufReader<Box<dyn Read>>> {
4646
if file_path_str == "-" {
@@ -51,7 +51,6 @@ pub fn get_dynamic_reader_w_stdin(file_path_str: &str) -> Result<BufReader<Box<d
5151
}
5252
}
5353

54-
5554
///
5655
/// Create a region-to-id hash-map from a list of regions
5756
///

gtars/src/digests/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313
//! # Usage
1414
//!
1515
//! The `sha512t24u` function can be used to compute the GA4GH sha512t24 checksum of a string.
16-
//!
16+
//!
1717
//! ```rust
1818
//! use gtars::digests::sha512t24u;
1919
//!
2020
//! let digest = sha512t24u("hello world");
2121
//! ```
22-
use std::io::prelude::{Read, Write};
23-
use std::io;
2422
use std::fs::File;
23+
use std::io;
24+
use std::io::prelude::{Read, Write};
2525
use std::path::Path;
2626

2727
use anyhow::Result;
2828
use md5::Md5;
29+
use seq_io::fasta::{Reader, Record, RefRecord};
2930
use sha2::{Digest, Sha512};
30-
use seq_io::fasta::{Reader, RefRecord, Record};
3131

3232
use crate::common::utils::get_dynamic_reader;
3333

@@ -75,7 +75,6 @@ pub fn md5(string: &str) -> String {
7575
format!("{:x}", result)
7676
}
7777

78-
7978
/// Processes a FASTA file to compute the digests of each sequence in the file.
8079
///
8180
/// This function reads a FASTA file, computes the SHA-512 and MD5 digests for each sequence,
@@ -103,7 +102,8 @@ pub fn digest_fasta(file_path: &str) -> Result<Vec<DigestResult>> {
103102
let file_reader = get_dynamic_reader(&path)?;
104103
let mut fasta_reader = Reader::new(file_reader);
105104
let mut results = Vec::new();
106-
while let Some(record) = fasta_reader.next() { // returns a RefRecord object
105+
while let Some(record) = fasta_reader.next() {
106+
// returns a RefRecord object
107107
let record = record.expect("Error found when retrieving next record.");
108108
let id = record.id().expect("No ID found for the FASTA record");
109109
let mut sha512_hasher = Sha512::new();
@@ -123,7 +123,7 @@ pub fn digest_fasta(file_path: &str) -> Result<Vec<DigestResult>> {
123123
id: id.to_string(),
124124
length: length,
125125
sha512t24u: sha512,
126-
md5: md5
126+
md5: md5,
127127
});
128128
}
129129
Ok(results)
@@ -169,10 +169,10 @@ mod tests {
169169
assert_eq!(results[0].sha512t24u, "iYtREV555dUFKg2_agSJW6suquUyPpMw");
170170
assert_eq!(results[0].md5, "5f63cfaa3ef61f88c9635fb9d18ec945");
171171
}
172-
172+
173173
#[test]
174174
fn bogus_fasta_file() {
175175
let result = digest_fasta("tests/data/bogus.fa");
176176
assert!(result.is_err(), "Expected an error for a bogus fasta file");
177177
}
178-
}
178+
}

gtars/src/uniwig/counting.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub fn start_end_counts(
3535
smoothsize: i32,
3636
stepsize: i32,
3737
) -> (Vec<u32>, Vec<i32>) {
38-
3938
let mut v_coordinate_positions: Vec<i32> = Vec::new(); // these are the final coordinates after any adjustments
4039
let mut v_coord_counts: Vec<u32> = Vec::new(); // u8 stores 0:255 This may be insufficient. u16 max is 65535
4140

gtars/src/uniwig/mod.rs

+23-20
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub fn run_uniwig(matches: &ArgMatches) {
191191
}
192192

193193
/// Ensures that the start position is at a minimum equal to `1`
194-
fn clamped_start_position(start: i32, smoothsize: i32, wig_shift:i32) -> i32 {
194+
fn clamped_start_position(start: i32, smoothsize: i32, wig_shift: i32) -> i32 {
195195
std::cmp::max(1, start - smoothsize + wig_shift)
196196
}
197197
/// Ensure that the start position is at a minimum equal to `0`
@@ -222,7 +222,6 @@ pub fn uniwig_main(
222222
.build()
223223
.unwrap();
224224

225-
226225
// Determine Input File Type
227226
let input_filetype = FileType::from_str(filetype.to_lowercase().as_str());
228227
// Set up output file names
@@ -319,7 +318,7 @@ pub fn uniwig_main(
319318
clamped_start_position(
320319
primary_start.0,
321320
smoothsize,
322-
1 //must shift wiggle starts and core by 1 since it is 1 based
321+
1, //must shift wiggle starts and core by 1 since it is 1 based
323322
),
324323
stepsize,
325324
current_chrom_size,
@@ -449,7 +448,7 @@ pub fn uniwig_main(
449448
clamped_start_position(
450449
primary_end.0,
451450
smoothsize,
452-
0
451+
0,
453452
),
454453
stepsize,
455454
meta_data_file_names[1].clone(),
@@ -468,7 +467,7 @@ pub fn uniwig_main(
468467
clamped_start_position(
469468
primary_end.0,
470469
smoothsize,
471-
0
470+
0,
472471
),
473472
stepsize,
474473
meta_data_file_names[1].clone(),
@@ -520,7 +519,7 @@ pub fn uniwig_main(
520519
&core_results.0,
521520
file_name.clone(),
522521
chrom_name.clone(),
523-
clamped_start_position(primary_start.0, 0,1), //starts are 1 based must be shifted by 1
522+
clamped_start_position(primary_start.0, 0, 1), //starts are 1 based must be shifted by 1
524523
stepsize,
525524
current_chrom_size,
526525
);
@@ -589,9 +588,9 @@ pub fn uniwig_main(
589588
);
590589
}
591590
}
592-
"npy" =>{
591+
"npy" => {
593592
// populate hashmap for the npy meta data
594-
for chromosome in final_chromosomes.iter(){
593+
for chromosome in final_chromosomes.iter() {
595594
let chr_name = chromosome.chrom.clone();
596595
let current_chrom_size =
597596
*chrom_sizes.get(&chromosome.chrom).unwrap() as i32;
@@ -605,42 +604,46 @@ pub fn uniwig_main(
605604
}
606605

607606
for location in vec_count_type.iter() {
608-
609-
let temp_meta_file_name = format!("{}{}.{}", bwfileheader, *location, "meta");
607+
let temp_meta_file_name =
608+
format!("{}{}.{}", bwfileheader, *location, "meta");
610609

611610
if let Ok(file) = File::open(&temp_meta_file_name) {
612-
613611
let reader = BufReader::new(file);
614612

615613
for line in reader.lines() {
616614
let line = line.unwrap();
617615
let parts: Vec<&str> = line.split_whitespace().collect();
618616
if parts.len() >= 3 {
619-
let chrom = parts[1].split('=')
620-
.nth(1)
621-
.expect("Processing npy metadata file: Missing chromosome in line");
617+
let chrom = parts[1].split('=').nth(1).expect(
618+
"Processing npy metadata file: Missing chromosome in line",
619+
);
622620
let start_str = parts[2].split('=')
623621
.nth(1)
624622
.expect("Processing npy metadata file: Missing start position in line");
625-
let starting_position: i32 = start_str.parse().expect("Processing npy metadata file: Invalid start position");
623+
let starting_position: i32 = start_str.parse().expect(
624+
"Processing npy metadata file: Invalid start position",
625+
);
626626

627-
if let Some(current_chr_data) = npy_meta_data_map.get_mut(chrom) {
628-
current_chr_data.insert((*location.to_string()).parse().unwrap(), starting_position);
627+
if let Some(current_chr_data) = npy_meta_data_map.get_mut(chrom)
628+
{
629+
current_chr_data.insert(
630+
(*location.to_string()).parse().unwrap(),
631+
starting_position,
632+
);
629633
}
630634
}
631635
}
632636
// Remove the file after it is used.
633637
let path = std::path::Path::new(&temp_meta_file_name);
634638
let _ = remove_file(path).unwrap();
635639
}
636-
637640
}
638641
//write combined metadata as json
639642
let json_string = serde_json::to_string_pretty(&npy_meta_data_map).unwrap();
640-
let combined_npy_meta_file_path = format!("{}{}.{}", bwfileheader, "npy_meta", "json");
643+
let combined_npy_meta_file_path =
644+
format!("{}{}.{}", bwfileheader, "npy_meta", "json");
641645
let mut file = File::create(combined_npy_meta_file_path).unwrap();
642646
file.write_all(json_string.as_bytes()).unwrap();
643-
644647
}
645648
_ => {}
646649
}

0 commit comments

Comments
 (0)