Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all 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
52 changes: 40 additions & 12 deletions .github/workflows/python-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,76 @@ jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout current repository
uses: actions/checkout@v3

- name: Clone remote repository
run: |
git clone https://github.com/david-bouyssie/mzcore.git ../mzcore
ls /home/runner/work/mzio/mzcore

- uses: PyO3/maturin-action@v1
with:
manylinux: auto
manylinux: off # auto
command: build
args: --release --sdist -o dist --find-interpreter
args: -o dist --strip --find-interpreter
working-directory: mzio-py

- name: Upload wheels to artifact
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist
path: mzio-py/dist

- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Checkout current repository
uses: actions/checkout@v3

- name: Clone remote repository
run: |
git clone https://github.com/david-bouyssie/mzcore.git ../mzcore
ls ../mzcore

- uses: PyO3/maturin-action@v1
with:
command: build
args: --release -o dist --find-interpreter
args: -o dist --strip --find-interpreter
working-directory: mzio-py
- name: Upload wheels

- name: Upload wheels to artifact
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist
path: mzio-py/dist

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Checkout current repository
uses: actions/checkout@v3

- name: Clone remote repository
run: |
git clone https://github.com/david-bouyssie/mzcore.git ../mzcore
ls ../mzcore

- uses: PyO3/maturin-action@v1
with:
command: build
args: --release -o dist --universal2 --find-interpreter
args: -o dist --strip --find-interpreter --target universal2-apple-darwin
working-directory: mzio-py
- name: Upload wheels

- name: Upload wheels to artifact
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist
path: mzio-py/dist

# release:
# name: Release
Expand Down
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]

members = [
"mzio-rs",
"mzio-py"
]
6 changes: 3 additions & 3 deletions mzio-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "mzio_py"
crate-type = ["cdylib"]

[dependencies]
anyhow = "1.0.68"
anyhow = "1.0.75"
fallible-iterator = "0.2.0"
mzio = { path = "../mzio-rs" }
pyo3 = { version = "0.17.3", features = ["extension-module", "anyhow"] }
pyo3 = { version = "0.20.0", features = ["extension-module", "anyhow"] }
mzio = { path = "../mzio-rs", features = ["fasta", "mgf"] }
2 changes: 1 addition & 1 deletion mzio-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ doc = [
]

[build-system]
requires = ["maturin>=0.14,<0.15"]
requires = ["maturin>=1.0.0,<1.3.0"]
build-backend = "maturin"
35 changes: 22 additions & 13 deletions mzio-py/src/fasta/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
use std::collections::HashMap;

// 3rd party imports
use anyhow::Result;
use pyo3::prelude::*;
use mzio::fasta::entry::Entry as BaseEntry;
use mzio::fasta::entry::FastaEntry as BaseEntry;

/// Wrapper for the rust implementation entry
///
Expand Down Expand Up @@ -35,37 +36,38 @@ impl Entry {
entry_name,
protein_name,
keyword_attributes,
sequence
sequence,
None
)
}
}

