bioinform 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72172a64bbccdcaa9557bcb4b0d42a1672f1e980
4
- data.tar.gz: f2c48539d5f1ce77f6d3c001fd7ff65291e3ee71
3
+ metadata.gz: 8a22c28659b2ef2205e84ba7dcd9778d392ec54b
4
+ data.tar.gz: f7280fc53cd3dbdd195278b9df06d91367d5baa0
5
5
  SHA512:
6
- metadata.gz: bcb7090242e539ba35c1d92388838035d5c815f7d849510ec7587db365771c02bac293894a9752b2425a0f13c7b95288597df2a7f0f3279b8f6b5cccac711d43
7
- data.tar.gz: 2577baac4b171379573597fb9b37e34d029542cdbf0a79d1e5abba1ae9a6da85a65862edcb8a79ddc78a6a3722cd5c1bebbfed04a0e1f88f67214b82898b102a
6
+ metadata.gz: 08999aa322ad4c0119a92b2e41087312afcc2747a01e2cf11a772a59e6d47d2eb30f3bb232a1dfc0400ffd363359a01b61235abafcd6e2561aba7742aba4ca56
7
+ data.tar.gz: 9a2662d63282b3362340006dea59e2da0f95869f673d4b80a9aa29433e49d0f7f85ec1464123a280b7053a6f502adeea9325f7aef9a2d73ad7b31d3c0931b26a
data/LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2012 Ilya Vorontsov
1
+ Copyright (c) 2012-2014 Ilya Vorontsov
2
+ bioinform utilizes several methods from the `activesupport` gem.
2
3
 
3
4
  MIT License
4
5
 
@@ -19,4 +20,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
20
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
21
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
22
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
data/bin/pcm2pwm CHANGED
File without changes
data/bin/split_motifs CHANGED
File without changes
@@ -20,5 +20,15 @@ module Bioinform
20
20
  def to_ppm
21
21
  ConversionAlgorithms::PCM2PPMConverter.convert(self)
22
22
  end
23
+
24
+ def self.valid_matrix?(matrix, options = {})
25
+ super && matrix.all?{|pos| pos.all?{|el| el >=0 } }
26
+ end
27
+
28
+ def validation_errors(options = {})
29
+ validation_errors = []
30
+ validation_errors << "PCM matrix should contain only non-negative elements" unless matrix.all?{|pos| pos.all?{|el| el >=0 } }
31
+ super + validation_errors
32
+ end
23
33
  end
24
34
  end
@@ -43,16 +43,20 @@ module Bioinform
43
43
  self.name = result.name
44
44
  # self.tags = result.tags || []
45
45
  self.background = result.background || [1, 1, 1, 1]
46
- raise 'matrix not valid' unless valid?
47
46
  end
48
47
 
48
+ def self.new_with_validation(input, parser = nil)
49
+ obj = self.new(input, parser)
50
+ raise 'matrix not valid' unless obj.valid?
51
+ obj
52
+ end
49
53
  def ==(other)
50
54
  @matrix == other.matrix && background == other.background && name == other.name
51
55
  rescue
52
56
  false
53
57
  end
54
58
 
55
- def self.valid_matrix?(matrix)
59
+ def self.valid_matrix?(matrix, options = {})
56
60
  matrix.is_a?(Array) &&
57
61
  ! matrix.empty? &&
58
62
  matrix.all?{|pos| pos.is_a?(Array)} &&
@@ -62,8 +66,24 @@ module Bioinform
62
66
  false
63
67
  end
64
68
 
65
- def valid?
66
- self.class.valid_matrix?(@matrix)
69
+ def validation_errors(options = {})
70
+ errors = []
71
+ if !matrix.is_a?(Array)
72
+ errors << 'Matrix is not an array'
73
+ elsif matrix.empty?
74
+ errors << 'Matrix is not an array'
75
+ elsif ! matrix.all?{|pos| pos.is_a?(Array)}
76
+ errors << 'Some of matrix positions aren\'t represented as arrays'
77
+ elsif ! matrix.all?{|pos| pos.size == 4}
78
+ errors << 'Some of matrix positions have number of columns other than 4'
79
+ elsif ! matrix.all?{|pos| pos.all?{|el| el.is_a?(Numeric)}}
80
+ errors << 'Some of matrix elements aren\'t represented by numbers'
81
+ end
82
+ errors
83
+ end
84
+
85
+ def valid?(options = {})
86
+ self.class.valid_matrix?(@matrix, options)
67
87
  end
68
88
 
69
89
  def each_position
@@ -6,5 +6,16 @@ module Bioinform
6
6
  def to_ppm
7
7
  self
8
8
  end
9
+ def self.valid_matrix?(matrix, options = {})
10
+ precision = options[:precision] || 0.01
11
+ super && matrix.all?{|pos| ((pos.inject(0, &:+) - 1.0).abs <= precision) && pos.all?{|el| el >=0 } }
12
+ end
13
+ def validation_errors(options = {})
14
+ precision = options[:precision] || 0.01
15
+ validation_errors = []
16
+ validation_errors << "PPM matrix should contain only non-negative elements" unless matrix.all?{|pos| pos.all?{|el| el >=0 } }
17
+ validation_errors << "Sum of PPM matrix elements for each position should equal to 1" unless matrix.all?{|pos| ((pos.inject(0, &:+) - 1.0).abs <= precision) }
18
+ super + validation_errors
19
+ end
9
20
  end
10
21
  end
@@ -1,3 +1,3 @@
1
1
  module Bioinform
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bioinform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Vorontsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-16 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  requirements: []
182
182
  rubyforge_project:
183
- rubygems_version: 2.1.11
183
+ rubygems_version: 2.2.1
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Classes for work with different input formats of positional matrices and