bio-ucsc-util 0.1.0
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.
- data/.document +5 -0
- data/.rvmrc +41 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +49 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/bio-ucsc-util.gemspec +75 -0
- data/ext/ucsc-util/README +142 -0
- data/ext/ucsc-util/makefile +66 -0
- data/ext/ucsc-util/mkrf_conf.rb +64 -0
- data/ext/ucsc-util/ucsc-util-src-v268.tgz +0 -0
- data/lib/bio-ucsc-util.rb +3 -0
- data/lib/bio/ucsc/big_wig.rb +216 -0
- data/lib/bio/ucsc/binding.rb +128 -0
- data/lib/bio/ucsc/library.rb +38 -0
- data/lib/bio/ucsc/src/Version +1 -0
- data/lib/bio/ucsc/util.rb +52 -0
- data/test/1.bed +12 -0
- data/test/1.bw +0 -0
- data/test/1.wig +20 -0
- data/test/1_smoothed.bw +0 -0
- data/test/chrom.sizes +3 -0
- data/test/helper.rb +20 -0
- data/test/test_big_wig.rb +162 -0
- metadata +142 -0
@@ -0,0 +1 @@
|
|
1
|
+
v268
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# == ucsc_util.rb
|
2
|
+
# This file contains the UcscUtil class implementing the ucsc utility programs
|
3
|
+
#
|
4
|
+
# == Contact
|
5
|
+
#
|
6
|
+
# Author:: Nicholas A. Thrower
|
7
|
+
# Copyright:: Copyright (c) 2012 Nicholas A Thrower
|
8
|
+
# License:: See LICENSE.txt for more details
|
9
|
+
|
10
|
+
# :nodoc:
|
11
|
+
module Bio
|
12
|
+
# -
|
13
|
+
module Ucsc
|
14
|
+
class Util
|
15
|
+
# UcscUtil implements the utility programs from the ucsc source as class methods.
|
16
|
+
# Names are converted by ruby convention to snake case (underscore) based on the camel case C routines
|
17
|
+
require 'bio/ucsc/binding'
|
18
|
+
# Converts ascii Wig file to binary BigWig
|
19
|
+
# - :wig_file => input wiggle file
|
20
|
+
# - :chrom_file => two column file: <chromosome name> <size in bases> for each entry
|
21
|
+
# - :big_wig_file => output indexed file
|
22
|
+
# Options:
|
23
|
+
# * :blockSize => Number of items to bundle in r-tree [256]
|
24
|
+
# * :itemsPerSlot => Number of data points bundled at lowest level [1024]
|
25
|
+
# * :clip => If set just issue warning messages rather than dying if wig file contains items off end of chromosome
|
26
|
+
# * :unc => If set, do not use compression
|
27
|
+
def self.wig_to_big_wig(wig_file, chrom_file, big_wig_file, opts={})
|
28
|
+
block_size = opts[:block_size]||256
|
29
|
+
items_per_slot = opts[:items_per_slot]||1024
|
30
|
+
clip = opts[:clip]||false
|
31
|
+
unc = opts[:unc]||false
|
32
|
+
do_compress = !unc
|
33
|
+
Binding::bigWigFileCreate(wig_file,chrom_file,block_size,items_per_slot,clip,do_compress,big_wig_file)
|
34
|
+
return BigWig.open(big_wig_file)
|
35
|
+
end
|
36
|
+
# Converts ascii bedGraph file to binary bigWig.
|
37
|
+
# The input bedGraph file must be sorted, use the unix sort command:
|
38
|
+
# sort -k1,1 -k2,2n unsorted.bedGraph > sorted.bedGraph
|
39
|
+
# - :bed_file => input bedGraph
|
40
|
+
# - :chrom_file => two column file: <chromosome name> <size in bases> for each entry
|
41
|
+
# - :big_wig_file => output indexed file
|
42
|
+
def self.bed_graph_to_big_wig(wig_file, chrom_file, big_wig_file, opts={})
|
43
|
+
block_size = opts[:block_size]||256
|
44
|
+
items_per_slot = opts[:items_per_slot]||1024
|
45
|
+
unc = opts[:unc]||false
|
46
|
+
do_compress = !unc
|
47
|
+
Binding::bedGraphToBigWig(wig_file,chrom_file,block_size,items_per_slot,do_compress,big_wig_file)
|
48
|
+
return BigWig.open(big_wig_file)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/test/1.bed
ADDED
data/test/1.bw
ADDED
Binary file
|
data/test/1.wig
ADDED
data/test/1_smoothed.bw
ADDED
Binary file
|
data/test/chrom.sizes
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'test/unit'
|
13
|
+
require 'shoulda'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
17
|
+
require 'bio-ucsc-util'
|
18
|
+
|
19
|
+
class Test::Unit::TestCase
|
20
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestBioUcscUtil < Test::Unit::TestCase
|
4
|
+
include Bio::Ucsc
|
5
|
+
TEST_BW = "test/1.bw"
|
6
|
+
TEST_WIG = "test/1.wig"
|
7
|
+
TEST_BED = "test/1.bed"
|
8
|
+
TEST_WIG_OUT = "test/1.wig.bw"
|
9
|
+
TEST_BED_OUT = "test/2.bed.bw"
|
10
|
+
CHROM_FILE = "test/chrom.sizes"
|
11
|
+
BAD_FILE = 'test/not_existing_file'
|
12
|
+
TEST_SMOOTH_FILE = 'test/1_smoothed.bw'
|
13
|
+
TEST_SMOOTH_OUT_FILE = 'test/smoothed.bw'
|
14
|
+
|
15
|
+
context "a new big wig" do
|
16
|
+
setup do
|
17
|
+
@bw = BigWig.new
|
18
|
+
end
|
19
|
+
should "not be open and have no filename" do
|
20
|
+
assert_equal nil, @bw.bbi_file
|
21
|
+
assert_equal nil, @bw.filename
|
22
|
+
end
|
23
|
+
should "allowing setting filename" do
|
24
|
+
@bw.filename = TEST_BW
|
25
|
+
assert_equal TEST_BW, @bw.filename
|
26
|
+
end
|
27
|
+
should "report no filename on open" do
|
28
|
+
assert_raise ArgumentError do
|
29
|
+
@bw.open
|
30
|
+
end
|
31
|
+
end
|
32
|
+
should "report bad filename on open" do
|
33
|
+
@bw.filename = BAD_FILE
|
34
|
+
assert_raise NameError do
|
35
|
+
@bw.open
|
36
|
+
end
|
37
|
+
end
|
38
|
+
should "report bad format on open" do
|
39
|
+
@bw.filename = TEST_BED
|
40
|
+
assert_raise LoadError do
|
41
|
+
@bw.open
|
42
|
+
end
|
43
|
+
end
|
44
|
+
should "allow opening a good file" do
|
45
|
+
@bw.filename = TEST_BW
|
46
|
+
assert_nothing_raised do
|
47
|
+
@bw.open
|
48
|
+
end
|
49
|
+
assert_not_nil @bw.bbi_file
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "an open big wig" do
|
54
|
+
setup do
|
55
|
+
@bw = BigWig.open(TEST_BW)
|
56
|
+
@out = StringIO.new
|
57
|
+
$stdout = @out
|
58
|
+
end
|
59
|
+
should "already be open" do
|
60
|
+
assert_not_nil @bw.bbi_file
|
61
|
+
end
|
62
|
+
should "allow closing a file" do
|
63
|
+
@bw.close
|
64
|
+
assert_nil @bw.bbi_file
|
65
|
+
end
|
66
|
+
should "have detailed info" do
|
67
|
+
@bw.info
|
68
|
+
assert_equal "version: 4\nisCompressed: no\nisSwapped: 0\nprimaryDataSize: 116\nprimaryIndexSize: 6204\nzoomLevels: 1\nchromCount: 1\nbasesCovered: 7\nmean: 52.857143\nmin: 10.000000\nmax: 100.000000\nstd: 36.839420\n", @out.string
|
69
|
+
end
|
70
|
+
should "allow chrom details" do
|
71
|
+
@bw.info({:chroms => true})
|
72
|
+
assert @out.string=~/chr1 0 5000/
|
73
|
+
end
|
74
|
+
should "allow zoom details" do
|
75
|
+
@bw.info({:zooms => true})
|
76
|
+
assert @out.string=~/32 36/
|
77
|
+
end
|
78
|
+
should "allow min/max" do
|
79
|
+
@bw.info({:minMax => true})
|
80
|
+
assert_equal "10.000000 100.000000\n", @out.string
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "a new big wig from wig" do
|
85
|
+
setup do
|
86
|
+
@bw = Util.wig_to_big_wig(TEST_WIG,CHROM_FILE,TEST_WIG_OUT)
|
87
|
+
end
|
88
|
+
should "have summary data" do
|
89
|
+
assert_same_elements( [5.0,10.0], @bw.summary("chr1",2,4,2,{:type => 'max'}) )
|
90
|
+
end
|
91
|
+
should "have min 1.0" do
|
92
|
+
assert_equal 1.0, @bw.min
|
93
|
+
end
|
94
|
+
should "have max 10.0" do
|
95
|
+
assert_equal 10.0, @bw.max
|
96
|
+
end
|
97
|
+
should "have std of 2.94.." do
|
98
|
+
assert_equal 2.9480801329998196, @bw.std_dev
|
99
|
+
end
|
100
|
+
should "have a mean of 4.23.." do
|
101
|
+
assert_equal 4.235294117647059, @bw.mean
|
102
|
+
end
|
103
|
+
should "have 17 bases covered" do
|
104
|
+
assert_equal 17, @bw.bases_covered
|
105
|
+
end
|
106
|
+
should "have total chromosome length of 17500" do
|
107
|
+
assert_equal 17500, @bw.chrom_length
|
108
|
+
end
|
109
|
+
should "have total coverage of" do
|
110
|
+
assert_equal 0.0009714285714285714, @bw.coverage
|
111
|
+
end
|
112
|
+
should "have chr1 length of" do
|
113
|
+
assert_equal 5000, @bw.chrom_length('chr1')
|
114
|
+
end
|
115
|
+
should "have chr1 coverage of" do
|
116
|
+
assert_equal 0.0014, @bw.coverage('chr1')
|
117
|
+
end
|
118
|
+
should "have chr2 min of 2" do
|
119
|
+
assert_equal 2, @bw.min('chr2')
|
120
|
+
end
|
121
|
+
should "have chr2 max of 8" do
|
122
|
+
assert_equal 8, @bw.max('chr2')
|
123
|
+
end
|
124
|
+
should "have chr2 mean of 5.0" do
|
125
|
+
assert_equal 5.0, @bw.mean('chr2')
|
126
|
+
end
|
127
|
+
should "have chr3 std of 1.0" do
|
128
|
+
assert_equal 1.0, @bw.std_dev('chr3')
|
129
|
+
end
|
130
|
+
should "allow smoothing" do
|
131
|
+
assert_nothing_raised do
|
132
|
+
@bw.smooth(TEST_SMOOTH_OUT_FILE)
|
133
|
+
end
|
134
|
+
`rm #{TEST_SMOOTH_OUT_FILE}`
|
135
|
+
end
|
136
|
+
teardown do
|
137
|
+
`rm #{TEST_WIG_OUT}`
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "a new big wig from bed" do
|
142
|
+
setup do
|
143
|
+
@bw = Util.bed_graph_to_big_wig(TEST_BED,CHROM_FILE,TEST_BED_OUT)
|
144
|
+
end
|
145
|
+
should "have summary data" do
|
146
|
+
assert_same_elements [5.0,10.0], @bw.summary("chr1",3,5,2,{:type => 'max'})
|
147
|
+
end
|
148
|
+
should "have min 1.0" do
|
149
|
+
assert_equal 1.0, @bw.min
|
150
|
+
end
|
151
|
+
should "have max 10.0" do
|
152
|
+
assert_equal 10.0, @bw.max
|
153
|
+
end
|
154
|
+
should "have chr2 length of 2500" do
|
155
|
+
assert_equal 2500, @bw.chrom_length('chr2')
|
156
|
+
end
|
157
|
+
teardown do
|
158
|
+
`rm #{TEST_BED_OUT}`
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bio-ucsc-util
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- throwern
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.3
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.3
|
78
|
+
description: ! 'Ruby FFI binding and implmentation of the ucsc utilities: bigWigInfo,
|
79
|
+
bigWigSummary and wigToBigWig'
|
80
|
+
email: throwern@msu.edu
|
81
|
+
executables: []
|
82
|
+
extensions:
|
83
|
+
- ext/ucsc-util/mkrf_conf.rb
|
84
|
+
extra_rdoc_files:
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.rdoc
|
87
|
+
files:
|
88
|
+
- .document
|
89
|
+
- .rvmrc
|
90
|
+
- Gemfile
|
91
|
+
- Gemfile.lock
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.rdoc
|
94
|
+
- Rakefile
|
95
|
+
- VERSION
|
96
|
+
- bio-ucsc-util.gemspec
|
97
|
+
- ext/ucsc-util/README
|
98
|
+
- ext/ucsc-util/makefile
|
99
|
+
- ext/ucsc-util/mkrf_conf.rb
|
100
|
+
- ext/ucsc-util/ucsc-util-src-v268.tgz
|
101
|
+
- lib/bio-ucsc-util.rb
|
102
|
+
- lib/bio/ucsc/big_wig.rb
|
103
|
+
- lib/bio/ucsc/binding.rb
|
104
|
+
- lib/bio/ucsc/library.rb
|
105
|
+
- lib/bio/ucsc/src/Version
|
106
|
+
- lib/bio/ucsc/util.rb
|
107
|
+
- test/1.bed
|
108
|
+
- test/1.bw
|
109
|
+
- test/1.wig
|
110
|
+
- test/1_smoothed.bw
|
111
|
+
- test/chrom.sizes
|
112
|
+
- test/helper.rb
|
113
|
+
- test/test_big_wig.rb
|
114
|
+
homepage: http://github.com/throwern/bio-ucsc-util
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: -1186691304766418588
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.8.24
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Ruby binding to the ucsc kent utilities
|
142
|
+
test_files: []
|