Skip to content

Instantly share code, notes, and snippets.

@drio
Created July 6, 2009 17:31
Show Gist options
  • Save drio/141567 to your computer and use it in GitHub Desktop.
Save drio/141567 to your computer and use it in GitHub Desktop.
class EgOutput
attr_accessor :chrm, :pos, :id, :al_cs, :al_seq, :counters
def initialize(others, counters)
@chrm, @pos, @id, @ref, @var = others
@counters = counters.map{|c| c.to_i }
end
def +(ec)
new_obj = self.clone
([email protected]).each do |i|
new_obj.counters[i] = @counters[i] + ec.counters[i]
end
new_obj
end
def to_s
"#{@chrm},#{@pos},#{@id},#{@ref},#{@var}," +
@counters.inject("") {|all, c| all << c.to_s + ","}.gsub(/,$/, '')
end
end
entries = {}
ic = 1
File.open(@eg_file).each do |i|
STDERR.puts "#{Time.now}: #{ic}" if (ic % 100000 == 0)
eo = EgOutput.new(i.split(',')[0,5], i.split(",")[-15..-1])
entries[eo.id] = entries.key?(eo.id) ? entries[eo.id] + eo : eo
ic+=1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment