Skip to content

Commit

Permalink
Merge pull request #35 from unipept/migrated/pr-35/feature/add-tests
Browse files Browse the repository at this point in the history
Add tests and improve code style
  • Loading branch information
bmesuere committed Aug 14, 2019
2 parents dd28150 + a31d570 commit 91e9eb1
Show file tree
Hide file tree
Showing 56 changed files with 2,843 additions and 917 deletions.
26 changes: 26 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
AllCops:
Include:
-
Exclude:
- 'unipept.gemspec'
- 'vendor/**/*'

Style/ClassAndModuleChildren:
EnforcedStyle: compact
Enabled: false

# disable for now
Style/ClassVars:
Enabled: false
Style/Documentation:
Enabled: false
Style/RescueModifier:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Enabled: false
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: ruby
rvm:
- 2.2.2
- 2.1.6
- 2.0.0
- 1.9.3
- jruby-19mode
18 changes: 8 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
source "http://rubygems.org"
source 'http://rubygems.org'
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"

gem "cri", "~> 2.7"
gem "typhoeus", "~> 0.6"
gem 'cri', '~> 2.7'
gem 'typhoeus', '~> 0.6'

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", "~> 3.5"
gem "rdoc", "~> 3.12"
gem "bundler", "~> 1.0"
gem "jeweler", "~> 2.0"
gem "simplecov", "~> 0.8"
gem 'rake'
gem 'minitest'
gem 'rubocop'
gem 'jeweler'
gem 'coveralls', require: false
end
56 changes: 35 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
GEM
remote: http://rubygems.org/
specs:
activesupport (4.2.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
ast (2.0.0)
astrolabe (1.3.0)
parser (>= 2.2.0.pre.3, < 3.0)
builder (3.2.2)
colored (1.2)
coveralls (0.7.1)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
cri (2.7.0)
colored (~> 1.2)
descendants_tracker (0.0.4)
Expand All @@ -31,7 +34,6 @@ GEM
oauth2
hashie (3.4.1)
highline (1.7.2)
i18n (0.7.0)
jeweler (2.0.1)
builder
bundler (>= 1.0)
Expand All @@ -43,11 +45,13 @@ GEM
rdoc
json (1.8.2)
jwt (1.4.1)
mime-types (2.4.3)
mini_portile (0.6.2)
minitest (5.6.1)
multi_json (1.11.0)
multi_xml (0.5.5)
multipart-post (2.0.0)
netrc (0.9.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oauth2 (1.0.0)
Expand All @@ -56,35 +60,45 @@ GEM
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
parser (2.2.0.2)
ast (>= 1.1, < 3.0)
powerpack (0.0.9)
rack (1.6.0)
rainbow (2.0.0)
rake (10.4.2)
rdoc (3.12.2)
rdoc (4.2.0)
json (~> 1.4)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.1)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
rest-client (1.7.2)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rubocop (0.28.0)
astrolabe (~> 1.3)
parser (>= 2.2.0.pre.7, < 3.0)
powerpack (~> 0.0.6)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.1)
simplecov (0.10.0)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
term-ansicolor (1.3.0)
tins (~> 1.0)
thor (0.19.1)
thread_safe (0.3.5)
tins (1.3.3)
typhoeus (0.7.1)
ethon (>= 0.7.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.0)
coveralls
cri (~> 2.7)
jeweler (~> 2.0)
rdoc (~> 3.12)
shoulda (~> 3.5)
simplecov (~> 0.8)
jeweler
minitest
rake
rubocop
typhoeus (~> 0.6)
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# unipept-cli

