Skip to content

Commit aa37437

Browse files
committed
init python bindings
1 parent e54d05c commit aa37437

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "genimtools"
3-
version = "0.0.2"
3+
version = "0.0.3"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

bindings/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "genimtools-py"
3-
version = "0.1.0"
3+
version = "0.0.3"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

bindings/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["maturin>=1.3,<2.0"]
33
build-backend = "maturin"
44

55
[project]
6-
name = "bindings"
6+
name = "genimtools"
77
requires-python = ">=3.8"
88
classifiers = [
99
"Programming Language :: Rust",

bindings/src/functions.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::io::Write;
2+
use std::fs::File;
3+
4+
use pyo3::prelude::*;
5+
6+
use genimtools::vocab::create_count_map;
7+
8+
#[pyfunction]
9+
pub fn prune_universe(universe: &str, data: &str, min_count: Option<u32>, output: Option<&str>) -> PyResult<()> {
10+
11+
let min_count = min_count.unwrap_or(1);
12+
let output = output.unwrap_or("output.bed");
13+
14+
let cnt_map = create_count_map(data, universe).unwrap();
15+
16+
// create output file
17+
let mut file = File::create(output).unwrap();
18+
for (region, cnt) in cnt_map {
19+
if cnt < min_count {
20+
// skip this region
21+
continue;
22+
}
23+
let line = format!("{}\t{}\t{}\n", region.chr, region.start, region.end);
24+
25+
// write to file
26+
file.write_all(line.as_bytes())?;
27+
}
28+
29+
Ok(())
30+
}

bindings/src/lib.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use pyo3::prelude::*;
22

3-
/// Formats the sum of two numbers as string.
4-
#[pyfunction]
5-
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
6-
Ok((a + b).to_string())
7-
}
3+
use crate::functions::prune_universe;
4+
5+
mod functions;
86

9-
/// A Python module implemented in Rust.
107
#[pymodule]
118
fn genimtools(_py: Python, m: &PyModule) -> PyResult<()> {
12-
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
9+
m.add_function(wrap_pyfunction!(prune_universe, m)?)?;
1310
Ok(())
14-
}
11+
}

docs/changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.0.3]
8+
- work on python bindings initialization
9+
710
## [0.0.2]
811
- prepare for first release
912

0 commit comments

Comments
 (0)