-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from databio/digests
add ga4gh refget digest functionality
- Loading branch information
Showing
11 changed files
with
311 additions
and
8 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 |
---|---|---|
@@ -1,18 +1,35 @@ | ||
# gtars | ||
|
||
This is a python wrapper around the `gtars` crate. It provides an easy interface for using `gtars` in python. It is currently in early development, and as such, it does not have a lot of functionality yet, but new tools are being worked on right now. | ||
|
||
## Installation | ||
|
||
You can get `gtars` from PyPI: | ||
|
||
```bash | ||
pip install gtars | ||
``` | ||
|
||
## Usage | ||
|
||
Import the package, and use the tools: | ||
```python | ||
import gtars as gt | ||
|
||
gt.prune_universe(...) | ||
``` | ||
## Developer docs | ||
Write the develop docs here... | ||
|
||
To build for development: | ||
|
||
```bash | ||
cd bindings/python | ||
maturin build --release | ||
``` | ||
|
||
Then install the local wheel that was just built: | ||
|
||
``` | ||
version=`grep '^version =' Cargo.toml | cut -d '"' -f 2` | ||
pip install --force-reinstall target/wheels/gtars-${version}-cp312-cp312-manylinux_2_38_x86_64.whl | ||
``` |
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 @@ | ||
from .gtars.digests import * # noqa: F403 |
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,71 @@ | ||
// This is intended to provide minimal Python bindings to functions in the `digests` module of the `gtars` crate. | ||
|
||
use pyo3::prelude::*; | ||
use gtars::digests::{sha512t24u, md5, DigestResult}; | ||
|
||
#[pyfunction] | ||
pub fn sha512t24u_digest(readable: &str) -> String { | ||
return sha512t24u(readable); | ||
} | ||
|
||
#[pyfunction] | ||
pub fn md5_digest(readable: &str) -> String { | ||
return md5(readable); | ||
} | ||
|
||
#[pyfunction] | ||
pub fn digest_fasta(fasta: &str) -> PyResult<Vec<PyDigestResult>> { | ||
match gtars::digests::digest_fasta(fasta) { | ||
Ok(digest_results) => { | ||
let py_digest_results: Vec<PyDigestResult> = digest_results.into_iter().map(PyDigestResult::from).collect(); | ||
Ok(py_digest_results) | ||
}, | ||
Err(e) => Err(PyErr::new::<pyo3::exceptions::PyIOError, _>(format!("Error processing FASTA file: {}", e))), | ||
} | ||
} | ||
|
||
#[pyclass] | ||
#[pyo3(name="DigestResult")] | ||
pub struct PyDigestResult { | ||
#[pyo3(get,set)] | ||
pub id: String, | ||
#[pyo3(get,set)] | ||
pub length: usize, | ||
#[pyo3(get,set)] | ||
pub sha512t24u: String, | ||
#[pyo3(get,set)] | ||
pub md5: String | ||
} | ||
|
||
#[pymethods] | ||
impl PyDigestResult { | ||
fn __repr__(&self) -> String { | ||
format!("<DigestResult for {}>", self.id) | ||
} | ||
|
||
fn __str__(&self) -> PyResult<String> { | ||
Ok(format!("DigestResult for sequence {}\n length: {}\n sha512t24u: {}\n md5: {}", self.id, self.length, self.sha512t24u, self.md5)) | ||
} | ||
} | ||
|
||
impl From<DigestResult> for PyDigestResult { | ||
fn from(value: DigestResult) -> Self { | ||
PyDigestResult { | ||
id: value.id, | ||
length: value.length, | ||
sha512t24u: value.sha512t24u, | ||
md5: value.md5 | ||
} | ||
} | ||
} | ||
|
||
// This represents the Python module to be created | ||
#[pymodule] | ||
pub fn digests(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(sha512t24u_digest, m)?)?; | ||
m.add_function(wrap_pyfunction!(md5_digest, m)?)?; | ||
m.add_function(wrap_pyfunction!(digest_fasta, m)?)?; | ||
m.add_class::<PyDigestResult>()?; | ||
Ok(()) | ||
} | ||
|
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
Oops, something went wrong.