Class: BEL::Nanopub::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/bel/translator/plugins/rdf/monkey_patch.rb

Instance Method Summary collapse

Instance Method Details

#rdf_typeObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 81

def rdf_type
  if respond_to? 'fx'
    fx = @fx.respond_to?(:short_form) ? @fx.short_form : @fx.to_s.to_sym
    if [:p, :proteinAbundance].include?(fx) &&
       @arguments.find{ |x|
         if x.is_a? ::BEL::Nanopub::Term
           arg_fx = x.fx
           arg_fx = arg_fx.respond_to?(:short_form) ? arg_fx.short_form : arg_fx.to_s.to_sym
           [:pmod, :proteinModification].include?(arg_fx)
         else
           false
         end
       }

      return BELRDF::BELV.ModifiedProteinAbundance
    end

    if [:p, :proteinAbundance].include?(fx) &&
       @arguments.find{ |x|
         if x.is_a? ::BEL::Nanopub::Term
           arg_fx = x.fx
           arg_fx = arg_fx.respond_to?(:short_form) ? arg_fx.short_form : arg_fx.to_s.to_sym
           BELRDF::PROTEIN_VARIANT.include?(arg_fx)
         else
           false
         end
       }

      return BELRDF::BELV.ProteinVariantAbundance
    end

    BELRDF::FUNCTION_TYPE[fx] || BELRDF::BELV.Abundance
  end
end

#to_rdf(graph_name = nil, remap = nil) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 116

def to_rdf(graph_name = nil, remap = nil)
  uri = to_uri
  statements = []

  # rdf:type
  type = rdf_type
  statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, BELRDF::BELV.Term, :graph_name => graph_name)
  statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, type, :graph_name => graph_name)
  fx = @fx.respond_to?(:short_form) ? @fx.short_form : @fx.to_s.to_sym
  if BELRDF::ACTIVITY_TYPE.include? fx
    statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasActivityType, BELRDF::ACTIVITY_TYPE[fx], :graph_name => graph_name)
  end

  # rdfs:label
  statements << ::RDF::Statement.new(uri, BELRDF::RDFS.label, to_s.force_encoding('UTF-8'), :graph_name => graph_name)

  # special proteins (does not recurse into pmod)
  if [:p, :proteinAbundance].include?(fx)
    pmod =
      @arguments.find{ |x|
        if x.is_a? ::BEL::Nanopub::Term
          arg_fx = x.fx
          arg_fx = arg_fx.respond_to?(:short_form) ? arg_fx.short_form : arg_fx.to_s.to_sym
          [:pmod, :proteinModification].include?(arg_fx)
        else
          false
        end
      }
    if pmod
      mod_string = pmod.arguments.map(&:to_s).join(',')
      mod_type = BELRDF::MODIFICATION_TYPE.find {|k,v| mod_string.start_with? k}
      mod_type = (mod_type ? mod_type[1] : BELRDF::BELV.Modification)
      statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasModificationType, mod_type, :graph_name => graph_name)
      last = pmod.arguments.last.to_s
      if last.match(/^\d+$/)
        statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasModificationPosition, last.to_i, :graph_name => graph_name)
      end
      # link root protein abundance as hasChild
      root_param = @arguments.find{|x| x.is_a? ::BEL::Nanopub::Parameter}
      (root_id, root_statements) = ::BEL::Nanopub::Term.new(:p, [root_param]).to_rdf(graph_name, remap)
      statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, root_id, :graph_name => graph_name)
      statements.concat(root_statements)
      return [uri, statements]
    elsif @arguments.find{|x| x.is_a? ::BEL::Nanopub::Term and BELRDF::PROTEIN_VARIANT.include? x.fx}
      # link root protein abundance as hasChild
      root_param = @arguments.find{|x| x.is_a? ::BEL::Nanopub::Parameter}
      (root_id, root_statements) = ::BEL::Nanopub::Term.new(:p, [root_param]).to_rdf(graph_name, remap)
      statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, root_id, :graph_name => graph_name)
      statements.concat(root_statements)
      return [uri, statements]
    end
  end

  # BELRDF::BELV.hasConcept
  @arguments.find_all{ |x|
    x.is_a? ::BEL::Nanopub::Parameter and x.ns != nil
  }.each do |param|
    param_uri, encoding_statements = param.to_rdf(graph_name, remap)
    statements.concat(encoding_statements)
    statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasConcept, param_uri, :graph_name => graph_name)
  end

  # BELRDF::BELV.hasChild]
  @arguments.find_all{|x| x.is_a? ::BEL::Nanopub::Term}.each do |child|
    (child_id, child_statements) = child.to_rdf(graph_name, remap)
    statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, child_id, :graph_name => graph_name)
    statements.concat(child_statements)
  end

  [uri, statements]
end

#to_uriObject



76
77
78
79
# File 'lib/bel/translator/plugins/rdf/monkey_patch.rb', line 76

def to_uri
  tid = to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_')
  BELRDF::BELR[URI::encode(tid)]
end