Skip to content

Commit f687486

Browse files
committed
adding seqmetrics functions to microbiorust-py
1 parent 2a993ed commit f687486

3 files changed

Lines changed: 123 additions & 5 deletions

File tree

microbiorust-py/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ extension-module = ["pyo3/extension-module"]
2727

2828
[dependencies]
2929
microBioRust = "0.1.2"
30+
microBioRust-seqmetrics = "0.1.2"
31+

microbiorust-py/K12_ribo.gbk

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
LOCUS NC_000913 913 bp DNA linear CON 01-Sep-2025
2+
DEFINITION Escherichia coli
3+
ACCESSION NC_000913
4+
KEYWORDS .
5+
SOURCE Escherichia coli str. K-12 substr. MG1655
6+
ORGANISM Escherichia coli str. K-12 substr. MG1655
7+
Bacteria; Pseudomonadati; Pseudomonadota; Gammaproteobacteria;
8+
Enterobacterales; Enterobacteriaceae; Escherichia.
9+
FEATURES Location/Qualifiers
10+
source <1..>913
11+
/id="source_1"
12+
/organism="Escherichia coli str. K-12 substr. MG1655"
13+
/mol_type="genomic DNA"
14+
/strain="K-12"
15+
/sub_strain="MG1655"
16+
/db_xref="taxon:511145"
17+
source complement(1..913)
18+
gene complement(10..363)
19+
/gene="rplR"
20+
/locus_tag="b3304"
21+
/gene_synonym="ECK3291"
22+
/db_xref="ASAP:ABE-0010825"
23+
/db_xref="ECOCYC:EG10879"
24+
/db_xref="GeneID:947804"
25+
CDS complement(10..363)
26+
/gene="rplR"
27+
/locus_tag="b3304"
28+
/gene_synonym="ECK3291"
29+
/codon_start=1
30+
/transl_table=11
31+
/product="50S ribosomal subunit protein L18"
32+
/protein_id="NP_417763.1"
33+
/db_xref="UniProtKB/Swiss-Prot:P0C018"
34+
/db_xref="ASAP:ABE-0010825"
35+
/db_xref="ECOCYC:EG10879"
36+
/db_xref="GeneID:947804"
37+
/translation="MDKKSARIRRATRARRKLQELGATRLVVHRTPRHIYAQVIAPNG
38+
SEVLVAASTVEKAIAEQLKYTGNKDAAAAVGKAVAERALEKGIKDVSFDRSGFQYHGR
39+
VQALADAAREAGLQF"
40+
gene complement(373..906)
41+
/gene="rplF"
42+
/locus_tag="b3305"
43+
/gene_synonym="ECK3292"
44+
/db_xref="ASAP:ABE-0010827"
45+
/db_xref="ECOCYC:EG10869"
46+
/db_xref="GeneID:947803"
47+
CDS complement(373..906)
48+
/gene="rplF"
49+
/locus_tag="b3305"
50+
/gene_synonym="ECK3292"
51+
/codon_start=1
52+
/transl_table=11
53+
/product="50S ribosomal subunit protein L6"
54+
/protein_id="NP_417764.1"
55+
/db_xref="UniProtKB/Swiss-Prot:P0AG55"
56+
/db_xref="ASAP:ABE-0010827"
57+
/db_xref="ECOCYC:EG10869"
58+
/db_xref="GeneID:947803"
59+
/translation="MSRVAKAPVVVPAGVDVKINGQVITIKGKNGELTRTLNDAVEVK
60+
HADNTLTFGPRDGYADGWAQAGTARALLNSMVIGVTEGFTKKLQLVGVGYRAAVKGNV
61+
INLSLGFSHPVDHQLPAGITAECPTQTEIVLKGADKQVIGQVAADLRAYRRPEPYKGK
62+
GVRYADEVVRTKEAKKK"
63+
BASE COUNT 214 a 256 c 223 g 220 t
64+
ORIGIN
65+
1 acctctacct tagaactgaa ggccagcttc acgggcagca tctgccagtg cctggacacg
66+
61 accatgatat tggaacccgg aacggtcaaa ggatacatct ttgatgcctt tttccagagc
67+
121 gcgttcagcg acagctttac ccacagctgc agccgcgtct ttgttaccgg tgtacttcag
68+
181 ttgttcagcg atagcttttt ctacagtaga agcagctacc agaacttcag aaccgttcgg
69+
241 tgcaattacc tgtgcgtaaa tgtgacgcgg ggtacgatgt accaccaggc gagttgcgcc
70+
301 cagctcctgg agcttgcggc gtgcgcgggt cgcacgacgg atacgagcag atttcttatc
71+
361 catagtgtta ccttacttct tcttagcctc tttggtacgc acgacttcgt cggcgtaacg
72+
421 aacacccttg cctttataag gctcaggacg acggtaggcg cgcagatccg ctgcaacctg
73+
481 gccgatcacc tgcttatcag cgcctttcag cacgatttca gtctgagtcg gacattcagc
74+
541 agtgataccc gcaggcagct gatggtcaac aggatgagag aaacccagag acaggttaat
75+
601 cacattgcct ttaaccgctg cacggtaacc tacaccaacc agctgcagct tcttagtgaa
76+
661 gccttcggta acaccgataa ccattgagtt cagcagggca cgcgcggtac cagcctgtgc
77+
721 ccaaccgtct gcgtaaccat cacgcggacc gaaggtcagg gtattatctg catgtttaac
78+
781 ttcaacagca tcgttgagag tacgagtcag ctcgccgttt ttacctttga tcgtaataac
79+
841 ctgaccgttg atttttacgt caacgccggc aggaacaacg accggtgctt tagcaacacg
80+
901 agacattttt tcc
81+
//

microbiorust-py/src/lib.rs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,25 @@
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

2327
use pyo3::{
2428
prelude::*,
2529
types::PyModule,
2630
};
2731
use microBioRust::genbank;
32+
use std::collections::HashMap;
2833
use std::{
2934
collections::BTreeMap,
3035
io::{self, Write},
@@ -33,6 +38,9 @@ use std::{
3338
use microBioRust::gbk::{Record, Reader, RangeValue, gff_write};
3439
use microBioRust::embl;
3540
use 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]
3846
fn 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)]
168202
mod 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

Comments
 (0)