-
Notifications
You must be signed in to change notification settings - Fork 2
/
fastarecord.rb
41 lines (36 loc) · 919 Bytes
/
fastarecord.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class FastaRecord
attr_accessor :id, :descr, :seq
def initialize id, descr, seq
@id = id
@descr = descr
@seq = seq
end
end
class FastaPairedRecord
attr_reader :nt, :aa
def initialize nt, aa
@nt = nt
@aa = aa
raise "ID error NT #{nt.id} not matching AA #{aa.id}" if nt.id != aa.id
if nt.seq.size == aa.seq.size*3-1
# account for EMBOSS cleverness
nt.seq.chop!
nt.seq.chop!
aa.seq.chop!
end
if nt.seq.size == aa.seq.size*3-2
# account for EMBOSS cleverness
nt.seq.chop!
aa.seq.chop!
end
if nt.seq.size == aa.seq.size*3-3
aa.seq.chop!
end
nt_size = nt.seq.size
expected_size = aa.seq.size*3
# raise "Sequence size mismatch for #{nt.id} <nt:#{nt.seq.size} != #{aa.seq.size*3} (aa:#{aa.seq.size}*3)>" if expected_size - 3 > nt_size and nt_size > expected_size + 3
end
def id
@aa.id
end
end