sequence_logo 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2411aa5c78c5efae4860eafaa8743acbbc526f04
4
- data.tar.gz: b4451fceda9c126ed40a8db058b649f626a0ba7a
3
+ metadata.gz: a53d6d681797aec870766358a55b460aa10a87f1
4
+ data.tar.gz: 43c4712e2b1bbef50ac8de24626c115c5492dfaf
5
5
  SHA512:
6
- metadata.gz: 32b810e2ed04ede3d15face6e91cf9fe677a30217f24c9f535fdd97f681028fd706d8c0f488d3198d984ab455bce982de0717367c6fc315462e8ff7f2419bb1c
7
- data.tar.gz: fcf545d611c2ce7fd9b449273e25fac6fe094b158b9c676b39b934f8e84f480f4a4697e54779263832594e1b26f59b87f0585133cf89226309631c62ebf18f44
6
+ metadata.gz: 4331c46e148cb21342e7cb5d39ab635ff633086974a3e87d20a8d1efd1534f5590d6df7ccd50f0a5e7eea1d6222fc8a03709a2200f90432083a63a016bf3f9fa
7
+ data.tar.gz: 7b1013ed36a55848884760f55bb2418789e98fd9cd040e846a8748360889c3bcf34d0a92d520b3e034d501eb21ec2df3948a5d3be41b1b1f22aad699a7546e3b
data/TODO.txt CHANGED
@@ -1,3 +1,7 @@
1
+ Fix word count to calculate column-wise word-counts where possible! Selex logos are bad
2
+
3
+ Make use of bioinform gem
4
+
1
5
  AssetsPath shouldn't be used at draw_logo level because it makes it impossible to change scheme on one folder that is outside the gem
2
6
  And how to make possible use schemes inside the assets path
3
7
 
@@ -48,7 +48,7 @@ module SequenceLogo
48
48
  items_normalized.each do |item|
49
49
  canvas.add_image item.render(canvas_factory)
50
50
  end
51
- canvas.background(Magick::HatchFill.new('white', 'white'))
51
+ canvas.background(canvas_factory.background_fill)
52
52
  canvas.image
53
53
  end
54
54
 
@@ -3,7 +3,7 @@ require_relative 'canvases'
3
3
 
4
4
  module SequenceLogo
5
5
  class CanvasFactory
6
- attr_reader :x_unit, :y_unit, :text_size, :logo_shift
6
+ attr_reader :x_unit, :y_unit, :text_size, :logo_shift, :background_fill
7
7
  attr_reader :letter_images
8
8
 
9
9
  def initialize(letter_images, options = {})
@@ -12,6 +12,7 @@ module SequenceLogo
12
12
  @x_unit = options[:x_unit] || 30
13
13
  @y_unit = options[:y_unit] || 60
14
14
  @text_size = options[:text_size] || 24
15
+ @background_fill = options[:background_fill] || Magick::SolidFill.new('transparent')
15
16
  end
16
17
 
17
18
  def text_image(text, img_height = y_unit)
@@ -14,6 +14,7 @@ module SequenceLogo
14
14
  end
15
15
  def parser
16
16
  @parser ||= OptionParser.new do |opts|
17
+ opts.version = ::SequenceLogo::VERSION
17
18
  opts.on('-x', '--x-unit X_UNIT', 'Single letter width') do |v|
18
19
  options[:x_unit] = v.to_i
19
20
  end
@@ -36,15 +36,11 @@ module SequenceLogo
36
36
 
37
37
  def render(canvas_factory)
38
38
  canvas = LogoCanvas.new(canvas_factory)
