Skip to content

Commit

Permalink
Codon alignment test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjotrp committed Mar 4, 2012
1 parent ce3abff commit 860bb2d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/bio-alignment/column.rb
Expand Up @@ -22,11 +22,12 @@ def num_columns
rows.first.length
end

# Return an alignment which match columns
# Return an alignment which match columns. The originating
# sequences should have methods 'empty_copy' and '<<'
def columns_where &block
seqs = []
rows.each do | seq |
new_seq = Sequence.new(seq.id,"")
new_seq = seq.empty_copy
seq.each_with_index do | e,i |
new_seq << e if block.call(columns[i])
end
Expand Down
4 changes: 4 additions & 0 deletions lib/bio-alignment/sequence.rb
Expand Up @@ -45,6 +45,10 @@ def to_s
def << element
@seq += element.to_s
end

def empty_copy
Sequence.new(@id,"")
end
end
end
end
6 changes: 4 additions & 2 deletions spec/bio-alignment_spec.rb
Expand Up @@ -84,10 +84,12 @@
columns2.count { |e| e.state.deleted? }.should == 6
aln2.columns[0].state.should == columns2[0].state
aln2.columns[0].state.should_not == columns[0].state
aln3.rows.first.to_s.should == "SNSFSRPTIIFSGCSTACSGKSELVCGFRSFMLSDV"

aln2.rows.first.to_s.should == "----SNSFSRPTIIFSGCSTACSGK--SELVCGFRSFMLSDV"
# now write out the alignment with deleted columns removed
aln3 = aln2.columns_where { |col| !col.state.deleted? }
print aln3.to_s,"\n"
aln3.rows.first.to_s.should == "SNSFSRPTIIFSGCSTACSGKSELVCGFRSFMLSDV"

# We are going to do the same for a codon alignment
test == false
end

0 comments on commit 860bb2d

Please sign in to comment.