bio-genomic-interval 0.1.0 → 0.1.1

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.
@@ -1,7 +1,7 @@
1
1
  = bio-genomic-interval
2
2
 
3
3
  Author:: MISHIMA, Hiroyuki (hmishima AT nagasaki-u.ac.jp, missy AT be.to)
4
- Version:: 0.1.0
4
+ Version:: 0.1.1
5
5
  Copyright:: Copyright (c) MISHIMA, Hiroyuki, 2011
6
6
  License:: the MIT/X11 license
7
7
 
@@ -23,6 +23,14 @@ Last one is generated from a "Zero-based half-closed[start, end)" interval
23
23
  , which used in UCSC Genobe Browser's BED format, instead of usual
24
24
  "One-based full-closed [start, end]" intervals.
25
25
 
26
+ d = Bio::GenomicInetrval.zero_based("chr1", 100, 100)
27
+ d.to_s # => "chr1:101-101"
28
+ d.length # => 1
29
+
30
+ In the BED format, an insertion position is like "chr1:100-100", whose size is 0.
31
+ This interval is converted into "chr1:101-101" in the one-based format.
32
+ Note that size is changed to 1.
33
+
26
34
  == Comparison
27
35
  ref = Bio::GenomicInterval.parse("chr1:123-456")
28
36
  cmp = Bio::GenomicInterval.parse("chr1:234-567")
@@ -43,7 +51,7 @@ Last one is generated from a "Zero-based half-closed[start, end)" interval
43
51
  cmp = Bio::GenomicInterval.parse("chr1:15-25")
44
52
  ref.overlap(cmp) # => 6
45
53
  cmp2 = Bio::GenomicInterval.parse("chr1:25-35")
46
- ref.overlap(cmp) # => -4
54
+ ref.overlap(cmp2) # => -4
47
55
 
48
56
  == Expansion (or integration)
49
57
  ref = Bio::GenomicInterval.parse("chr1:400-600")
data/Rakefile CHANGED
@@ -11,17 +11,20 @@ require 'rake'
11
11
 
12
12
  require 'jeweler'
13
13
  Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
14
+ # gem is a Gem::Specification...
15
+ # see http://docs.rubygems.org/read/chapter/20 for more options
15
16
  gem.name = "bio-genomic-interval"
16
17
  gem.homepage = "http://github.com/misshie/bioruby-genomic-interval"
17
18
  gem.license = "MIT"
18
19
  gem.summary = %Q{a BioRuby plugin: handling genomic interavals and overlaps}
19
20
  gem.description =
20
- %Q{a BioRuby plugin: handling genomic intervals,such as "chr1:123-456", and overlaps between two intervalsrake }
21
+ %Q{a BioRuby plugin: handling genomic intervals,such as "chr1:123-456", and overlap state between two intervals }
21
22
  gem.email = "missy@be.to"
22
23
  gem.authors = ["Hiroyuki Mishima"]
23
- # Include your dependencies below. Runtime dependencies are required when using your gem,
24
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # Include your dependencies below.
25
+ # Runtime dependencies are required when using your gem,
26
+ # and development dependencies are only needed for development
27
+ # (ie running rake tasks, tests, etc)
25
28
  # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
29
  # gem.add_development_dependency 'rspec', '> 1.2.3'
27
30
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bio-genomic-interval}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Hiroyuki Mishima"]
12
- s.date = %q{2011-04-07}
13
- s.description = %q{a BioRuby plugin: handling genomic intervals,such as "chr1:123-456", and overlaps between two intervalsrake }
12
+ s.date = %q{2011-04-18}
13
+ s.description = %q{a BioRuby plugin: handling genomic intervals,such as "chr1:123-456", and overlap state between two intervals }
14
14
  s.email = %q{missy@be.to}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.homepage = %q{http://github.com/misshie/bioruby-genomic-interval}
34
34
  s.licenses = ["MIT"]
35
35
  s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.6.2}
36
+ s.rubygems_version = %q{1.3.7}
37
37
  s.summary = %q{a BioRuby plugin: handling genomic interavals and overlaps}
38
38
  s.test_files = [
39
39
  "spec/bio-genomic-interval_spec.rb",
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
  ]
42
42
 
43
43
  if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
45
  s.specification_version = 3
45
46
 
46
47
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -1,12 +1,14 @@
1
1
  module Bio
2
2
 
3
3
  #
4
- # =a class for manupirate genomic intervals such as "chr1:123-456"
4
+ # a class for manupirate genomic intervals such as "chr1:123-456"
5
5
  #
6
6
  class GenomicInterval
7
7
  # a default value to determine the adjacent/very near distance in bp
8
8
  DEFAULT_ADJACENT = 20
9
9
 
10
+ attr_accessor :chrom, :chr_start, :chr_end, :adjacent
11
+
10
12
  def initialize(chrom = "", chr_start = 1, chr_end = 1)
