Skip to content

add example of #[pyclass] usage#38

Closed
davidhewitt wants to merge 1 commit intoLCrossman:mainfrom
davidhewitt:pyclass
Closed

add example of #[pyclass] usage#38
davidhewitt wants to merge 1 commit intoLCrossman:mainfrom
davidhewitt:pyclass

Conversation

@davidhewitt
Copy link
Copy Markdown
Contributor

Hello! Just pushing this example following our chat right now.

Feel free to ping me to ask further, hope this proves useful to play with 🚀

@davidhewitt davidhewitt marked this pull request as draft March 13, 2026 13:18
@LCrossman
Copy link
Copy Markdown
Owner

Hi, thanks this is greatly helpful

@LCrossman
Copy link
Copy Markdown
Owner

@davidhewitt following up....

see changes in: branch

  • wrote pytests, previously only had a rust test that functions were added to the pymodule
  • converted the Faa pyclass we talked about to a SequenceCollection as below for a more generic use to handle both Faa (protein sequence) and Ffn (gene sequence)
  • created the following pyclasses and return types:

PyRecord:

  • has pymethods write_faa, write_ffn, and write_fna which write directly to file
  • wraps InternalRecord (either gbk or embl), has .sequences() and .features() pymethods returning multiple features and sequences gene data as a HashMap<String, Py>

SequenceCollection - is a HashMap<String, Py>, created by PyRecord .sequences() or directly conversion functions gbk_to_faa etc. , returns as a PyResult

FeatureCollection - is a HashMap<String, Py>, created by PyRecord pymethod .features()

RecordCollection - HashMap<String, Py>, top-level return of parse_gbk/parse_embl, returns as a PyResult

PyFeatureInfo - contains per single gene info: key: locus_tag, gene, product, start, stop, strand, codon_start, extras (extras is a store for optional tags that can crop up like old_locus_tag etc)

PySequenceInfo - contains per single gene info: key: locus_tag, sequence_faa (protein), sequence_ffn (gene sequence), extras

LocusTagIterator - key iterator returned by iter on any collection.

Future - moving away from a separate gbk, embl (stored in InternalRecord) towards a more generic record on the Rust side so built with that in mind for ease of later change.

I am getting: (mac osx benchmarks)
microBioRust Rust-only benchmarking file conversion: 79.9 ms
microbiorust-py using write_faa directly: 86.9 ms
microbiorust-py using .sequences() returning PyResult<String, Py>: 90.4 ms

Big improvement on python integration!

  • planning to integrate at the end of the week - please comment if you have time or comments

@LCrossman
Copy link
Copy Markdown
Owner

Closing this with thanks, as integrated into microbiorust-py with pyclasses and pymethods

@LCrossman LCrossman closed this May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants