bio-alignment 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -41,6 +41,19 @@ aligmment (note codon gaps are represented by '---')
41
41
  end
42
42
  ```
43
43
 
44
+ ### BioRuby Sequence objects
45
+
46
+ The BioAlignment supports BioRuby's Bio::Sequence objects:
47
+
48
+ ```ruby
49
+ require 'bio' # BioRuby
50
+ require 'bio-alignment/bioruby' # make Bio::Sequence enumerable
51
+
52
+ aln = Alignment.new
53
+ aln << Bio::Sequence::NA.new("atgcatgcaaaa")
54
+ aln << Bio::Sequence::NA.new("atg---tcaaaa")
55
+ ```
56
+
44
57
  ### Pal2nal
45
58
 
46
59
  A protein (amino acid) to nucleotide alignment would first load
@@ -82,16 +95,18 @@ Write a (simple) version of pal2nal would be something like
82
95
  end
83
96
  ```
84
97
 
85
- With amino acid aln1 and nucleotide aln2 loaded, the library version is the shorter
98
+ With amino acid aln1 and nucleotide aln2 loaded, the library version
99
+ includes validation, and is the shorter command
86
100
 
87
101
  ```ruby
88
- aln3 = aln1.pal2nal(aln2)
102
+ aln3 = aln1.pal2nal(aln2, :codon_table => 3)
89
103
  ```
90
104
 
91
- aln3 containing the codon alignment.
105
+ resulting in the codon alignment.
92
106
 
