Here is a quick way to fix your problem:
...
transcription_factor, proteins = line.chomp.split("\t")
proteins.to_s.gsub(/"/,'').split(',').each do |protein|
if hash.has_key? protein
hash[protein] << transcription_factor
else
hash[protein] = [transcription_factor]
end
end
...
The above snippet basically removes the quotes from the proteins if there are any and then for each protein found it does what you had already written.
Also if you would like to eliminate the if you can define the hash like this:
hash = Hash.new {|hash,key| hash[key]= []}
which means that for every new key
it will return a new array. So now you can skip the if
and write
hash[protein] << transcription_factor