39
- if icd_mode == :discrete
40
- canvas.background(Magick::HatchFill.new('white', 'white'))
41
- if enable_threshold_lines
42
- canvas.draw_threshold_line(ppm.get_line(ppm.icd2of4))
43
- canvas.draw_threshold_line(ppm.get_line(ppm.icdThc))
44
- canvas.draw_threshold_line(ppm.get_line(ppm.icdTlc))
45
- end
46
- else
47
- canvas.background(Magick::HatchFill.new('white', 'bisque'))
39
+ canvas.background(canvas_factory.background_fill)
40
+ if icd_mode == :discrete && enable_threshold_lines
41
+ canvas.draw_threshold_line(ppm.get_line(ppm.icd2of4))
42
+ canvas.draw_threshold_line(ppm.get_line(ppm.icdThc))
43
+ canvas.draw_threshold_line(ppm.get_line(ppm.icdTlc))
48
44
  end
49
45
 
50
46
  logo_matrix.each do |position|
@@ -23,7 +23,10 @@ module SequenceLogo
23
23
  end
24
24
 
25
25
  def render(canvas_factory)
26
- @direct_image
26
+ layers = Magick::ImageList.new
27
+ layers.put_image_at(@direct_image, 0, 0)
28
+ layers.unshift Magick::Image.new(@direct_image.columns, @direct_image.rows, canvas_factory.background_fill)
29
+ layers.flatten_images
27
30
  end
28
31
  end
29
32
  end
@@ -19,7 +19,7 @@ module SequenceLogo
19
19
 
20
20
  def render(canvas_factory)
21
21
  canvas = LogoCanvas.new(canvas_factory)
22
- canvas.background(Magick::HatchFill.new('white', 'white'))
22
+ canvas.background(canvas_factory.background_fill)
23
23
  sequence.each_char do |letter|
24
24
  canvas.add_letter(letter)
25
25
  end
@@ -30,7 +30,7 @@ module SequenceLogo
30
30
 
31
31
  def render(canvas_factory)
32
32
  canvas = LogoCanvas.new(canvas_factory)
33
- canvas.background(Magick::HatchFill.new('white', 'white'))
33
+ canvas.background(canvas_factory.background_fill)
34
34
  left.each_char{|letter| canvas.add_letter(letter) }
35
35
  canvas.add_position_ordered(snp_position_heights)
36
36
  right.each_char{|letter| canvas.add_letter(letter) }
@@ -78,7 +78,9 @@ begin
78
78
 
79
79
  argv = ARGV
80
80
  total_orientation = :direct
81
- default_options = {x_unit: 30, y_unit: 60, words_count: nil, icd_mode: :discrete, threshold_lines: false, scheme: 'nucl_simpa', logo_shift: 300, text_size: 24}
81
+ default_options = { x_unit: 30, y_unit: 60, logo_shift: 300, scheme: 'nucl_simpa',
82
+ words_count: nil, icd_mode: :discrete, threshold_lines: false,
83
+ text_size: 24, background_color: 'white' }
82
84
  cli = SequenceLogo::CLI.new(default_options)
83
85
  cli.instance_eval do
84
86
  parser.banner = doc
@@ -93,6 +95,14 @@ begin
93
95
  raise ArgumentError, 'Orientation can be either direct or revcomp or both' unless [:direct, :revcomp, :both].include?(v)
94
96
  total_orientation = v
95
97
  end
98
+
99
+ parser.on('--bg-fill FILL', 'Background fill. Specify either `transparent` or `color` or `color,hatch_color`') do |v|
100
+ if v.match(/^\w+,\w+$/)
101
+ options[:background_fill] = Magick::HatchFill.new(*v.split(','))
102
+ else
103
+ options[:background_fill] = Magick::SolidFill.new(v)
104
+ end
105
+ end
96
106
  end
97
107
  options = cli.parse_options!(argv)
98
108
 
@@ -105,8 +115,9 @@ begin
105
115
 
106
116
  scheme_dir = File.join(SequenceLogo::AssetsPath, options[:scheme])
107
117
  letter_images = SequenceLogo::CanvasFactory.letter_images(scheme_dir)
