bioinform 0.1.16 → 0.1.17
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 792006e928db4e7ce443f56f93b94e9f5cbc2e95
|
4
|
+
data.tar.gz: f7f4f25e156071fee5f242cc50ecdcd80741b596
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d0c1b14cba03745ecdf19b14579533489619f22f584e3fda64a77b4d72ba0998930b8239ceb5212b0d09ca6aa88879abc29057354cd8b4650ae35dab5845a7e
|
7
|
+
data.tar.gz: 8e0a3b680e4e5ef765697abd6c0c449dc303ea75c1d886aef4c01a4a34f38a67008ac9bf2dc4f173ba0f7a3cd769cd22424670689fa727946bcc15767a5689ed
|
@@ -23,7 +23,7 @@ module Bioinform
|
|
23
23
|
# end
|
24
24
|
|
25
25
|
def self.choose_parser(input)
|
26
|
-
[TrivialParser, YAMLParser, Parser, StringParser, StringFantomParser, JasparParser, TrivialCollectionParser, YAMLCollectionParser].find do |parser|
|
26
|
+
[TrivialParser, YAMLParser, Parser, StringParser, Bioinform::MatrixParser.new(has_name: false).wrapper, Bioinform::MatrixParser.new(has_name: true).wrapper, StringFantomParser, JasparParser, TrivialCollectionParser, YAMLCollectionParser].find do |parser|
|
27
27
|
self.new(input, parser) rescue nil
|
28
28
|
end
|
29
29
|
end
|
@@ -40,6 +40,7 @@ module Bioinform
|
|
40
40
|
raise 'No one parser can process input' unless parser
|
41
41
|
result = parser.new(input).parse
|
42
42
|
@matrix = result.matrix
|
43
|
+
raise 'Non valid matrix' unless self.class.valid_matrix?(@matrix)
|
43
44
|
self.name = result.name
|
44
45
|
# self.tags = result.tags || []
|
45
46
|
self.background = result.background || [1, 1, 1, 1]
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module Bioinform
|
2
4
|
class MatrixParser
|
3
5
|
def initialize(options = {})
|
@@ -24,7 +26,7 @@ module Bioinform
|
|
24
26
|
|
25
27
|
matrix = matrix.transpose if @nucleotides_in == :rows
|
26
28
|
# raise 'Matrix not valid' unless ! matrix.empty? && matrix.all?{|pos| pos.size == 4 }
|
27
|
-
|
29
|
+
OpenStruct.new(matrix: matrix, name: name)
|
28
30
|
end
|
29
31
|
|
30
32
|
def parse(input)
|
@@ -36,5 +38,28 @@ module Bioinform
|
|
36
38
|
rescue
|
37
39
|
false
|
38
40
|
end
|
41
|
+
|
42
|
+
class TemporaryWrapper
|
43
|
+
attr_reader :input
|
44
|
+
include Bioinform::Parser::ClassMethods
|
45
|
+
include Bioinform::Parser::SingleMotifParser::ClassMethods
|
46
|
+
def initialize(parser)
|
47
|
+
@parser, input = parser, input
|
48
|
+
end
|
49
|
+
def parse
|
50
|
+
@parser.parse(@input)
|
51
|
+
end
|
52
|
+
def parse!
|
53
|
+
@parser.parse!(@input)
|
54
|
+
end
|
55
|
+
def new(input)
|
56
|
+
@input = input
|
57
|
+
self
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def wrapper
|
62
|
+
TemporaryWrapper.new(self)
|
63
|
+
end
|
39
64
|
end
|
40
65
|
end
|
@@ -33,56 +33,60 @@ module Bioinform
|
|
33
33
|
parse! rescue nil
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
module ClassMethods
|
37
|
+
def choose(input, data_model = PM)
|
38
|
+
data_model.choose_parser(input).new(input)
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
def parse!(*input)
|
42
|
+
new(*input).parse!
|
43
|
+
end
|
44
|
+
def parse(*input)
|
45
|
+
new(*input).parse
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
def valid_matrix?(matrix)
|
49
|
+
PM.valid_matrix?(matrix)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
# {A: 1, C: 2, G: 3, T: 4} --> [1,2,3,4]
|
53
|
+
# {A: [1,2], C: [3,4], G: [5,6], T: [7,8]} --> [[1,3,5,7],[2,4,6,8]] ( == [[1,2], [3,4], [5,6], [7,8]].transpose)
|
54
|
+
def array_from_acgt_hash(hsh)
|
55
|
+
hsh = normalize_hash_keys(hsh)
|
56
|
+
raise 'some of hash keys A,C,G,T are missing or hash has excess keys' unless hsh.keys.sort == [:A,:C,:G,:T]
|
57
|
+
result = [:A,:C,:G,:T].collect{|letter| hsh[letter] }
|
58
|
+
result.all?{|el| el.is_a?(Array)} ? result.transpose : result
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
# {a: 1, C: 2, 'g' => 3, 'T' => 4} --> {A: 1, C: 2, G: 3, T: 4}
|
62
|
+
def normalize_hash_keys(hsh)
|
63
|
+
hsh.collect_hash{|key,value| [key.to_s.upcase.to_sym, value] }
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
# [[1,2,3,4], [2,3,4,5]] --> [[1,2,3,4], [2,3,4,5]]
|
67
|
+
# [{A:1, C:2, G:3, T:4}, {A:2, C:3, G:4, T:5}] --> [{A:1, C:2, G:3, T:4}, {A:2, C:3, G:4, T:5}]
|
68
|
+
# {:A => [1,2,3], :c => [2,3,4], 'g' => [3,4,5], 'T' => [4,5,6]} --> [[1,2,3],[2,3,4],[3,4,5],[4,5,6]].transpose
|
69
|
+
def try_convert_to_array(input)
|
70
|
+
case input
|
71
|
+
when Array then input
|
72
|
+
when Hash then array_from_acgt_hash(input)
|
73
|
+
else raise TypeError, 'input of Bioinform::Parser::array_from_acgt_hash should be Array or Hash'
|
74
|
+
end
|
73
75
|
end
|
74
|
-
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
def transform_input(input)
|
78
|
+
result = try_convert_to_array(input).map{|el| try_convert_to_array(el)}
|
79
|
+
need_tranpose?(result) ? result.transpose : result
|
80
|
+
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
# point whether matrix input positions(need not be transposed -- false) or letters(need -- true) as first index
|
83
|
+
# [[1,3,5,7], [2,4,6,8]] --> false
|
84
|
+
# [[1,2],[3,4],[5,6],[7,8]] --> true
|
85
|
+
def need_tranpose?(input)
|
86
|
+
(input.size == 4) && input.any?{|x| x.size != 4}
|
87
|
+
end
|
86
88
|
end
|
89
|
+
|
90
|
+
extend ClassMethods
|
87
91
|
end
|
88
92
|
end
|
data/lib/bioinform/version.rb
CHANGED
data/spec/data_models/pm_spec.rb
CHANGED
@@ -3,15 +3,15 @@ require_relative '../../lib/bioinform/data_models/pm'
|
|
3
3
|
|
4
4
|
module Bioinform
|
5
5
|
describe PM do
|
6
|
-
{:as_pcm => PCM, :as_pwm => PWM, :as_ppm => PPM}.each do |converter_method, result_klass|
|
6
|
+
{:as_pcm => [PCM, [[1,10,3,4],[5,6,7,0]]], :as_pwm => [PWM, [[1,2,3,4],[5,6,7,8]]], :as_ppm => [PPM, [[0.1,0.2,0.3,0.4],[0.5,0.1,0.3,0.1]]]}.each do |converter_method, (result_klass, matrix)|
|
7
7
|
describe "##{converter_method}" do
|
8
8
|
before :each do
|
9
9
|
@collection = Collection.new(name: 'Collection 1')
|
10
|
-
@matrix =
|
10
|
+
@matrix = matrix
|
11
11
|
@name = 'PM_motif'
|
12
12
|
@background = [0.2,0.3,0.3,0.2]
|
13
13
|
@tags = [@collection, 'Collection 2']
|
14
|
-
@pm = PM.new(matrix:
|
14
|
+
@pm = PM.new(matrix: matrix, name: @name, background: @background, tags: @tags)
|
15
15
|
@conv_motif = @pm.send converter_method
|
16
16
|
end
|
17
17
|
it "should return an instance of #{result_klass}" do
|
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.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Vorontsov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docopt
|