Skip to content

Commit

Permalink
start bringing #1943
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Oct 17, 2022
1 parent f88ea32 commit da587db
Show file tree
Hide file tree
Showing 23 changed files with 1,701 additions and 286 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.

2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ include/sourmash.h: src/core/src/lib.rs \
src/core/src/ffi/hyperloglog.rs \
src/core/src/ffi/minhash.rs \
src/core/src/ffi/signature.rs \
src/core/src/ffi/manifest.rs \
src/core/src/ffi/picklist.rs \
src/core/src/ffi/nodegraph.rs \
src/core/src/ffi/index/mod.rs \
src/core/src/ffi/index/revindex.rs \
Expand Down
74 changes: 74 additions & 0 deletions include/sourmash.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 +52,26 @@ typedef struct SourmashHyperLogLog SourmashHyperLogLog;

typedef struct SourmashKmerMinHash SourmashKmerMinHash;

typedef struct SourmashLinearIndex SourmashLinearIndex;

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 +92,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 @@ -269,6 +291,32 @@ SourmashKmerMinHash *kmerminhash_to_mutable(const SourmashKmerMinHash *ptr);

bool kmerminhash_track_abundance(const SourmashKmerMinHash *ptr);

void linearindex_free(SourmashLinearIndex *ptr);

uint64_t linearindex_len(const SourmashLinearIndex *ptr);

SourmashStr linearindex_location(const SourmashLinearIndex *ptr);

const SourmashManifest *linearindex_manifest(const SourmashLinearIndex *ptr);

SourmashLinearIndex *linearindex_new(SourmashZipStorage *storage_ptr,
SourmashManifest *manifest_ptr,
SourmashSelection *selection_ptr,
bool use_manifest);

SourmashLinearIndex *linearindex_select(SourmashLinearIndex *ptr,
const SourmashSelection *selection_ptr);

void linearindex_set_manifest(SourmashLinearIndex *ptr, SourmashManifest *manifest_ptr);

SourmashSignatureIter *linearindex_signatures(const SourmashLinearIndex *ptr);

const SourmashZipStorage *linearindex_storage(const SourmashLinearIndex *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 @@ -313,6 +361,16 @@ 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 revindex_free(SourmashRevIndex *ptr);

const SourmashSearchResult *const *revindex_gather(const SourmashRevIndex *ptr,
Expand Down Expand Up @@ -358,6 +416,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 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 @@ -30,6 +30,7 @@ bytecount = "0.6.0"
byteorder = "1.4.3"
cfg-if = "1.0"
counter = "0.5.4"
csv = "1.1.6"
finch = { version = "0.4.1", optional = true }
fixedbitset = "0.4.0"
getset = "0.1.1"
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_vendor = "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_vendor = "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,
}
}
}
91 changes: 91 additions & 0 deletions src/core/src/ffi/index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub mod revindex;

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

use crate::signature::Signature;

use crate::ffi::signature::SourmashSignature;
Expand Down Expand Up @@ -35,3 +38,91 @@ 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 {
SourmashSelection::from_rust(Selection::default())
}

#[no_mangle]
pub unsafe extern "C" fn selection_ksize(ptr: *const SourmashSelection) -> u32 {
let sel = SourmashSelection::as_rust(ptr);
if let Some(ksize) = sel.ksize() {
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) {
let sel = SourmashSelection::as_rust_mut(ptr);
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 {
iter: Box<dyn Iterator<Item = SigStore>>,
}

pub struct SourmashSignatureIter;

impl ForeignObject for SourmashSignatureIter {
type RustObject = SignatureIterator;
}

#[no_mangle]
pub unsafe extern "C" fn signatures_iter_next(
ptr: *mut SourmashSignatureIter,
) -> *const SourmashSignature {
let iterator = SourmashSignatureIter::as_rust_mut(ptr);

match iterator.iter.next() {
Some(sig) => SourmashSignature::from_rust(sig.into()),
None => std::ptr::null(),
}
}
Loading

0 comments on commit da587db

Please sign in to comment.