Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ jobs:
platform:
- runner: ubuntu-22.04
target: x86_64
- runner: ubuntu-22.04
target: aarch64
python-version:
- "3.11"
- "3.12"
- "3.13"
steps:
- uses: actions/checkout@v4
- name: Build wheels
Expand Down Expand Up @@ -55,6 +58,7 @@ jobs:
python-version:
- "3.11"
- "3.12"
- "3.13"
steps:
- uses: actions/checkout@v4
- name: Build wheels
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bytecount = { version = "0.6", features = ["runtime-dispatch-simd"] }
bzip2 = { version = "0.4", optional = true }
flate2 = { version = "1.0.30", optional = true }
memchr = "2.7.2"
pyo3 = { version = "0.21.2", optional = true }
pyo3 = { version = "0.24.0", optional = true }
liblzma = { version = "0.3.1", optional = true }
zstd = { version = "0.13.2", optional = true }

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[build-system]
requires = ["maturin>=1.7,<2.0"]
requires = ["maturin>=1.8,<2.0"]
build-backend = "maturin"

[project]
name = "needletail"
requires-python = ">=3.8"
dynamic = ["version"]
classifier = [
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Rust",
"License :: OSI Approved :: MIT License",
"Topic :: Scientific/Engineering :: Bio-Informatics",
]
Expand Down
17 changes: 11 additions & 6 deletions src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use pyo3::{create_exception, wrap_pyfunction};
use std::hash::{DefaultHasher, Hash, Hasher};
use std::io::Cursor;
use std::path::PathBuf;
use std::sync::Mutex;

create_exception!(needletail, NeedletailError, pyo3::exceptions::PyException);

Expand Down Expand Up @@ -56,7 +57,7 @@ fn get_seq_snippet(seq: &str, max_len: usize) -> String {
/// A class representing a FASTA/FASTQ sequence record.
#[pyclass]
pub struct PyFastxReader {
reader: Box<dyn FastxReader>,
reader: Mutex<Box<dyn FastxReader>>,
}

#[pymethods]
Expand All @@ -69,8 +70,8 @@ impl PyFastxReader {
slf
}

fn __next__(mut slf: PyRefMut<Self>) -> PyResult<Option<Record>> {
if let Some(rec) = slf.reader.next() {
fn __next__(slf: PyRefMut<Self>) -> PyResult<Option<Record>> {
if let Some(rec) = slf.reader.lock().unwrap().next() {
let record = py_try!(rec);
Ok(Some(Record::from_sequence_record(&record)))
} else {
Expand Down Expand Up @@ -280,7 +281,9 @@ impl Record {
#[pyfunction]
fn parse_fastx_file(path: PathBuf) -> PyResult<PyFastxReader> {
let reader = py_try!(rs_parse_fastx_file(path));
Ok(PyFastxReader { reader })
Ok(PyFastxReader {
reader: reader.into(),
})
}

/// Parse sequence records from a FASTA/FASTQ string.
Expand Down Expand Up @@ -310,7 +313,9 @@ fn parse_fastx_file(path: PathBuf) -> PyResult<PyFastxReader> {
#[pyfunction]
fn parse_fastx_string(content: &str) -> PyResult<PyFastxReader> {
let reader = py_try!(parse_fastx_reader(Cursor::new(content.to_owned())));
Ok(PyFastxReader { reader })
Ok(PyFastxReader {
reader: reader.into(),
})
}

/// Normalize the sequence string of nucleotide records by:
Expand Down Expand Up @@ -383,6 +388,6 @@ fn needletail(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(parse_fastx_string))?;
m.add_wrapped(wrap_pyfunction!(normalize_seq))?;
m.add_wrapped(wrap_pyfunction!(reverse_complement))?;
m.add("NeedletailError", py.get_type_bound::<NeedletailError>())?;
m.add("NeedletailError", py.get_type::<NeedletailError>())?;
Ok(())
}
Loading