93
- The API documentation is online. For more code examples see ./spec/*.rb and
94
- ./features/*
107
+ The API documentation is online. For more code examples see
108
+ [./spec/*.rb](https://github.com/pjotrp/bioruby-alignment/tree/master/spec) and
109
+ [./features/*](https://github.com/pjotrp/bioruby-alignment/tree/master/features).
95
110
 
96
111
  ## Cite
97
112
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -0,0 +1,80 @@
1
+ require 'bio' # yes, we use BioRuby here
2
+
3
+ $: << 'lib'
4
+
5
+ require 'bio-alignment/bioruby'
6
+
7
+ Given /^I have multiple Bio::Sequence objects$/ do
8
+ @list = []
9
+ # Read a Fasta file
10
+ fasta = Bio::FlatFile.open(Bio::FastaFormat, 'test/data/fasta/codon/codon-alignment.fa')
11
+ fasta.each_entry do |f|
12
+ naseq = f.naseq
13
+ # test we can index the sequence
14
+ ['a','-'].index(naseq[0]).should_not be nil
15
+ @list << naseq # inject Bio::Sequence object
16
+ end
17
+ end
18
+
19
+ When /^I assign BioAlignment$/ do
20
+ @aln = Alignment.new
21
+ end
22
+
23
+ Then /^it should accept the objects$/ do
24
+ @list.each do | bioruby_naseq |
25
+ @aln.sequences << bioruby_naseq
26
+ end
27
+ end
28
+
29
+ Then /^and return a partial sequence$/ do
30
+ @aln.rows[0][0..8].should == 'atgcccact'
31
+ end
32
+
33
+ Then /^be indexable$/ do
34
+ @aln.rows[0][0].should == 'a'
35
+ end
36
+
37
+ # ---
38
+
39
+ Given /^I have multiple Bio::Sequence::AA objects$/ do
40
+ @aalist = []
41
+ # Read a Fasta file
42
+ fasta = Bio::FlatFile.open(Bio::FastaFormat, 'test/data/fasta/codon/aa-alignment.fa')
43
+ fasta.each_entry do |f|
44
+ aaseq = f.aaseq
45
+ @aalist << aaseq # inject Bio::Sequence object
46
+ end
47
+ end
48
+
49
+ When /^I assign BioAlignment for AA$/ do
50
+ @aa_aln = Alignment.new
51
+ end
52
+
53
+ Then /^it should accept the Bio::Sequence::AA objects$/ do
54
+ @aalist.each do | bioruby_aaseq |
55
+ @aa_aln.sequences << bioruby_aaseq
56
+ end
57
+ end
58
+
59
+ Then /^and return a partial AA sequence$/ do
60
+ @aa_aln.rows[0][0..8].should == 'MPTRLDIVG'
61
+ end
62
+
63
+ Then /^be AA indexable$/ do
64
+ @aa_aln.rows[0][0].should == 'M'
65
+ end
66
+
67
+ # ----
68
+
69
+ Given /^I have a BioAlignment$/ do
70
+ pending # express the regexp above with the code you wish you had
71
+ end
72
+
73
+ When /^I convert$/ do
74
+ pending # express the regexp above with the code you wish you had
75
+ end
76
+
77
+ Then /^I should have a Bio::Alignment$/ do
78
+ pending # express the regexp above with the code you wish you had
79
+ end
80
+
@@ -0,0 +1,23 @@
1
+ Feature: BioAlignment should play with BioRuby
2
+ In order to use BioRuby functionality
3
+ I want to convert BioAlignment to Bio::Alignment
4
+ And I want to support Bio::Sequence objects
5
+
6
+ Scenario: Use Bio::Sequence to fill BioAlignment
7
+ Given I have multiple Bio::Sequence objects
8
+ When I assign BioAlignment
9
+ Then it should accept the objects
10
+ And and return a partial sequence
11
+ And be indexable
12
+
13
+ Scenario: Use Bio::Sequence to fill BioAlignment with AA
14
+ Given I have multiple Bio::Sequence::AA objects
15
+ When I assign BioAlignment for AA
16
+ Then it should accept the Bio::Sequence::AA objects
17
+ And and return a partial AA sequence
18
+ And be AA indexable
19
+
20
+ Scenario: Convert BioAlignment to Bio::Alignment
21
+ Given I have a BioAlignment
22
+ When I convert
23
+ Then I should have a Bio::Alignment
@@ -3,6 +3,7 @@
3
3
  require 'bio-alignment/pal2nal'
4
4
 
5
5
  module Bio
6
+
6
7
  module BioAlignment
7
8
 
8
9
  class Alignment
@@ -17,6 +18,10 @@ module Bio
17
18
 
18
19
  alias rows sequences
19
20
 
21
+ # def [] index <- need matrix
22
+ # rows[index]
23
+ # end
24
+
20
25
  def each
21
26
  rows.each { | seq | yield seq }
22
27
  end
@@ -0,0 +1,22 @@
1
+ module Bio
2
+ # Here we override BioRuby Sequence classes, so they are enumerable
3
+ class Sequence
4
+ class NA
5
+ include Enumerable
6
+ def each
7
+ to_s.each_byte do | c |
8
+ yield c
9
+ end
10
+ end
11
+ end
12
+ class AA
13
+ include Enumerable
14
+ def each
15
+ to_s.each_byte do | c |
16
+ yield c
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -3,14 +3,14 @@
3
3
  module Bio
4
4
  module BioAlignment
5
5
  module Pal2Nal
6
- def pal2nal nt_aln
6
+ def pal2nal nt_aln, options = { :codon_table => 1 }
7
7
  aa_aln = self
8
8
  codon_aln = Alignment.new
9
9
  aa_aln.each_with_index do | aaseq, i |
10
10
  ntseq = nt_aln.sequences[i]
11
11
  raise "pal2nal sequence IDs do not match (for #{aaseq.id} != #{ntseq.id})" if aaseq.id != ntseq.id
12
12
  raise "pal2nal sequence size does not match (for #{aaseq.id}'s #{aaseq.to_s.size}!= #{ntseq.to_s.size * 3})" if aaseq.id != ntseq.id
13
- codonseq = CodonSequence.new(ntseq.id, ntseq.seq)
13
+ codonseq = CodonSequence.new(ntseq.id, ntseq.seq, options)
14
14
 
15
15
  codon_pos = 0
16
16
  result = []
@@ -26,7 +26,7 @@ module Bio
26
26
  codon.to_s
27
27
  end
28
28
  end
29
- codon_seq = CodonSequence.new(aaseq.id, result.join(''))
29
+ codon_seq = CodonSequence.new(aaseq.id, result.join(''), options)
30
30
  codon_aln.sequences << codon_seq
31
31
  end
32
32
  codon_aln
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-alignment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-04 00:00:00.000000000Z
12
+ date: 2012-02-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bio-logger
16
- requirement: &23657180 !ruby/object:Gem::Requirement
16
+ requirement: &16310560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *23657180
24
+ version_requirements: *16310560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bio
27
- requirement: &23655840 !ruby/object:Gem::Requirement
27
+ requirement: &16309720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.4.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *23655840
35
+ version_requirements: *16309720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bio-bigbio
38
- requirement: &23654620 !ruby/object:Gem::Requirement
38
+ requirement: &16309060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>'
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.1.3
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *23654620
46
+ version_requirements: *16309060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: cucumber
49
- requirement: &23653020 !ruby/object:Gem::Requirement
49
+ requirement: &16308000 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *23653020
57
+ version_requirements: *16308000
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &23651800 !ruby/object:Gem::Requirement
60
+ requirement: &16306500 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.3.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *23651800
68
+ version_requirements: *16306500
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
- requirement: &23650920 !ruby/object:Gem::Requirement
71
+ requirement: &16305460 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *23650920
79
+ version_requirements: *16305460
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: jeweler
82
- requirement: &23650280 !ruby/object:Gem::Requirement
82
+ requirement: &16304680 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 1.7.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *23650280
90
+ version_requirements: *16304680
91
91
  description: Alignment handler for multiple sequence alignments (MSA)
92
92
  email: pjotr.public01@thebird.nl
93
93
  executables:
@@ -106,12 +106,15 @@ files:
106
106
  - VERSION
107
107
  - bin/bio-alignment
108
108
  - doc/bio-alignment-design.md
109
+ - features/bioruby-feature.rb
110
+ - features/bioruby.feature
109
111
  - features/codon-feature.rb
110
112
  - features/codon.feature
111
113
  - features/pal2nal-feature.rb
112
114
  - features/pal2nal.feature
113
115
  - lib/bio-alignment.rb
114
116
  - lib/bio-alignment/alignment.rb
117
+ - lib/bio-alignment/bioruby.rb
115
118
  - lib/bio-alignment/codonsequence.rb
116
119
  - lib/bio-alignment/pal2nal.rb
117
120
  - lib/bio-alignment/sequence.rb
@@ -138,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
141
  version: '0'
139
142
  segments:
140
143
  - 0
141
- hash: -3154039158347420524
144
+ hash: -237499918493109825
142
145
  required_rubygems_version: !ruby/object:Gem::Requirement
143
146
  none: false
144
147
  requirements: