Skip to content

Commit

Permalink
34 failing
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed May 3, 2022
1 parent 14ecd58 commit 81fb358
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 15 deletions.
8 changes: 8 additions & 0 deletions include/sourmash.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,20 @@ double searchresult_score(const SourmashSearchResult *ptr);

SourmashSignature *searchresult_signature(const SourmashSearchResult *ptr);

bool selection_abund(const SourmashSelection *ptr);

uint32_t selection_ksize(const SourmashSelection *ptr);

HashFunctions selection_moltype(const SourmashSelection *ptr);

SourmashSelection *selection_new(void);

void selection_set_abund(SourmashSelection *ptr, bool new_abund);

void selection_set_ksize(SourmashSelection *ptr, uint32_t new_ksize);

void selection_set_moltype(SourmashSelection *ptr, HashFunctions new_moltype);

void signature_add_protein(SourmashSignature *ptr, const char *sequence);

void signature_add_sequence(SourmashSignature *ptr, const char *sequence, bool force);
Expand Down
36 changes: 36 additions & 0 deletions src/core/src/ffi/index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod revindex;

use crate::encodings::HashFunctions;
use crate::index::{Selection, SigStore};
use crate::signature::Signature;

Expand Down Expand Up @@ -66,6 +67,41 @@ pub unsafe extern "C" fn selection_set_ksize(ptr: *mut SourmashSelection, new_ks
sel.set_ksize(new_ksize);
}

#[no_mangle]
pub unsafe extern "C" fn selection_abund(ptr: *const SourmashSelection) -> bool {
let sel = SourmashSelection::as_rust(ptr);
if let Some(abund) = sel.abund() {
abund
} else {
todo!("empty abund case not supported yet")
}
}

#[no_mangle]
pub unsafe extern "C" fn selection_set_abund(ptr: *mut SourmashSelection, new_abund: bool) {
let sel = SourmashSelection::as_rust_mut(ptr);
sel.set_abund(new_abund);
}

#[no_mangle]
pub unsafe extern "C" fn selection_moltype(ptr: *const SourmashSelection) -> HashFunctions {
let sel = SourmashSelection::as_rust(ptr);
if let Some(hash_function) = sel.moltype() {
hash_function
} else {
todo!("empty hash_function case not supported yet")
}
}

#[no_mangle]
pub unsafe extern "C" fn selection_set_moltype(
ptr: *mut SourmashSelection,
new_moltype: HashFunctions,
) {
let sel = SourmashSelection::as_rust_mut(ptr);
sel.set_moltype(new_moltype);
}

//================================================================
//
pub struct SignatureIterator {
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/ffi/index/revindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ unsafe fn linearindex_new(
let manifest = if manifest_ptr.is_null() {
if use_manifest {
// Load manifest from zipstorage
Manifest::from_reader(storage.load("SOURMASH-MANIFEST.csv")?.as_slice())?
Some(Manifest::from_reader(storage.load("SOURMASH-MANIFEST.csv")?.as_slice())?)
} else {
todo!("throw error")
None
}
} else {
*SourmashManifest::into_rust(manifest_ptr)
Some(*SourmashManifest::into_rust(manifest_ptr))
};

let _selection = if !selection_ptr.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/ffi/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl From<&Record> for SourmashManifestRow {
with_abundance: record.with_abundance() as u8,
md5: record.md5().into(),
name: record.name().into(),
moltype: record.moltype().into(),
moltype: record.moltype().to_string().into(),
internal_location: record
.internal_location()
.to_str()
Expand Down
19 changes: 19 additions & 0 deletions src/core/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;

use crate::encodings::HashFunctions;
use crate::errors::ReadDataError;
use crate::index::sbt::{Node, SBT};
use crate::index::search::{search_minhashes, search_minhashes_containment};
Expand All @@ -32,6 +33,8 @@ pub type MHBT = SBT<Node<Nodegraph>>;
#[derive(Default)]
pub struct Selection {
ksize: Option<u32>,
abund: Option<bool>,
moltype: Option<HashFunctions>,
}

impl Selection {
Expand All @@ -42,6 +45,22 @@ impl Selection {
pub fn set_ksize(&mut self, ksize: u32) {
self.ksize = Some(ksize);
}

pub fn abund(&self) -> Option<bool> {
self.abund
}

pub fn set_abund(&mut self, value: bool) {
self.abund = Some(value);
}

pub fn moltype(&self) -> Option<HashFunctions> {
self.moltype
}

pub fn set_moltype(&mut self, value: HashFunctions) {
self.moltype = Some(value);
}
}

/* FIXME: bring back after MQF works on macOS and Windows
Expand Down
19 changes: 14 additions & 5 deletions src/core/src/index/revindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,26 @@ pub struct LinearRevIndex {

impl LinearRevIndex {
pub fn new(
sig_files: Manifest,
sig_files: Option<Manifest>,
template: &Sketch,
keep_sigs: bool,
ref_sigs: Option<Vec<Signature>>,
storage: Option<ZipStorage>,
) -> Self {
let search_sigs: Vec<_> = sig_files.internal_locations().map(PathBuf::from).collect();
if ref_sigs.is_none() && sig_files.is_none() {
todo!("throw error, one need to be set");
}

let ref_sigs = if let Some(ref_sigs) = ref_sigs {
Some(ref_sigs.into_iter().map(|m| m.into()).collect())
} else if keep_sigs {
let search_sigs: Vec<_> = sig_files
.as_ref()
.unwrap()
.internal_locations()
.map(PathBuf::from)
.collect();

#[cfg(feature = "parallel")]
let sigs_iter = search_sigs.par_iter();

Expand Down Expand Up @@ -168,7 +177,7 @@ impl LinearRevIndex {
let storage = storage.map(Arc::new);

LinearRevIndex {
sig_files,
sig_files: sig_files.unwrap(),
template: template.clone(),
ref_sigs,
storage,
Expand Down Expand Up @@ -665,7 +674,7 @@ impl RevIndex {
// If threshold is zero, let's merge all queries and save time later
let merged_query = queries.and_then(|qs| Self::merge_queries(qs, threshold));

let linear = LinearRevIndex::new(search_sigs.into(), template, keep_sigs, None, None);
let linear = LinearRevIndex::new(Some(search_sigs.into()), template, keep_sigs, None, None);
linear.index(threshold, merged_query, queries)
}

Expand All @@ -684,7 +693,7 @@ impl RevIndex {
let search_sigs: Vec<_> = manifest.internal_locations().map(PathBuf::from).collect();

let linear = LinearRevIndex::new(
search_sigs.as_slice().into(),
Some(search_sigs.as_slice().into()),
template,
keep_sigs,
None,
Expand Down
18 changes: 15 additions & 3 deletions src/core/src/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::convert::TryInto;
use std::io::Read;
use std::ops::Deref;
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use crate::encodings::HashFunctions;
use crate::index::Selection;
use crate::Error;

Expand Down Expand Up @@ -50,8 +52,8 @@ impl Record {
self.name.as_ref()
}

pub fn moltype(&self) -> &str {
self.moltype.as_ref()
pub fn moltype(&self) -> HashFunctions {
self.moltype.as_str().try_into().unwrap()
}
}

Expand Down Expand Up @@ -79,12 +81,22 @@ impl Manifest {

pub fn select_to_manifest(&self, selection: &Selection) -> Result<Self, Error> {
let rows = self.records.iter().filter(|row| {
let mut valid = false;
let mut valid = true;
valid = if let Some(ksize) = selection.ksize() {
row.ksize == ksize
} else {
valid
};
valid = if let Some(abund) = selection.abund() {
valid && row.with_abundance() == abund
} else {
valid
};
valid = if let Some(moltype) = selection.moltype() {
valid && row.moltype() == moltype
} else {
valid
};
valid
});

Expand Down
15 changes: 12 additions & 3 deletions src/sourmash/index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,24 @@ def _selection_as_rust(selection: Selection):
if key == "ksize":
rustcall(lib.selection_set_ksize, ptr, v)
elif key == "moltype":
...
hash_function = None
if v.lower() == "dna":
hash_function = lib.HASH_FUNCTIONS_MURMUR64_DNA
elif v.lower() == "protein":
hash_function = lib.HASH_FUNCTIONS_MURMUR64_PROTEIN
elif v.lower() == "dayhoff":
hash_function = lib.HASH_FUNCTIONS_MURMUR64_DAYHOFF
elif v.lower() == "hp":
hash_function = lib.HASH_FUNCTIONS_MURMUR64_HP
rustcall(lib.selection_set_moltype, ptr, hash_function)
elif key == "num":
...
elif key == "scaled":
...
elif key == "containment":
...
elif key == "abund":
...
rustcall(lib.selection_set_abund, ptr, bool(v))
elif key == "picklist":
...
else:
Expand Down Expand Up @@ -627,7 +636,7 @@ def __len__(self):

@property
def location(self):
return self._methodcall(lib.linearindex_location)
return decode_str(self._methodcall(lib.linearindex_location))

@property
def storage(self):
Expand Down

0 comments on commit 81fb358

Please sign in to comment.