Skip to content

Commit

Permalink
Start implementing manifest, picklist and selection
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Aug 20, 2023
1 parent 777c252 commit 593775a
Show file tree
Hide file tree
Showing 16 changed files with 839 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 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 All @@ -42,6 +48,7 @@ enum SourmashErrorCode {
SOURMASH_ERROR_CODE_PARSE_INT = 100003,
SOURMASH_ERROR_CODE_SERDE_ERROR = 100004,
SOURMASH_ERROR_CODE_NIFFLER_ERROR = 100005,
SOURMASH_ERROR_CODE_CSV_ERROR = 100006,
};
typedef uint32_t SourmashErrorCode;

Expand All @@ -51,14 +58,24 @@ typedef struct SourmashHyperLogLog SourmashHyperLogLog;

typedef struct SourmashKmerMinHash SourmashKmerMinHash;

typedef struct SourmashManifest SourmashManifest;

typedef struct SourmashManifestRowIter SourmashManifestRowIter;

typedef struct SourmashNodegraph SourmashNodegraph;

typedef struct SourmashPicklist SourmashPicklist;

typedef struct SourmashRevIndex SourmashRevIndex;

typedef struct SourmashSearchResult SourmashSearchResult;

typedef struct SourmashSelection SourmashSelection;

typedef struct SourmashSignature SourmashSignature;

typedef struct SourmashSignatureIter SourmashSignatureIter;

typedef struct SourmashZipStorage SourmashZipStorage;

