Skip to content

Commit

Permalink
Merge pull request #45 from unipept/feature/improved-fa-calculation
Browse files Browse the repository at this point in the history
use references instead of cloning the data
  • Loading branch information
pverscha authored Aug 23, 2024
2 parents e38c854 + 1fa4cc4 commit a559dea
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions api/src/helpers/fa_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ pub struct FunctionalAggregation {

pub fn calculate_fa(proteins: &[ProteinInfo]) -> FunctionalAggregation {
// Keep track of the proteins that have any annotation
let mut proteins_with_annotations: HashSet<String> = HashSet::new();
let mut proteins_with_annotations: HashSet<&str> = HashSet::new();

// Keep track of the proteins that have a certain annotation
let mut proteins_with_ec: HashSet<String> = HashSet::new();
let mut proteins_with_go: HashSet<String> = HashSet::new();
let mut proteins_with_ipr: HashSet<String> = HashSet::new();
let mut proteins_with_ec: HashSet<&str> = HashSet::new();
let mut proteins_with_go: HashSet<&str> = HashSet::new();
let mut proteins_with_ipr: HashSet<&str> = HashSet::new();

// Keep track of the counts of the different annotations
let mut data: HashMap<String, u32> = HashMap::new();
Expand All @@ -28,16 +28,16 @@ pub fn calculate_fa(proteins: &[ProteinInfo]) -> FunctionalAggregation {
for annotation in protein.functional_annotations.split(';') {
match annotation.chars().next() {
Some('E') => {
proteins_with_ec.insert(protein.uniprot_accession.clone());
proteins_with_annotations.insert(protein.uniprot_accession.clone());
proteins_with_ec.insert(&protein.uniprot_accession);
proteins_with_annotations.insert(&protein.uniprot_accession);
}
Some('G') => {
proteins_with_go.insert(protein.uniprot_accession.clone());
proteins_with_annotations.insert(protein.uniprot_accession.clone());
proteins_with_go.insert(&protein.uniprot_accession);
proteins_with_annotations.insert(&protein.uniprot_accession);
}
Some('I') => {
proteins_with_ipr.insert(protein.uniprot_accession.clone());
proteins_with_annotations.insert(protein.uniprot_accession.clone());
proteins_with_ipr.insert(&protein.uniprot_accession);
proteins_with_annotations.insert(&protein.uniprot_accession);
}
_ => {}
};
Expand Down

0 comments on commit a559dea

Please sign in to comment.