lib/transrate/assembly.rb
# Return a hash of statistics about this assembly. Stats are
# calculated in parallel by splitting the assembly into
# equal-sized bins and calling Assembly#basic_bin_stat on each
# bin in a separate thread.
#
# @param threads [Integer] number of threads to use
#
# @return [Hash] basic statistics about the assembly
Return a hash of statistics about this assembly. Stats are
calculated in parallel by splitting the assembly into
equal-sized bins and calling Assembly#basic_bin_stat on each
bin in a separate thread.
Return a hash of statistics about this assembly . Stats are calculated in parallel by splitting the assembly into equal - sized bins and calling Assembly#basic_bin_stat on each bin in a separate thread .
def basic_stats threads=8
      threads = 1
      queue = Queue.new
      binsize = (@assembly.size / threads.to_f).ceil
      @assembly.each_slice(binsize) do |bin|
        queue << bin
      end
      threadpool = []
      semaphore = Mutex.new
      stats = []
      threads.times do
        threadpool << Thread.new do |thread|
          until queue.empty?
            bin = queue.pop(true) rescue nil
            if bin
              bin_stats = basic_bin_stats bin
              semaphore.synchronize { stats << bin_stats }
            end
          end
        end
      end
      threadpool.each(&:join)
      stats[0]
    end
def basic_stats threads = 8 threads = 1 queue = Queue . new binsize = ( @assembly . size / threads . to_f ) . ceil @assembly . each_slice ( binsize ) do | bin | queue << bin end threadpool = [ ] semaphore = Mutex . new stats = [ ] threads . times do threadpool << Thread . new do | thread | until queue . empty? bin = queue . pop ( true ) rescue nil if bin bin_stats = basic_bin_stats bin semaphore . synchronize { stats << bin_stats } end end end end threadpool . each ( & :join ) stats [ 0 ] end
Return a hash of statistics about this assembly.
Return a hash of statistics about this assembly .
# disable threading basic stats for now # create a work queue to process contigs in parallel # split the contigs into equal sized bins, one bin per thread # a classic threadpool - an Array of threads that allows # us to assign work to each thread and then aggregate their # results when they are all finished # assign one bin of contigs to each thread from the queue. # each thread will process its bin of contigs and then wait # for the others to finish. # keep looping until we run out of bins # use non-blocking pop, so an exception is raised # when the queue runs dry # calculate basic stats for the bin, storing them # in the current thread so they can be collected # in the main thread. # collect the stats calculated in each thread and join # the threads to terminate them # merge the collected stats and return then # merge_basic_stats stats # as threading is currently disabled there's no need to do merging
basic statistics about the assembly
basic statistics about the assembly
Hash
threads
number of threads to use
number of threads to use