bio-svgenes 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bio-svgenes.gemspec +2 -2
- data/lib/bio/graphics/page.rb +13 -6
- data/lib/bio/graphics/track.rb +28 -12
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/bio-svgenes.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "bio-svgenes"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dan MacLean"]
|
12
|
-
s.date = "2014-01-
|
12
|
+
s.date = "2014-01-06"
|
13
13
|
s.description = "This bio-gem facilitates the creation of pretty, publication quality SVG images from feature data."
|
14
14
|
s.email = "maclean.daniel@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/bio/graphics/page.rb
CHANGED
@@ -231,16 +231,23 @@ module Bio
|
|
231
231
|
old_nt_per_px_x = @nt_per_px_x
|
232
232
|
@tracks.each do |track|
|
233
233
|
highest = track.features.map { |feat|
|
234
|
-
|
235
|
-
feat_end += (8 * @nt_per_px_x * feat.id.to_s.length).to_i if feat.id
|
236
|
-
feat_end
|
234
|
+
compute_boundaries(feat)[1]
|
237
235
|
}.max
|
238
|
-
|
239
|
-
|
236
|
+
if highest > @scale_stop
|
237
|
+
@scale_stop = highest
|
238
|
+
@nt_per_px_x = (@scale_stop - @scale_start).to_f / @width.to_f
|
239
|
+
end
|
240
240
|
end
|
241
241
|
end while (@nt_per_px_x - old_nt_per_px_x).abs > 1
|
242
242
|
end
|
243
243
|
|
244
|
+
def compute_boundaries(feature)
|
245
|
+
feat_end = feature.end
|
246
|
+
feat_end += (8 * @nt_per_px_x * feature.id.to_s.length).to_i if feature.id and @nt_per_px_x
|
247
|
+
[feature.start, feat_end]
|
248
|
+
end
|
249
|
+
|
250
|
+
|
244
251
|
#Adds scale bar to the list of objects to be rendered in the final
|
245
252
|
def draw_scale
|
246
253
|
Glyph.scale(:start => @scale_start,
|
@@ -322,7 +329,7 @@ module Bio
|
|
322
329
|
if track.label
|
323
330
|
draw_label(:text => track.name, :y => @track_top += 30, :x => 3)
|
324
331
|
end
|
325
|
-
track.get_rows ##work out how many rows and which features belong in each row...
|
332
|
+
track.get_rows(self) ##work out how many rows and which features belong in each row...
|
326
333
|
track.features.each_with_index do |f, index|
|
327
334
|
x = to_px(f.start - @scale_start) #bottom left of feature
|
328
335
|
all_sub_blocks = []
|
data/lib/bio/graphics/track.rb
CHANGED
@@ -118,31 +118,47 @@ class Track
|
|
118
118
|
|
119
119
|
#Calculates how many rows are needed per track for overlapping features
|
120
120
|
#and which row each feature should be in. Usually only called by the enclosing Bio::Graphics::Page object.
|
121
|
-
def get_rows
|
122
|
-
|
123
|
-
|
121
|
+
def get_rows(page=nil)
|
122
|
+
@feature_rows = Array.new(@features.length, -1)
|
123
|
+
rows = Hash.new { |h,k| h[k] = [] }
|
124
124
|
@features.each_with_index do |f1, i|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
current_row = 1
|
126
|
+
begin
|
127
|
+
found = true
|
128
|
+
rows[current_row].each_with_index do |f2, j|
|
129
|
+
if overlaps(f1, f2, page)
|
130
|
+
found = false
|
131
|
+
current_row += 1
|
132
|
+
break
|
133
|
+
end
|
129
134
|
end
|
130
|
-
end
|
131
|
-
@
|
135
|
+
end until found
|
136
|
+
@feature_rows[i] = current_row
|
137
|
+
rows[current_row] << f1
|
132
138
|
end
|
139
|
+
@number_rows = @feature_rows.max
|
133
140
|
end
|
134
141
|
|
135
142
|
#Calculates whether two Bio::Graphics::MiniFeature objects overlap by examining their start and end positions.
|
143
|
+
#If the page where they are placed is given, then the function also considers the features' labels.
|
136
144
|
#
|
137
145
|
#+args+
|
138
146
|
#* f1 - a Bio::Graphics::MiniFeature object
|
139
147
|
#* f2 - a Bio::Graphics::MiniFeature object
|
140
|
-
|
141
|
-
|
148
|
+
#* page - the optional Bio::Graphics::Page object where the features are placed
|
149
|
+
def overlaps(f1, f2, page=nil)
|
150
|
+
if not page
|
151
|
+
b1 = [f1.start, f1.end]
|
152
|
+
b2 = [f2.start, f2.end]
|
153
|
+
else
|
154
|
+
b1 = page.compute_boundaries(f1)
|
155
|
+
b2 = page.compute_boundaries(f2)
|
156
|
+
end
|
157
|
+
(b2[0] <= b1[1]) and (b1[0] <= b2[1])
|
142
158
|
end
|
143
159
|
|
144
160
|
end
|
145
161
|
|
146
162
|
|
147
163
|
end
|
148
|
-
end
|
164
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bio-svgenes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
@@ -333,7 +333,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
333
333
|
version: '0'
|
334
334
|
segments:
|
335
335
|
- 0
|
336
|
-
hash: -
|
336
|
+
hash: -1702096108071708551
|
337
337
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
338
338
|
none: false
|
339
339
|
requirements:
|