Sha256: d99b3a12ab600636d415177a9224f607435635659fb37e128466c80af77f2ca1

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require 'set'
require 'ms/ident/protein_group'

module Ms
  module Quant
    module SpectralCounts
      Counts = Struct.new(:spectral, :aaseqcharge, :aaseq)

      # 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
      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
    end
  end
end



Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ms-quant-0.0.6 lib/ms/quant/spectral_counts.rb