-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrote crude wrapper around rawhash for signal mapping
- Loading branch information
1 parent
dd0ac71
commit 95fd6ae
Showing
9 changed files
with
175 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#%% | ||
from pathlib import Path | ||
import cppyy | ||
import os | ||
|
||
os.chdir("/home/mmordig/rawhash_project/rawhash2_new/build/extern") | ||
|
||
header_file = Path("/home/mmordig/rawhash_project/rawhash2_new/src/rawhash_wrapper.hpp") | ||
library_file = Path("/home/mmordig/rawhash_project/rawhash2_new/build/src/librawhash2_wrapper.so") | ||
cppyy.include(str(header_file)) | ||
# cppyy.add_library_path("/home/mmordig/rawhash_project/rawhash2_new/build/extern/hdf5/lib") | ||
cppyy.add_library_path("/home/mmordig/rawhash_project/rawhash2_new/build/src") # for shared libs | ||
cppyy.load_library("librawhash2_wrapper") | ||
|
||
# cppyy.add_library_path(str(library_file.parent)) | ||
# cppyy.load_library(str(library_file.name)) | ||
# cppyy.load_library(str(library_file)) | ||
|
||
# cppyy.gbl.RawHashMapper(5, [b"hello"]) | ||
args = ["my_program", "-x", "sensitive", "-t", "8", "-p", "/home/mmordig/rawhash_project/rawhash2_new/extern/kmer_models/legacy/legacy_r9.4_180mv_450bps_6mer/template_median68pA.model", "-d", "example_out/ref.ind", "/home/mmordig/rawhash_project/rawhash2_new/test/data/d2_ecoli_r94/ref.fa", ] | ||
mapper = cppyy.gbl.RawHashMapper(len(args), args) | ||
mapper.idx_info() | ||
#%% | ||
import numpy as np | ||
|
||
# Create a numpy array | ||
arr = np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float32) | ||
|
||
# Ensure the numpy array is contiguous | ||
arr = np.ascontiguousarray(arr, dtype=np.float32) | ||
|
||
import cppyy.ll | ||
cppyy.set_debug() | ||
# Call the C++ function with the numpy array | ||
alignments = mapper.map(cppyy.ll.cast["float*"](arr.ctypes.data), len(arr)) | ||
|
||
def format_alignment(alignment): | ||
# return alignment | ||
return f"Alignment(contig: {alignment.contig}, start: {alignment.ref_start}, end: {alignment.ref_end}, strand: {alignment.is_pos_strand})" | ||
|
||
for (i, alignment) in enumerate(alignments): | ||
print(f"Alignment {i}: {format_alignment(alignment)}") | ||
#%% | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,42 @@ | ||
#pragma once | ||
#include <cstdint> | ||
#include <vector> | ||
|
||
struct Alignment { | ||
const char* contig; | ||
uint32_t ref_start; | ||
uint32_t ref_end; // exclusive | ||
bool is_pos_strand; | ||
}; | ||
|
||
class RawHashMapper { | ||
/** | ||
* @brief Wrapper that can be used from other code (as an alternative to the CLI) | ||
* | ||
* This API is inefficient (no threading) and only for experimenting | ||
* with RawHash from Python without having to load the index repeatedly. | ||
* | ||
* Also mixes malloc/free and new/delete | ||
*/ | ||
public: | ||
RawHashMapper(int argc, char *argv[]); | ||
~RawHashMapper(); | ||
void info(); | ||
|
||
// private: | ||
/* | ||
* Map the reads | ||
* Same as ri_map_file_frag -> map_worker_pipeline -> map_worker_for, | ||
* except it reads from memory rather than the file | ||
* and does not perform the pipeline step | ||
*/ | ||
std::vector<Alignment> map(float* raw_signal, int signal_length); | ||
|
||
/** | ||
* Get info about the index | ||
*/ | ||
void idx_info() const; | ||
|
||
private: | ||
// ri_idx_t *ri; | ||
void *_ri; | ||
void *_ri; // ri_idx_t* | ||
void* _opt; // ri_mapopt_t* | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters