bio-svgenes 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +88 -0
- data/VERSION +1 -1
- data/bio-svgenes.gemspec +131 -8
- data/doc/classes/Bio.html +131 -0
- data/doc/classes/Bio/Graphics.html +142 -0
- data/doc/classes/Bio/Graphics/Glyph.html +987 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000001.html +26 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000002.html +27 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000003.html +32 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000004.html +27 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000005.html +25 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000006.html +29 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000007.html +107 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000008.html +51 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000009.html +23 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000010.html +18 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000011.html +75 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000012.html +51 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000013.html +23 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000014.html +26 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000015.html +27 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000016.html +32 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000017.html +27 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000018.html +25 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000019.html +29 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000020.html +107 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000021.html +51 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000022.html +23 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000023.html +18 -0
- data/doc/classes/Bio/Graphics/Glyph.src/M000024.html +75 -0
- data/doc/classes/Bio/Graphics/MiniFeature.html +243 -0
- data/doc/classes/Bio/Graphics/MiniFeature.src/M000001.html +25 -0
- data/doc/classes/Bio/Graphics/MiniFeature.src/M000003.html +25 -0
- data/doc/classes/Bio/Graphics/MiniFeature.src/M000024.html +25 -0
- data/doc/classes/Bio/Graphics/Page.html +705 -0
- data/doc/classes/Bio/Graphics/Page.src/M000010.html +35 -0
- data/doc/classes/Bio/Graphics/Page.src/M000011.html +83 -0
- data/doc/classes/Bio/Graphics/Page.src/M000012.html +24 -0
- data/doc/classes/Bio/Graphics/Page.src/M000013.html +29 -0
- data/doc/classes/Bio/Graphics/Page.src/M000014.html +24 -0
- data/doc/classes/Bio/Graphics/Page.src/M000015.html +20 -0
- data/doc/classes/Bio/Graphics/Page.src/M000016.html +20 -0
- data/doc/classes/Bio/Graphics/Page.src/M000017.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000018.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000019.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000020.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000021.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000022.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000023.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000024.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000025.html +35 -0
- data/doc/classes/Bio/Graphics/Page.src/M000026.html +83 -0
- data/doc/classes/Bio/Graphics/Page.src/M000027.html +24 -0
- data/doc/classes/Bio/Graphics/Page.src/M000028.html +29 -0
- data/doc/classes/Bio/Graphics/Page.src/M000029.html +24 -0
- data/doc/classes/Bio/Graphics/Page.src/M000030.html +20 -0
- data/doc/classes/Bio/Graphics/Page.src/M000031.html +20 -0
- data/doc/classes/Bio/Graphics/Page.src/M000032.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000033.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000034.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000035.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000036.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000037.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000038.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000039.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000040.html +107 -0
- data/doc/classes/Bio/Graphics/Page.src/M000041.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000042.html +23 -0
- data/doc/classes/Bio/Graphics/Page.src/M000043.html +18 -0
- data/doc/classes/Bio/Graphics/Page.src/M000044.html +18 -0
- data/doc/classes/Bio/Graphics/Primitive.html +204 -0
- data/doc/classes/Bio/Graphics/Primitive.src/M000001.html +21 -0
- data/doc/classes/Bio/Graphics/Primitive.src/M000002.html +20 -0
- data/doc/classes/Bio/Graphics/Primitive.src/M000008.html +21 -0
- data/doc/classes/Bio/Graphics/Primitive.src/M000009.html +20 -0
- data/doc/classes/Bio/Graphics/Primitive.src/M000022.html +21 -0
- data/doc/classes/Bio/Graphics/Primitive.src/M000023.html +20 -0
- data/doc/classes/Bio/Graphics/SVGEE.html +290 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000002.html +24 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000003.html +18 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000004.html +24 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000005.html +18 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000006.html +18 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000007.html +21 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000008.html +27 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000009.html +23 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000016.html +24 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000017.html +18 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000018.html +18 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000019.html +21 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000020.html +27 -0
- data/doc/classes/Bio/Graphics/SVGEE.src/M000021.html +23 -0
- data/doc/classes/Bio/Graphics/Track.html +473 -0
- data/doc/classes/Bio/Graphics/Track.src/M000001.html +35 -0
- data/doc/classes/Bio/Graphics/Track.src/M000002.html +18 -0
- data/doc/classes/Bio/Graphics/Track.src/M000003.html +28 -0
- data/doc/classes/Bio/Graphics/Track.src/M000004.html +18 -0
- data/doc/classes/Bio/Graphics/Track.src/M000010.html +35 -0
- data/doc/classes/Bio/Graphics/Track.src/M000011.html +18 -0
- data/doc/classes/Bio/Graphics/Track.src/M000012.html +28 -0
- data/doc/classes/Bio/Graphics/Track.src/M000013.html +18 -0
- data/doc/created.rid +1 -9
- data/doc/files/lib/bio-svgenes_rb.html +131 -0
- data/doc/files/lib/bio/graphics/glyph_rb.html +101 -0
- data/doc/files/lib/bio/graphics/mini_feature_rb.html +101 -0
- data/doc/files/lib/bio/graphics/page_rb.html +111 -0
- data/doc/files/lib/bio/graphics/primitive_rb.html +101 -0
- data/doc/files/lib/bio/graphics/svgee_rb.html +101 -0
- data/doc/files/lib/bio/graphics/track_rb.html +101 -0
- data/doc/fr_class_index.html +34 -0
- data/doc/fr_file_index.html +33 -0
- data/doc/fr_method_index.html +70 -0
- data/doc/index.html +21 -91
- data/doc/manual/bootstrap/css/bootstrap-responsive.css +1109 -0
- data/doc/manual/bootstrap/css/bootstrap-responsive.min.css +9 -0
- data/doc/manual/bootstrap/css/bootstrap.css +6158 -0
- data/doc/manual/bootstrap/css/bootstrap.min.css +9 -0
- data/doc/manual/bootstrap/img/glyphicons-halflings-white.png +0 -0
- data/doc/manual/bootstrap/img/glyphicons-halflings.png +0 -0
- data/doc/manual/bootstrap/js/bootstrap.js +2276 -0
- data/doc/manual/bootstrap/js/bootstrap.min.js +6 -0
- data/doc/manual/img/circle.png +0 -0
- data/doc/manual/img/directed.png +0 -0
- data/doc/manual/img/down_triangle.png +0 -0
- data/doc/manual/img/histogram.png +0 -0
- data/doc/manual/img/span.png +0 -0
- data/doc/manual/img/transcript.png +0 -0
- data/doc/manual/img/up_triangle.png +0 -0
- data/doc/manual/manual.html +360 -0
- data/doc/manual/manual.md +307 -0
- data/doc/rdoc-style.css +208 -0
- data/examples/example.rb +12 -8
- data/examples/{make_example.rb → example2.rb} +5 -16
- data/lib/bio/graphics/glyph.rb +293 -126
- data/lib/bio/graphics/mini_feature.rb +24 -17
- data/lib/bio/graphics/page.rb +112 -54
- data/lib/bio/graphics/primitive.rb +12 -9
- data/lib/bio/graphics/svgee.rb +9 -11
- data/lib/bio/graphics/track.rb +92 -10
- metadata +132 -9
- data/README.rdoc +0 -19
- data/examples/annotate_snps.rb +0 -86
- data/examples/eg2.rb +0 -40
- data/examples/get_coverage_in_windows.rb +0 -176
@@ -1,30 +1,37 @@
|
|
1
1
|
module Bio
|
2
2
|
class Graphics
|
3
|
+
|
3
4
|
##
|
4
|
-
#
|
5
|
-
#
|
5
|
+
#A Bio::Graphics::MiniFeature object represents a single genomic feature (e.g. a gene, transcript, exon, start codon, etc), it is a lightweight object that
|
6
|
+
#holds the minimum information needed to do the render.
|
6
7
|
class MiniFeature
|
7
8
|
attr_accessor :start, :end, :strand, :exons, :utrs, :block_gaps, :segment_height, :id
|
8
9
|
#Creates a new MiniFeature
|
9
10
|
#
|
10
|
-
|
11
|
-
#* start = the start position of the feature
|
12
|
-
#* end = the end position of the feature
|
13
|
-
#* strand = the strand of the feature
|
14
|
-
#* exons = an array of exon positions
|
15
|
-
#* utrs = an array of utrs positions
|
16
|
-
#*
|
17
|
-
#* id = the name
|
18
|
-
#*
|
11
|
+
#== args
|
12
|
+
#* :start = the start position of the feature
|
13
|
+
#* :end = the end position of the feature
|
14
|
+
#* :strand = the strand of the feature
|
15
|
+
#* :exons = an array of exon positions
|
16
|
+
#* :utrs = an array of utrs positions
|
17
|
+
#* :block_gaps = an array of regions with nothing to be drawn, e.g. introns
|
18
|
+
#* :id = the name for the feature such as the gene name or transcript ID
|
19
|
+
#* :segment_height = the height of the current feature
|
19
20
|
#
|
20
|
-
#==Example usage
|
21
|
+
#== Example usage
|
21
22
|
#
|
22
|
-
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
#
|
23
|
+
## mini1 = Bio::Graphics::MiniFeature.new(
|
24
|
+
# :start=>3631,
|
25
|
+
# :end=>5899,
|
26
|
+
# :strand=>'+',
|
27
|
+
# :exons=>[4000, 4500, 4700, 5000],
|
28
|
+
# :utrs=>[3631, 3650],
|
29
|
+
# :segment_height=>5,
|
30
|
+
# :id=>"AT1G01010"
|
31
|
+
# )
|
27
32
|
#
|
33
|
+
#=== MiniFeatures and Tracks
|
34
|
+
#MiniFeatures are created and added to Bio::Graphics::Track objects which will take responsibility for positioning and syling them.#
|
28
35
|
def initialize(args)
|
29
36
|
@start = args[:start]
|
30
37
|
@end = args[:end]
|
data/lib/bio/graphics/page.rb
CHANGED
@@ -2,31 +2,17 @@ module Bio
|
|
2
2
|
class Graphics
|
3
3
|
|
4
4
|
##
|
5
|
-
#The Page class represents the top level container
|
6
|
-
#
|
5
|
+
#The Bio::Graphics::Page class represents the page of the final rendered SVG and is the top level container into which Bio::Graphics::Tracks are added.
|
6
|
+
#It will contain a scale
|
7
|
+
#and all the tracks along with their features. The scale is calculated will start at the genomic co-ordinates of the start
|
7
8
|
#of the first feature and stop at the end of the last feature)
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
9
|
class Page
|
12
10
|
#Creates a new Page object.
|
13
11
|
#
|
14
|
-
|
15
|
-
#* height = the height of the page
|
16
|
-
#* width = the width of the page
|
17
|
-
#*
|
18
|
-
#* svg = a new SVGEE object
|
19
|
-
#* scale_start = the scale-start of the page (1.0/0.0)
|
20
|
-
#* scale_stop = the scale-stop of the page (-1.0/0.0)
|
21
|
-
#* tracks = an array of track objects with loads of features in it...
|
22
|
-
#* nt_per_percent = the number of nucleotides that are represented by 1% of the page (1);
|
23
|
-
#* num_intervals = the number of intervals
|
24
|
-
#* track_top = the position of the top of the first track (30)
|
25
|
-
#
|
26
|
-
#A new page maybe set up as follows:
|
27
|
-
# @page = Bio::Graphics::Page.new(:width => 800,
|
28
|
-
# :height => 110, :number_of_intervals => 10)
|
29
|
-
#
|
12
|
+
#== args
|
13
|
+
#* :height = the minimum height of the rendered page
|
14
|
+
#* :width = the minimum width of the rendered page
|
15
|
+
#* :background_color = the background color of the page (default none), can be any SVG colour eg rgb(256,0,0) or #FF0000
|
30
16
|
def initialize(args)
|
31
17
|
@height = args[:height]
|
32
18
|
@width = args[:width]
|
@@ -47,9 +33,9 @@ module Bio
|
|
47
33
|
# @width = width
|
48
34
|
#end
|
49
35
|
end
|
50
|
-
#Takes a custom-written json file and writes an svg page to file which will contain the given features described within the json file.
|
51
|
-
#* +args+ - a custom-written json file describing the parameters and resources needed for a new page
|
52
36
|
|
37
|
+
#Takes a custom-written json file and uses it to generate an SVG document based on the information in that page.
|
38
|
+
#* :json a JSON file describing the parameters and files needed to build an SVG document
|
53
39
|
def self.from_json(args)
|
54
40
|
require 'rubygems'
|
55
41
|
require 'json'
|
@@ -120,8 +106,8 @@ module Bio
|
|
120
106
|
end
|
121
107
|
|
122
108
|
#Parses a GFF file into an Array of Bio::GFF::GFF3::Record[http://bioruby.org/rdoc/Bio/GFF/GFF3/Record.html] objects
|
123
|
-
#*
|
124
|
-
#*
|
109
|
+
#* gff_file - a GFF-formatted file
|
110
|
+
#* returns - an Array of Bio::GFF::GFF3::Record[http://bioruby.org/rdoc/Bio/GFF/GFF3/Record.html] objects
|
125
111
|
def self.parse_gff(gff_file)
|
126
112
|
require 'bio'
|
127
113
|
a = []
|
@@ -132,9 +118,91 @@ module Bio
|
|
132
118
|
a
|
133
119
|
end
|
134
120
|
|
135
|
-
#
|
136
|
-
|
137
|
-
|
121
|
+
#adds a new Bio::Graphics::Track object to the current Bio::Graphics::Page object
|
122
|
+
#
|
123
|
+
#==args
|
124
|
+
#
|
125
|
+
#* :glyph = one of Bio::Graphics::Glyphs#glyphs currently
|
126
|
+
# [:generic, :directed, :transcript, :scale, :label, :histogram, :circle, :down_triangle, :up_triangle, :span]
|
127
|
+
#* :stroke_color = the outline colour of the glyphs in the track (default = "black"), can be any SVG colour eg rgb(256,0,0) or #FF0000
|
128
|
+
#* :fill_color = the fill colour of the glyphs in the track (default = 'red'), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients
|
129
|
+
# [:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial ]
|
130
|
+
#or a custom definition of a gradient
|
131
|
+
# {:type => :radial,
|
132
|
+
# :id => :custom,
|
133
|
+
# :cx => 5,
|
134
|
+
# :cy => 5,
|
135
|
+
# :r => 50,
|
136
|
+
# :fx => 50,
|
137
|
+
# :fy => 50,
|
138
|
+
# :stops => [ {
|
139
|
+
# :offset => 0,
|
140
|
+
# :color => 'rgb(255,255,255)',
|
141
|
+
# :opacity => 0
|
142
|
+
# }, {
|
143
|
+
# :offset => 100,
|
144
|
+
# :color => 'rgb(0,127,200)',
|
145
|
+
# :opacity => 1
|
146
|
+
# }, ]
|
147
|
+
# }
|
148
|
+
#* :track_height = minimum height for the track, will be modified automatically if more space is needed e.g for overlapping features (default = auto),
|
149
|
+
#* :name = a displayed name for the track (default = 'feature_track')
|
150
|
+
#* :label = display the name given to the track (default = true),
|
151
|
+
#* :stroke_width = width in pixels of the outline of the glyphs (default=1)
|
152
|
+
#* :x_round = x radius of the ellipse used to round off the corners of rectangles (default = 1)
|
153
|
+
#* :y_round = y radius of the ellipse used to round off the corners of rectangles (default = 1)
|
154
|
+
#:utr_fill_color = the fill colour of the utr part of the glyph (default = 'black'), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients
|
155
|
+
# [:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial ]
|
156
|
+
#or a custom definition of a gradient
|
157
|
+
# {:type => :radial,
|
158
|
+
# :id => :custom,
|
159
|
+
# :cx => 5,
|
160
|
+
# :cy => 5,
|
161
|
+
# :r => 50,
|
162
|
+
# :fx => 50,
|
163
|
+
# :fy => 50,
|
164
|
+
# :stops => [ {
|
165
|
+
# :offset => 0,
|
166
|
+
# :color => 'rgb(255,255,255)',
|
167
|
+
# :opacity => 0
|
168
|
+
# }, {
|
169
|
+
# :offset => 100,
|
170
|
+
# :color => 'rgb(0,127,200)',
|
171
|
+
# :opacity => 1
|
172
|
+
# }, ]
|
173
|
+
# }
|
174
|
+
#* :utr_stroke = the outline colour of the utr part of the glyph (default = "black"), can be any SVG colour eg rgb(256,0,0) or #FF0000
|
175
|
+
#* :utr_stroke_width = The width of the outline stroke for the utr part of the glyph (default = 1)
|
176
|
+
#* :exon_fill_color = the fill colour of the utr part of the glyph (default = 'red'), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients or a custom definition of a gradient
|
177
|
+
# [:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial ]
|
178
|
+
#or a custom definition of a gradient
|
179
|
+
# {:type => :radial,
|
180
|
+
# :id => :custom,
|
181
|
+
# :cx => 5,
|
182
|
+
# :cy => 5,
|
183
|
+
# :r => 50,
|
184
|
+
# :fx => 50,
|
185
|
+
# :fy => 50,
|
186
|
+
# :stops => [ {
|
187
|
+
# :offset => 0,
|
188
|
+
# :color => 'rgb(255,255,255)',
|
189
|
+
# :opacity => 0
|
190
|
+
# }, {
|
191
|
+
# :offset => 100,
|
192
|
+
# :color => 'rgb(0,127,200)',
|
193
|
+
# :opacity => 1
|
194
|
+
# }, ]
|
195
|
+
#
|
196
|
+
#* :exon_stroke = the outline colour of the exon part of the glyph (default = "black") can be any SVG colour eg rgb(256,0,0) or #FF0000
|
197
|
+
#* :exon_stroke_width = The width of the outline stroke for the exon part of the glyph (default = 1)
|
198
|
+
#* :line_color = the colour for the line part that joins the blocks (default = 'black') can be any SVG colour eg rgb(256,0,0) or #FF0000
|
199
|
+
#* :line_width = the width ffor the line part that joins the blocks (default = 1)
|
200
|
+
#* :exon_style = an arbitrary SVG compliant style string eg "fill-opacity:0.4;"
|
201
|
+
#* :utr_style = an arbitrary SVG compliant style string eg "fill-opacity:0.4;"
|
202
|
+
#* :line_style = an arbitrary SVG compliant style string eg "fill-opacity:0.4;"
|
203
|
+
#* :gap_marker = style of the line between blocks - either angled or straight
|
204
|
+
#=== returns
|
205
|
+
# a new Bio::Graphics::Track object
|
138
206
|
def add_track(args)
|
139
207
|
#sort out the colour/gradient options
|
140
208
|
[:fill_color, :exon_fill_color, :utr_fill_color].each do |colour_tag|
|
@@ -161,12 +229,13 @@ module Bio
|
|
161
229
|
end
|
162
230
|
end
|
163
231
|
|
164
|
-
#Adds the
|
232
|
+
#Adds scale bar to the list of objects to be rendered in the final
|
165
233
|
def draw_scale
|
166
234
|
Glyph.scale(:start => @scale_start,
|
167
235
|
:stop => @scale_stop,
|
168
236
|
:number_of_intervals => @num_intervals, :page_width => @width).each { |g| @svg.add_primitive(g) }
|
169
237
|
end
|
238
|
+
|
170
239
|
#Adds the Bio::Graphics::Primitive objects to the SVGEE object
|
171
240
|
#* +args+ - an Array of Bio::Graphics::Primitive object
|
172
241
|
def draw_label(args)
|
@@ -174,48 +243,41 @@ module Bio
|
|
174
243
|
:x => args[:x],
|
175
244
|
:y => args[:y]).each { |g| @svg.add_primitive(g) }
|
176
245
|
end
|
177
|
-
|
178
|
-
|
246
|
+
|
247
|
+
|
179
248
|
def draw_generic(args) #remember presentation info comes from track@args when the track is defined
|
180
249
|
Glyph.generic(args).each { |g| @svg.add_primitive(g) }
|
181
250
|
end
|
182
|
-
|
183
|
-
#* +args+ - an Array of Bio::Graphics::Primitive objects of the stated type
|
251
|
+
|
184
252
|
def draw_directed(args)
|
185
253
|
Glyph.directed(args).each { |g| @svg.add_primitive(g) }
|
186
254
|
end
|
187
|
-
|
188
|
-
#* +args+ - an Array of Bio::Graphics::Primitive objects of the stated type
|
255
|
+
|
189
256
|
def draw_circle(args)
|
190
257
|
Glyph.circle(args).each { |g| @svg.add_primitive(g) }
|
191
258
|
end
|
192
|
-
|
193
|
-
#* +args+ - an Array of Bio::Graphics::Primitive objects of the stated type
|
259
|
+
|
194
260
|
def draw_transcript(args)
|
195
261
|
Glyph.transcript(args).each { |g| @svg.add_primitive(g) }
|
196
262
|
end
|
197
|
-
|
198
|
-
#* +args+ - an Array of Bio::Graphics::Primitive objects of the stated type
|
263
|
+
|
199
264
|
def draw_histogram(args)
|
200
265
|
Glyph.generic(args).each { |g| @svg.add_primitive(g) }
|
201
266
|
end
|
202
|
-
|
203
|
-
#* +args+ - an Array of Bio::Graphics::Primitive objects of the stated type
|
267
|
+
|
204
268
|
def draw_up_triangle(args)
|
205
269
|
Glyph.up_triangle(args).each { |g| @svg.add_primitive(g) }
|
206
270
|
end
|
207
|
-
|
208
|
-
#* +args+ - an Array of Bio::Graphics::Primitive objects of the stated type
|
271
|
+
|
209
272
|
def draw_down_triangle(args)
|
210
273
|
Glyph.down_triangle(args).each { |g| @svg.add_primitive(g) }
|
211
274
|
end
|
212
|
-
|
213
|
-
#* +args+ - an Array of Bio::Graphics::Primitive objects of the stated type
|
275
|
+
|
214
276
|
def draw_span(args)
|
215
277
|
Glyph.span(args).each { |g| @svg.add_primitive(g) }
|
216
278
|
end
|
217
279
|
|
218
|
-
#Takes a Bio::Graphics::Track object and
|
280
|
+
#Takes a Bio::Graphics::Track object and does the work to draw features
|
219
281
|
#
|
220
282
|
#It examines the the type of track and calculates the required parameters
|
221
283
|
#* +args+ - an Array of Bio::Graphics::Track object
|
@@ -311,15 +373,12 @@ module Bio
|
|
311
373
|
#@svg.update_width(@width + 200)
|
312
374
|
|
313
375
|
end
|
314
|
-
#
|
315
|
-
#* +num+ - the number of nucleotides
|
316
|
-
#* +returns+ - the required number of pixels to draw the object
|
376
|
+
#Calculates the pixel value for a given number
|
317
377
|
def to_px(num)
|
318
378
|
(num.to_f / @nt_per_px_x.to_f)
|
319
379
|
end
|
320
380
|
|
321
|
-
#
|
322
|
-
#Uses the methods +get_limits+ and +draw_scale+ and then +draw_feature+ for each track on the page
|
381
|
+
#generates the SVG text
|
323
382
|
def get_markup
|
324
383
|
get_limits
|
325
384
|
draw_scale
|
@@ -328,13 +387,12 @@ module Bio
|
|
328
387
|
end
|
329
388
|
@svg.draw
|
330
389
|
end
|
331
|
-
#Prints
|
390
|
+
#Prints the svg text to STDOUT
|
332
391
|
def draw
|
333
392
|
puts get_markup
|
334
393
|
end
|
335
394
|
|
336
|
-
#Writes the
|
337
|
-
#* +file+ - the file to which the svg text should be written
|
395
|
+
#Writes the SVG text to a file
|
338
396
|
def write(file)
|
339
397
|
File.open(file, 'w').write(get_markup)
|
340
398
|
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
module Bio
|
2
2
|
class Graphics
|
3
|
-
|
4
|
-
#
|
3
|
+
|
4
|
+
#The Bio::Graphics::Primitive class is used to describe simple shapes. It is basically a simple data container that
|
5
|
+
#has lots of dynamically set instance variables including a name. The Bio::Graphics::Primitive object is later translated
|
6
|
+
#to an SVG string by the Bio::Graphics::SVGEE class.
|
5
7
|
class Primitive
|
6
8
|
attr_reader :primitive
|
7
|
-
|
9
|
+
|
10
|
+
#Creates a new Primitive and initialises instance variables dynamically from the args hash
|
8
11
|
#
|
9
|
-
|
10
|
-
#* primitive = the Primitive type
|
11
|
-
#* args = a hash of parameters needed to
|
12
|
+
#== args+
|
13
|
+
#* :primitive = the Primitive type
|
14
|
+
#* args = a hash of parameters needed to describe the attributes of the primitive type
|
12
15
|
def initialize(primitive,args)
|
13
16
|
@primitive = primitive
|
14
17
|
args.each_key do |k|
|
@@ -16,10 +19,10 @@ class Primitive
|
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
19
|
-
#Updates a Primitive and
|
22
|
+
#Updates a Primitive and sets the provided values as instance variables
|
20
23
|
#
|
21
|
-
|
22
|
-
#* args = a hash of new parameters for the given
|
24
|
+
#== args
|
25
|
+
#* args = a hash of new parameters for the given primitive type
|
23
26
|
def update(args)
|
24
27
|
args.each_key do |k|
|
25
28
|
self.instance_variable_set("@#{k}", args[k])
|
data/lib/bio/graphics/svgee.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
module Bio
|
2
2
|
class Graphics
|
3
|
-
|
4
|
-
#
|
5
|
-
#necessary to display the given glyphs.
|
3
|
+
|
4
|
+
#The Bio::Graphics::SVGEE class takes argument information in a hash and creates SVG Markup tags, which it will draw
|
6
5
|
class SVGEE
|
7
6
|
attr_reader :primitives, :defs, :supported_primitives
|
8
|
-
#Creates a new SVGEE object which will contain all the necessary objects to display all the features on a page
|
7
|
+
#Creates a new Bio::Graphics::SVGEE object which will contain all the necessary objects to display all the features on a page
|
9
8
|
#
|
10
|
-
|
11
|
-
#* width = the
|
12
|
-
#* height = the amount of the page height the svg should take up (100%)
|
13
|
-
#* style = the svg style information
|
14
|
-
#* primitives = an array of glyphs
|
15
|
-
#* defs = the gradients that will be used in the SVG
|
16
|
-
#* \supported_primitives = a list of permitted Glyphs
|
9
|
+
#== args
|
10
|
+
#* :width = the width of the SVG page (100%)
|
11
|
+
#* :height = the amount of the page height the svg should take up (100%)
|
12
|
+
#* :style = the svg style information
|
17
13
|
def initialize(args)
|
18
14
|
opts = {:width => '100%', :height => '100%'}.merge!(args)
|
19
15
|
@width = opts[:width]
|
@@ -23,10 +19,12 @@ class SVGEE
|
|
23
19
|
@defs = []
|
24
20
|
@supported_primitives = [:circle, :rectangle, :ellipse, :line, :polyline, :text]
|
25
21
|
end
|
22
|
+
|
26
23
|
#Produces the opening text for an svg file
|
27
24
|
def open_tag
|
28
25
|
%{<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="#{@width}" height="#{@height}" style="#{@style}" xmlns:xlink="http://www.w3.org/1999/xlink">}
|
29
26
|
end
|
27
|
+
|
30
28
|
#Produces the closing text for an svg file
|
31
29
|
def close_tag
|
32
30
|
%{</svg>}
|
data/lib/bio/graphics/track.rb
CHANGED
@@ -1,11 +1,95 @@
|
|
1
1
|
module Bio
|
2
2
|
class Graphics
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
#The Bio::Graphics::Track object acts as a container for Bio::Graphics::MiniFeature objects. The Bio::Graphics::Track takes style information on instantiation.
|
5
|
+
#Style information is applied to each feature in the track by the track
|
5
6
|
class Track
|
6
7
|
attr_reader :glyph, :name, :label, :args, :track_height, :scale, :max_y, :min_width
|
7
8
|
attr_accessor :features, :feature_rows, :name, :number_rows, :feature_height
|
8
|
-
|
9
|
+
|
10
|
+
#Creates a new Bio::Graphics::Track
|
11
|
+
#
|
12
|
+
#==args
|
13
|
+
#
|
14
|
+
#* :glyph = one of Bio::Graphics::Glyphs#glyphs currently
|
15
|
+
# [:generic, :directed, :transcript, :scale, :label, :histogram, :circle, :down_triangle, :up_triangle, :span]
|
16
|
+
#* :stroke_color = the outline colour of the glyphs in the track (default = "black"), can be any SVG colour eg rgb(256,0,0) or #FF0000
|
17
|
+
#* :fill_color = the fill colour of the glyphs in the track (default = 'red'), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients
|
18
|
+
# [:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial ]
|
19
|
+
#or a custom definition of a gradient
|
20
|
+
# {:type => :radial,
|
21
|
+
# :id => :custom,
|
22
|
+
# :cx => 5,
|
23
|
+
# :cy => 5,
|
24
|
+
# :r => 50,
|
25
|
+
# :fx => 50,
|
26
|
+
# :fy => 50,
|
27
|
+
# :stops => [ {
|
28
|
+
# :offset => 0,
|
29
|
+
# :color => 'rgb(255,255,255)',
|
30
|
+
# :opacity => 0
|
31
|
+
# }, {
|
32
|
+
# :offset => 100,
|
33
|
+
# :color => 'rgb(0,127,200)',
|
34
|
+
# :opacity => 1
|
35
|
+
# }, ]
|
36
|
+
# }
|
37
|
+
#* :track_height = minimum height for the track, will be modified automatically if more space is needed e.g for overlapping features (default = auto),
|
38
|
+
#* :name = a displayed name for the track (default = 'feature_track')
|
39
|
+
#* :label = display the name given to the track (default = true),
|
40
|
+
#* :stroke_width = width in pixels of the outline of the glyphs (default=1)
|
41
|
+
#* :x_round = x radius of the ellipse used to round off the corners of rectangles (default = 1)
|
42
|
+
#* :y_round = y radius of the ellipse used to round off the corners of rectangles (default = 1)
|
43
|
+
#:utr_fill_color = the fill colour of the utr part of the glyph (default = 'black'), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients
|
44
|
+
# [:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial ]
|
45
|
+
#or a custom definition of a gradient
|
46
|
+
# {:type => :radial,
|
47
|
+
# :id => :custom,
|
48
|
+
# :cx => 5,
|
49
|
+
# :cy => 5,
|
50
|
+
# :r => 50,
|
51
|
+
# :fx => 50,
|
52
|
+
# :fy => 50,
|
53
|
+
# :stops => [ {
|
54
|
+
# :offset => 0,
|
55
|
+
# :color => 'rgb(255,255,255)',
|
56
|
+
# :opacity => 0
|
57
|
+
# }, {
|
58
|
+
# :offset => 100,
|
59
|
+
# :color => 'rgb(0,127,200)',
|
60
|
+
# :opacity => 1
|
61
|
+
# }, ]
|
62
|
+
# }
|
63
|
+
#* :utr_stroke = the outline colour of the utr part of the glyph (default = "black"), can be any SVG colour eg rgb(256,0,0) or #FF0000
|
64
|
+
#* :utr_stroke_width = The width of the outline stroke for the utr part of the glyph (default = 1)
|
65
|
+
#* :exon_fill_color = the fill colour of the utr part of the glyph (default = 'red'), can be any SVG colour eg rgb(256,0,0) or #FF0000, or one of the built in gradient types Bio::Graphics::Glyph#gradients or a custom definition of a gradient
|
66
|
+
# [:red_white_h, :green_white_h, :blue_white_h, :yellow_white_h, :red_white_radial, :green_white_radial, :blue_white_radial, :yellow_white_radial ]
|
67
|
+
#or a custom definition of a gradient
|
68
|
+
# {:type => :radial,
|
69
|
+
# :id => :custom,
|
70
|
+
# :cx => 5,
|
71
|
+
# :cy => 5,
|
72
|
+
# :r => 50,
|
73
|
+
# :fx => 50,
|
74
|
+
# :fy => 50,
|
75
|
+
# :stops => [ {
|
76
|
+
# :offset => 0,
|
77
|
+
# :color => 'rgb(255,255,255)',
|
78
|
+
# :opacity => 0
|
79
|
+
# }, {
|
80
|
+
# :offset => 100,
|
81
|
+
# :color => 'rgb(0,127,200)',
|
82
|
+
# :opacity => 1
|
83
|
+
# }, ]
|
84
|
+
#
|
85
|
+
#* :exon_stroke = the outline colour of the exon part of the glyph (default = "black") can be any SVG colour eg rgb(256,0,0) or #FF0000
|
86
|
+
#* :exon_stroke_width = The width of the outline stroke for the exon part of the glyph (default = 1)
|
87
|
+
#* :line_color = the colour for the line part that joins the blocks (default = 'black') can be any SVG colour eg rgb(256,0,0) or #FF0000
|
88
|
+
#* :line_width = the width ffor the line part that joins the blocks (default = 1)
|
89
|
+
#* :exon_style = an arbitrary SVG compliant style string eg "fill-opacity:0.4;"
|
90
|
+
#* :utr_style = an arbitrary SVG compliant style string eg "fill-opacity:0.4;"
|
91
|
+
#* :line_style = an arbitrary SVG compliant style string eg "fill-opacity:0.4;"
|
92
|
+
#* :gap_marker = style of the line between blocks - either angled or straight
|
9
93
|
def initialize(args)
|
10
94
|
@args = {:glyph => :generic,
|
11
95
|
:name => "feature_track",
|
@@ -27,14 +111,13 @@ class Track
|
|
27
111
|
|
28
112
|
end
|
29
113
|
|
30
|
-
#Adds a new MiniFeature to the
|
114
|
+
#Adds a new Bio::Graphics::MiniFeature object to the current Bio::Graphics::Track
|
31
115
|
def add(feature)
|
32
116
|
@features << feature
|
33
117
|
end
|
34
118
|
|
35
119
|
#Calculates how many rows are needed per track for overlapping features
|
36
|
-
#and which row each feature should be in
|
37
|
-
|
120
|
+
#and which row each feature should be in. Usually only called by the enclosing Bio::Graphics::Page object.
|
38
121
|
def get_rows
|
39
122
|
current_row = 1
|
40
123
|
@feature_rows = Array.new(@features.length,1)
|
@@ -49,12 +132,11 @@ class Track
|
|
49
132
|
end
|
50
133
|
end
|
51
134
|
|
52
|
-
#Calculates
|
53
|
-
#If two features overlap then then will be placed on separate rows of the track
|
135
|
+
#Calculates whether two Bio::Graphics::MiniFeature objects overlap by examining their start and end positions.
|
54
136
|
#
|
55
137
|
#+args+
|
56
|
-
#* f1 - a MiniFeature object
|
57
|
-
#* f2 - a MiniFeature object
|
138
|
+
#* f1 - a Bio::Graphics::MiniFeature object
|
139
|
+
#* f2 - a Bio::Graphics::MiniFeature object
|
58
140
|
def overlaps(f1, f2)
|
59
141
|
(f1.start >= f2.start and f1.start <= f2.end) or (f1.end >= f2.start and f1.end <= f2.end)
|
60
142
|
end
|