@@ -7,8 +7,8 @@ use std::collections::HashMap;
77use thin_vec:: ThinVec ;
88
99use mzcv:: {
10- CVError , CVFile , CVSource , CVVersion , HashBufReader , OboIdentifier , OboOntology , OboStanzaType ,
11- OboValue , RelationType ,
10+ CVError , CVFile , CVSource , CVVersion , Comment , HashBufReader , Modifier , OboIdentifier ,
11+ OboOntology , OboStanzaType , OboValue , RelationType ,
1212} ;
1313
1414use crate :: {
@@ -148,7 +148,7 @@ impl CVSource for XlMod {
148148 }
149149
150150 if properties. sites == Some ( 2 ) {
151- let mut m =
151+ let mut m =
152152 OntologyModification {
153153 formula : properties. formula . unwrap_or_default ( ) ,
154154 name,
@@ -186,7 +186,7 @@ impl CVSource for XlMod {
186186 m. add_relationships ( & obj. relationship ) ;
187187 mods. push ( m) ;
188188 } else if properties. sites == Some ( 1 ) {
189- let mut m =
189+ let mut m =
190190 OntologyModification {
191191 formula : properties. formula . unwrap_or_default ( ) ,
192192 name,
@@ -245,10 +245,7 @@ struct Properties {
245245}
246246
247247fn parse_property_values (
248- property_values : & HashMap <
249- Box < str > ,
250- Vec < ( OboValue , Vec < ( Box < str > , Box < str > ) > , Option < Box < str > > ) > ,
251- > ,
248+ property_values : & HashMap < Box < str > , Vec < ( OboValue , Vec < Modifier > , Comment ) > > ,
252249 properties : & mut Properties ,
253250 id : OboIdentifier ,
254251) -> Vec < BoxedError < ' static , CVError > > {
@@ -471,9 +468,16 @@ fn parse_property_values(
471468 }
472469 "neutralLossFormula" => {
473470 for ( def, _, _) in value {
474- properties
475- . neutral_losses
476- . push ( MolecularFormula :: xlmod ( & def. to_string ( ) ) . unwrap ( ) . into ( ) ) ;
471+ match MolecularFormula :: xlmod ( & def. to_string ( ) ) {
472+ Ok ( v) => properties. neutral_losses . push ( v. into ( ) ) ,
473+ Err ( err) => combine_error (
474+ & mut errors,
475+ err. to_owned ( )
476+ . convert :: < CVError , BoxedError < ' static , CVError > > ( |_| {
477+ CVError :: ItemError
478+ } ) ,
479+ ) ,
480+ }
477481 }
478482 }
479483 "bridgeFormula" => {
@@ -489,8 +493,11 @@ fn parse_property_values(
489493 ) ;
490494 }
491495 properties. sites = properties. sites . or ( Some ( 2 ) ) ;
492- properties. formula =
493- Some ( MolecularFormula :: xlmod ( & value[ 0 ] . 0 . to_string ( ) ) . unwrap ( ) ) ;
496+ properties. formula = MolecularFormula :: xlmod ( & value[ 0 ] . 0 . to_string ( ) )
497+ . map_err ( |e| {
498+ combine_error ( & mut errors, e. to_owned ( ) . convert ( |_| CVError :: ItemError ) ) ;
499+ } )
500+ . ok ( ) ;
494501 }
495502 "specificities" => {
496503 // specificities: "(C,U)" xsd:string
@@ -599,9 +606,16 @@ fn parse_property_values(
599606 }
600607 "reporterFormula" => {
601608 for ( def, _, _) in value {
602- properties. diagnostic_ions . push ( DiagnosticIon (
603- MolecularFormula :: xlmod ( & def. to_string ( ) ) . unwrap ( ) ,
604- ) ) ;
609+ match MolecularFormula :: xlmod ( & def. to_string ( ) ) {
610+ Ok ( v) => properties. diagnostic_ions . push ( v. into ( ) ) ,
611+ Err ( err) => combine_error (
612+ & mut errors,
613+ err. to_owned ( )
614+ . convert :: < CVError , BoxedError < ' static , CVError > > ( |_| {
615+ CVError :: ItemError
616+ } ) ,
617+ ) ,
618+ }
605619 }
606620 }
607621 "stubDefinition" | "stubFormula" => {
@@ -610,23 +624,24 @@ fn parse_property_values(
610624 // TODO: Extend the stub logic to handle the techniques and neutral losses
611625 for ( def, _, _) in value {
612626 if let OboValue :: String ( definition) = & def {
613- let ( techniques , definition) = definition. split_once ( '=' ) . unwrap ( ) ;
627+ let ( _techniques , definition) = definition. split_once ( '=' ) . unwrap ( ) ;
614628 let ( first, second) = definition. split_once ( ':' ) . unwrap ( ) ;
615629 let mut split_first = first. split ( ',' ) ;
616630 let mut split_second = second. split ( ',' ) ;
617- let formula_first =
618- split_first. next ( ) . map_or ( MolecularFormula :: default ( ) , |v| {
631+ let formula_first = split_first
632+ . next ( )
633+ . map_or_else ( MolecularFormula :: default, |v| {
619634 MolecularFormula :: xlmod ( v) . unwrap ( )
620635 } ) ;
621- let losses_first : Vec < NeutralLoss > = split_first
636+ let _losses_first : Vec < NeutralLoss > = split_first
622637 . map ( |v| MolecularFormula :: xlmod ( v) . unwrap ( ) . into ( ) )
623638 . collect ( ) ;
624639 let formula_second = split_second
625640 . next ( )
626- . map_or ( MolecularFormula :: default ( ) , |v| {
641+ . map_or_else ( MolecularFormula :: default, |v| {
627642 MolecularFormula :: xlmod ( v) . unwrap ( )
628643 } ) ;
629- let losses_second : Vec < NeutralLoss > = split_second
644+ let _losses_second : Vec < NeutralLoss > = split_second
630645 . map ( |v| MolecularFormula :: xlmod ( v) . unwrap ( ) . into ( ) )
631646 . collect ( ) ;
632647 properties. stubs . push ( ( formula_first, formula_second) ) ;
0 commit comments