From d3524a295189338df71482298e67d11587375420 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Tue, 19 Feb 2013 13:40:46 +0000 Subject: [PATCH] added provisional write sam support git-svn-id: http://biopieces.googlecode.com/svn/trunk@2093 74ccb610-7750-0410-82ae-013aeee3265d --- code_ruby/lib/maasha/sam.rb | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/code_ruby/lib/maasha/sam.rb b/code_ruby/lib/maasha/sam.rb index ba9ffb0..5ef7de5 100644 --- a/code_ruby/lib/maasha/sam.rb +++ b/code_ruby/lib/maasha/sam.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2007-2011 Martin A. Hansen. +# Copyright (C) 2007-2013 Martin A. Hansen. # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -80,16 +80,40 @@ class Sam < Filesys end if sam.has_key? :NM and sam[:NM].to_i > 0 + bp[:NM] = sam[:NM] + bp[:MD] = sam[:MD] bp[:ALIGN] = self.align_descriptors(sam) end bp end - # Class method to convert a Biopiece record - # into a SAM entry. - def self.to_sam(bp) - "FISK" # FIXME + # Class method to create a new SAM entry from a Biopiece record. + # FIXME + def self.new_bp(bp) + qname = bp[:Q_ID] + flag = 0 + rname = bp[:S_ID] + pos = bp[:S_BEG] + mapq = bp[:MAPQ] + cigar = bp[:CIGAR] + rnext = bp[:Q_ID2] || '*' + pnext = bp[:S_BEG2] || 0 + tlen = bp[:TLEN] || 0 + seq = bp[:SEQ] + qual = bp[:SCORES] || '*' + nm = "NM:i:#{bp[:NM]}" if bp[:NM] + md = "MD:Z:#{bp[:MD]}" if bp[:MD] + + flag |= FLAG_REVCOMP if bp[:STRAND] == '+' + + if qname && flag && rname && pos && mapq && cigar && rnext && pnext && tlen && seq && qual + ary = [qname, flag, rname, pos, mapq, cigar, rnext, pnext, tlen, seq, qual] + ary << nm if nm + ary << md if md + + ary.join("\t") + end end # Create alignment descriptors according to the KISS -- 2.39.2