Module: Sinatra::RbbtMiscHelpers
- Defined in:
- lib/rbbt/rest/helpers.rb
Instance Method Summary collapse
- #exome_bed_file_for_genes(genes) ⇒ Object
- #file_mimetype(path) ⇒ Object
- #format_name(name) ⇒ Object
- #job_url(job) ⇒ Object
- #OR_matrices(m1, m2) ⇒ Object
- #param_file(name) ⇒ Object
- #post_uri ⇒ Object
- #values2d3(data) ⇒ Object
Instance Method Details
#exome_bed_file_for_genes(genes) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rbbt/rest/helpers.rb', line 80 def exome_bed_file_for_genes(genes) bed = TSV.setup({}, :key_field => "Ensembl Exon ID", :fields => %w(chr start end gene), :type => :list) organism = genes.organism exon_info = Organism.exons(organism).tsv :fields => ["Chromosome Name", "Exon Chr Start", "Exon Chr End"], :persist => true exons_for = Organism.exons(organism).tsv :key_field => "Ensembl Gene ID", :fields => ["Ensembl Exon ID"], :persist => true, :merge => true, :type => :flat genes.each do |gene| exons = exons_for[gene.ensembl] exons.each do |exon| chr, start, eend = exon_info[exon] bed[exon] = [chr, start, eend, gene] end end bed end |
#file_mimetype(path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rbbt/rest/helpers.rb', line 33 def file_mimetype(path) require 'mimemagic' mime = nil Open.open(path) do |io| begin mime = MimeMagic.by_path(path) if mime.nil? io.rewind mime = MimeMagic.by_magic(io) end if mime.nil? io.rewind mime = "text/tab-separated-values" if io.gets =~ /^#/ and io.gets.include? "\t" end rescue Exception Log.exception $! end end mime end |
#format_name(name) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/rbbt/rest/helpers.rb', line 95 def format_name(name) parts = name.split("_") hash = parts.pop clean_name = parts * "_" "<span class='name' jobname='#{ name }'>#{ clean_name }</span> <span class='hash'>#{ hash }</span>" end |
#job_url(job) ⇒ Object
3 4 5 |
# File 'lib/rbbt/rest/helpers.rb', line 3 def job_url(job) job_url = File.join("/", job.workflow.to_s, job.task_name.to_s, job.name) end |
#OR_matrices(m1, m2) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rbbt/rest/helpers.rb', line 54 def OR_matrices(m1, m2) samples = m1.fields new = TSV.setup({}, :key_field => "Ensembl Gene ID", :fields => samples) m1.each do |gene, values| new[gene] = values end m2.each do |gene, values| if new.include? gene new[gene] = new[gene].zip(values).collect do |old, new| case when old == new old else "TRUE" end end else new[gene] = values end end new end |
#param_file(name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rbbt/rest/helpers.rb', line 7 def param_file(name) name = name.to_s if @params[name + '__param_file'] @params[name + '__param_file']['tempfile'] elsif @params[name] StringIO.new @params[name] else nil end end |
#post_uri ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rbbt/rest/helpers.rb', line 18 def post_uri new_params = {} @params.each do |k,v| if m = k.match(/(.*)__param_file/) new_params[m[1]] = v['filename'] else new_params[k] = v end end hash = Misc.obj2digest(new_params) params["__post_hash_id"] = hash @uri + "?__post_hash_id=#{hash}" end |
#values2d3(data) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rbbt/rest/helpers.rb', line 102 def values2d3(data) data = data.to_single if data.respond_to? :to_single and not data.type == :single values = [] data.each do |key, value| name = key.respond_to?(:name) ? key.name || key : key values << {:label => name, :value => value} end values end |