Skip to content

Commit

Permalink
Reverse seq
Browse files Browse the repository at this point in the history
  • Loading branch information
pjotrp committed Jan 21, 2011
1 parent 97d2d0d commit 3cd6f2b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
26 changes: 22 additions & 4 deletions lib/bigbio/db/emitters/orf_emitter.rb
Expand Up @@ -34,6 +34,21 @@ def CreateShortFrame.create_right fr,orfs,rseq
nseq = seq[remove..-1] + rseq
ShortFrameState.new nseq,ntseq_pos,fr.min_size_codons*3
end

def CreateShortFrame.create_left fr,orfs,lseq
seq = fr.seq # original sequence
ntseq_pos = fr.ntseq_pos # right side of seq
bridge = seq.size % 3 # chomp left side
remove = if orfs.size > 0
# remove the tail of the sequence
seq.size - bridge - (orfs.first.pos)*3 +1
else
0
end
ntseq_pos += remove
nseq = lseq + seq[0..(seq.size-remove)]
ShortFrameState.new nseq,ntseq_pos,fr.min_size_codons*3
end
end

class FrameCodonSequence
Expand Down Expand Up @@ -150,13 +165,16 @@ def split codons, is_splitter_func

end

# This is the reversed version, which is rather the same as the forward,
# though the tracked ntseq_pos should be seen from the end of the sequence,
# as we are emmiting sequences from the end(!) Also we need to make sure
# the sequence is always in frame (from the left).
class ShortReversedFrameState < ShortFrameState

def initialize seq, ntseq_pos, ntmin_size
chop = seq.size % 3
@chopped_seq = seq[0..chop-1] if chop
seq = seq[chop..-1]
super seq,ntseq_pos,ntmin_size
chop = seq.size % 3 # align on codons
super seq[chop..-1],ntseq_pos,ntmin_size
@seq = seq # but record full seq
end

end
Expand Down
18 changes: 11 additions & 7 deletions spec/emitter_spec.rb
Expand Up @@ -183,22 +183,26 @@
end

it "should combine a reverse frame" do
s1 = "atggattaaatgta"
s2 = "tatttaaatggatttaatgtaaatt"
# ~===xxx============---...
s1 = "atggattaaatgta"
# ......xxx=====
# now move the other way, as sequences get emitted on the left
fr = ShortReversedFrameState.new s2,0,0
# p fr
fr.codons.to_seq.should == "ATTTAAATGGATTTAATGTAAATT"
fr.ntseq_pos.should == 0
orfs = fr.get_stopstop_orfs
# p orfs
orfs.map{ | orf | orf.to_seq }.should == ["ATGGATTTAATGTAA"]
orfs.first.pos.should == 2 # in codons
fr3 = FrameCodonHelpers::CreateShortFrame.create_right(fr,orfs,s2)
fr3.ntseq_pos.should == 9
fr3.codons.to_seq.should == "ATGTAATGGATTTAATGTAAA"
fr3 = FrameCodonHelpers::CreateShortFrame.create_left(fr,orfs,s1)
fr3.ntseq_pos.should == 19
fr3.codons.to_seq.should == "ATGGATTAAATGTATATTTAA"
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]
p orfs
orfs.map{ | orf | orf.to_seq }.should == ["ATGGATTTAATGTAA", "ATGTATATTTAA"]
orfs.map{ | orf | orf.track_ntseq_pos }.should == [18,18+12]
end

end
Expand Down

0 comments on commit 3cd6f2b

Please sign in to comment.