1111//!
1212//! Once developed, the PyModule can be loaded into Python and used:
1313//!
14- //! import microbiorust
14+ //! from microbiorust import gbk_to_faa
1515//! result = gbk_to_faa("test_input.gbk")
1616//! for r in result:
1717//! print(r)
1818//! gbk_to_gff("test_input.gbk")
1919//!
20- //! Other pyfunctions that can be run include gbk_to_faa, embl_to_faa, gbk_to_gff and embl_to_gff
20+ //! Other pyfunctions that can be run include gbk_to_faa, embl_to_faa, gbk_to_gff, embl_to_gff, amino_counts, amino_percentage, hydrophobicity
21+ //!
22+ //! from microbiorust import amino_percentage
23+ //! result = amino_percentage("MSNTQKKNVPELRFPGFEGEWEEKKLGDLTTKIGSGKTPKGGSENYTNKGIPFLRSQNIRNGKLNLNDLVYISKDIDDEMKNSRTY")
24+ //! print(result)
2125
2226
2327use pyo3:: {
2428 prelude:: * ,
2529 types:: PyModule ,
2630} ;
2731use microBioRust:: genbank;
32+ use std:: collections:: HashMap ;
2833use std:: {
2934 collections:: BTreeMap ,
3035 io:: { self , Write } ,
@@ -33,6 +38,9 @@ use std::{
3338use microBioRust:: gbk:: { Record , Reader , RangeValue , gff_write} ;
3439use microBioRust:: embl;
3540use microBioRust:: embl:: gff_write as embl_gff_write;
41+ use microBioRust_seqmetrics:: metrics:: hydrophobicity as rust_hydrophobicity;
42+ use microBioRust_seqmetrics:: metrics:: amino_counts as rust_amino_counts;
43+ use microBioRust_seqmetrics:: metrics:: amino_percentage as rust_amino_percentage;
3644
3745#[ pyfunction]
3846fn gbk_to_faa ( filename : & str ) -> PyResult < Vec < String > > {
@@ -155,15 +163,41 @@ fn embl_to_gff(filename: &str, dna: bool) -> PyResult<()> {
155163 return Ok ( ( ) ) ;
156164}
157165
166+ #[ allow( unused_imports) ]
167+ #[ allow( unused_variables) ]
168+ #[ pyfunction]
169+ fn hydrophobicity ( seq : & str , window_size : usize ) -> Vec < f64 > {
170+ rust_hydrophobicity ( seq, window_size)
171+ }
172+
173+ #[ allow( unused_imports) ]
174+ #[ allow( unused_variables) ]
175+ #[ pyfunction]
176+ fn amino_percentage ( seq : & str ) -> HashMap < char , f64 > {
177+ rust_amino_percentage ( seq)
178+ }
179+
180+ #[ allow( unused_imports) ]
181+ #[ allow( unused_variables) ]
182+ #[ pyfunction]
183+ fn amino_counts ( seq : & str ) -> HashMap < char , u64 > {
184+ rust_amino_counts ( seq)
185+ }
186+
187+
158188#[ pymodule]
159- fn microbiorust ( m : & Bound < ' _ , PyModule > ) -> PyResult < ( ) > {
189+ fn microbiorust ( py : Python , m : & Bound < ' _ , PyModule > ) -> PyResult < ( ) > {
160190 m. add_function ( wrap_pyfunction ! ( gbk_to_faa, m) ?) ?;
161191 m. add_function ( wrap_pyfunction ! ( embl_to_faa, m) ?) ?;
162192 m. add_function ( wrap_pyfunction ! ( gbk_to_gff, m) ?) ?;
163193 m. add_function ( wrap_pyfunction ! ( embl_to_gff, m) ?) ?;
194+ m. add_function ( wrap_pyfunction ! ( hydrophobicity, m) ?) ?;
195+ m. add_function ( wrap_pyfunction ! ( amino_counts, m) ?) ?;
196+ m. add_function ( wrap_pyfunction ! ( amino_percentage, m) ?) ?;
164197 Ok ( ( ) )
165198}
166199
200+
167201#[ cfg( test) ]
168202mod tests {
169203 use crate :: microbiorust;
@@ -174,10 +208,11 @@ mod tests {
174208 fn test_functions_are_registered ( ) {
175209 Python :: with_gil ( |py| {
176210 let m = PyModule :: new ( py, "microbiorust" ) . unwrap ( ) ;
177- microbiorust ( & m) . unwrap ( ) ;
178- for func in & [ "gbk_to_faa" , "embl_to_faa" , "gbk_to_gff" , "embl_to_gff" ] {
211+ microbiorust ( py , & m) . unwrap ( ) ;
212+ for func in & [ "gbk_to_faa" , "embl_to_faa" , "gbk_to_gff" , "embl_to_gff" , "hydrophobicity" , "amino_counts" , "amino_percentage" ] {
179213 assert ! ( m. getattr( func) . is_ok( ) , "Function {} not found" , func) ;
180214 }
181215 } ) ;
182216 }
217+
183218}
0 commit comments