From cad3fb5967d28e8d2035a6dbd6aaf704bfaf7ff0 Mon Sep 17 00:00:00 2001 From: tibvdm Date: Wed, 28 Aug 2024 20:31:37 +0200 Subject: [PATCH] return references of the proteins instead of cloning the entire struct --- sa-index/src/peptide_search.rs | 14 +++++++------- sa-mappings/Cargo.toml | 2 ++ sa-mappings/src/proteins.rs | 2 ++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sa-index/src/peptide_search.rs b/sa-index/src/peptide_search.rs index 5f4d8b3..47ff3e1 100644 --- a/sa-index/src/peptide_search.rs +++ b/sa-index/src/peptide_search.rs @@ -5,9 +5,9 @@ use serde::Serialize; use crate::sa_searcher::{SearchAllSuffixesResult, Searcher}; #[derive(Debug, Serialize)] -pub struct SearchResult { +pub struct SearchResult<'a> { pub sequence: String, - pub proteins: Vec, + pub proteins: Vec<&'a Protein>, pub cutoff_used: bool } @@ -75,12 +75,12 @@ pub fn search_proteins_for_peptide<'a>( Some((cutoff_used, proteins)) } -pub fn search_peptide(searcher: &Searcher, peptide: &str, cutoff: usize, equate_il: bool) -> Option { +pub fn search_peptide<'a>(searcher: &'a Searcher, peptide: &str, cutoff: usize, equate_il: bool) -> Option> { let (cutoff_used, proteins) = search_proteins_for_peptide(searcher, peptide, cutoff, equate_il)?; Some(SearchResult { sequence: peptide.to_string(), - proteins: proteins.iter().map(|&protein| protein.into()).collect(), + proteins, cutoff_used }) } @@ -99,12 +99,12 @@ pub fn search_peptide(searcher: &Searcher, peptide: &str, cutoff: usize, equate_ /// # Returns /// /// Returns an `OutputData` object with the search results for the peptides -pub fn search_all_peptides( - searcher: &Searcher, +pub fn search_all_peptides<'a>( + searcher: &'a Searcher, peptides: &Vec, cutoff: usize, equate_il: bool -) -> Vec { +) -> Vec> { peptides .par_iter() .filter_map(|peptide| search_peptide(searcher, peptide, cutoff, equate_il)) diff --git a/sa-mappings/Cargo.toml b/sa-mappings/Cargo.toml index b20a2bf..69d13c6 100644 --- a/sa-mappings/Cargo.toml +++ b/sa-mappings/Cargo.toml @@ -11,3 +11,5 @@ tempdir = "0.3.7" [dependencies] fa-compression = { path = "../fa-compression" } bytelines = "2.5.0" +serde = { version = "1.0.197", features = ["derive"] } +serde_json = "1.0.116" diff --git a/sa-mappings/src/proteins.rs b/sa-mappings/src/proteins.rs index 7597b8d..35777c9 100644 --- a/sa-mappings/src/proteins.rs +++ b/sa-mappings/src/proteins.rs @@ -5,6 +5,7 @@ use std::{error::Error, fs::File, io::BufReader, ops::Index, str::from_utf8}; use bytelines::ByteLines; use fa_compression::algorithm1::{decode, encode}; +use serde::Serialize; /// The separation character used in the input string pub static SEPARATION_CHARACTER: u8 = b'-'; @@ -13,6 +14,7 @@ pub static SEPARATION_CHARACTER: u8 = b'-'; /// This character should be smaller than the separation character pub static TERMINATION_CHARACTER: u8 = b'$'; +#[derive(Debug, Clone, Serialize)] /// A struct that represents a protein and its linked information pub struct Protein { /// The id of the protein