Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: enforce a single scaled on a CollectionSet #3397

Open
wants to merge 1 commit into
base: latest
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion src/core/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::manifest::{Manifest, Record};
use crate::prelude::*;
use crate::storage::{FSStorage, InnerStorage, MemStorage, SigStore, ZipStorage};
use crate::{Error, Result};
use crate::{Error, Result, ScaledType};

#[cfg(feature = "parallel")]
use rayon::prelude::*;
Expand Down Expand Up @@ -52,6 +52,11 @@
return Ok(Self { collection });
};

let (min_scaled, max_scaled) = collection.min_max_scaled().expect("empty collection!?");
if min_scaled != max_scaled {
return Err(Error::MismatchScaled);
}

collection
.manifest
.iter()
Expand Down Expand Up @@ -219,6 +224,17 @@
pub fn intersect_manifest(&mut self, mf: &Manifest) {
self.manifest = self.manifest.intersect_manifest(mf);
}

// CTB: question, should we do something about num here?
pub fn min_max_scaled(&self) -> Option<(&ScaledType, &ScaledType)> {
self.manifest.first().map(|first| {

Check warning on line 230 in src/core/src/collection.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/collection.rs#L229-L230

Added lines #L229 - L230 were not covered by tests
self.manifest
.iter()
.fold((first.scaled(), first.scaled()), |f, r| {

Check warning on line 233 in src/core/src/collection.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/collection.rs#L233

Added line #L233 was not covered by tests
(f.0.min(r.scaled()), f.1.max(r.scaled()))
})
})
}
}

impl Select for Collection {
Expand Down Expand Up @@ -483,6 +499,50 @@
}
}

#[test]
fn collection_from_collectionset() -> () {
use crate::collection::CollectionSet;

let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

let test_sigs = vec![PathBuf::from("../../tests/test-data/prot/all.zip")];

let full_paths: Vec<PathBuf> = test_sigs
.into_iter()
.map(|sig| base_path.join(sig))
.collect();

let collection = Collection::from_zipfile(&full_paths[0]).unwrap();

let mut selection = Selection::default();
selection.set_moltype(HashFunctions::Murmur64Protein);
selection.set_scaled(200);

let collection = collection.select(&selection).expect("should pass");
let (min_scaled, max_scaled) = collection.min_max_scaled().expect("not empty");
assert_eq!(*min_scaled, *max_scaled);
assert_eq!(*min_scaled, 200);
let _cs: CollectionSet = collection.try_into().expect("should pass");
}

#[test]
#[should_panic]
fn collection_from_collectionset_fail() -> () {
use crate::collection::CollectionSet;

let base_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

let test_sigs = vec![PathBuf::from("../../tests/test-data/prot/all.zip")];

let full_paths: Vec<PathBuf> = test_sigs
.into_iter()
.map(|sig| base_path.join(sig))
.collect();

let collection = Collection::from_zipfile(&full_paths[0]).unwrap();
let _cs: CollectionSet = collection.try_into().expect("should fail");
}

#[test]
#[cfg(all(feature = "branchwater", not(target_arch = "wasm32")))]
fn collection_from_rocksdb_storage() -> Result<()> {
Expand Down
Loading