Skip to content

Commit

Permalink
Fixed forward specs
Browse files Browse the repository at this point in the history
  • Loading branch information
pjotrp committed Jan 21, 2011
1 parent 138e5f8 commit 97d2d0d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
17 changes: 11 additions & 6 deletions lib/bigbio/db/emitters/orf_emitter.rb
Expand Up @@ -83,7 +83,12 @@ class ShortFrameState
def initialize seq, ntseq_pos, ntmin_size
# @seq = seq.upcase
@seq = seq
@min_size_codons = (ntmin_size/3).to_i
@min_size_codons = if ntmin_size > 3
(ntmin_size/3).to_i
else
2 # otherwise we get single STOP codons
end

@codons = FrameCodonSequence.new(seq,ntseq_pos)
@ntseq_pos = ntseq_pos # nucleotides
# @codons.track_sequence_pos = seq_pos
Expand All @@ -105,16 +110,15 @@ def get_startstop_orfs
# the first sequence is returned when incomplete. +strip_leading+
# is used to remove the shared codon with the last sequence.
#
def get_codon_orfs1 splitter_func,do_include_leftmost,do_strip_leading
def get_codon_orfs1 splitter_func,do_include_leftmost_orf,do_strip_leading_codon
orfs = split(@codons,splitter_func)
return [] if orfs.size == 0
# Drop the first sequence, if there is no match on the first position
orfs.shift if !do_include_leftmost and !splitter_func.call(orfs.first[0])
orfs.shift if !do_include_leftmost_orf and !splitter_func.call(orfs.first[0])
orfs = orfs.map { |codons|
codons = codons.shift if do_strip_leading and splitter_func.call(codons[0])
codons = codons.shift if do_strip_leading_codon and splitter_func.call(codons[0])
codons
}
orfs = orfs.find_all { | orf | orf.size > 0 }
TrackSequenceTrait.update_sequence_pos(orfs,@ntseq_pos) # nail against parent
end

Expand All @@ -135,10 +139,11 @@ def split codons, is_splitter_func
if is_splitter_func.call(c)
node.push c
size = node.size
# p node
list.push FrameCodonSequence.new(node,pos+1-size) if size > @min_size_codons
node = []
end
node.push c
node.push c # always push boundary codon
end
list
end
Expand Down
27 changes: 15 additions & 12 deletions spec/emitter_spec.rb
Expand Up @@ -44,8 +44,8 @@
it "should handle min_size" do
fr = ShortFrameState.new "atggattaaatgtaatggatttaatgtaaa",0,9
orfs = fr.get_stopstop_orfs
orfs.map{ | orf | orf.pos }.should == [ 5 ]
orfs.map{ | orf | orf.to_seq }.should == [ "TGGATTTAA"]
orfs.map{ | orf | orf.pos }.should == [ 5 ]
fr.get_startstop_orfs.should == []
end
it "should find ORFs in" do
Expand Down Expand Up @@ -147,36 +147,39 @@

it "should combine a forward frame without ORFs in first seq" do
s1 = "atggattaaatgta"
s2 = "atggatttaatgtaaa"
# ......---===xx
s2 = "atggatttaattattataaa"
# x======xxx======xxx.
fr = ShortFrameState.new s1,0,0
fr.ntseq_pos.should == 0
orfs = fr.get_stopstop_orfs
orfs.size == 0 # in codons
fr3 = FrameCodonHelpers::CreateShortFrame.create_right(fr,orfs,s2)
# p fr3
fr3.ntseq_pos.should == 9
fr3.codons.to_seq.should == "ATGTAATGGATTTAATGTAAA"
fr3.ntseq_pos.should == 0
fr3.codons.to_seq.should == "ATGGATTAAATGTAATGGATTTAATTATTATAA"
norfs = fr3.get_stopstop_orfs
orfs += norfs
orfs.map{ | orf | orf.to_seq }.should == ["ATGGATTAA", "TGGATTTAA"]
orfs.map{ | orf | orf.track_sequence_pos }.should == [0,11]
orfs = norfs
orfs.map{ | orf | orf.to_seq }.should == ["ATGTAA","TGGATTTAA","TTATTATAA"]
orfs.map{ | orf | orf.track_ntseq_pos }.should == [9,9+6,9+6+9]
end

it "should combine a forward frame without ORFs in first seq" do
s1 = "atggattaaatgta"
# ......---===xx
s2 = "atggatttaatgtaaa"
# x======xxx
fr = ShortFrameState.new s1,0,0
fr.ntseq_pos.should == 0
orfs = fr.get_stopstop_orfs
orfs.size == 0 # in codons
fr3 = FrameCodonHelpers::CreateShortFrame.create_right(fr,orfs,s2)
# p fr3
fr3.ntseq_pos.should == 9
fr3.codons.to_seq.should == "ATGTAATGGATTTAATGTAAA"
fr3.ntseq_pos.should == 0 # on the combined sequences
fr3.codons.to_seq.should == "ATGGATTAAATGTAATGGATTTAATGTAAA"
norfs = fr3.get_stopstop_orfs
orfs += norfs
orfs.map{ | orf | orf.to_seq }.should == ["ATGGATTAA", "TGGATTTAA"]
orfs.map{ | orf | orf.track_sequence_pos }.should == [0,11]
orfs.map{ | orf | orf.to_seq }.should == ["ATGTAA", "TGGATTTAA"]
orfs.map{ | orf | orf.track_ntseq_pos }.should == [9,9+6]
end

it "should combine a reverse frame" do
Expand Down

0 comments on commit 97d2d0d

Please sign in to comment.