Skip to content

Commit

Permalink
allow preliminary enzyme numbers (x.x.x.nx)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibvdm committed May 28, 2024
1 parent 64a0aba commit 7096a0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
14 changes: 7 additions & 7 deletions fa-compression/src/algorithm1/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,39 +82,39 @@ mod tests {

#[test]
fn test_decode_single_ec() {
assert_eq!(decode(&[44, 44, 44, 189, 208]), "EC:1.1.1.-")
assert_eq!(decode(&[44, 44, 44, 190, 224]), "EC:1.1.1.-")
}

#[test]
fn test_decode_single_go() {
assert_eq!(decode(&[209, 17, 163, 138, 208]), "GO:0009279")
assert_eq!(decode(&[225, 17, 163, 138, 224]), "GO:0009279")
}

#[test]
fn test_decode_single_ipr() {
assert_eq!(decode(&[221, 18, 116, 117]), "IPR:IPR016364")
assert_eq!(decode(&[238, 18, 116, 117]), "IPR:IPR016364")
}

#[test]
fn test_decode_no_ec() {
assert_eq!(
decode(&[209, 17, 163, 138, 209, 39, 71, 94, 17, 153, 39]),
decode(&[225, 17, 163, 138, 225, 39, 71, 95, 17, 153, 39]),
"GO:0009279;IPR:IPR016364;IPR:IPR008816"
)
}

#[test]
fn test_decode_no_go() {
assert_eq!(
decode(&[44, 44, 44, 190, 44, 60, 44, 141, 209, 39, 71, 80]),
decode(&[44, 44, 44, 191, 44, 60, 44, 142, 225, 39, 71, 80]),
"EC:1.1.1.-;EC:1.2.1.7;IPR:IPR016364"
)
}

#[test]
fn test_decode_no_ipr() {
assert_eq!(
decode(&[44, 44, 44, 189, 17, 26, 56, 174, 17, 26, 56, 173]),
decode(&[44, 44, 44, 190, 17, 26, 56, 175, 17, 26, 56, 174]),
"EC:1.1.1.-;GO:0009279;GO:0009279"
)
}
Expand All @@ -123,7 +123,7 @@ mod tests {
fn test_decode_all() {
assert_eq!(
decode(&[
44, 44, 44, 189, 17, 26, 56, 173, 18, 116, 117, 225, 67, 116, 110, 17, 153, 39
44, 44, 44, 190, 17, 26, 56, 174, 18, 116, 117, 241, 67, 116, 111, 17, 153, 39
]),
"EC:1.1.1.-;GO:0009279;IPR:IPR016364;IPR:IPR032635;IPR:IPR008816"
)
Expand Down
14 changes: 7 additions & 7 deletions fa-compression/src/algorithm1/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,48 @@ mod tests {

#[test]
fn test_encode_single_ec() {
assert_eq!(encode("EC:1.1.1.-"), vec![44, 44, 44, 189, 208])
assert_eq!(encode("EC:1.1.1.-"), vec![44, 44, 44, 190, 224])
}

#[test]
fn test_encode_single_go() {
assert_eq!(encode("GO:0009279"), vec![209, 17, 163, 138, 208])
assert_eq!(encode("GO:0009279"), vec![225, 17, 163, 138, 224])
}

#[test]
fn test_encode_single_ipr() {
assert_eq!(encode("IPR:IPR016364"), vec![221, 18, 116, 117])
assert_eq!(encode("IPR:IPR016364"), vec![238, 18, 116, 117])
}

#[test]
fn test_encode_no_ec() {
assert_eq!(
encode("IPR:IPR016364;GO:0009279;IPR:IPR008816"),
vec![209, 17, 163, 138, 209, 39, 71, 94, 17, 153, 39]
vec![225, 17, 163, 138, 225, 39, 71, 95, 17, 153, 39]
)
}

#[test]
fn test_encode_no_go() {
assert_eq!(
encode("IPR:IPR016364;EC:1.1.1.-;EC:1.2.1.7"),
vec![44, 44, 44, 190, 44, 60, 44, 141, 209, 39, 71, 80]
vec![44, 44, 44, 191, 44, 60, 44, 142, 225, 39, 71, 80]
)
}

#[test]
fn test_encode_no_ipr() {
assert_eq!(
encode("EC:1.1.1.-;GO:0009279;GO:0009279"),
vec![44, 44, 44, 189, 17, 26, 56, 174, 17, 26, 56, 173]
vec![44, 44, 44, 190, 17, 26, 56, 175, 17, 26, 56, 174]
)
}

#[test]
fn test_encode_all() {
assert_eq!(
encode("IPR:IPR016364;EC:1.1.1.-;IPR:IPR032635;GO:0009279;IPR:IPR008816"),
vec![44, 44, 44, 189, 17, 26, 56, 173, 18, 116, 117, 225, 67, 116, 110, 17, 153, 39]
vec![44, 44, 44, 190, 17, 26, 56, 174, 18, 116, 117, 241, 67, 116, 111, 17, 153, 39]
)
}
}
22 changes: 10 additions & 12 deletions fa-compression/src/algorithm1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ enum CharacterSet {
/// Special Enzyme Commission characters
Dash,
Point,
Preliminary,

/// Different annotation type separator
Comma,
Expand Down Expand Up @@ -106,6 +107,7 @@ impl Encode for CharacterSet {
b'9' => CharacterSet::Nine,
b'-' => CharacterSet::Dash,
b'.' => CharacterSet::Point,
b'n' => CharacterSet::Preliminary,
b',' => CharacterSet::Comma,
b';' => CharacterSet::Semicolon,
_ => panic!("Invalid character")
Expand Down Expand Up @@ -138,8 +140,9 @@ impl Decode for CharacterSet {
10 => '9',
11 => '-',
12 => '.',
13 => ',',
14 => ';',
13 => 'n',
14 => ',',
15 => ';',
_ => panic!("Invalid character")
}
}
Expand Down Expand Up @@ -167,10 +170,10 @@ impl BitOr for CharacterSet {
mod tests {
use super::*;

static CHARACTERS: [u8; 15] =
[b'$', b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'-', b'.', b',', b';'];
static CHARACTERS: [u8; 16] =
[b'$', b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'-', b'.', b'n', b',', b';'];

static CHARACTER_SETS: [CharacterSet; 15] = [
static CHARACTER_SETS: [CharacterSet; 16] = [
CharacterSet::Empty,
CharacterSet::Zero,
CharacterSet::One,
Expand All @@ -184,6 +187,7 @@ mod tests {
CharacterSet::Nine,
CharacterSet::Dash,
CharacterSet::Point,
CharacterSet::Preliminary,
CharacterSet::Comma,
CharacterSet::Semicolon
];
Expand Down Expand Up @@ -233,13 +237,7 @@ mod tests {
#[test]
#[should_panic]
fn test_decode_invalid() {
CharacterSet::decode(15);
}

#[test]
#[should_panic]
fn test_decode_pair_invalid() {
CharacterSet::decode_pair(0b11111111);
CharacterSet::decode(16);
}

#[test]
Expand Down

0 comments on commit 7096a0d

Please sign in to comment.