Skip to content

Commit 65e3355

Browse files
committed
Update error label and fix some io related issue
1 parent 6c3e2e4 commit 65e3355

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/core/fitness/epistasis.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ impl EpistasisTable {
8585
.shape(&shape)
8686
.writer(writer)
8787
.begin_nd()
88-
.map_err(|e| VirolutionError::InitializationError(format!("{}", e)))?;
88+
.map_err(|e| VirolutionError::WriteError(format!("{}", e)))?;
8989

9090
// Write entries to file
9191
npy_writer
9292
.extend(entries)
93-
.map_err(|e| VirolutionError::InitializationError(format!("{}", e)))?;
93+
.map_err(|e| VirolutionError::WriteError(format!("{}", e)))?;
9494
npy_writer
9595
.finish()
96-
.map_err(|e| VirolutionError::InitializationError(format!("{}", e)))?;
96+
.map_err(|e| VirolutionError::WriteError(format!("{}", e)))?;
9797

9898
Ok(())
9999
}

src/core/fitness/table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ impl FitnessTable {
9393
.shape(shape)
9494
.writer(writer)
9595
.begin_nd()
96-
.map_err(|e| VirolutionError::InitializationError(format!("{}", e)))?;
96+
.map_err(|e| VirolutionError::WriteError(format!("{}", e)))?;
9797
npy_writer
9898
.extend(self.table.clone())
99-
.map_err(|e| VirolutionError::InitializationError(format!("{}", e)))?;
99+
.map_err(|e| VirolutionError::WriteError(format!("{}", e)))?;
100100
npy_writer
101101
.finish()
102-
.map_err(|e| VirolutionError::InitializationError(format!("{}", e)))?;
102+
.map_err(|e| VirolutionError::WriteError(format!("{}", e)))?;
103103
Ok(())
104104
}
105105
}

src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub enum VirolutionError {
99
ImplementationError(String),
1010
InitializationError(String),
1111
ReadError(String),
12+
WriteError(String),
1213
}
1314

1415
impl fmt::Display for VirolutionError {
@@ -23,6 +24,9 @@ impl fmt::Display for VirolutionError {
2324
VirolutionError::ReadError(message) => {
2425
write!(f, "ReadError: {}", message)
2526
}
27+
VirolutionError::WriteError(message) => {
28+
write!(f, "WriteError: {}", message)
29+
}
2630
}
2731
}
2832
}

src/runner.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,17 @@ impl Runner {
212212
}
213213

214214
fn write_fitness_tables(providers: &[&FitnessProvider], path: Option<&Path>) {
215-
let sequence_path = path.unwrap_or_else(|| Path::new("./"));
215+
let write_path = path.unwrap_or_else(|| Path::new("./"));
216+
217+
// create output directory
218+
fs::create_dir_all(write_path).unwrap_or_else(|_| {
219+
eprintln!("Unable to create output directory.");
220+
std::process::exit(1);
221+
});
222+
223+
// write fitness tables
216224
providers.iter().for_each(|provider| {
217-
provider.write(sequence_path).unwrap();
225+
provider.write(write_path).unwrap();
218226
});
219227
}
220228

0 commit comments

Comments
 (0)