Class: BEL::Model::Term
- Inherits:
-
Object
- Object
- BEL::Model::Term
- Includes:
- Comparable
- Defined in:
- lib/bel/evidence_model/bel_term.rb,
lib/bel/extensions/rdf/rdf.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#fx ⇒ Object
Returns the value of attribute fx.
-
#signature ⇒ Object
Returns the value of attribute signature.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(fx, *arguments) ⇒ Term
constructor
A new instance of Term.
- #invalid_signatures ⇒ Object
- #rdf_type ⇒ Object
- #to_bel ⇒ Object (also: #to_s)
- #to_rdf ⇒ Object
- #to_uri ⇒ Object
- #valid? ⇒ Boolean
- #valid_signatures ⇒ Object
Constructor Details
#initialize(fx, *arguments) ⇒ Term
Returns a new instance of Term.
7 8 9 10 |
# File 'lib/bel/evidence_model/bel_term.rb', line 7 def initialize(fx, *arguments) @fx = fx @arguments = (arguments ||= []).flatten end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/bel/evidence_model/bel_term.rb', line 5 def arguments @arguments end |
#fx ⇒ Object
Returns the value of attribute fx.
5 6 7 |
# File 'lib/bel/evidence_model/bel_term.rb', line 5 def fx @fx end |
#signature ⇒ Object
Returns the value of attribute signature.
5 6 7 |
# File 'lib/bel/evidence_model/bel_term.rb', line 5 def signature @signature end |
Instance Method Details
#<<(item) ⇒ Object
38 39 40 |
# File 'lib/bel/evidence_model/bel_term.rb', line 38 def <<(item) @arguments << item end |
#==(other) ⇒ Object Also known as: eql?
66 67 68 69 |
# File 'lib/bel/evidence_model/bel_term.rb', line 66 def ==(other) return false if other == nil @fx == other.fx && @arguments == other.arguments end |
#hash ⇒ Object
62 63 64 |
# File 'lib/bel/evidence_model/bel_term.rb', line 62 def hash [@fx, @arguments].hash end |
#invalid_signatures ⇒ Object
58 59 60 |
# File 'lib/bel/evidence_model/bel_term.rb', line 58 def invalid_signatures @fx.signatures.find_all { |sig| (@signature <=> sig) < 0 } end |
#rdf_type ⇒ Object
74 75 76 77 78 79 80 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 |
# File 'lib/bel/extensions/rdf/rdf.rb', line 74 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::Model::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 BEL::RDF::BELV.ModifiedProteinAbundance end if [:p, :proteinAbundance].include?(fx) && @arguments.find{ |x| if x.is_a? BEL::Model::Term arg_fx = x.fx arg_fx = arg_fx.respond_to?(:short_form) ? arg_fx.short_form : arg_fx.to_s.to_sym BEL::RDF::PROTEIN_VARIANT.include?(arg_fx) else false end } return BEL::RDF::BELV.ProteinVariantAbundance end BEL::RDF::FUNCTION_TYPE[fx] || BEL::RDF::BELV.Abundance end end |
#to_bel ⇒ Object Also known as: to_s
72 73 74 75 |
# File 'lib/bel/evidence_model/bel_term.rb', line 72 def to_bel arguments = [@arguments].flatten.map(&:to_bel).join(',') "#{@fx.short_form}(#{arguments})" end |
#to_rdf ⇒ Object
109 110 111 112 113 114 115 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 |
# File 'lib/bel/extensions/rdf/rdf.rb', line 109 def to_rdf uri = to_uri statements = [] # rdf:type type = rdf_type statements << [uri, BEL::RDF::RDF.type, BEL::RDF::BELV.Term] statements << [uri, BEL::RDF::RDF.type, type] fx = @fx.respond_to?(:short_form) ? @fx.short_form : @fx.to_s.to_sym if BEL::RDF::ACTIVITY_TYPE.include? fx statements << [uri, BEL::RDF::BELV.hasActivityType, BEL::RDF::ACTIVITY_TYPE[fx]] end # rdfs:label statements << [uri, BEL::RDF::RDFS.label, to_s.force_encoding('UTF-8')] # special proteins (does not recurse into pmod) if [:p, :proteinAbundance].include?(fx) pmod = @arguments.find{ |x| if x.is_a? BEL::Model::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 = BEL::RDF::MODIFICATION_TYPE.find {|k,v| mod_string.start_with? k} mod_type = (mod_type ? mod_type[1] : BEL::RDF::BELV.Modification) statements << [uri, BEL::RDF::BELV.hasModificationType, mod_type] last = pmod.arguments.last.to_s if last.match(/^\d+$/) statements << [uri, BEL::RDF::BELV.hasModificationPosition, last.to_i] end # link root protein abundance as hasChild root_param = @arguments.find{|x| x.is_a? BEL::Model::Parameter} (root_id, root_statements) = BEL::Model::Term.new(:p, [root_param]).to_rdf statements << [uri, BEL::RDF::BELV.hasChild, root_id] statements += root_statements return [uri, statements] elsif @arguments.find{|x| x.is_a? BEL::Model::Term and BEL::RDF::PROTEIN_VARIANT.include? x.fx} # link root protein abundance as hasChild root_param = @arguments.find{|x| x.is_a? BEL::Model::Parameter} (root_id, root_statements) = BEL::Model::Term.new(:p, [root_param]).to_rdf statements << [uri, BEL::RDF::BELV.hasChild, root_id] statements += root_statements return [uri, statements] end end # BEL::RDF::BELV.hasConcept] @arguments.find_all{ |x| x.is_a? BEL::Model::Parameter and x.ns != nil }.each do |param| concept_uri = param.ns.to_rdf_vocabulary[param.value.to_s] statements << [uri, BEL::RDF::BELV.hasConcept, BEL::RDF::RDF::URI(Addressable::URI.encode(concept_uri))] end # BEL::RDF::BELV.hasChild] @arguments.find_all{|x| x.is_a? BEL::Model::Term}.each do |child| (child_id, child_statements) = child.to_rdf statements << [uri, BEL::RDF::BELV.hasChild, child_id] statements += child_statements end return [uri, statements] end |
#to_uri ⇒ Object
69 70 71 72 |
# File 'lib/bel/extensions/rdf/rdf.rb', line 69 def to_uri tid = to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_') BEL::RDF::BELR[URI::encode(tid)] end |
#valid? ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bel/evidence_model/bel_term.rb', line 42 def valid? invalid_signatures = @arguments.find_all { |arg| arg.is_a? Term }.find_all { |term| not term.valid? } return false if not invalid_signatures.empty? sigs = @fx.signatures sigs.any? do |sig| (@signature <=> sig) >= 0 end end |
#valid_signatures ⇒ Object
54 55 56 |
# File 'lib/bel/evidence_model/bel_term.rb', line 54 def valid_signatures @fx.signatures.find_all { |sig| (@signature <=> sig) >= 0 } end |