Skip to content

Commit

Permalink
[MRG] Produce list of hashes from a sequence (#1653)
Browse files Browse the repository at this point in the history
* test for seq_to_hashes

* working seq_to_hashes

* Update src/core/src/signature.rs

Co-authored-by: Luiz Irber <luizirber@users.noreply.github.com>

* Update src/core/src/signature.rs

Co-authored-by: Luiz Irber <luizirber@users.noreply.github.com>

* Update src/core/src/ffi/minhash.rs

Co-authored-by: Luiz Irber <luizirber@users.noreply.github.com>

* Update src/core/src/ffi/minhash.rs

Co-authored-by: Luiz Irber <luizirber@users.noreply.github.com>

* fixes to adapt luiz's suggestions

* support is_protein in seq_to_hashes

* extended tests for seq_to_hashes

* Update src/sourmash/minhash.py

Co-authored-by: C. Titus Brown <titus@idyll.org>

* SeqToHashes Iterator dna

* Update src/sourmash/minhash.py

Co-authored-by: C. Titus Brown <titus@idyll.org>

* iterator implemented, missing exceptions

* better performance?

* one step away

* python tests pass

* test for long seqs with all kmers are invalid

* dev comments

* ✔️ 🎉 all passes

* 🐛 fix adding a single protein kmer

* fix test for moltype

* retain protein kmers hashes order

* seq_to_hashes rust test case

* more rust test coverage

* iterator refactoring

* partially enhance add_protein

* fully enhance add_protein

* ignore ffi coverage

* final refactoring

Co-authored-by: Luiz Irber <luizirber@users.noreply.github.com>
Co-authored-by: C. Titus Brown <titus@idyll.org>
  • Loading branch information
3 people committed Jul 21, 2021
1 parent b223638 commit 22c858f
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 116 deletions.
4 changes: 3 additions & 1 deletion codecov.yml
@@ -1,6 +1,8 @@
# config file for codecov, https://app.codecov.io/gh/dib-lab/sourmash/
# config file for codecov, https://app.codecov.io/gh/sourmash-bio/sourmash/

# use path fixing to properly report code coverage on source code
# per https://docs.codecov.io/docs/fixing-paths
fixes:
- "sourmash::src/sourmash"
ignores:
- "src/core/src/ffi"
7 changes: 7 additions & 0 deletions include/sourmash.h
Expand Up @@ -235,6 +235,13 @@ void kmerminhash_remove_many(SourmashKmerMinHash *ptr,

uint64_t kmerminhash_seed(const SourmashKmerMinHash *ptr);

const uint64_t *kmerminhash_seq_to_hashes(SourmashKmerMinHash *ptr,
const char *sequence,
uintptr_t insize,
bool force,
bool is_protein,
uintptr_t *size);

void kmerminhash_set_abundances(SourmashKmerMinHash *ptr,
const uint64_t *hashes_ptr,
const uint64_t *abunds_ptr,
Expand Down
29 changes: 29 additions & 0 deletions src/core/src/ffi/minhash.rs
Expand Up @@ -4,6 +4,7 @@ use std::slice;

use crate::encodings::{aa_to_dayhoff, aa_to_hp, translate_codon, HashFunctions};
use crate::ffi::utils::{ForeignObject, SourmashStr};
use crate::signature::SeqToHashes;
use crate::signature::SigsTrait;
use crate::sketch::minhash::KmerMinHash;

Expand Down Expand Up @@ -58,6 +59,34 @@ unsafe fn kmerminhash_add_sequence(ptr: *mut SourmashKmerMinHash, sequence: *con
}
}

ffi_fn! {
unsafe fn kmerminhash_seq_to_hashes(ptr: *mut SourmashKmerMinHash, sequence: *const c_char, insize: usize, force: bool, is_protein: bool, size: *mut usize) ->
Result<*const u64> {

let mh = SourmashKmerMinHash::as_rust_mut(ptr);

let buf = {
assert!(!ptr.is_null());
slice::from_raw_parts(sequence as *const u8, insize)
};

let mut output: Vec<u64> = Vec::with_capacity(insize);

for hash_value in SeqToHashes::new(buf, mh.ksize(), force, is_protein, mh.hash_function(), mh.seed()){
match hash_value{
Ok(0) => continue,
Ok(x) => output.push(x),
Err(err) => return Err(err),
}
}

*size = output.len();

// FIXME: make a SourmashSlice_u64 type?
Ok(Box::into_raw(output.into_boxed_slice()) as *const u64)
}
}

ffi_fn! {
unsafe fn kmerminhash_add_protein(ptr: *mut SourmashKmerMinHash, sequence: *const c_char) ->
Result<()> {
Expand Down

0 comments on commit 22c858f

Please sign in to comment.