[![Code Climate](https://codeclimate.com/github/unipept/unipept-cli/badges/gpa.svg)](https://codeclimate.com/github/unipept/unipept-cli)
[![Gem Version](https://badge.fury.io/rb/unipept.svg)](http://badge.fury.io/rb/unipept)
[![Build Status](https://api.travis-ci.org/unipept/unipept-cli.svg)](https://travis-ci.org/unipept/unipept-cli)
[![Coverage Status](https://coveralls.io/repos/unipept/unipept-cli/badge.svg)](https://coveralls.io/r/unipept/unipept-cli)
[![Code Climate](https://codeclimate.com/github/unipept/unipept-cli/badges/gpa.svg)](https://codeclimate.com/github/unipept/unipept-cli)

Unipept-cli offers a command line interface to the [Unipept](http://unipept.ugent.be) web service.
Documentation about the web service can be found at [http://unipept.ugent.be/apidocs](http://unipept.ugent.be/apidocs).
Expand Down
21 changes: 11 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ rescue Bundler::BundlerError => e
exit e.status_code
end
require 'rake'
require 'rake/testtask'
require 'rubocop/rake_task'

require 'jeweler'
Jeweler::Tasks.new do |gem|
Expand All @@ -30,19 +32,18 @@ Jeweler::Tasks.new do |gem|
end
Jeweler::RubygemsDotOrgTasks.new

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
task :test_unit do
require './test/helper.rb'

desc 'Code coverage detail'
task :simplecov do
ENV['COVERAGE'] = 'true'
Rake::Task['test'].execute
FileList['./test/**/test_*.rb', './test/**/*_spec.rb'].each do |fn|
require fn
end
end

RuboCop::RakeTask.new(:test_style)

task test: [:test_unit, :test_style]

task default: :test

require 'rdoc/task'
Expand Down
46 changes: 2 additions & 44 deletions bin/peptfilter
Original file line number Diff line number Diff line change
@@ -1,49 +1,7 @@
#!/usr/bin/env ruby
require 'cri'
require_relative '../lib/commands'

Signal.trap('PIPE', 'EXIT')
Signal.trap('INT', 'EXIT')
root_cmd = Cri::Command.new_basic_root.modify do
name 'peptfilter'
summary 'Filter peptides based on specific criteria.'
usage 'peptfilter [options]'
description <<-EOS
The peptfilter command filters a list of peptides according to specific criteria. The command expects a list of peptides that are passed

- as separate command line arguments
- in one or more text files that are passed as an argument to the -i option
- to standard input
The command will give priority to the first way peptides are passed, in the order as listed above. Text files and standard input should have one peptide per line. FASTA headers are preserved in the output, so that peptides remain bundled.
EOS
# flag :u, :unique, "filter duplicate peptides."
required nil, :minlen, 'only retain tryptic peptides that have at least min (default: 5) amino acids.'
required nil, :maxlen, 'only retain tryptic peptides that have at most max (default: 50) amino acids.'
required :l, :lacks, 'only retain tryptic peptides that lack all amino acids from the string of residues.'
required :c, :contains, 'only retain tryptic peptides that contain all amino acids from the string of residues.'
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)
Unipept::Commands::Peptfilter.run(ARGV)
53 changes: 4 additions & 49 deletions bin/prot2pept
Original file line number Diff line number Diff line change
@@ -1,52 +1,7 @@
#!/usr/bin/env ruby
require 'cri'
require_relative '../lib/commands'

Signal.trap("PIPE", "EXIT")
Signal.trap("INT", "EXIT")
root_cmd = Cri::Command.new_basic_root.modify do
name 'prot2pept'
summary 'Split protein sequences into peptides.'
usage 'prot2pept [options]'
description <<-EOS
The prot2pept command splits each protein sequence into a list of peptides according to a given cleavage-pattern. The command expects a list of protein sequences that are passed
Signal.trap('PIPE', 'EXIT')
Signal.trap('INT', 'EXIT')

- as separate command line arguments
- in one or more text files that are passed as an argument to the -i option
- to standard input
The command will give priority to the first way protein sequences are passed, in the order as listed above. Text files and standard input should have either one protein sequence per line or contain a FASTA formatted list of protein sequences. FASTA headers are preserved in the output, so that peptides can be bundled per protein sequence.
EOS
required :p, :pattern, 'specify cleavage-pattern (regex) as the pattern after which the next peptide will be cleaved (default: ([KR])([^P]) for tryptic peptides).'
run do |opts, args, cmd|
pattern = opts.fetch(:pattern, "([KR])([^P])")
# decide if we have FASTA input
fasta_header = $stdin.gets
if fasta_header.start_with? '>'
# fasta input, need to join lines
while !$stdin.eof?
prot = ""
# Sometimes you just got to accept this weird and ugly code
until $stdin.eof? || (line = gets).start_with?('>')
prot += line.chomp
end
puts fasta_header
puts prot.gsub(/#{pattern}/,"\\1\n\\2").gsub(/#{pattern}/, "\\1\n\\2").split("\n").reject(&:empty?)

fasta_header = line
end
else
# handle our already read line
puts fasta_header.gsub(/#{pattern}/,"\\1\n\\2").gsub(/#{pattern}/, "\\1\n\\2").split("\n").reject(&:empty?)

# we no longer have to join lines as input is now more sane
$stdin.each_line do |prot|
puts prot.gsub(/#{pattern}/,"\\1\n\\2").gsub(/#{pattern}/, "\\1\n\\2").split("\n").reject(&:empty?)
end
end
end
end

root_cmd.run(ARGV)
Unipept::Commands::Prot2pept.run(ARGV)

0 comments on commit 91e9eb1

Please sign in to comment.