Module: BioVcf::Turtle
- Defined in:
- lib/bio-vcf/vcfrdf.rb
Class Method Summary collapse
- .identifier(id) ⇒ Object
-
.mangle_identifier(s) ⇒ Object
Replace letters/symbols that are not allowed in a Turtle identifier (short hand URI).
- .stringify_literal(literal) ⇒ Object
Class Method Details
.identifier(id) ⇒ Object
86 87 88 |
# File 'lib/bio-vcf/vcfrdf.rb', line 86 def Turtle::identifier(id) raise "Illegal identifier #{id}" if id != Turtle::mangle_identifier(id) end |
.mangle_identifier(s) ⇒ Object
Replace letters/symbols that are not allowed in a Turtle identifier (short hand URI). This should be the definite mangler and replace the ones in bioruby-table and bio-exominer. Manglers are useful when using data from other sources and trying to transform them into simple RDF identifiers.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bio-vcf/vcfrdf.rb', line 96 def Turtle::mangle_identifier(s) id = s.strip.gsub(/[^[:print:]]/, '').gsub(/[#)(,]/,"").gsub(/[%]/,"perc").gsub(/(\s|\.|\$|\/|\\|\>)+/,"_") id = id.gsub(/\[|\]/,'') # id = URI::escape(id) id = id.gsub(/\|/,'_') id = id.gsub(/\-|:/,'_') if id != s # Don't want Bio depency in templates! # logger = Bio::Log::LoggerPlus.new 'bio-rdf' # logger.warn "\nWARNING: Changed identifier <#{s}> to <#{id}>" # $stderr.print "\nWARNING: Changed identifier <#{s}> to <#{id}>" end if not RDF::valid_uri?(id) raise "Invalid URI after mangling <#{s}> to <#{id}>!" end valid_id = if id =~ /^\d/ 'r' + id else id end valid_id # we certainly hope so! end |
.stringify_literal(literal) ⇒ Object
82 83 84 |
# File 'lib/bio-vcf/vcfrdf.rb', line 82 def Turtle::stringify_literal(literal) RDF::stringify_literal(literal) end |