11
13
  raise ArgumentError unless chr_start >= 1
12
14
  raise ArgumentError unless chr_end >= 1
@@ -17,12 +19,8 @@ module Bio
17
19
  @adjacent = DEFAULT_ADJACENT
18
20
  end
19
21
 
20
- attr_accessor :chrom, :chr_start, :chr_end, :adjacent
21
-
22
- #
23
22
  # generate an interval object from a string expressing
24
23
  # one-based full-closed interval such as "chr1:123-456"
25
- #
26
24
  def self.parse(interval)
27
25
  chrom, start_end = interval.split(":")
28
26
  str_start, str_end = start_end.split("-")[0..1]
@@ -33,45 +31,36 @@ module Bio
33
31
  chr_end, chr_start = chr_start, chr_end
34
32
  end
35
33
  self.new(chrom, chr_start, chr_end)
36
- end
34
+ end
37
35
 
38
- #
39
36
  # generate an interval object from three atguments expressing
40
37
  # zero-based half-closed interval such as "chr1", 122, 456
41
- #
42
38
  def self.zero_based(chrom = "", z_start = 0, z_end = 1)
39
+ z_end += 1 if (z_start == z_end)
43
40
  z_start += 1
44
41
  self.new(chrom, z_start, z_end)
45
42
  end
46
43
 
47
- #
48
44
  # returns one-based full-closed interval such as "chr1:123-456"
49
- #
50
45
  def to_s
51
46
  "#{@chrom}:#{@chr_start}-#{@chr_end}"
52
47
  end
53
48
 
54
- #
55
49
  # returns zero-based half-closed start position
56
- #
57
50
  def zero_start
58
51
  @chr_start - 1
59
52
  end
60
53
 
61
- #
62
54
  # returns zero-based half-closed end position
63
- #
64
55
  def zero_end
65
56
  @chr_end
66
57
  end
67
58
 
68
- #
69
59
  # returns one of the followings:
70
60
  # :different_chrom, :left_adjacent, :right_adjacent
71
61
  # :left_off, :right_off, :equal
72
- # :contained, :containing, :left_overlapped, :right_overlapped
62
+ # :contained_by, :contains, :left_overlapped, :right_overlapped
73
63
  # Imagine that the receiver object is fixed on a number line
74
- #
75
64
  def compare(other)
76
65
  case
77
66
  when self.chrom != other.chrom
@@ -89,10 +78,10 @@ module Bio
89
78
  :equal
90
79
  when (other.chr_start.between?(self.chr_start, self.chr_end)) &&
91
80
  (other.chr_end.between?(self.chr_start, self.chr_end))
92
- :contained
81
+ :contained_by
93
82
  when (self.chr_start.between?(other.chr_start, other.chr_end)) &&
94
83
  (self.chr_end.between?(other.chr_start, other.chr_end))
95
- :containing
84
+ :contains
96
85
  when (other.chr_start < self.chr_start) &&
97
86
  (other.chr_end.between?(self.chr_start, self.chr_end))
98
87
  :left_overlapped
@@ -107,13 +96,13 @@ module Bio
107
96
  def nearly_overlapped?(other)
108
97
  result = compare(other)
109
98
  [ :left_adjacent, :right_adjacent,
110
- :equal, :contained, :containing,
99
+ :equal, :contained_by, :contains,
111
100
  :left_overlapped, :right_overlapped].any?{|x| x == result}
112
101
  end
113
102
 
114
103
  def overlapped?(other)
115
104
  result = compare(other)
