|
|
@@ -51,6 +51,23 @@ pub struct VepLine {
|
|
|
impl FromStr for VepLine {
|
|
|
type Err = anyhow::Error;
|
|
|
|
|
|
+ /// Parses a VEP output line into a VepLine struct.
|
|
|
+ ///
|
|
|
+ /// This method expects the input string to be a tab-separated line
|
|
|
+ /// containing exactly 14 fields, as per standard VEP output format.
|
|
|
+ ///
|
|
|
+ /// # Arguments
|
|
|
+ /// * `s` - A string slice representing a single line of VEP output
|
|
|
+ ///
|
|
|
+ /// # Returns
|
|
|
+ /// * `Ok(VepLine)` if parsing is successful
|
|
|
+ /// * `Err(anyhow::Error)` if the input doesn't contain the expected number of fields
|
|
|
+ ///
|
|
|
+ /// # Example
|
|
|
+ /// ```
|
|
|
+ /// let vep_line = VepLine::from_str("").unwrap();
|
|
|
+ /// assert_eq!(vep_line.gene, "ENSG00000135744");
|
|
|
+ /// ```
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
let parts: Vec<&str> = s.split('\t').collect();
|
|
|
if parts.len() != 14 {
|
|
|
@@ -446,6 +463,31 @@ impl FromStr for VepConsequence {
|
|
|
impl TryFrom<&VepLine> for VEP {
|
|
|
type Error = anyhow::Error;
|
|
|
|
|
|
+ /// Attempts to convert a VepLine reference into a VEP struct.
|
|
|
+ ///
|
|
|
+ /// This implementation provides a way to transform the raw VEP output line
|
|
|
+ /// (represented by VepLine) into a more structured and typed VEP representation.
|
|
|
+ ///
|
|
|
+ /// # Arguments
|
|
|
+ /// * `d` - A reference to a VepLine struct
|
|
|
+ ///
|
|
|
+ /// # Returns
|
|
|
+ /// * `Ok(VEP)` if the conversion is successful
|
|
|
+ /// * `Err(anyhow::Error)` if any parsing errors occur
|
|
|
+ ///
|
|
|
+ /// # Behavior
|
|
|
+ /// - Converts "-" strings to None for optional fields
|
|
|
+ /// - Parses the consequence field into a Vec<VepConsequence>
|
|
|
+ /// - Parses the extra field into a VEPExtra struct
|
|
|
+ ///
|
|
|
+ /// # Example
|
|
|
+ /// ```
|
|
|
+ /// let vep_line = VepLine { /* ... */ };
|
|
|
+ /// match VEP::try_from(&vep_line) {
|
|
|
+ /// Ok(vep) => println!("Converted VEP: {:?}", vep),
|
|
|
+ /// Err(e) => eprintln!("Conversion failed: {}", e),
|
|
|
+ /// }
|
|
|
+ /// ```
|
|
|
fn try_from(d: &VepLine) -> anyhow::Result<Self> {
|
|
|
let or_opt = |s: &str| match s {
|
|
|
"-" => None,
|