pub struct PeptideDb {
pub peptides: Vec<TheoPeptide>,
pub n_targets: usize,
pub n_decoys: usize,
}Expand description
Mass-sorted peptide database with binary-search candidate lookup.
Fields§
§peptides: Vec<TheoPeptide>Sorted ascending by mass.
n_targets: usize§n_decoys: usizeImplementations§
Source§impl PeptideDb
impl PeptideDb
Sourcepub fn build(fasta_path: impl AsRef<Path>, cfg: &DigestConfig) -> Result<Self>
pub fn build(fasta_path: impl AsRef<Path>, cfg: &DigestConfig) -> Result<Self>
Build the database from a FASTA file using the given digest config.
Examples found in repository?
examples/export_quant_digest.rs (line 14)
6fn main() -> Result<()> {
7 let args: Vec<_> = std::env::args().skip(1).collect();
8 ensure!(
9 args.len() == 3,
10 "usage: export_quant_digest FASTA DIGEST_CONFIG_JSON OUTPUT_TSV"
11 );
12 let mut config: DigestConfig = serde_json::from_str(&std::fs::read_to_string(&args[1])?)?;
13 config.generate_decoys = false;
14 let db = PeptideDb::build(&args[0], &config)?;
15 let mut peptides: Vec<_> = db.peptides.iter().filter(|p| !p.decoy).collect();
16 peptides.sort_by(|a, b| {
17 a.sequence
18 .cmp(&b.sequence)
19 .then_with(|| a.mass.total_cmp(&b.mass))
20 });
21 let file = std::fs::OpenOptions::new()
22 .write(true)
23 .create_new(true)
24 .open(&args[2])?;
25 let mut out = std::io::BufWriter::new(file);
26 writeln!(out, "sequence\tmass\tproteins")?;
27 for p in &peptides {
28 let mut proteins: Vec<_> = p.proteins.iter().map(|x| x.as_ref()).collect();
29 proteins.sort();
30 proteins.dedup();
31 writeln!(out, "{}\t{}\t{}", p.sequence, p.mass, proteins.join(";"))?;
32 }
33 out.flush()?;
34 eprintln!("{} target peptide entries", peptides.len());
35 Ok(())
36}pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn candidates(&self, lo: f64, hi: f64) -> &[TheoPeptide]
pub fn candidates(&self, lo: f64, hi: f64) -> &[TheoPeptide]
Candidate peptides whose mass falls in [lo, hi] (inclusive), as a slice
of the sorted vector.
Auto Trait Implementations§
impl Freeze for PeptideDb
impl RefUnwindSafe for PeptideDb
impl Send for PeptideDb
impl Sync for PeptideDb
impl Unpin for PeptideDb
impl UnsafeUnpin for PeptideDb
impl UnwindSafe for PeptideDb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.