Module: Circola
- Defined in:
- lib/circola.rb
Class Method Summary collapse
- .clean_up(files) ⇒ Object
- .make_ideogram(opts) ⇒ Object
-
.pick_color(opts, index) ⇒ Object
gets an array of colour tags from circos conf file, eg.
- .prep_conf(opts) ⇒ Object
- .run_circos(opts) ⇒ Object
Instance Method Summary collapse
-
#each_to_karyotype(opts) ⇒ Object
from any Bio::FlatFile or object iterates through the entries and writes a file in Circos’ karyotype format.
-
#full_path ⇒ Object
gives the full path of a File object.
- #get_color_list ⇒ Object
- #must_be(type) ⇒ Object
-
#relative_path ⇒ Object
gives relative path from working dir to file.
-
#text_to_karyotype(opts) ⇒ Object
assumes text file has idtlength.
Class Method Details
.clean_up(files) ⇒ Object
135 136 137 |
# File 'lib/circola.rb', line 135 def Circola.clean_up(files) files.each{|f| File.delete f } end |
.make_ideogram(opts) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/circola.rb', line 94 def Circola.make_ideogram(opts) opts = { :file => nil, :default => "2u", :pairwise => nil }.merge!(opts) f = File.open(opts[:file], "w") f.puts "<ideogram>\n<spacing>\n#default = {opts[:default]}\n</spacing></ideogram>" f.close f end |
.pick_color(opts, index) ⇒ Object
gets an array of colour tags from circos conf file, eg. colors.brewer.conf
59 60 61 62 |
# File 'lib/circola.rb', line 59 def Circola.pick_color(opts, index) offset = index - ((opts[:colors].length) * (index / opts[:colors].length) ) opts[:colors][offset] end |
.prep_conf(opts) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/circola.rb', line 106 def Circola.prep_conf(opts) opts = { :file => nil, :chromosomes_units => 1000000, :chromosomes_display_default => "yes", :karyotype => nil, :includes => [] }.merge!(opts) f = File.open(opts[:file], "w") [:karyotype, :chromosomes_units, :chromosomes_display_default].each do |par| f.puts "#{par} = #{opts[par]}" end opts[:includes].each do |inc| f.puts "<<include #{inc}>>" end f.close f end |
.run_circos(opts) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/circola.rb', line 125 def Circola.run_circos(opts) opts = { :circos => nil, :conf => nil }.merge!(opts) command = "#{opts[:circos]} -conf #{opts[:conf]}" $stderr.puts "executing ... #{command}" Kernel.exec(command) end |
Instance Method Details
#each_to_karyotype(opts) ⇒ Object
from any Bio::FlatFile or object iterates through the entries and writes a file in Circos’ karyotype format.
opts: :id => array of [string method, arg1, arg2, … ] to apply to entry_id of Bio::Flatfile entry for Circos id column :label => array of [string method, arg1, arg2, … ] to apply to entry_id of Bio::Flatfile entry for Circos id column :color => array of color strings for Circos color column. Used in order, looped round if too few provided :file => name of file to write to, Defaults to STDOUT if absent or false. returns a File object if written to file
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/circola.rb', line 14 def each_to_karyotype(opts) opts = { :id => [:gsub, //,""], :label => [:gsub, //,""], :colors => ['red', 'green', 'blue', 'purple', 'orange'], :file => nil }.merge!(opts) #raise TypeError "not a Bio::Flatfile" unless self.is_a?(Bio::FlatFile) self.must_be Bio::FlatFile file = File.open(opts[:file], "w") self.each_with_index do |entry, index| id = entry.entry_id.send( *opts[:id] ) label = entry.entry_id.send( *opts[:label] ) color = Circola.pick_color(opts, index)#opts[:colors][offset] file.puts "chr - #{id} #{label} 0 #{entry.length} #{color}" end file.close file end |
#full_path ⇒ Object
gives the full path of a File object
83 84 85 86 |
# File 'lib/circola.rb', line 83 def full_path must_be File File.realpath(self.path) end |
#get_color_list ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/circola.rb', line 64 def get_color_list self.must_be File colors = [] self.each do |line| next if line =~ /^[<#\s]/ colors << line.split(/\s/)[0] end colors end |
#must_be(type) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/circola.rb', line 74 def must_be type begin raise "not a #{type}" unless self.is_a?(type) rescue Exception => e $stderr.puts e.backtrace end end |
#relative_path ⇒ Object
gives relative path from working dir to file
89 90 91 92 |
# File 'lib/circola.rb', line 89 def relative_path must_be File Pathname.new(self.full_path).relative_path_from(Pathname.new(Dir.pwd)).to_s end |
#text_to_karyotype(opts) ⇒ Object
assumes text file has idtlength
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/circola.rb', line 36 def text_to_karyotype(opts) opts = { :id => [:gsub, //,""], :label => [:gsub, //,""], :colors => ['red', 'green', 'blue', 'purple', 'orange'], :file => nil }.merge!(opts) self.must_be File file = File.open(opts[:file], "w") self.each_with_index do |line, index| color = Circola.pick_color(opts, index) id,stop = line.chomp.split(/\t/) label = id id = id.send( *opts[:id] ) label = label.send( *opts[:label] ) file.puts "chr - #{id} #{label} 0 #{stop} #{color}" end file.close file end |