Permalink
Browse files

Bridges in codon sequence

  • Loading branch information...
1 parent d2a04c5 commit ba8a433c5bb86a7979e6c35da4d4cc994d6f6450 @pjotrp committed Mar 5, 2012
Showing with 31 additions and 8 deletions.
  1. +7 −7 doc/bio-alignment-design.md
  2. +8 −0 lib/bio-alignment/codonsequence.rb
  3. +16 −1 spec/bio-alignment_spec.rb
@@ -70,7 +70,7 @@ acid with
print codons.seq[0].to_aa
```
-in fact, because Sequence is indexable we can write directly
+in fact, because Sequence is index-able we can write directly
```ruby
print codons[0].to_aa # 'M'
@@ -155,7 +155,7 @@ named del_bridges:
```
in other words, the functionality in DelBridges gets attached to the
-aln instance at run time, without affecting any other instatiated
+aln instance at run time, without affecting any other instantiated
object(!) Also, when not requiring 'bio-alignment/edit/del_bridges',
the functionality is never visible, and never added to the
environment. This type of runtime plugin is something you can only do
@@ -165,12 +165,12 @@ Note: if we wanted only to allow one plugin per instance at a time, we can
create a generic interface with a method of the same name for every
plugged in module.
-## Methods returning alignments
+## Methods returning alignments and concurrency
When an alignment gets changed, e.g. by one of the editing modules, the
-original is copied using the 'clone' method. The idea is never to share
-data. Ruby does not have immutable data, so the only safe way to write
-concurrent code is to copy all data that changes. The 'clone' methods
-implemented in the Alignment class are 'deep' clones.
+original is copied using the 'clone' method. The idea is never to share data in
+this library. Ruby does not really have guaranteed immutable data, so the only
+safe way to write concurrent code is to copy all data before changing. The
+'clone' methods implemented in the Alignment class are 'deep' clones.
Copyright (C) 2012 Pjotr Prins <pjotr.prins@thebird.nl>
@@ -95,6 +95,14 @@ def to_nt
def to_aa
@seq.map { |codon| codon.to_aa }.join('')
end
+
+ def empty_copy
+ CodonSequence.new(@id,"")
+ end
+
+ def << codon
+ @seq << codon
+ end
end
@@ -89,7 +89,22 @@
aln3 = aln2.columns_where { |col| !col.state.deleted? }
print aln3.to_s,"\n"
aln3.rows.first.to_s.should == "SNSFSRPTIIFSGCSTACSGKSELVCGFRSFMLSDV"
+end
+describe "BioAlignment::DelBridges for codons" do
# We are going to do the same for a codon alignment
- test == false
+ aln = Alignment.new
+ fasta = FastaReader.new('test/data/fasta/codon/codon-alignment.fa')
+ fasta.each do | rec |
+ aln.sequences << CodonSequence.new(rec.id, rec.seq)
+ end
+ aln.extend DelBridges
+ aln2 = aln.mark_bridges
+ # print aln2[0].to_s,"\n"
+ aln2.columns.size.should == 404
+ # count deleted columns
+ aln2.columns.count { |col| col.state.deleted? }.should == 5
+ # create new alignment
+ aln3 = aln2.columns_where { |col| !col.state.deleted? }
+ aln3.columns.size.should == 399
end

0 comments on commit ba8a433

Please sign in to comment.