module Mspire::Quant::SpectralCounts

Constants

Counts

Public Class Methods

counts(peptide_hits, &share_the_pephit) click to toggle source

returns a parallel array of Count objects. If split_hits then counts are split between groups sharing the hit. peptide_hits must respond to :charge and :aaseq. If a block is given, the weight of a particular hit can be given (typically this will be 1/#proteins sharing the hit

# File lib/mspire/quant/spectral_counts.rb, line 21
def self.counts(peptide_hits, &share_the_pephit)
  uniq_aaseq = {}
  uniq_aaseq_charge = {}
  weights = peptide_hits.map do |hit|
    weight = share_the_pephit ? share_the_pephit.call(hit) : 1
    # these guys will end up clobbering themselves, but the
    # linked_to_size should be consistent if the key is the same
    uniq_aaseq_charge[[hit.aaseq, hit.charge]] = weight
    uniq_aaseq[hit.aaseq] = weight
    weight
  end
  counts_data = [weights, uniq_aaseq_charge.values, uniq_aaseq.values].map do |array|
    array.reduce(:+)
  end
  Counts.new(*counts_data)
end