# Class method to convert a Biopiece record
# into a SAM entry.
def self.to_sam(bp)
- "FISK"
+ "FISK" # FIXME
end
# Create alignment descriptors according to the KISS
# format description:
# http://code.google.com/p/biopieces/wiki/KissFormat
def self.align_descriptors(sam)
- offset = 0
- align = []
+ offset = 0
+ align = []
# Insertions
sam[:CIGAR].each do |len, op|
if m =~ /\d+/ # Matches
offset += m.to_i
elsif m[0] == '^' # Deletions
- 1.upto(m.size - 1).each do
- nt = sam[:SEQ].seq[offset]
-
- align << [offset, "#{nt}>-"]
-
- deletions += 1
- offset += 1
+ m.each_char do |nt|
+ unless nt == '^'
+ align << [offset, "#{nt}>-"]
+ deletions += 1
+ offset += 1
+ end
end
else # Mismatches
m.each_char do |nt|
assert_equal("SAM", Sam.to_bp(s)[:REC_TYPE])
assert_equal("ID00036734", Sam.to_bp(s)[:Q_ID])
assert_equal("-", Sam.to_bp(s)[:STRAND])
- assert_equal("gi48994873", Sam.to_bp(s)[:S_ID])
+ assert_equal("gi48994873", Sam.to_bp(s)[:S_ID])
assert_equal(366089, Sam.to_bp(s)[:S_BEG])
assert_equal(37, Sam.to_bp(s)[:MAPQ])
assert_equal("37M1I62M", Sam.to_bp(s)[:CIGAR])
assert_equal("37:->T", Sam.to_bp(s)[:ALIGN])
end
end
+
+ def test_Sam_to_bp_alignment_descriptor_without_mismatch_or_indel_returns_correctly
+ string = "q_id\t0\ts_id\t1000\t40\t10M\t*\t0\t0\tGTTCCGCTAT\t*\tXT:A:U\tNM:i:0\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:10\n"
+
+ sam = Sam.new(StringIO.new(string))
+
+ sam.each do |s|
+ assert_equal(nil, Sam.to_bp(s)[:ALIGN])
+ end
+ end
+
+ def test_Sam_to_bp_alignment_descriptor_with_mismatches_returns_correctly
+ string = "q_id\t0\ts_id\t1000\t40\t10M\t*\t0\t0\tgTTCCGCTAt\t*\tXT:A:U\tNM:i:2\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:0C8A\n"
+
+ sam = Sam.new(StringIO.new(string))
+
+ sam.each do |s|
+ assert_equal("0:C>g,9:A>t", Sam.to_bp(s)[:ALIGN])
+ end
+ end
+
+ def test_Sam_to_bp_alignment_descriptor_with_insertions_returns_correctly
+ string = "q_id\t0\ts_id\t1000\t40\t1I10M1I\t*\t0\t0\taGTTCCGCTATc\t*\tXT:A:U\tNM:i:2\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:12\n"
+
+ sam = Sam.new(StringIO.new(string))
+
+ sam.each do |s|
+ assert_equal("0:->a,11:->c", Sam.to_bp(s)[:ALIGN])
+ end
+ end
+
+ def test_Sam_to_bp_alignment_descriptor_with_deletions_returns_correctly
+ string = "q_id\t0\ts_id\t1000\t40\t2D10M\t*\t0\t0\tGTTCCGCTAT\t*\tXT:A:U\tNM:i:2\tX0:i:1\tX1:i:0\tXM:i:0\tXO:i:1\tXG:i:1\tMD:Z:^AC10\n"
+
+ sam = Sam.new(StringIO.new(string))
+
+ sam.each do |s|
+ assert_equal("0:A>-,1:C>-", Sam.to_bp(s)[:ALIGN])
+ end
+ end
end