116
- [ :equal, :contained, :containing,
105
+ [ :equal, :contained_by, :contains,
117
106
  :left_overlapped, :right_overlapped].any?{|x| x == result}
118
107
  end
119
108
 
@@ -137,16 +126,15 @@ module Bio
137
126
 
138
127
  # * When a overlap exist, return a positive integers (>1) for the overlap length.
139
128
  # * When a overlap does not exist, return a zero or a negative (<= 0) for the space size between the intervals.
140
- #
141
- def overlap(other)
129
+ def overlap(other)
142
130
  case self.compare(other)
143
131
  when :different_chrom
144
132
  0
145
133
  when :left_off, :left_adjacent, :left_overlapped
146
134
  other.chr_end - self.chr_start + 1
147
- when :contained, :equal
135
+ when :contained_by, :equal
148
136
  other.size
149
- when :containing
137
+ when :contains
150
138
  self.size
151
139
  when :right_off, :right_adjacent, :right_overlapped
152
140
  self.chr_end - other.chr_start + 1
@@ -154,5 +142,7 @@ module Bio
154
142
  raise Exception, "must not happen"
155
143
  end
156
144
  end
157
- end
158
- end
145
+
146
+ end # class GenomicInterval
147
+
148
+ end # module Bio
@@ -60,6 +60,15 @@ describe "Bio::GenomicInterval" do
60
60
  end
61
61
  end
62
62
 
63
+ describe ".zero_based" do
64
+ context 'given ("chr1", 100, 100) <e.g. insertion position>' do
65
+ it 'represents "chr1:101-101" by the to_s method' do
66
+ Bio::GenomicInterval.zero_based("chr1", 100, 100).to_s.should == "chr1:101-101"
67
+ end
68
+ end
69
+ end
70
+
71
+
63
72
  #
64
73
  # instance methods
65
74
  #
@@ -123,26 +132,26 @@ describe "Bio::GenomicInterval" do
123
132
  end
124
133
 
125
134
  context 'given "chr1:450-550"' do
126
- it 'returns :contained' do
135
+ it 'returns :contained_by' do
127
136
  receiver = Bio::GenomicInterval.parse("chr1:400-600")
128
137
  subject = Bio::GenomicInterval.parse("chr1:450-550")
129
- receiver.compare(subject).should == :contained
138
+ receiver.compare(subject).should == :contained_by
130
139
  end
131
140
  end
132
141
 
133
142
  context 'given "chr1:400-400" (size == 1)' do
134
- it 'returns :contained' do
143
+ it 'returns :contained_by' do
135
144
  receiver = Bio::GenomicInterval.parse("chr1:400-600")
136
145
  subject = Bio::GenomicInterval.parse("chr1:400-400")
137
- receiver.compare(subject).should == :contained
146
+ receiver.compare(subject).should == :contained_by
138
147
  end
139
148
  end
140
149
 
141
150
  context 'given "chr1:300-700"' do
142
- it 'returns :containing' do
151
+ it 'returns :contains' do
143
152
  receiver = Bio::GenomicInterval.parse("chr1:400-600")
144
153
  subject = Bio::GenomicInterval.parse("chr1:300-700")
145
- receiver.compare(subject).should == :containing
154
+ receiver.compare(subject).should == :contains
146
155
  end
147
156
  end
148
157
 
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-genomic-interval
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 1
9
- - 0
10
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Hiroyuki Mishima
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-04-07 00:00:00 +09:00
17
+ date: 2011-04-18 00:00:00 +09:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -25,7 +24,6 @@ dependencies:
25
24
  requirements:
26
25
  - - ~>
27
26
  - !ruby/object:Gem::Version
28
- hash: 3
29
27
  segments:
30
28
  - 2
31
29
  - 3
@@ -41,7 +39,6 @@ dependencies:
41
39
  requirements:
42
40
  - - ~>
43
41
  - !ruby/object:Gem::Version
44
- hash: 23
45
42
  segments:
46
43
  - 1
47
44
  - 0
@@ -57,7 +54,6 @@ dependencies:
57
54
  requirements:
58
55
  - - ~>
59
56
  - !ruby/object:Gem::Version
60
- hash: 7
61
57
  segments:
62
58
  - 1
63
59
  - 5
@@ -73,7 +69,6 @@ dependencies:
73
69
  requirements:
74
70
  - - ">="
75
71
  - !ruby/object:Gem::Version
76
- hash: 3
77
72
  segments:
78
73
  - 0
79
74
  version: "0"
@@ -87,7 +82,6 @@ dependencies:
87
82
  requirements:
88
83
  - - ">="
89
84
  - !ruby/object:Gem::Version
90
- hash: 5
91
85
  segments:
92
86
  - 1
93
87
  - 4
@@ -96,7 +90,7 @@ dependencies:
96
90
  type: :development
97
91
  prerelease: false
98
92
  version_requirements: *id005
99
- description: "a BioRuby plugin: handling genomic intervals,such as \"chr1:123-456\", and overlaps between two intervalsrake "
93
+ description: "a BioRuby plugin: handling genomic intervals,such as \"chr1:123-456\", and overlap state between two intervals "
100
94
  email: missy@be.to
101
95
  executables: []
102
96
 
@@ -132,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
126
  requirements:
133
127
  - - ">="
134
128
  - !ruby/object:Gem::Version
135
- hash: 3
129
+ hash: 2089191038881076262
136
130
  segments:
137
131
  - 0
138
132
  version: "0"
@@ -141,14 +135,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
135
  requirements:
142
136
  - - ">="
143
137
  - !ruby/object:Gem::Version
144
- hash: 3
145
138
  segments:
146
139
  - 0
147
140
  version: "0"
148
141
  requirements: []
149
142
 
150
143
  rubyforge_project:
151
- rubygems_version: 1.6.2
144
+ rubygems_version: 1.3.7
152
145
  signing_key:
153
146
  specification_version: 3
154
147
  summary: "a BioRuby plugin: handling genomic interavals and overlaps"