Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
Johanna committed Sep 10, 2024
1 parent 04ecd37 commit df66f24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 61 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,20 +493,21 @@ pub fn main() -> Result<(), Error> {

log::info!("Reaging input genomes");
let path = Path::new(genome_ids);
let file = File::open(&path)?;
let file = File::open(path)?;
let reader = std::io::BufReader::new(file);

// Read in genomes to
let ids: Vec<String> = reader.lines().filter_map(|line| line.ok()).collect();

// let ids: Vec<String> = reader.lines().filter_map(|line| line.ok()).collect();
let ids: Vec<String> = reader.lines().map_while(Result::ok).collect();

log::info!("Reading input metadata");
let mut sketches: MultiSketch = MultiSketch::load(ref_db)
.unwrap_or_else(|_| panic!("Could not read sketch metadata from {}.skm", ref_db));


println!("BLUB");
// write new .skm
sketches.remove_metadata(ref_db, output_file, &ids);
let _ = sketches.remove_metadata(output_file, &ids);

// remove samples from .skd file
log::info!("Remove genomes and writing output");
Expand Down
20 changes: 1 addition & 19 deletions src/multisketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ impl MultiSketch {
}
pub fn remove_metadata(
&mut self,
input_prefix: &str,
output_file_name: &str,
genome_ids_to_remove: &[String],
) -> std::io::Result<()> {
Expand All @@ -207,7 +206,7 @@ impl MultiSketch {
}
}
self.sketch_metadata = new_sketch_metadata;
self.save_metadata(output_file_name);
let _ = self.save_metadata(output_file_name);
Ok(())
}

Expand Down Expand Up @@ -255,23 +254,6 @@ impl MultiSketch {
Ok(())
}

// pub fn get_genome_positions(&self, genome_ids: &[String], positions: &mut Vec<usize>) {
// let mut missing_ids = Vec::new();

// for id in genome_ids {
// if let Some(&position) = self.name_map.get(id) {
// positions.push(position);
// } else {
// missing_ids.push(id.clone());
// }
// }

// if !missing_ids.is_empty() {
// panic!("The following genome IDs were not found: {:?}", missing_ids);
// }

// positions.sort();
// }

// This function is called when sketches are merged, not when they are
// first sketched (this is handled by sketch::sketch_files())
Expand Down
52 changes: 14 additions & 38 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,20 @@ impl TestSetup {
pub fn setup() -> Self {
let wd = assert_fs::TempDir::new().unwrap();

println!("Current working directory: {:?}", std::env::current_dir().unwrap());

// Debug: Print FILE_IN and FILE_TEST paths
println!("FILE_IN constant value: {:?}", FILE_IN);
println!("FILE_TEST constant value: {:?}", FILE_TEST);

let file_in_path = Path::new(FILE_IN);
let file_test_path = Path::new(FILE_TEST);

println!("FILE_IN absolute path: {:?}", file_in_path.canonicalize());
println!("FILE_TEST absolute path: {:?}", file_test_path.canonicalize());

// Check if the directories exist
println!("FILE_IN exists: {}", file_in_path.exists());
println!("FILE_TEST exists: {}", file_test_path.exists());

// Attempt to create symlink for SYM_IN
match wd.child(SYM_IN).symlink_to_dir(file_in_path.canonicalize().unwrap_or_else(|e| {
panic!("Failed to canonicalize FILE_IN path: {:?}. Error: {:?}", file_in_path, e);
})) {
Ok(_) => println!("Successfully created symlink for {}", SYM_IN),
Err(e) => println!("Failed to create symlink for {}: {:?}", SYM_IN, e),
}

// Attempt to create symlink for SYM_TEST
match wd.child(SYM_TEST).symlink_to_dir(file_test_path.canonicalize().unwrap_or_else(|e| {
panic!("Failed to canonicalize FILE_TEST path: {:?}. Error: {:?}", file_test_path, e);
})) {
Ok(_) => println!("Successfully created symlink for {}", SYM_TEST),
Err(e) => println!("Failed to create symlink for {}: {:?}", SYM_TEST, e),
}

// Debug: Print contents of temporary directory
println!("Contents of temporary directory:");
for entry in std::fs::read_dir(&wd.path()).unwrap() {
let entry = entry.unwrap();
println!(" {:?}", entry.path());
}
wd.child(SYM_IN)
.symlink_to_dir(
Path::new(FILE_IN)
.canonicalize()
.expect("Could not link expected files"),
)
.unwrap();
wd.child(SYM_TEST)
.symlink_to_dir(
Path::new(FILE_TEST)
.canonicalize()
.expect("Could not link expected files"),
)
.unwrap();

Self { wd }
}
Expand Down

0 comments on commit df66f24

Please sign in to comment.