Sha256: df74084f00847016bc89532942b1942db8f3ccbc0c970b2d6852d6e3578a24e4

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

#!/usr/bin/env ruby
require 'cri'

Signal.trap("PIPE", "EXIT")
Signal.trap("INT", "EXIT")
root_cmd = Cri::Command.new_basic_root.modify do
  name 'peptfilter'
  flag :i, :unique, "only output unique peptides"
  required :l, :minlen, "minimum length (default: 5)"
  required :u, :maxlen, "minimum length (default: 50)"
  required :a, :lacks, "a string whose letters represent amino acids that may not occur in the peptide"
  required :c, :contains, "a string whose letters represent amino acids that must all occur in the peptide"
  run do |opts, args, cmd|
    minlen = opts.fetch(:minlen, "5").to_i
    maxlen = opts.fetch(:maxlen, "50").to_i
    lacks = opts.fetch(:lacks, "").chars.to_a
    contains = opts.fetch(:contains, "").chars.to_a
    $stdin.each_line do |pept|
      # FASTA headers
      if pept.start_with? '>'
        puts pept
        next
      end
      pept = pept.chomp
      length_ok = pept.length >= minlen && pept.length <= maxlen
      lacks_ok = (pept.chars.to_a & lacks).size == 0
      contains_ok = (pept.chars.to_a & contains).size == contains.size

      if length_ok && lacks_ok && contains_ok
        puts pept
      end
    end
  end
end

root_cmd.run(ARGV)

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
unipept-0.6.4 bin/peptfilter
unipept-0.6.2 bin/peptfilter
unipept-0.6.1 bin/peptfilter
unipept-0.5.7 bin/peptfilter
unipept-0.5.6 bin/peptfilter
unipept-0.5.5 bin/peptfilter
unipept-0.5.4 bin/peptfilter
unipept-0.5.3 bin/peptfilter
unipept-0.5.2 bin/peptfilter
unipept-0.5.1 bin/peptfilter
unipept-0.5.0 bin/peptfilter