<commit_before>module Bio
  module Gadget
    class Fq1l < Thor
      
      desc 'nr', 'Extract non-redundant best-quality sequences, esp. for UMI'
      
      method_option :buffer_size,
                    banner: 'SIZE',
                    aliases: '-S',
                    desc: 'Use SIZE for main memory buffer'
      
      def nr
        pseq = ''
        prefix = options.prefix_coreutils
        command = <<CMD
| #{prefix}sort --parallel=`#{prefix}nproc` -r -k2,4 \
    #{options.key?('buffer_size') ? '-S '+options.buffer_size : ''}
CMD
        open(command).each do |line|
          acc, seq, tmp, qual = line.split /\t/
          if pseq != seq
            puts line.rstrip
            pseq = seq
          end
        end
      end
      
    end
  end
end
<commit_msg>add degenerated mode for fq1l:nr<commit_after>module Bio
  module Gadget
    class Fq1l < Thor
      
      desc 'nr', 'Extract non-redundant best-quality sequences, esp. for UMI'

      method_option :buffer_size,
                    banner: 'SIZE',
                    aliases: '-S',
                    desc: 'Use SIZE for main memory buffer'

      method_option :degenerated_mode,
                    aliases: '-d',
                    type: :boolean,
                    default: false,
                    desc: 'Exclude redundant and shorter sequece'
      
      def nr
        pseq = ''
        prefix = options.prefix_coreutils
        if options.degenerated_mode
          command = <<CMD
| #{prefix}sort -t '\t' --parallel=`#{prefix}nproc` -r -k2,4 \
    #{options.key?('buffer_size') ? '-S '+options.buffer_size : ''}
CMD
          open(command).each do |line|
            acc, seq, tmp, qual = line.split /\t/
            if pseq != seq
              puts line.rstrip
              pseq = seq
            end
          end
        else
          command = <<CMD
| #{prefix}sort -t '\t' --parallel=`#{prefix}nproc` -r -k2,2 \
    #{options.key?('buffer_size') ? '-S '+options.buffer_size : ''}
CMD
          pseql = 2**(0.size * 8 -2) -1
          open(command).each do |line|
            acc, seq, tmp, qual = line.split /\t/
            if seq.length >= pseq.length || !Regexp.new("^#{seq}").match(pseq).nil?
              puts line.rstrip
              pseq = seq
              pseql = pseq.length
            end
          end
        end
      end
      
    end
  end
end

{'fraction_non_alphanumeric': 0.11811685582177385, 'fraction_numerical': 0.0058848255569567045, 'mean_word_length': 1.408906882591093, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1520006', 'n_tokens_mistral': 733, 'n_tokens_neox': 718, 'n_words': 194}