Skip to content

Commit

Permalink
Merge pull request #216 from noamteyssier/215-slim-features-for-clean…
Browse files Browse the repository at this point in the history
…er-install

215 slim features for cleaner install
  • Loading branch information
noamteyssier authored Nov 22, 2024
2 parents 0218e01 + d5efbe9 commit 86a6327
Show file tree
Hide file tree
Showing 23 changed files with 136 additions and 118 deletions.
29 changes: 17 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ggetrs"
version = "0.1.86"
version = "0.1.87"
edition = "2021"
license = "MIT"
description = "Efficient querying of biological databases from the command line"
Expand All @@ -21,31 +21,36 @@ default = ["pyo3/extension-module"]
[dependencies]
anyhow = "1.0.64"
bitvec = "1.0.1"
bon = "2.3.0"
bon = "3.0.2"
chrono = "0.4.22"
clap = { version = "4.0.18", features = ["derive"] }
clap_complete = "4.0.3"
ftp = "3.0.1"
futures = "0.3.24"
indicatif = "0.17.5"
mysql = { version = "25.0.1", default-features = false, features = [
"minimal",
"rustls-tls",
"minimal",
"rustls-tls",
] }
polars = { version = "0.43.1", default-features = false, features = ["json"] }
pyo3 = { version = "0.22.2", features = ["extension-module", "anyhow"] }
# polars = { version = "0.43.1", default-features = false, features = ["json"] }
polars-core = { version = "0.44.2", default-features = false }
polars-io = { version = "0.44.2", default-features = false, features = [
"json",
"csv",
] }
pyo3 = { version = "0.23.1", features = ["extension-module", "anyhow"] }
regex = "1.6.0"
reqwest = { version = "0.12.5", default-features = false, features = [
"json",
"multipart",
"blocking",
"stream",
"rustls-tls",
"json",
"multipart",
"blocking",
"stream",
"rustls-tls",
] }
serde = { version = "1.0.144", features = ["derive"] }
serde-xml-rs = "0.6.0"
serde_json = "1.0.85"
tokio = { version = "1.21.0", features = ["full"] }
tokio = { version = "1.21.0", default-features = false }

[lints.clippy]
pedantic = { level = "warn", priority = -1 }
Expand Down
2 changes: 1 addition & 1 deletion src/archs4/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn python_archs4_tissue<'py>(

