|
| 1 | +use std::collections::HashSet; |
| 2 | +use index::ProteinInfo; |
| 3 | +use crate::helpers::filters::protein_filter::ProteinFilter; |
| 4 | +use crate::helpers::filters::UniprotFilter; |
| 5 | + |
| 6 | +pub struct CrapFilter { |
| 7 | + protein_filter: ProteinFilter, |
| 8 | +} |
| 9 | + |
| 10 | +impl UniprotFilter for CrapFilter { |
| 11 | + fn filter(&self, protein: &ProteinInfo) -> bool { |
| 12 | + self.protein_filter.filter(protein) |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +impl Default for CrapFilter { |
| 17 | + fn default() -> Self { |
| 18 | + Self::new() |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +impl CrapFilter { |
| 23 | + pub fn new() -> Self { |
| 24 | + CrapFilter { |
| 25 | + protein_filter: ProteinFilter::new(Self::get_crap_proteins()), |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + fn get_crap_proteins() -> HashSet<String> { |
| 30 | + let crap_accessions = vec![ |
| 31 | + "P02769", "P0DTE7", "P0DTE8", "P0DUB6", "P02662", "P02663", |
| 32 | + "P02666", "P02668", "P00766", "P00767", "P13645", "O77727", |
| 33 | + "P35527", "Q15323", "Q14532", "O76011", "Q92764", "O76013", |
| 34 | + "O76014", "O76015", "O76009", "P01920", "P02534", "P02539", |
| 35 | + "P35908", "P04264", "P15241", "P25691", "P02444", "P81054", |
| 36 | + "P02445", "P02443", "P02441", "Q02958", "P02438", "P02439", |
| 37 | + "P02440", "P08131", "Q14533", "Q9NSB4", "P78385", "Q9NSB2", |
| 38 | + "P78386", "O43790", "P26372", "P00711", "Q7M135", "P00792", |
| 39 | + "P00791", "Q10735", "P30879", "P0C1U8", "P00760", "Q29463", |
| 40 | + "A0A8K0BFD9", "P02768", "P01008", "D6RCN3", "P61769", "P55957", |
| 41 | + "P00915", "P00918", "P04040", "P07339", "P08311", "P01031", |
| 42 | + "P02741", "P00167", "P99999", "P01133", "P05413", "P06396", |
| 43 | + "Q9BX51", "A0A2R8Y5E5", "P69905", "P68871", "P01344", "P10145", |
| 44 | + "P06732", "P00709", "P80384", "P61626", "P02144", "Q15843", |
| 45 | + "P15559", "U3KQG7", "P01127", "P62937", "A0A0A0MRQ5", "P01112", |
| 46 | + "P02753", "P00441", "B8ZZN6", "P12081", "P10636", "P10599", |
| 47 | + "P01375", "P02787", "P02788", "P51965", "O00762", "A8MUA9", |
| 48 | + "P62979", "P32503", "P00004", "P00921", "P00330", "P00883", |
| 49 | + "P00698", "P68082", "P01012", "P00722", "P00366", "A0A5J6CYK8", |
| 50 | + "A0A182BM84", "P15252" |
| 51 | + ]; |
| 52 | + |
| 53 | + crap_accessions.into_iter().map(String::from).collect() |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +#[cfg(test)] |
| 58 | +mod tests { |
| 59 | + use super::*; |
| 60 | + |
| 61 | + #[test] |
| 62 | + fn test_protein_in_crap_filter() { |
| 63 | + let filter = CrapFilter::new(); |
| 64 | + let protein_in_filter = ProteinInfo { |
| 65 | + taxon: 1, |
| 66 | + uniprot_accession: "P68082".to_string(), |
| 67 | + functional_annotations: "GO:0001234;GO:0005678".to_string() |
| 68 | + }; |
| 69 | + |
| 70 | + assert!(filter.filter(&protein_in_filter)); |
| 71 | + } |
| 72 | + |
| 73 | + #[test] |
| 74 | + fn test_protein_not_in_crap_filter() { |
| 75 | + let filter = CrapFilter::new(); |
| 76 | + let protein_not_in_filter = ProteinInfo { |
| 77 | + taxon: 1, |
| 78 | + uniprot_accession: "PXXXXX".to_string(), |
| 79 | + functional_annotations: "GO:0001234;GO:0005678".to_string() |
| 80 | + }; |
| 81 | + |
| 82 | + assert!(!filter.filter(&protein_not_in_filter)); |
| 83 | + } |
| 84 | +} |
0 commit comments