Skip to content

Instantly share code, notes, and snippets.

@drio
Created January 16, 2009 20:30
Show Gist options
  • Save drio/48104 to your computer and use it in GitHub Desktop.
Save drio/48104 to your computer and use it in GitHub Desktop.
def process_command
File.open(@o_file, 'w') do |of|
File.open(@i_file).each_line do |l|
of.puts affy_to_csv(l.split)
end
end
end
private
def affy_to_csv(affy_line)
AffyLine.new(affy_line).to_csv
end
# Encapsulate a line of an Affy file. And help us
# perform conversions to csv.
class AffyLine
attr_accessor :chrm, :pos, :id, :var, :ref, :seq
def initialize(args)
@chrm, @pos, @id, @var, @ref, @seq = args
end
# chromosome, position, SNPid, fiveP, threeP, reference, variant
def to_csv
t = "\t"
@chrm + t + @pos + t + @id + t + split_seq + t + split_var
end
private
# AAANCCC -> AAA CCC
def split_seq
@seq.split('N').join("\t")
end
# A/C -> A C
def split_var
@ref.split('/').join("\t")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment