Skip to content

Commit

Permalink
more picklist
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Oct 20, 2022
1 parent abbdcb7 commit 2819307
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 6 deletions.
12 changes: 12 additions & 0 deletions include/sourmash.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ enum HashFunctions {
};
typedef uint32_t HashFunctions;

enum PickStyle {
PICK_STYLE_INCLUDE = 1,
PICK_STYLE_EXCLUDE = 2,
};
typedef uint32_t PickStyle;

enum SourmashErrorCode {
SOURMASH_ERROR_CODE_NO_ERROR = 0,
SOURMASH_ERROR_CODE_PANIC = 1,
Expand Down Expand Up @@ -371,6 +377,8 @@ void picklist_set_column_name(SourmashPicklist *ptr, const char *prop_ptr, uintp

void picklist_set_pickfile(SourmashPicklist *ptr, const char *prop_ptr, uintptr_t insize);

void picklist_set_pickstyle(SourmashPicklist *ptr, PickStyle pickstyle);

void revindex_free(SourmashRevIndex *ptr);

const SourmashSearchResult *const *revindex_gather(const SourmashRevIndex *ptr,
Expand Down Expand Up @@ -428,6 +436,8 @@ SourmashSelection *selection_new(void);

uint32_t selection_num(const SourmashSelection *ptr);

const SourmashPicklist *selection_picklist(const SourmashSelection *ptr);

uint32_t selection_scaled(const SourmashSelection *ptr);

void selection_set_abund(SourmashSelection *ptr, bool new_abund);
Expand All @@ -440,6 +450,8 @@ void selection_set_moltype(SourmashSelection *ptr, HashFunctions new_moltype);

void selection_set_num(SourmashSelection *ptr, uint32_t new_num);

void selection_set_picklist(SourmashSelection *ptr, SourmashPicklist *new_picklist);

void selection_set_scaled(SourmashSelection *ptr, uint32_t new_scaled);

void signature_add_protein(SourmashSignature *ptr, const char *sequence);
Expand Down
23 changes: 23 additions & 0 deletions src/core/src/ffi/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::index::{Selection, SigStore};

use crate::signature::Signature;

use crate::ffi::picklist::SourmashPicklist;
use crate::ffi::signature::SourmashSignature;
use crate::ffi::utils::{ForeignObject, SourmashStr};

Expand Down Expand Up @@ -154,6 +155,28 @@ pub unsafe extern "C" fn selection_set_moltype(
sel.set_moltype(new_moltype);
}

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

#[no_mangle]
pub unsafe extern "C" fn selection_set_picklist(
ptr: *mut SourmashSelection,
new_picklist: *mut SourmashPicklist,
) {
let sel = SourmashSelection::as_rust_mut(ptr);
let pick = SourmashPicklist::into_rust(new_picklist);
sel.set_picklist(*pick);
}

//================================================================
//
pub struct SignatureIterator {
Expand Down
15 changes: 14 additions & 1 deletion src/core/src/ffi/picklist.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::os::raw::c_char;
use std::slice;

use crate::picklist::Picklist;
use crate::picklist::{PickStyle, Picklist};

use crate::ffi::utils::ForeignObject;

Expand Down Expand Up @@ -74,3 +74,16 @@ unsafe fn picklist_set_column_name(
Ok(())
}
}

ffi_fn! {
unsafe fn picklist_set_pickstyle(
ptr: *mut SourmashPicklist,
pickstyle: PickStyle,
) -> Result<()> {
let pl = SourmashPicklist::as_rust_mut(ptr);

pl.set_pickstyle(pickstyle);

Ok(())
}
}
10 changes: 10 additions & 0 deletions src/core/src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use typed_builder::TypedBuilder;
use crate::encodings::HashFunctions;
use crate::errors::ReadDataError;
use crate::index::search::{search_minhashes, search_minhashes_containment};
use crate::picklist::Picklist;
use crate::prelude::*;
use crate::signature::SigsTrait;
use crate::sketch::Sketch;
Expand All @@ -32,6 +33,7 @@ pub struct Selection {
scaled: Option<u32>,
containment: Option<bool>,
moltype: Option<HashFunctions>,
picklist: Option<Picklist>,
}

impl Selection {
Expand Down Expand Up @@ -82,6 +84,14 @@ impl Selection {
pub fn set_moltype(&mut self, value: HashFunctions) {
self.moltype = Some(value);
}

pub fn picklist(&self) -> Option<Picklist> {
self.picklist.clone()
}

pub fn set_picklist(&mut self, value: Picklist) {
self.picklist = Some(value);
}
}

pub trait Index<'a> {
Expand Down
14 changes: 13 additions & 1 deletion src/core/src/picklist.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use getset::{CopyGetters, Getters, Setters};
use typed_builder::TypedBuilder;

#[derive(Default, TypedBuilder, CopyGetters, Getters, Setters)]
#[derive(Default, TypedBuilder, CopyGetters, Getters, Setters, Clone)]
pub struct Picklist {
#[getset(get = "pub", set = "pub")]
#[builder(default = "".into())]
Expand All @@ -14,4 +14,16 @@ pub struct Picklist {
#[getset(get = "pub", set = "pub")]
#[builder(default = "".into())]
column_name: String,

#[getset(get = "pub", set = "pub")]
#[builder]
pickstyle: PickStyle,
}

#[derive(Default, Clone)]
#[repr(u32)]
pub enum PickStyle {
#[default]
Include = 1,
Exclude = 2,
}
8 changes: 4 additions & 4 deletions src/sourmash/picklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ def _as_rust(self):

ptr = lib.picklist_new()

rustcall(lib.picklist_set_coltype, ptr, self.coltype)
rustcall(lib.picklist_set_pickfile, ptr, self.pickfile)
rustcall(lib.picklist_set_column_name, ptr, self.column_name)
rustcall(lib.picklist_set_pickstyle, ptr, self.pickstyle)
rustcall(lib.picklist_set_coltype, ptr, self.coltype.encode('utf-8'), len(self.coltype))
rustcall(lib.picklist_set_pickfile, ptr, self.pickfile.encode('utf-8'), len(self.pickfile))
rustcall(lib.picklist_set_column_name, ptr, self.column_name.encode('utf-8'), len(self.column_name))
rustcall(lib.picklist_set_pickstyle, ptr, self.pickstyle.value)

#self.preprocess_fn = preprocess[coltype]
#self.pickset = None
Expand Down

0 comments on commit 2819307

Please sign in to comment.