Skip to content

Commit

Permalink
return references of the proteins instead of cloning the entire struct
Browse files Browse the repository at this point in the history
  • Loading branch information
tibvdm committed Aug 28, 2024
1 parent 0bdd1f2 commit cad3fb5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sa-index/src/peptide_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProteinInfo>,
pub proteins: Vec<&'a Protein>,
pub cutoff_used: bool
}

Expand Down Expand Up @@ -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<SearchResult> {
pub fn search_peptide<'a>(searcher: &'a Searcher, peptide: &str, cutoff: usize, equate_il: bool) -> Option<SearchResult<'a>> {
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
})
}
Expand All @@ -99,12 +99,12 @@ pub fn search_peptide(searcher: &Searcher, peptide: &str, cutoff: usize, equate_
/// # Returns
///
/// Returns an `OutputData<SearchOnlyResult>` 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<String>,
cutoff: usize,
equate_il: bool
) -> Vec<SearchResult> {
) -> Vec<SearchResult<'a>> {
peptides
.par_iter()
.filter_map(|peptide| search_peptide(searcher, peptide, cutoff, equate_il))
Expand Down
2 changes: 2 additions & 0 deletions sa-mappings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions sa-mappings/src/proteins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'-';
Expand All @@ -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
Expand Down

0 comments on commit cad3fb5

Please sign in to comment.