-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from unipept/migrated/pr-35/feature/add-tests
Add tests and improve code style
- Loading branch information
Showing
56 changed files
with
2,843 additions
and
917 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.