/// Wraps `ARCHS4` specific functions into a python submodule
pub fn python_archs4(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> {
let submodule = PyModule::new_bound(py, "archs4")?;
let submodule = PyModule::new(py, "archs4")?;
submodule.add_function(wrap_pyfunction!(python_archs4_tissue, module)?)?;
submodule.add_function(wrap_pyfunction!(python_archs4_correlate, module)?)?;
module.add_submodule(&submodule)?;
Expand Down
4 changes: 2 additions & 2 deletions src/archs4/types/correlation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl fmt::Display for Correlations {
}
impl Correlations {
pub fn as_pydict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
dict.set_item(
"correlations",
self.correlations
Expand Down Expand Up @@ -90,7 +90,7 @@ impl fmt::Display for Correlation {
}
impl Correlation {
pub fn as_pydict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
dict.set_item("gene_symbol", &self.gene_symbol)?;
dict.set_item("pearson_correlation", self.pearson_correlation)?;
Ok(dict)
Expand Down
4 changes: 2 additions & 2 deletions src/archs4/types/tissue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ResponseTissue {
.collect()
}
pub fn as_pydict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
dict.set_item(
"tissues",
self.results
Expand Down Expand Up @@ -124,7 +124,7 @@ impl ResultTissue {
}

pub fn as_pydict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
dict.set_item("id", &self.id)?;
dict.set_item("min", self.min)?;
dict.set_item("q1", self.q1)?;
Expand Down
3 changes: 1 addition & 2 deletions src/blast/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use pyo3::{
signature = (query, program = None, database = None, limit = None, expect = None, low_comp_filter = None, megablast = None)
)]
#[allow(clippy::too_many_arguments)]

pub fn python_blast<'py>(
py: Python<'py>,
query: &str,
Expand Down Expand Up @@ -61,5 +60,5 @@ pub fn python_blast<'py>(
low_comp_filter,
megablast,
)?;
Ok(response.into_py_dict_bound(py))
Ok(response.into_py_dict(py)?)
}
22 changes: 11 additions & 11 deletions src/blast/types/result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pyo3::{
types::{IntoPyDict, PyDict, PyDictMethods},
Bound,
Bound, PyResult,
};
use serde::{Deserialize, Serialize};
use std::fmt;
Expand All @@ -19,20 +19,20 @@ impl fmt::Display for BlastResult {
)
}
}
impl IntoPyDict for BlastResult {
fn into_py_dict_bound(self, py: pyo3::Python<'_>) -> Bound<'_, PyDict> {
let map = PyDict::new_bound(py);
impl<'py> IntoPyDict<'py> for BlastResult {
fn into_py_dict(self, py: pyo3::Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let map = PyDict::new(py);
map.set_item("query", self.query).unwrap();
map.set_item(
"results",
self.results
.iter()
.cloned()
.map(|x| x.into_py_dict_bound(py))
.collect::<Vec<Bound<'_, PyDict>>>(),
.map(|x| x.into_py_dict(py).unwrap())
.collect::<Vec<Bound<'py, PyDict>>>(),
)
.unwrap();
map
Ok(map)
}
}
impl BlastResult {
Expand Down Expand Up @@ -97,9 +97,9 @@ impl BlastHit {
}
}
}
impl IntoPyDict for BlastHit {
fn into_py_dict_bound(self, py: pyo3::Python<'_>) -> Bound<'_, PyDict> {
let map = PyDict::new_bound(py);
impl<'py> IntoPyDict<'py> for BlastHit {
fn into_py_dict(self, py: pyo3::Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let map = PyDict::new(py);
map.set_item("num", self.num).unwrap();
map.set_item("id", self.num).unwrap();
map.set_item("definition", self.num).unwrap();
Expand All @@ -114,7 +114,7 @@ impl IntoPyDict for BlastHit {
map.set_item("query_end", self.num).unwrap();
map.set_item("subject_start", self.num).unwrap();
map.set_item("subject_end", self.num).unwrap();
map
Ok(map)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub enum Commands {
#[clap(required = true)]
search_terms: Vec<String>,

/// Species name to use: currently this MUST match the taxon_id
/// Species name to use: currently this MUST match the `taxon_id`
#[clap(short, long, default_value = "homo_sapiens")]
species: String,

Expand All @@ -129,7 +129,7 @@ pub enum Commands {
output: Option<String>,
},

/// Queries sequences from ensembl and UniProt
/// Queries sequences from ensembl and `UniProt`
Seq {
/// Search terms to query (can be Ensembl IDs or Gene Symbols)
#[clap(value_parser, required = true)]
Expand Down
2 changes: 1 addition & 1 deletion src/cli/enrichr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::Subcommand;
pub enum ModEnrichr {
/// Perform the Enrichr gene set enrichment analysis
Enrichr {
/// any database listed at: https://maayanlab.cloud/Enrichr/#libraries
/// any database listed at: <https://maayanlab.cloud/Enrichr/#libraries>
/// some shorthands include: pathway, transcription, ontology, diseases_drugs, celltypes,
/// and kinase_interactions.
#[clap(short, long)]
Expand Down
15 changes: 9 additions & 6 deletions src/enrichr/types/enrich.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ impl fmt::Display for ResponseEnrich {
}
impl ResponseEnrich {
pub fn as_pydict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
for (key, results) in &self.0 {
let all_results: Vec<Bound<'py, PyDict>> = results
.iter()
.map(|x| x.as_pydict(py).expect("could not create dictionary"))
.collect();
let all_results =
results
.iter()
.try_fold(Vec::new(), |mut acc, x| -> PyResult<Vec<_>> {
acc.push(x.as_pydict(py)?);
Ok(acc)
})?;
dict.set_item(key, all_results)?;
}
Ok(dict)
Expand Down Expand Up @@ -72,7 +75,7 @@ impl fmt::Display for ResultEnrichr {
}
impl ResultEnrichr {
pub fn as_pydict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
dict.set_item("rank", self.rank)?;
dict.set_item("term_name", &self.term_name)?;
dict.set_item("pvalue", self.pvalue)?;
Expand Down
4 changes: 2 additions & 2 deletions src/ensembl/functions/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use mysql::{prelude::Queryable, Conn, OptsBuilder};
pub fn database(filter: &Option<String>) -> anyhow::Result<ResponseDatabases> {
let opts = get_mysql_options();
let mut conn = Conn::new(opts)?;
let query = build_search_query(filter);
let query = build_search_query(filter.as_ref());
let results: Vec<Database> = conn.query_map(query, Database)?;
if results.is_empty() {
match filter {
Expand All @@ -28,7 +28,7 @@ fn get_mysql_options() -> OptsBuilder {
/// Generates the search query.
///
/// Searches through databases for a related token
fn build_search_query(search_term: &Option<String>) -> String {
fn build_search_query(search_term: Option<&String>) -> String {
if let Some(token) = search_term {
format!("SHOW databases LIKE '%{token}%'")
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/ensembl/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub fn python_ensembl_species(
}

pub fn python_ensembl(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> {
let submodule = PyModule::new_bound(py, "ensembl")?;
let submodule = PyModule::new(py, "ensembl")?;
submodule.add_function(wrap_pyfunction!(python_ensembl_search, module)?)?;
submodule.add_function(wrap_pyfunction!(python_ensembl_database, module)?)?;
submodule.add_function(wrap_pyfunction!(python_ensembl_release, module)?)?;
Expand Down
2 changes: 1 addition & 1 deletion src/ensembl/types/ftpfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl FtpFile {
}

pub fn as_pydict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
dict.set_item("url", &self.url)?;
dict.set_item("ensembl_release", self.ensembl_release)?;
dict.set_item("release_date", &self.release_date)?;
Expand Down
4 changes: 2 additions & 2 deletions src/ensembl/types/search_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl fmt::Display for SearchResults {
}
impl SearchResults {
pub fn as_pydict<'py>(&self, py: Python<'py>) -> Result<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
dict.set_item(
"results",
self.0
Expand Down Expand Up @@ -82,7 +82,7 @@ impl SearchResult {
}

pub fn as_pydict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
let dict = PyDict::new(py);
dict.set_item("stable_id", &self.stable_id)?;
dict.set_item("display_label", &self.display_label)?;
dict.set_item("ensembl_description", &self.ensembl_description)?;
Expand Down
2 changes: 1 addition & 1 deletion src/info/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ pub fn python_info(
let species = species.unwrap_or("homo_sapiens".to_string());
let taxon_id = taxon_id.unwrap_or(9606);
let results = info(&search_terms, &species, taxon_id)?;
Ok(results.into_py_dict_bound(py))
Ok(results.into_py_dict(py)?)
}
21 changes: 11 additions & 10 deletions src/info/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
ensembl::types::LookupResponse, ncbi::types::NcbiResults, uniprot::UniprotInfoContainer,
};
use pyo3::types::{IntoPyDict, PyDict, PyDictMethods};
use pyo3::Bound;
use pyo3::{Bound, PyResult};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt;
Expand All @@ -19,13 +19,14 @@ impl fmt::Display for InfoContainer {
)
}
}
impl IntoPyDict for InfoContainer {
fn into_py_dict_bound(self, py: pyo3::Python<'_>) -> Bound<'_, PyDict> {
let map = PyDict::new_bound(py);
impl<'py> IntoPyDict<'py> for InfoContainer {
fn into_py_dict(self, py: pyo3::Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let map = PyDict::new(py);
self.0.iter().for_each(|(k, v)| {
map.set_item(k, v.clone().into_py_dict_bound(py)).unwrap();
map.set_item(k, v.clone().into_py_dict(py).unwrap())
.unwrap();
});
map
Ok(map)
}
}
impl InfoContainer {
Expand Down Expand Up @@ -69,9 +70,9 @@ impl fmt::Display for Info {
)
}
}
impl IntoPyDict for Info {
fn into_py_dict_bound(self, py: pyo3::Python<'_>) -> Bound<'_, PyDict> {
let map = PyDict::new_bound(py);
impl<'py> IntoPyDict<'py> for Info {
fn into_py_dict(self, py: pyo3::Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let map = PyDict::new(py);
map.set_item("ensembl_id", &self.ensembl_id).unwrap();
map.set_item("uniprot_id", &self.uniprot_id).unwrap();
map.set_item("ncbi_id", &self.ncbi_id).unwrap();
Expand All @@ -85,7 +86,7 @@ impl IntoPyDict for Info {
.unwrap();
map.set_item("species", &self.species).unwrap();
map.set_item("assembly_name", &self.assembly_name).unwrap();
map
Ok(map)
}
}
impl Info {
Expand Down
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ pub mod seq;
pub type RequestError = Box<dyn std::error::Error + Send + Sync>;

#[pymodule]
fn ggetrs(py: Python<'_>, module: Bound<'_, PyModule>) -> PyResult<()> {
module.add_function(wrap_pyfunction!(enrichr::python_enrichr, &module)?)?;
fn ggetrs(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> {
module.add_function(wrap_pyfunction!(enrichr::python_enrichr, module)?)?;
module.add_function(wrap_pyfunction!(
enrichr::python_enrichr_background,
&module
module
)?)?;
archs4::python_archs4(py, &module)?;
ensembl::python_ensembl(py, &module)?;
ucsc::python_ucsc(py, &module)?;
module.add_function(wrap_pyfunction!(ensembl::python_ensembl_search, &module)?)?;
module.add_function(wrap_pyfunction!(seq::python_seq, &module)?)?;
module.add_function(wrap_pyfunction!(info::python_info, &module)?)?;
module.add_function(wrap_pyfunction!(blast::python_blast, &module)?)?;
archs4::python_archs4(py, module)?;
ensembl::python_ensembl(py, module)?;
ucsc::python_ucsc(py, module)?;
module.add_function(wrap_pyfunction!(ensembl::python_ensembl_search, module)?)?;
module.add_function(wrap_pyfunction!(seq::python_seq, module)?)?;
module.add_function(wrap_pyfunction!(info::python_info, module)?)?;
module.add_function(wrap_pyfunction!(blast::python_blast, module)?)?;
Ok(())
}
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ use ggetrs::{
ncbi::{launch_ncbi_query_ids, launch_ncbi_query_symbols, launch_ncbi_taxons},
pdb::{launch_pdb_resource, launch_pdb_structure},
seq::launch_seq,
string::*,
string::{
launch_string_annotations, launch_string_enrichment, launch_string_homology,
launch_string_interactions, launch_string_mapping, launch_string_network,
launch_string_ppi_enrichment,
},
ucsc::launch_ucsc_blat,
uniprot::launch_uniprot_query,
utils::autocomplete::print_completions,
Expand Down Expand Up @@ -250,7 +254,7 @@ fn main() -> Result<(), RequestError> {
ModString::Enrichment { args, output } => launch_string_enrichment(args, output)?,
ModString::Annotations { args, output } => launch_string_annotations(args, output)?,
ModString::PpiEnrichment { args, output } => {
launch_string_ppi_enrichment(args, output)?
launch_string_ppi_enrichment(args, output)?;
}
},
Commands::Autocomplete { shell } => print_completions(*shell, &mut Cli::command()),
Expand Down
Loading

0 comments on commit 86a6327

Please sign in to comment.