/// Returns the database type
///
#[getter]
pub fn database(&self) -> PyResult<&str> {
Ok(&self.base_entry.get_database())
pub fn database(&self) -> Result<&String> {
Ok(self.base_entry.get_database())
}

/// Returns the accession
///
#[getter]
pub fn accession(&self) -> PyResult<&str> {
Ok(&self.base_entry.get_accession())
pub fn accession(&self) -> Result<&String> {
Ok(self.base_entry.get_accession())
}

/// Entry name
///
#[getter]
pub fn entry_name(&self) -> PyResult<&str> {
Ok(&self.base_entry.get_entry_name())
pub fn entry_name(&self) -> Result<&String> {
Ok(self.base_entry.get_entry_name())
}

/// Returns the protein name
///
#[getter]
pub fn protein_name(&self) -> PyResult<&str> {
Ok(&self.base_entry.get_protein_name())
pub fn protein_name(&self) -> Result<&String> {
Ok(self.base_entry.get_protein_name())
}

/// Returns additional keyword attributes, e.g
Expand All @@ -74,16 +76,23 @@ impl Entry {
///
// !!! TODO Reference to HasMap is no convertible to PyResult by default.
#[getter]
pub fn keyword_attributes(&self) -> PyResult<HashMap<String, String>> {
pub fn keyword_attributes(&self) -> Result<HashMap<String, String>> {
// TODO: avoid clone?
Ok(self.base_entry.get_keyword_attributes().clone())
}

/// Returns the amino acid sequence
///
#[getter]
pub fn sequence(&self) -> PyResult<&str> {
Ok(&self.base_entry.get_sequence())
pub fn sequence(&self) -> Result<&String> {
Ok(self.base_entry.get_sequence())
}

/// Returns the plain header (before parsing)
///
#[getter]
pub fn plain_header(&self) -> Result<&String> {
Ok(self.base_entry.get_sequence())
}
}

Expand Down
11 changes: 6 additions & 5 deletions mzio-py/src/fasta/reader.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// std imports
use std::path::PathBuf;

// 3rd party modules
use pyo3::prelude::*;
// 3rd party imports
use anyhow::Result;
use mzio::fasta::reader::Reader as BaseReader;
use pyo3::prelude::*;
use mzio::fasta::reader::FastaReader as BaseReader;

// internal imports
use crate::fasta::entry::Entry;
Expand All @@ -17,8 +17,9 @@ pub struct Reader {
#[pymethods]
impl Reader {
#[new]
fn new(fasta_file_path: PathBuf, buffer_size: usize) -> Result<Self> {
match BaseReader::new(&fasta_file_path, buffer_size) {
fn new(fasta_file_path: PathBuf, buffer_size: usize, keep_plain_header: bool) -> Result<Self> {
match BaseReader::new(&fasta_file_path, buffer_size, keep_plain_header
) {
Ok(base_reader) => Ok(Self{base_reader}),
Err(err) => Err(err)
}
Expand Down
13 changes: 6 additions & 7 deletions mzio-py/src/fasta/writer.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// std imports
use std::path::PathBuf;

// 3rd party modules
// 3rd party imports
use anyhow::Result;
use pyo3::prelude::*;
use mzio::fasta::writer::Writer as BaseWriter;
use mzio::fasta::writer::FastaWriter as BaseWriter;

// internal imports
use crate::fasta::entry::Entry;


#[pyclass]
pub struct Writer {
base_writer: BaseWriter
Expand All @@ -24,15 +23,15 @@ impl Writer {
/// * `fasta_file_path` - Path to FASTA file
///
#[new]
pub fn new(fasta_file_path: PathBuf) -> PyResult<Self> {
match BaseWriter::new(&fasta_file_path) {
pub fn new(fasta_file_path: PathBuf, sort_keyword_attributes: bool) -> PyResult<Self> {
match BaseWriter::new_with_default_seq_formatting(&fasta_file_path, sort_keyword_attributes) {
Ok(base_writer) => Ok(Self{base_writer}),
Err(err) => Err(err.into())
}
}

pub fn write_entry(&mut self, entry: &Entry, sort_keyword_attributes: bool) -> Result<usize> {
match self.base_writer.write_entry(entry.into(), sort_keyword_attributes) {
pub fn write_entry(&mut self, entry: &Entry) -> Result<usize> {
match self.base_writer.write_entry(entry.into()) {
Ok(written_bytes) => Ok(written_bytes),
Err(err) => Err(err)
}
Expand Down
6 changes: 3 additions & 3 deletions mzio-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ fn register_fasta_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
/// `parent_module` - Parent module of the mgf module
fn register_mgf_module(py: Python, parent_module: &PyModule) -> PyResult<()> {
let child_module = PyModule::new(py, "mgf")?;
child_module.add_class::<mgf::spectrum::Spectrum>()?;
child_module.add_class::<mgf::reader::Reader>()?;
child_module.add_class::<mgf::writer::Writer>()?;
child_module.add_class::<mgf::spectrum::MgfSpectrum>()?;
child_module.add_class::<mgf::reader::MgfReader>()?;
child_module.add_class::<mgf::writer::MgfWriter>()?;
parent_module.add_submodule(child_module)?;
Ok(())
}
25 changes: 13 additions & 12 deletions mzio-py/src/mgf/reader.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
// std imports
use std::path::PathBuf;

// 3rd party modules
// 3rd party imports
use pyo3::prelude::*;
use anyhow::Result;
use mzio::mgf::reader::Reader as BaseReader;

use fallible_iterator::FallibleIterator;
use mzio::mgf::reader::MgfReader as BaseMgfReader;

// internal imports
use crate::mgf::spectrum::Spectrum;
use crate::mgf::spectrum::MgfSpectrum;

#[pyclass]
pub struct Reader {
base_reader: BaseReader
pub struct MgfReader {
base_reader: BaseMgfReader
}

#[pymethods]
impl Reader {
impl MgfReader {
#[new]
#[args(buffer_size=4096)]
#[pyo3(signature = (mgf_file_path, buffer_size=4096))]
fn new(mgf_file_path: PathBuf, buffer_size: usize) -> Result<Self> {
match BaseReader::new(&mgf_file_path, buffer_size) {
let base_reader = BaseMgfReader::new(&mgf_file_path, buffer_size)?;
Ok(Self{base_reader})
/*match BaseReader::new(&mgf_file_path, buffer_size) {
Ok(base_reader) => Ok(Self{base_reader}),
Err(err) => Err(err)
}
}*/
}

fn __iter__(slf: PyRef<'_, Self>) -> PyRef<'_, Self> {
slf
}

fn __next__(mut slf: PyRefMut<'_, Self>) -> Option<Spectrum> {
fn __next__(mut slf: PyRefMut<'_, Self>) -> Option<MgfSpectrum> {
match slf.base_reader.next().ok()? {
Some(base_spectrum) => Some(Spectrum::from(base_spectrum)),
Some(base_spectrum) => Some(MgfSpectrum::from(base_spectrum)),
None => None
}
}
Expand Down
Loading