Skip to content

Instantly share code, notes, and snippets.

@drio
Created January 28, 2009 23:06
Show Gist options
  • Save drio/54244 to your computer and use it in GitHub Desktop.
Save drio/54244 to your computer and use it in GitHub Desktop.
class DBEvent
attr_accessor :ref, :o_events, :sp
def initialize(sp, events)
@sp = sp
@ref = events.split('/')[0]
@raw_events = events
@o_events = Hash.new(Array.new) # Observed events
# Iterate over each observed event
# So AC/AT (start pos of the event = X) becomes:
# @o_events[X] = [ 'A' ]
# @o_events[X+1] = [ 'C', 'T' ]
each_v_event do |e|
snps = e.split('')
(0..snps.size-1).each {|p| @o_events[sp+p] << snps[p] }
end
# even this does not work
#@o_events[1] << "asdasf"
end
private
def s_var_events
@raw_events.split('/')[1]
end
def each_v_event
s_var_events.split('/').each {|e| yield(e) }
end
end
class DBEntry
attr_accessor :id, :chrm, :sp, :ep, :events
def initialize(args)
@id, @chrm, @sp, @ep = args[0, args.size-1]
@events = DBEvent.new(@sp.to_i, args[-1])
end
end
# inputs lines look like:
# rs242,chr1,20742048,20742048,+,-/T,in-del,byFrequency,0.18,unknown
entries = []
File.open("/tmp/input.txt").each_line do |l|
puts l
entries << DBEntry.new(l.split(",")[0,6])
end
puts entries[0].events.o_events.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment