-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from bzhanglab/dev
Add multi-omics and better CLI messages
- Loading branch information
Showing
6 changed files
with
310 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ interest.txt | |
latest.gmt | ||
ref.txt | ||
target_symbols.txt | ||
/*.gmt | ||
/*.rnk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,75 @@ | ||
use std::{error::Error, fmt}; | ||
|
||
pub mod methods; | ||
pub mod readers; | ||
pub mod stat; | ||
pub enum Error { | ||
|
||
trait CustomError { | ||
fn msg(&self) -> String; | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum WebGestaltError { | ||
MalformedFile(MalformedError), | ||
StatisticsError(StatisticsError), | ||
IOError(std::io::Error), | ||
} | ||
|
||
pub enum MalformedError { | ||
NoColumnsFound, | ||
WrongFormat, | ||
impl Error for WebGestaltError {} | ||
|
||
impl fmt::Display for WebGestaltError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
let msg: String = match &self { | ||
WebGestaltError::MalformedFile(x) => x.msg(), | ||
WebGestaltError::StatisticsError(x) => x.msg(), | ||
WebGestaltError::IOError(x) => x.to_string(), | ||
}; | ||
write!(f, "{}", msg) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct MalformedError { | ||
pub path: String, | ||
pub kind: MalformedErrorType, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum MalformedErrorType { | ||
NoColumnsFound { delimeter: String }, | ||
WrongFormat { found: String, expected: String }, | ||
Unknown, | ||
} | ||
|
||
impl CustomError for MalformedError { | ||
fn msg(&self) -> String { | ||
let error_msg = match &self.kind { | ||
MalformedErrorType::WrongFormat { found, expected } => format!( | ||
"Wrong Format Found. Found: {}; Expected: {}", | ||
found, expected | ||
), | ||
MalformedErrorType::Unknown => String::from("Unknown error type."), | ||
MalformedErrorType::NoColumnsFound { delimeter } => format!( | ||
"No column found with delimeter {}", | ||
if delimeter == "\t" { "\\t" } else { delimeter } | ||
), | ||
}; | ||
format!("Error in {}: {}.", self.path, error_msg) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum StatisticsError { | ||
FoundNANValue, | ||
InvalidValue, | ||
InvalidValue { value: f64 }, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
impl CustomError for StatisticsError { | ||
fn msg(&self) -> String { | ||
let error_msg = match &self { | ||
StatisticsError::FoundNANValue => String::from("Found a NAN value"), | ||
StatisticsError::InvalidValue { value } => format!("Found invalid value: {}", value), | ||
}; | ||
format!("Statstical Error: {}.", error_msg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.