Skip to content

Commit

Permalink
Added a hybrid feature that encodes amino-acid groups instead of amin…
Browse files Browse the repository at this point in the history
…o-acid itself
  • Loading branch information
khb7840 committed Feb 24, 2025
1 parent bd3b774 commit cc4cd7f
Show file tree
Hide file tree
Showing 13 changed files with 439 additions and 13 deletions.
30 changes: 28 additions & 2 deletions src/controller/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Author: Hyunbin Kim (khb7840@gmail.com)
// Copyright © 2024 Hyunbin Kim, All rights reserved

use crate::utils::convert::map_aa_to_u8;
use crate::utils::convert::{map_aa_to_u8, map_aa_to_u8_group};
use crate::structure::core::CompactStructure;
use crate::geometry::core::{GeometricHash, HashType};
use crate::utils::combination::CombinationIterator;
Expand Down Expand Up @@ -163,6 +163,31 @@ pub fn get_single_feature(
return true;
}
},
HashType::Hybrid => {
if i == 0 || j == 0 || i == structure.num_residues - 1 || j == structure.num_residues - 1 {
return false;
}
let res1 = structure.get_res_name(i);
let res2 = structure.get_res_name(j);
let res1_group = map_aa_to_u8_group(res1) as f32;
let res2_group = map_aa_to_u8_group(res2) as f32;

let feature = structure.get_hybrid_feature(i, j, dist_cutoff);
if let Some(feature) = feature {
feature_container[0] = res1_group;
feature_container[1] = res2_group;
feature_container[2] = feature.0;
feature_container[3] = feature.1;
feature_container[4] = feature.2;
feature_container[5] = feature.3;
feature_container[6] = feature.4;
feature_container[7] = feature.5;
feature_container[8] = feature.6;
return true;
} else {
return false;
}
},
// append new hash type here
_ => {
return false;
Expand Down Expand Up @@ -216,7 +241,7 @@ impl HashType {

pub fn dist_index(&self) -> Option<Vec<usize>> {
match self {
HashType::PDBMotif | HashType::PDBMotifSinCos | HashType::PDBTrRosetta => Some(vec![2, 3]),
HashType::PDBMotif | HashType::PDBMotifSinCos | HashType::PDBTrRosetta | HashType::Hybrid => Some(vec![2, 3]),
HashType::TrRosetta | HashType::PointPairFeature => Some(vec![2]),
HashType::TertiaryInteraction => Some(vec![7]),
_ => None
Expand All @@ -230,6 +255,7 @@ impl HashType {
HashType::PointPairFeature => Some(vec![3, 4, 5]),
HashType::PDBTrRosetta => Some(vec![4, 5, 6]),
HashType::TertiaryInteraction => Some(vec![0, 1, 2, 3, 4, 5, 6]),
HashType::Hybrid => Some(vec![4, 5, 6, 7, 8]),
_ => None
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/controller/retrieve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn retrieval_wrapper_for_foldcompdb(
let (index_set1, index_set2) = prefilter_amino_acid(&query_set, _hash_type, &compact);
CombinationVecIterator::new_from_btreesets(&index_set1, &index_set2)
} else {
CombinationVecIterator::new((0..compact.num_residues).collect(), (0..compact.num_residues).collect())
CombinationVecIterator::new(vec![], vec![])
};

// let (index_set1, index_set2) = prefilter_amino_acid(&query_set, _hash_type, &compact);
Expand All @@ -177,7 +177,7 @@ pub fn retrieval_wrapper_for_foldcompdb(
&compact, &query_set, aa_filter, _nbin_dist, _nbin_angle, multiple_bin,
dist_cutoff, ca_distance_cutoff, aa_dist_map
);

let candidate_pair_map: HashMap<usize, BTreeSet<(usize, usize)>> = candidate_pairs.into_iter().fold(
HashMap::new(), |mut map, (qi, pair)| {
if !map.contains_key(&qi) {
Expand Down Expand Up @@ -336,8 +336,16 @@ pub fn retrieval_wrapper(
let query_set: HashSet<GeometricHash> = HashSet::from_iter(query_vector.clone());
let query_symmetry_map = get_hash_symmetry_map(&query_set);

let (index_set1, index_set2) = prefilter_amino_acid(&query_set, _hash_type, &compact);
let aa_filter = CombinationVecIterator::new_from_btreesets(&index_set1, &index_set2);
// let (index_set1, index_set2) = prefilter_amino_acid(&query_set, _hash_type, &compact);

let aa_filter = if _hash_type.amino_acid_index().is_some() {
let (index_set1, index_set2) = prefilter_amino_acid(&query_set, _hash_type, &compact);
CombinationVecIterator::new_from_btreesets(&index_set1, &index_set2)
} else {
CombinationVecIterator::new(vec![], vec![])
};


let (indices_found , candidate_pairs) = retrieve_with_prefilter(
&compact, &query_set, aa_filter, _nbin_dist, _nbin_angle,
multiple_bin, dist_cutoff, ca_distance_cutoff, aa_dist_map
Expand Down
56 changes: 56 additions & 0 deletions src/geometry/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub enum HashType {
PDBTrRosetta,
PointPairFeature,
TertiaryInteraction,
Hybrid,
// append new hash type here
Other,
}
Expand All @@ -28,6 +29,7 @@ impl HashType {
3 => HashType::PDBTrRosetta,
4 => HashType::PointPairFeature,
5 => HashType::TertiaryInteraction,
6 => HashType::Hybrid,
// append new hash type here
_ => HashType::Other,
}
Expand All @@ -41,6 +43,7 @@ impl HashType {
"3" | "PDBTrRosetta" | "pdbtr" | "default" | "folddisco" => HashType::PDBTrRosetta,
"4" | "PointPairFeature" | "ppf" => HashType::PointPairFeature,
"5" | "TertiaryInteraction" | "tertiary" | "3di" => HashType::TertiaryInteraction,
"6" | "Hybrid" | "hybrid" => HashType::Hybrid,
// append new hash type here
_ => HashType::Other,
}
Expand All @@ -54,6 +57,7 @@ impl HashType {
HashType::PDBTrRosetta => "PDBTrRosetta".to_string(),
HashType::PointPairFeature => "PointPairFeature".to_string(),
HashType::TertiaryInteraction => "TertiaryInteraction".to_string(),
HashType::Hybrid => "Hybrid".to_string(),
// append new hash type here
HashType::Other => "Other".to_string(),
}
Expand All @@ -72,6 +76,7 @@ impl HashType {
HashType::PDBTrRosetta => 30usize,
HashType::PointPairFeature => 32usize,
HashType::TertiaryInteraction => 29usize,
HashType::Hybrid => 32usize,
// append new hash type here
HashType::Other => 32usize,
}
Expand All @@ -95,6 +100,7 @@ impl HashType {
"PDBTrRosetta" => HashType::PDBTrRosetta,
"PointPairFeature" => HashType::PointPairFeature,
"TertiaryInteraction" => HashType::TertiaryInteraction,
"Hybrid" => HashType::Hybrid,
// append new hash type here
_ => HashType::Other,
};
Expand All @@ -116,6 +122,7 @@ mod tests {
HashType::PDBTrRosetta,
HashType::PointPairFeature,
HashType::TertiaryInteraction,
HashType::Hybrid,
// append new hash type here
];
for hash_type in hash_type_vec {
Expand All @@ -134,6 +141,7 @@ pub enum GeometricHash {
PDBTrRosetta(super::pdb_tr::HashValue),
PointPairFeature(super::ppf::HashValue),
TertiaryInteraction(super::tertiary_interaction::HashValue),
Hybrid(super::hybrid::HashValue),
// append new hash type here
}

Expand All @@ -148,6 +156,7 @@ impl GeometricHash {
HashType::PDBTrRosetta => super::pdb_tr::HashValue::perfect_hash_default(feature),
HashType::PointPairFeature => super::ppf::HashValue::perfect_hash_default(feature),
HashType::TertiaryInteraction => super::tertiary_interaction::HashValue::perfect_hash_default(feature),
HashType::Hybrid => super::hybrid::HashValue::perfect_hash_default(feature),
// append new hash type here
_ => panic!("Invalid hash type"),
}
Expand Down Expand Up @@ -175,6 +184,9 @@ impl GeometricHash {
HashType::TertiaryInteraction => super::tertiary_interaction::HashValue::perfect_hash(
feature, nbin_dist, nbin_angle
),
HashType::Hybrid => super::hybrid::HashValue::perfect_hash(
feature, nbin_dist, nbin_angle
),
// append new hash type here
_ => panic!("Invalid hash type"),
}
Expand Down Expand Up @@ -212,6 +224,11 @@ impl GeometricHash {
super::tertiary_interaction::HashValue::perfect_hash_default(feature)
)
),
HashType::Hybrid => GeometricHash::Hybrid(
super::hybrid::HashValue(
super::hybrid::HashValue::perfect_hash_default(feature)
)
),
// append new hash type here
_ => panic!("Invalid hash type"),
}
Expand Down Expand Up @@ -251,6 +268,11 @@ impl GeometricHash {
super::tertiary_interaction::HashValue::perfect_hash(feature, nbin_dist, nbin_angle)
)
),
HashType::Hybrid => GeometricHash::Hybrid(
super::hybrid::HashValue(
super::hybrid::HashValue::perfect_hash(feature, nbin_dist, nbin_angle)
)
),
// append new hash type here
_ => panic!("Invalid hash type"),
}
Expand Down Expand Up @@ -294,6 +316,12 @@ impl GeometricHash {
output[i] = reversed[i];
}
},
GeometricHash::Hybrid(hash) => {
let reversed = hash.reverse_hash_default();
for i in 0..reversed.len() {
output[i] = reversed[i];
}
},
// append new hash type here
// _ => panic!("Invalid hash type"),
}
Expand Down Expand Up @@ -338,6 +366,12 @@ impl GeometricHash {
output[i] = reversed[i];
}
},
GeometricHash::Hybrid(hash) => {
let reversed = hash.reverse_hash(nbin_dist, nbin_angle);
for i in 0..reversed.len() {
output[i] = reversed[i];
}
},
// append new hash type here
// _ => panic!("Invalid hash type"),
}
Expand All @@ -352,6 +386,7 @@ impl GeometricHash {
GeometricHash::PointPairFeature(hash) => hash.hash_type(),
GeometricHash::PDBTrRosetta(hash) => hash.hash_type(),
GeometricHash::TertiaryInteraction(hash) => hash.hash_type(),
GeometricHash::Hybrid(hash) => hash.hash_type(),
// append new hash type here
// _ => panic!("Invalid hash type"),
}
Expand All @@ -378,6 +413,9 @@ impl GeometricHash {
HashType::TertiaryInteraction => GeometricHash::TertiaryInteraction(
super::tertiary_interaction::HashValue::from_u32(hashvalue)
),
HashType::Hybrid => GeometricHash::Hybrid(
super::hybrid::HashValue::from_u32(hashvalue)
),
// append new hash type here if it is encoded as u32
_ => panic!("Invalid hash type"),
}
Expand All @@ -403,6 +441,9 @@ impl GeometricHash {
HashType::TertiaryInteraction => GeometricHash::TertiaryInteraction(
super::tertiary_interaction::HashValue::from_u64(hashvalue)
),
HashType::Hybrid => GeometricHash::Hybrid(
super::hybrid::HashValue::from_u64(hashvalue)
),
// append new hash type here
_ => panic!("Invalid hash type"),
}
Expand All @@ -416,6 +457,7 @@ impl GeometricHash {
GeometricHash::PDBTrRosetta(hash) => hash.as_u32(),
GeometricHash::PointPairFeature(hash) => hash.as_u32(),
GeometricHash::TertiaryInteraction(hash) => hash.as_u32(),
GeometricHash::Hybrid(hash) => hash.as_u32(),
// append new hash type here
}
}
Expand All @@ -427,6 +469,7 @@ impl GeometricHash {
GeometricHash::PDBTrRosetta(hash) => hash.as_u64(),
GeometricHash::PointPairFeature(hash) => hash.as_u64(),
GeometricHash::TertiaryInteraction(hash) => hash.as_u64(),
GeometricHash::Hybrid(hash) => hash.as_u64(),
// append new hash type here
}
}
Expand All @@ -439,6 +482,7 @@ impl GeometricHash {
GeometricHash::PDBTrRosetta(hash) => hash.is_symmetric(),
GeometricHash::PointPairFeature(hash) => hash.is_symmetric(),
GeometricHash::TertiaryInteraction(hash) => hash.is_symmetric(),
GeometricHash::Hybrid(hash) => hash.is_symmetric(),
// append new hash type here
}
}
Expand Down Expand Up @@ -479,6 +523,12 @@ impl GeometricHash {
_ => panic!("Invalid hash type"),
}
}
pub fn downcast_hybrid(&self) -> super::hybrid::HashValue {
match self {
GeometricHash::Hybrid(hash) => hash.clone(),
_ => panic!("Invalid hash type"),
}
}
// append the downcast method for new hash type here

}
Expand All @@ -504,6 +554,9 @@ impl fmt::Debug for GeometricHash {
GeometricHash::TertiaryInteraction(hash) => {
write!(f, "TertiaryInteraction({:?})", hash)
},
GeometricHash::Hybrid(hash) => {
write!(f, "Hybrid({:?})", hash)
},
// append new hash type here
// _ => panic!("Invalid hash type"),
}
Expand Down Expand Up @@ -531,6 +584,9 @@ impl fmt::Display for GeometricHash {
GeometricHash::TertiaryInteraction(hash) => {
write!(f, "TertiaryInteraction\t{:?}", hash)
},
GeometricHash::Hybrid(hash) => {
write!(f, "Hybrid\t{:?}", hash)
},
// append new hash type here
// _ => panic!("Invalid hash type"),
}
Expand Down
Loading

0 comments on commit cc4cd7f

Please sign in to comment.