seq = fields[9]
qual = fields[10]
- raise SamError, "Bad qname: #{qname}" unless qname =~ /^[!-?A-~]{1,255}$/
- raise SamError, "Bad flag: #{flag}" unless (0 .. 2**16 - 1).include? flag
- raise SamError, "Bad rname: #{rname}" unless rname =~ /^(\*|[!-()+-<>-~][!-~]*)$/
- raise SamError, "Bad pos: #{pos}" unless (0 .. 2**29 - 1).include? pos
- raise SamError, "Bad mapq: #{mapq}" unless (0 .. 2**8 - 1).include? mapq
- raise SamError, "Bad cigar: #{cigar}" unless cigar =~ /^(\*|([0-9]+[MIDNSHPX=])+)$/
- raise SamError, "Bad rnext: #{rnext}" unless rnext =~ /^(\*|=|[!-()+-<>-~][!-~]*)$/
- raise SamError, "Bad pnext: #{pnext}" unless (0 .. 2**29 - 1).include? pnext
- raise SamError, "Bad tlen: #{tlen}" unless (-2**29 + 1 .. 2**29 - 1).include? tlen
- raise SamError, "Bad seq: #{seq}" unless seq =~ /^(\*|[A-Za-z=.]+)$/
- raise SamError, "Bad qual: #{qual}" unless qual =~ /^[!-~]+$/
-
+ check_qname(qname)
+ check_flag(flag)
check_rname(rname)
+ check_pos(pos)
+ check_mapq(mapq)
+ check_cigar(cigar)
+ check_rnext(rnext)
+ check_pnext(pnext)
+ check_tlen(tlen)
+ check_seq(seq)
+ check_qual(qual)
entry = {}
entry[:QNAME] = qname
entry[:RNEXT] = rnext
entry[:PNEXT] = pnext
entry[:TLEN] = tlen
- entry[:SEQ] = seq
+ entry[:SEQ] = Seq.new(qname, seq)
entry[:QUAL] = qual
entry
end
+ # Method to check qname.
+ def check_qname(qname)
+ raise SamError, "Bad qname: #{qname}" unless qname =~ /^[!-?A-~]{1,255}$/
+ end
+
+ # Method to check flag.
+ def check_flag(flag)
+ raise SamError, "Bad flag: #{flag}" unless (0 .. 2**16 - 1).include? flag
+ end
+
# Method to check if rname, when not '*' and
# @SQ header lines are present, is located in
# the header hash.
def check_rname(rname)
+ raise SamError, "Bad rname: #{rname}" unless rname =~ /^(\*|[!-()+-<>-~][!-~]*)$/
+
unless @header.empty? or rname == '*'
unless @header[:SQ][:SN].has_key? rname.to_sym
raise SamError, "rname not found in header hash: #{rname}"
end
end
+ # Method to check pos.
+ def check_pos(pos)
+ raise SamError, "Bad pos: #{pos}" unless (0 .. 2**29 - 1).include? pos
+ end
+
+ # Method to check mapq.
+ def check_mapq(mapq)
+ raise SamError, "Bad mapq: #{mapq}" unless (0 .. 2**8 - 1).include? mapq
+ end
+
+ # Method to check cigar.
+ def check_cigar(cigar)
+ raise SamError, "Bad cigar: #{cigar}" unless cigar =~ /^(\*|([0-9]+[MIDNSHPX=])+)$/
+ end
+
# Method to check if rnext, when not '*' or '='
# and @SQ header lines are present, is located
# in the header hash.
def check_rnext(rnext)
+ raise SamError, "Bad rnext: #{rnext}" unless rnext =~ /^(\*|=|[!-()+-<>-~][!-~]*)$/
+
unless @header.empty? or rnext == '*' or rnext == '='
unless @header[:SQ][:SN].has_key? rnext.to_sym
raise SamError, "rnext not found in header hash: #{rnext}"
end
end
end
+
+ # Method to check pnext.
+ def check_pnext(pnext)
+ raise SamError, "Bad pnext: #{pnext}" unless (0 .. 2**29 - 1).include? pnext
+ end
+
+ # Method to check tlen.
+ def check_tlen(tlen)
+ raise SamError, "Bad tlen: #{tlen}" unless (-2**29 + 1 .. 2**29 - 1).include? tlen
+ end
+
+ # Method to check seq.
+ def check_seq(seq)
+ raise SamError, "Bad seq: #{seq}" unless seq =~ /^(\*|[A-Za-z=.]+)$/
+ end
+
+ # Method to check qual.
+ def check_qual(qual)
+ raise SamError, "Bad qual: #{qual}" unless qual =~ /^[!-~]+$/
+ end
end