108
- canvas_factory = SequenceLogo::CanvasFactory.new(letter_images, x_unit: options[:x_unit], y_unit: options[:y_unit],
109
- text_size: options[:text_size], logo_shift: options[:logo_shift])
118
+ canvas_factory = SequenceLogo::CanvasFactory.new( letter_images, x_unit: options[:x_unit], y_unit: options[:y_unit],
119
+ text_size: options[:text_size], logo_shift: options[:logo_shift],
120
+ background_fill: options[:background_fill] )
110
121
 
111
122
  case total_orientation
112
123
  when :direct
@@ -44,7 +44,9 @@ begin
44
44
  EOS
45
45
 
46
46
  argv = ARGV
47
- default_options = {x_unit: 30, y_unit: 60, words_count: nil, orientation: :direct, logo_folder: '.', icd_mode: :discrete, threshold_lines: true, scheme: 'nucl_simpa'}
47
+ default_options = { x_unit: 30, y_unit: 60, scheme: 'nucl_simpa',
48
+ words_count: nil, orientation: :direct, icd_mode: :discrete, threshold_lines: true,
49
+ logo_folder: '.', background_color: 'white' }
48
50
  cli = SequenceLogo::CLI.new(default_options)
49
51
  cli.instance_eval do
50
52
  parser.banner = doc
@@ -63,6 +65,13 @@ begin
63
65
  parser.on('--sequence', 'Specify sequence (like ATCTCGCCTAAT) instead of motif filenames') do
64
66
  options[:sequence] = true
65
67
  end
68
+ parser.on('--bg-fill FILL', 'Background fill. Specify either `transparent` or `color` or `color,hatch_color`') do |v|
69
+ if v.match(/^\w+,\w+$/)
70
+ options[:background_fill] = Magick::HatchFill.new(*v.split(','))
71
+ else
72
+ options[:background_fill] = Magick::SolidFill.new(v)
73
+ end
74
+ end
66
75
  end
67
76
  options = cli.parse_options!(argv)
68
77
 
@@ -71,7 +80,8 @@ begin
71
80
 
72
81
  scheme_dir = File.join(SequenceLogo::AssetsPath, options[:scheme])
73
82
  letter_images = SequenceLogo::CanvasFactory.letter_images(scheme_dir)
74
- canvas_factory = SequenceLogo::CanvasFactory.new(letter_images, x_unit: options[:x_unit], y_unit: options[:y_unit])
83
+ canvas_factory = SequenceLogo::CanvasFactory.new( letter_images, x_unit: options[:x_unit], y_unit: options[:y_unit],
84
+ background_fill: options[:background_fill] )
75
85
 
76
86
  raise "Specify either sequence or sequence with SNP or none of them, but not both" if options[:sequence] && options[:sequence_w_snp]
77
87
 
@@ -1,14 +1,27 @@
1
1
  require 'RMagick'
2
2
 
3
- class Magick::ImageList
4
- def put_image_at(image, x, y)
5
- self << image
6
- cur_image.page = Magick::Rectangle.new(0, 0, x, y)
3
+ module Magick
4
+ class ImageList
5
+ def put_image_at(image, x, y)
6
+ self << image
7
+ cur_image.page = Magick::Rectangle.new(0, 0, x, y)
8
+ end
9
+
10
+ # add transparent layer so that full canvas size can't be less than given size
11
+ def set_minimal_size(x_size, y_size)
12
+ empty_image = Magick::Image.new(x_size, y_size){ self.background_color = 'transparent'}
13
+ self.unshift(empty_image)
14
+ end
7
15
  end
8
16
 
9
- # add transparent layer so that full canvas size can't be less than given size
10
- def set_minimal_size(x_size, y_size)
11
- empty_image = Magick::Image.new(x_size, y_size){ self.background_color = 'transparent'}
12
- self.unshift(empty_image)
17
+ class SolidFill
18
+ def initialize(bgcolor)
19
+ @bgcolor = bgcolor
20
+ end
21
+
22
+ def fill(img)
23
+ img.background_color = @bgcolor
24
+ img.erase!
25
+ end
13
26
  end
14
27
  end
@@ -1,3 +1,3 @@
1
1
  module SequenceLogo
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequence_logo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Vorontsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick