Assignment 2/InteractionNetwork.rb
## 2. annotate GO ID and GO terms for members of a network ##
2. annotate GO ID and GO terms for members of a network
2 . annotate GO ID and GO terms for members of a network
def annotate_go(members)
    go_annotations = Hash.new
    members.each do |member|
      go_annotations[member] = Array.new
      res = InteractionNetwork.fetch("http://togows.org/entry/ebi-uniprot/#{member}/dr.json")
      if res 
        data = JSON.parse(res.body)
        data[0]["GO"].each do |go|
          next unless go[0].match(/GO:\d+/)
          next unless go[1].match(/P:\w+/)
          go_id = go[0].match(/(\d+)/)[1]
          go_term = go[1].match(/:(.+)/)[1]
          go_annotations[member] << [go_id,go_term]
        end
      else 
        puts "the Web call failed - see STDERR for details...go"
      end
    end
    return go_annotations
  end
def annotate_go ( members ) go_annotations = Hash . new members . each do | member | go_annotations [ member ] = Array . new res = InteractionNetwork . fetch ( "http://togows.org/entry/ebi-uniprot/#{member}/dr.json" ) if res data = JSON . parse ( res . body ) data [ 0 ] [ "GO" ] . each do | go | next unless go [ 0 ] . match ( / GO: \d + / ) next unless go [ 1 ] . match ( / P: \w + / ) go_id = go [ 0 ] . match ( / ( \d +) / ) [ 1 ] go_term = go [ 1 ] . match ( / :(.+) / ) [ 1 ] go_annotations [ member ] << [ go_id , go_term ] end else puts "the Web call failed - see STDERR for details...go" end end return go_annotations end
2. annotate GO ID and GO terms for members of a network
2 . annotate GO ID and GO terms for members of a network
# same as KEGGs  # want to take the key "GO" # and iterate over the values (lists) # go to the next iteration if the first entry does not match a GO ID # go to the next iteration if the second entry does not match a p = biological process, followed by string # using regex to only take the number and the description as variables 
members
<not_specific>