- if record.has_key? :SEQ
- seq = Seq.new(nil, record[:SEQ])
-
- record[:HOMOPOL_MAX] = seq.homopol_max(options[:min])
+ if record[:SEQ]
+ seq = Seq.new(seq: record[:SEQ])
+
+ longest = Seq::Homopolymer.new("", 0, 0)
+ got_one = false
+ count = 0
+
+ seq.each_homopolymer(options[:min]) do |h|
+ got_one = true
+
+ record[:HOMOPOL_PAT] = h.pattern
+ record[:HOMOPOL_LEN] = h.length
+ record[:HOMOPOL_POS] = h.pos
+
+ if options[:longest]
+ longest = h.length > longest.length ? h : longest
+ else
+ output.puts record
+
+ count += 1
+
+ break if options[:limit] and options[:limit] == count
+ end
+ end
+
+ if options[:longest]
+ if longest.length > options[:min]
+ record[:HOMOPOL_PAT] = longest.pattern
+ record[:HOMOPOL_LEN] = longest.length
+ record[:HOMOPOL_POS] = longest.pos
+ end
+
+ output.puts record
+ elsif not got_one
+ output.puts record
+ end
+ else
+ output.puts record