Sha256: 8c956bc27881a574b6862e4333469d8a0ccc09e591b453bfe2a2c7cc4656788d
Contents?: true
Size: 1.85 KB
Versions: 15
Compression:
Stored size: 1.85 KB
Contents
#!/usr/bin/env ruby # vim: ts=2 sw=2 require 'bel' require 'csv' require 'optparse' include BEL::Language include BEL::Namespace options = {} OptionParser.new do |opts| opts.banner = '''Statistic report for BEL script. Usage: bel_summarize --bel [FILE]''' opts.on('-b', '--bel FILE', 'BEL file to summarize. STDIN (standard in) can also be used for BEL content.') do |bel| options[:bel] = bel end end.parse! # read bel content content = if options[:bel] File.open(options[:bel]).read else $stdin.read end CSV do |csv_out| report = { statement_group_count: 0, empty_statement_groups: 0, statement_count: 0, evidence_count: 0 } FUNCTIONS.each do |k, v| report['fx_' + v[:long_form].to_s] = 0 end RELATIONSHIPS.each do |r| report['rel_' + r.to_s] = 0 end active_group = nil BEL::Script.parse(content) do |obj| if obj.is_a? BEL::Language::StatementGroup report[:statement_group_count] += 1 active_group = obj end if obj.is_a? BEL::Language::UnsetStatementGroup if active_group.statements.empty? report[:empty_statement_groups] += 1 end end if obj.is_a? BEL::Language::Term report['fx_' + obj.fx[:long_form].to_s] += 1 end if obj.is_a? BEL::Language::Statement report[:statement_count] += 1 obj.relationship = case obj.relationship when :"->" :increases when :"-|" :decreases when :"=>" :directlyIncreases when :"=|" :directlyDecreases when :"--" :association else obj.relationship end if obj.relationship report['rel_' + obj.relationship.to_s] += 1 end end if obj.is_a? BEL::Language::Annotation report[:evidence_count] += 1 if obj.name == 'Evidence' end end csv_out << report.keys csv_out << report.values end
Version data entries
15 entries across 15 versions & 1 rubygems