Sha256: 43c150b478f8be8fc07dbcc582d5d62593ab75032488abb773fdc6f2df23e601

Contents?: true

Size: 1.38 KB

Versions: 19

Compression:

Stored size: 1.38 KB

Contents

require 'hash/inverse'

module Mspire ; module Quant ; end ; end

module Mspire::Quant::Cmdline

  # expects arguments in one of two forms.  The first form is grouped by
  # condition as shown:
  #
  #     condition1=file1,file2,file3... condition2=file4,file5...
  #
  # The second is where each file is its own condition (1 replicate):
  #
  #     file1 file2 file3
  #
  # Returns three ordered hashes (only ordered for ruby 1.9): 
  #
  #     1) Condition to an array of samplenames
  #     2) Samplename to the filename  
  #     3) Samplename to condition
  def self.args_to_hashes(args, replicate_postfix="-rep")
    # groupname => files
    condition_to_samplenames = {}
    samplename_to_filename = {}
    args.each do |arg|
      (condition, files) = 
        if arg.include?('=')
          (condition, filestring) = arg.split('=')
          [condition, filestring.split(',')]
        else
          [basename(arg), [arg]]
        end
      sample_to_file_pairs = files.each_with_index.map do |file,i| 
        rep_string = (files.size == 1) ? "" : "#{replicate_postfix}#{i+1}"
        ["#{condition}#{rep_string}", file] 
      end
      sample_to_file_pairs.each {|name,file| samplename_to_filename[name] = file }
      condition_to_samplenames[condition] = sample_to_file_pairs.map(&:first)
    end
    [samplename_to_filename, condition_to_samplenames, condition_to_samplenames.inverse]
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
mspire-0.10.8.0 lib/mspire/quant/cmdline.rb
mspire-0.10.7.3 lib/mspire/quant/cmdline.rb
mspire-0.10.7.2 lib/mspire/quant/cmdline.rb
mspire-0.10.7.1 lib/mspire/quant/cmdline.rb
mspire-0.10.7 lib/mspire/quant/cmdline.rb
mspire-0.10.6 lib/mspire/quant/cmdline.rb
mspire-0.10.5 lib/mspire/quant/cmdline.rb
mspire-0.10.4 lib/mspire/quant/cmdline.rb
mspire-0.10.3 lib/mspire/quant/cmdline.rb
mspire-0.10.2 lib/mspire/quant/cmdline.rb
mspire-0.10.1 lib/mspire/quant/cmdline.rb
mspire-0.10.0 lib/mspire/quant/cmdline.rb
mspire-0.9.2 lib/mspire/quant/cmdline.rb
mspire-0.9.1 lib/mspire/quant/cmdline.rb
mspire-0.9.0 lib/mspire/quant/cmdline.rb
mspire-0.8.7 lib/mspire/quant/cmdline.rb
mspire-0.8.6.2 lib/mspire/quant/cmdline.rb
mspire-0.8.6.1 lib/mspire/quant/cmdline.rb
mspire-0.8.6 lib/mspire/quant/cmdline.rb