/**
Expand All @@ -79,6 +96,15 @@ typedef struct {
bool owned;
} SourmashStr;

typedef struct {
uint32_t ksize;
uint8_t with_abundance;
SourmashStr md5;
SourmashStr internal_location;
SourmashStr name;
SourmashStr moltype;
} SourmashManifestRow;

bool computeparams_dayhoff(const SourmashComputeParameters *ptr);

bool computeparams_dna(const SourmashComputeParameters *ptr);
Expand Down Expand Up @@ -265,6 +291,10 @@ void kmerminhash_slice_free(uint64_t *ptr, uintptr_t insize);

bool kmerminhash_track_abundance(const SourmashKmerMinHash *ptr);

SourmashManifestRowIter *manifest_rows(const SourmashManifest *ptr);

const SourmashManifestRow *manifest_rows_iter_next(SourmashManifestRowIter *ptr);

void nodegraph_buffer_free(uint8_t *ptr, uintptr_t insize);

bool nodegraph_count(SourmashNodegraph *ptr, uint64_t h);
Expand Down Expand Up @@ -309,6 +339,18 @@ SourmashNodegraph *nodegraph_with_tables(uintptr_t ksize,
uintptr_t starting_size,
uintptr_t n_tables);

void picklist_free(SourmashPicklist *ptr);

SourmashPicklist *picklist_new(void);

void picklist_set_coltype(SourmashPicklist *ptr, const char *coltype_ptr, uintptr_t insize);

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

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 @@ -354,6 +396,36 @@ double searchresult_score(const SourmashSearchResult *ptr);

SourmashSignature *searchresult_signature(const SourmashSearchResult *ptr);

bool selection_abund(const SourmashSelection *ptr);

bool selection_containment(const SourmashSelection *ptr);

uint32_t selection_ksize(const SourmashSelection *ptr);

HashFunctions selection_moltype(const SourmashSelection *ptr);

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);

void selection_set_containment(SourmashSelection *ptr, bool new_containment);

void selection_set_ksize(SourmashSelection *ptr, uint32_t new_ksize);

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);

void signature_add_sequence(SourmashSignature *ptr, const char *sequence, bool force);
Expand Down Expand Up @@ -388,6 +460,8 @@ void signature_set_mh(SourmashSignature *ptr, const SourmashKmerMinHash *other);

void signature_set_name(SourmashSignature *ptr, const char *name);

const SourmashSignature *signatures_iter_next(SourmashSignatureIter *ptr);

SourmashSignature **signatures_load_buffer(const char *ptr,
uintptr_t insize,
bool _ignore_md5sum,
Expand Down
1 change: 1 addition & 0 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bytecount = "0.6.0"
byteorder = "1.4.3"
cfg-if = "1.0"
counter = "0.5.7"
csv = "1.1.6"
finch = { version = "0.6.0", optional = true }
fixedbitset = "0.4.0"
getrandom = { version = "0.2", features = ["js"] }
Expand Down
5 changes: 5 additions & 0 deletions src/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub enum SourmashError {
#[error(transparent)]
IOError(#[from] std::io::Error),

#[error(transparent)]
CsvError(#[from] csv::Error),

#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
#[error(transparent)]
Panic(#[from] crate::ffi::utils::Panic),
Expand Down Expand Up @@ -108,6 +111,7 @@ pub enum SourmashErrorCode {
ParseInt = 100_003,
SerdeError = 100_004,
NifflerError = 100_005,
CsvError = 100_006,
}

#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
Expand Down Expand Up @@ -137,6 +141,7 @@ impl SourmashErrorCode {
SourmashError::IOError { .. } => SourmashErrorCode::Io,
SourmashError::NifflerError { .. } => SourmashErrorCode::NifflerError,
SourmashError::Utf8Error { .. } => SourmashErrorCode::Utf8Error,
SourmashError::CsvError { .. } => SourmashErrorCode::CsvError,
}
}
}
165 changes: 165 additions & 0 deletions src/core/src/ffi/index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
pub mod revindex;

use crate::encodings::HashFunctions;
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 @@ -35,3 +39,164 @@ pub unsafe extern "C" fn searchresult_signature(
let result = SourmashSearchResult::as_rust(ptr);
SourmashSignature::from_rust((result.1).clone())
}

//================================================================

pub struct SourmashSelection;

impl ForeignObject for SourmashSelection {
type RustObject = Selection;
}

#[no_mangle]
pub unsafe extern "C" fn selection_new() -> *mut SourmashSelection {

Check warning on line 52 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L52

Added line #L52 was not covered by tests
SourmashSelection::from_rust(Selection::default())
}

#[no_mangle]
pub unsafe extern "C" fn selection_ksize(ptr: *const SourmashSelection) -> u32 {

Check warning on line 57 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L57

Added line #L57 was not covered by tests
let sel = SourmashSelection::as_rust(ptr);
if let Some(ksize) = sel.ksize() {

Check warning on line 59 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L59

Added line #L59 was not covered by tests
ksize
} else {
todo!("empty ksize case not supported yet")
}
}

#[no_mangle]
pub unsafe extern "C" fn selection_set_ksize(ptr: *mut SourmashSelection, new_ksize: u32) {

Check warning on line 67 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L67

Added line #L67 was not covered by tests
let sel = SourmashSelection::as_rust_mut(ptr);
sel.set_ksize(new_ksize);
}

#[no_mangle]
pub unsafe extern "C" fn selection_num(ptr: *const SourmashSelection) -> u32 {

Check warning on line 73 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L73

Added line #L73 was not covered by tests
let sel = SourmashSelection::as_rust(ptr);
if let Some(num) = sel.num() {

Check warning on line 75 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L75

Added line #L75 was not covered by tests
num
} else {
todo!("empty num case not supported yet")
}
}

#[no_mangle]
pub unsafe extern "C" fn selection_set_num(ptr: *mut SourmashSelection, new_num: u32) {

Check warning on line 83 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L83

Added line #L83 was not covered by tests
let sel = SourmashSelection::as_rust_mut(ptr);
sel.set_num(new_num);
}

#[no_mangle]
pub unsafe extern "C" fn selection_scaled(ptr: *const SourmashSelection) -> u32 {

Check warning on line 89 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L89

Added line #L89 was not covered by tests
let sel = SourmashSelection::as_rust(ptr);
if let Some(scaled) = sel.scaled() {

Check warning on line 91 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L91

Added line #L91 was not covered by tests
scaled
} else {
todo!("empty scaled case not supported yet")
}
}

#[no_mangle]
pub unsafe extern "C" fn selection_set_scaled(ptr: *mut SourmashSelection, new_scaled: u32) {

Check warning on line 99 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L99

Added line #L99 was not covered by tests
let sel = SourmashSelection::as_rust_mut(ptr);
sel.set_scaled(new_scaled);
}

#[no_mangle]
pub unsafe extern "C" fn selection_containment(ptr: *const SourmashSelection) -> bool {

Check warning on line 105 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L105

Added line #L105 was not covered by tests
let sel = SourmashSelection::as_rust(ptr);
if let Some(containment) = sel.containment() {

Check warning on line 107 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L107

Added line #L107 was not covered by tests
containment
} else {
todo!("empty scaled case not supported yet")
}
}

#[no_mangle]
pub unsafe extern "C" fn selection_set_containment(

Check warning on line 115 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L115

Added line #L115 was not covered by tests
ptr: *mut SourmashSelection,
new_containment: bool,
) {
let sel = SourmashSelection::as_rust_mut(ptr);
sel.set_containment(new_containment);
}

#[no_mangle]
pub unsafe extern "C" fn selection_abund(ptr: *const SourmashSelection) -> bool {

Check warning on line 124 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L124

Added line #L124 was not covered by tests
let sel = SourmashSelection::as_rust(ptr);
if let Some(abund) = sel.abund() {

Check warning on line 126 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L126

Added line #L126 was not covered by tests
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) {

Check warning on line 134 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L134

Added line #L134 was not covered by tests
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 {

Check warning on line 140 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L140

Added line #L140 was not covered by tests
let sel = SourmashSelection::as_rust(ptr);
if let Some(hash_function) = sel.moltype() {

Check warning on line 142 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L142

Added line #L142 was not covered by tests
hash_function
} else {
todo!("empty hash_function case not supported yet")
}
}

#[no_mangle]
pub unsafe extern "C" fn selection_set_moltype(

Check warning on line 150 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L150

Added line #L150 was not covered by tests
ptr: *mut SourmashSelection,
new_moltype: HashFunctions,
) {
let sel = SourmashSelection::as_rust_mut(ptr);
sel.set_moltype(new_moltype);
}

#[no_mangle]
pub unsafe extern "C" fn selection_picklist(

Check warning on line 159 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L159

Added line #L159 was not covered by tests
ptr: *const SourmashSelection,
) -> *const SourmashPicklist {
let sel = SourmashSelection::as_rust(ptr);
if let Some(picklist) = sel.picklist() {

Check warning on line 163 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L163

Added line #L163 was not covered by tests
SourmashPicklist::from_rust(picklist)
} else {
todo!("empty picklist case not supported yet")
}
}

#[no_mangle]
pub unsafe extern "C" fn selection_set_picklist(

Check warning on line 171 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L171

Added line #L171 was not covered by tests
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);

Check warning on line 177 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L177

Added line #L177 was not covered by tests
}

//================================================================
//
pub struct SignatureIterator {
iter: Box<dyn Iterator<Item = SigStore<Signature>>>,
}

pub struct SourmashSignatureIter;

impl ForeignObject for SourmashSignatureIter {
type RustObject = SignatureIterator;
}

#[no_mangle]
pub unsafe extern "C" fn signatures_iter_next(

Check warning on line 193 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L193

Added line #L193 was not covered by tests
ptr: *mut SourmashSignatureIter,
) -> *const SourmashSignature {
let iterator = SourmashSignatureIter::as_rust_mut(ptr);

match iterator.iter.next() {
Some(sig) => SourmashSignature::from_rust(sig.into()),

Check warning on line 199 in src/core/src/ffi/index/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/index/mod.rs#L198-L199

Added lines #L198 - L199 were not covered by tests
None => std::ptr::null(),
}
}
Loading

0 comments on commit 593775a

Please sign in to comment.