@@ -1236,28 +1236,28 @@ macro_rules! curie {
1236
1236
$crate:: params:: CURIE :: new( $crate:: params:: ControlledVocabulary :: MS , $acc)
1237
1237
} ;
1238
1238
( UO : $acc: literal) => {
1239
- $crate:: params:: CURIE :: new ( $crate:: params:: ControlledVocabulary :: UO , $acc)
1239
+ $crate:: params:: CURIE { controlled_vocabulary : $crate:: params:: ControlledVocabulary :: UO , accession : $acc }
1240
1240
} ;
1241
1241
( EFO : $acc: literal) => {
1242
- $crate:: params:: CURIE :: new ( $crate:: params:: ControlledVocabulary :: EFO , $acc)
1242
+ $crate:: params:: CURIE { controlled_vocabulary : $crate:: params:: ControlledVocabulary :: EFO , accession : $acc }
1243
1243
} ;
1244
1244
( BFO : $acc: literal) => {
1245
- $crate:: params:: CURIE :: new ( $crate:: params:: ControlledVocabulary :: BFO , $acc)
1245
+ $crate:: params:: CURIE { controlled_vocabulary : $crate:: params:: ControlledVocabulary :: BFO , accession : $acc }
1246
1246
} ;
1247
1247
( BTO : $acc: literal) => {
1248
- $crate:: params:: CURIE :: new ( $crate:: params:: ControlledVocabulary :: BTO , $acc)
1248
+ $crate:: params:: CURIE { controlled_vocabulary : $crate:: params:: ControlledVocabulary :: BTO , accession : $acc }
1249
1249
} ;
1250
1250
( OBI : $acc: literal) => {
1251
- $crate:: params:: CURIE :: new ( $crate:: params:: ControlledVocabulary :: OBI , $acc)
1251
+ $crate:: params:: CURIE { controlled_vocabulary : $crate:: params:: ControlledVocabulary :: OBI , accession : $acc }
1252
1252
} ;
1253
1253
( HANCESTRO : $acc: literal) => {
1254
- $crate:: params:: CURIE :: new ( $crate:: params:: ControlledVocabulary :: HANCESTRO , $acc)
1254
+ $crate:: params:: CURIE { controlled_vocabulary : $crate:: params:: ControlledVocabulary :: HANCESTRO , accession : $acc }
1255
1255
} ;
1256
1256
( NCIT : $acc: literal) => {
1257
- $crate:: params:: CURIE :: new ( $crate:: params:: ControlledVocabulary :: NCIT , $acc)
1257
+ $crate:: params:: CURIE { controlled_vocabulary : $crate:: params:: ControlledVocabulary :: NCIT , accession : $acc }
1258
1258
} ;
1259
1259
( PRIDE : $acc: literal) => {
1260
- $crate:: params:: CURIE :: new ( $crate:: params:: ControlledVocabulary :: PRIDE , $acc)
1260
+ $crate:: params:: CURIE { controlled_vocabulary : $crate:: params:: ControlledVocabulary :: PRIDE , accession : $acc }
1261
1261
} ;
1262
1262
}
1263
1263
@@ -1287,6 +1287,30 @@ impl CURIE {
1287
1287
}
1288
1288
}
1289
1289
1290
+ /// A CURIE is a namespace + accession identifier
1291
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
1292
+ struct PackedCURIE ( u64 ) ;
1293
+
1294
+ #[ allow( unused) ]
1295
+ impl PackedCURIE {
1296
+ pub fn from_curie ( curie : CURIE ) -> Self {
1297
+ let cv = curie. controlled_vocabulary ( ) ;
1298
+ let cv_id = cv as u64 ;
1299
+ let acc_code = curie. accession_int ( ) ;
1300
+ let code = acc_code as u64 ;
1301
+ Self ( cv_id << 56 | code)
1302
+ }
1303
+
1304
+ pub fn accession ( & self ) -> u64 {
1305
+ self . 0 & 0x00ffffffffffffff
1306
+ }
1307
+
1308
+ pub fn controlled_vocabulary ( & self ) -> ControlledVocabulary {
1309
+ ( ( self . 0 & 0xff00000000000000 ) as u8 ) . try_into ( ) . unwrap ( )
1310
+ }
1311
+ }
1312
+
1313
+
1290
1314
impl Display for CURIE {
1291
1315
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1292
1316
write ! (
@@ -1896,9 +1920,10 @@ impl Hash for Param {
1896
1920
/// Controlled vocabularies used in mass spectrometry data files
1897
1921
#[ derive( Debug , Clone , Copy , Hash , PartialEq , Eq ) ]
1898
1922
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
1923
+ #[ repr( u8 ) ]
1899
1924
pub enum ControlledVocabulary {
1900
1925
/// The PSI-MS Controlled Vocabulary [https://www.ebi.ac.uk/ols4/ontologies/ms](https://www.ebi.ac.uk/ols4/ontologies/ms)
1901
- MS ,
1926
+ MS = 1 ,
1902
1927
/// The Unit Ontology [https://www.ebi.ac.uk/ols4/ontologies/uo](https://www.ebi.ac.uk/ols4/ontologies/uo)
1903
1928
UO ,
1904
1929
/// The Experimental Factor Ontology <https://www.ebi.ac.uk/ols4/ontologies/efo>
@@ -1938,6 +1963,26 @@ const BTO_CV_BYTES: &[u8] = BTO_CV.as_bytes();
1938
1963
const NCIT_CV_BYTES : & [ u8 ] = NCIT_CV . as_bytes ( ) ;
1939
1964
const PRIDE_CV_BYTES : & [ u8 ] = PRIDE_CV . as_bytes ( ) ;
1940
1965
1966
+
1967
+ impl TryFrom < u8 > for ControlledVocabulary {
1968
+ type Error = ControlledVocabularyResolutionError ;
1969
+
1970
+ fn try_from ( value : u8 ) -> Result < Self , Self :: Error > {
1971
+ match value {
1972
+ 1 => Ok ( Self :: MS ) ,
1973
+ 2 => Ok ( Self :: UO ) ,
1974
+ 3 => Ok ( Self :: EFO ) ,
1975
+ 4 => Ok ( Self :: OBI ) ,
1976
+ 5 => Ok ( Self :: HANCESTRO ) ,
1977
+ 6 => Ok ( Self :: BFO ) ,
1978
+ 7 => Ok ( Self :: NCIT ) ,
1979
+ 8 => Ok ( Self :: BTO ) ,
1980
+ 9 => Ok ( Self :: PRIDE ) ,
1981
+ _ => Err ( ControlledVocabularyResolutionError :: UnknownControlledVocabularyCode ( value) ) ,
1982
+ }
1983
+ }
1984
+ }
1985
+
1941
1986
/// Anything that can be converted into an accession code portion of a [`CURIE`]
1942
1987
#[ derive( Debug , Clone ) ]
1943
1988
pub enum AccessionLike < ' a > {
@@ -2119,11 +2164,14 @@ impl<'a> ControlledVocabulary {
2119
2164
}
2120
2165
}
2121
2166
2122
- #[ doc( hidden) ]
2167
+ /// An error describing a failure to map a controlled vocabulary identifier
2168
+ /// to a known namespace
2123
2169
#[ derive( Debug , Clone , Error ) ]
2124
2170
pub enum ControlledVocabularyResolutionError {
2125
2171
#[ error( "Unrecognized controlled vocabulary {0}" ) ]
2126
2172
UnknownControlledVocabulary ( String ) ,
2173
+ #[ error( "Unrecognized controlled vocabulary code {0}" ) ]
2174
+ UnknownControlledVocabularyCode ( u8 )
2127
2175
}
2128
2176
2129
2177
impl FromStr for ControlledVocabulary {
0 commit comments