Skip to content

Commit

Permalink
corrects tests and DB comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Feb 4, 2016
1 parent 5139817 commit 07e32a3
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 24 deletions.
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--color
--require spec_helper
10 changes: 9 additions & 1 deletion rakefile.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
require 'byebug'

require 'rake/testtask'
require 'rake/clean'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = Dir.glob('test/**/test_*.rb')
t.pattern = Dir.glob('test/test_*.rb')
t.rspec_opts = '--format documentation'
# t.rspec_opts << ' more options'
end

RSpec::Core::RakeTask.new(:'spec:db') do |t|
t.pattern = Dir.glob('test/test_results_db.rb')
t.rspec_opts = '--format documentation'
# t.rspec_opts << ' more options'
end
Expand Down
16 changes: 13 additions & 3 deletions src/results_db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def row
end

def <=>(other)
(identity <=> other.identity &&
coverage <=> other.coverage &&
evalue <=> other.evalue)
(identity <=> other.identity).nonzero? ||
(coverage <=> other.coverage).nonzero? ||
(evalue <=> other.evalue).nonzero? ||
0
end

def [](key)
Expand Down Expand Up @@ -80,6 +81,10 @@ def initialize(identity_min, identity_max, output_dir, logger = nil)
@logger.progname = 'ResultDB'
end

def [](key)
db[key]
end

def values
@db.values.sort_by do |line|
[line['file'], line['pident'], line['qcovs'], line['sseqid']]
Expand Down Expand Up @@ -125,13 +130,18 @@ def add(db_id, new_row)
write_deleted new_row
return false
end
if db_id.nil?
db_id = size + 1
end
# set current row as existing one
cur_row = db[db_id]
# initialize best row as nil, to be assigned in the
# next if clause
best_row = nil
# check if there is a element in @db with the 'db_id'
if cur_row
#require 'byebug'
#byebug
# add to redundant array the worst element
old_row = if new_row > cur_row
best_row = new_row
Expand Down
2 changes: 1 addition & 1 deletion test/test_blastn.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'spec_helper'
require_relative 'test_helper'
require_relative 'blast_helpers'

RSpec.configure do |c|
Expand Down
File renamed without changes.
83 changes: 66 additions & 17 deletions test/test_results_db.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'spec_helper'
require_relative 'test_helper'
require_relative '../src/results_db'
require 'logger'

Expand All @@ -15,25 +15,29 @@
}
end

create_db = proc do |min = 40, max = 100|
ResultsDB.new min, max, './'
end

#
#
it 'should add all elements' do
results = ResultsDB.new 40
results = create_db.call(40)
#
results.add(1, create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
results.add(2, create_el.call('50', '40', '10E-20', 'aab', 'blackberry'))
results.add(3, create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
results.add(nil, create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
results.add(nil, create_el.call('50', '40', '10E-20', 'aab', 'blackberry'))
results.add(nil, create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))

expect(results.size).to eq(3)
end

it 'should prune duplicate qseq elements' do
results = ResultsDB.new 40
results = create_db.call(40)
#
results.add(1, create_el.call('30', '40', '10E-20', 'aaa', 'blackberry'))
results.add(2, create_el.call('50', '40', '10E-20', 'aab', 'blackberry'))
results.add(3, create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
results.add(4, create_el.call('70', '40', '10E-20', 'aaa', 'blackberry'))
results.add(nil, create_el.call('30', '40', '10E-20', 'aaa', 'blackberry'))
results.add(nil, create_el.call('50', '40', '10E-20', 'aab', 'blackberry'))
results.add(nil, create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
results.add(nil, create_el.call('70', '40', '10E-20', 'aaa', 'blackberry'))

results.remove_identical('qseq')

Expand All @@ -42,23 +46,68 @@

#
it 'should prune duplicate qseq elements and use the database' do
results = ResultsDB.new 40
results = create_db.call(40)
#
results.add(1, create_el.call('30', '40', '10E-20', 'aaa', 'blackberry'))
results.add(2, create_el.call('50', '40', '10E-20', 'aab', 'blackberry'))
results.add(3, create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
results.add(4, create_el.call('70', '40', '10E-20', 'aaa', 'blackberry'))
results.add(5, create_el.call('70', '40', '10E-20', 'aaa', 'bilberry'))
results.add(nil, create_el.call('30', '40', '10E-20', 'aaa', 'blackberry'))
results.add(nil, create_el.call('50', '40', '10E-20', 'aab', 'blackberry'))
results.add(nil, create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
results.add(nil, create_el.call('70', '40', '10E-20', 'aaa', 'blackberry'))
results.add(nil, create_el.call('70', '40', '10E-20', 'aaa', 'bilberry'))

results.remove_identical('qseq')

expect(results.size).to eq(3)
end

it 'should compare well between DB items' do
db1 = DB.new \
create_el.call('30', '40', '10E-20', 'aaa', 'blackberry')
db2 = DB.new \
create_el.call('40', '40', '10E-20', 'aaa', 'blackberry')

expect(db1).to be < db2

db1 = DB.new \
create_el.call('30', '50', '10E-20', 'aaa', 'blackberry')
db2 = DB.new \
create_el.call('30', '40', '10E-20', 'aaa', 'blackberry')

expect(db1).to be > db2

db1 = DB.new \
create_el.call('30', '40', '0', 'aaa', 'blackberry')
db2 = DB.new \
create_el.call('30', '40', '10E-20', 'aaa', 'blackberry')

expect(db1).to be < db2

db1 = DB.new \
create_el.call('30', '40', '10E-20', 'aaa', 'blackberry')
db2 = DB.new \
create_el.call('30', '40', '10E-20', 'aaa', 'blackberry')

expect(db1).to eq(db2)
end

#
#
it 'should only take the best one' do
results = create_db.call(40)
#
results.add('i', create_el.call('30', '40', '10E-20', 'aaa', 'blackberry'))
results.add('i', create_el.call('50', '40', '10E-20', 'aab', 'blackberry'))
results.add('i', create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
results.add('i', create_el.call('70', '40', '10E-20', 'aaa', 'blackberry'))
#
expect(results.size).to eq(1)
expect(results['i'].identity).to eq(70)
#
end

#
#
it 'should add only elements with different id' do
results = ResultsDB.new 40
results = create_db.call(40)
#
results.add('1', create_el.call('50', '40', '10E-20', 'aaa', 'blackberry'))
#
Expand Down
2 changes: 1 addition & 1 deletion test/test_tblastx.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_relative 'spec_helper'
require_relative 'test_helper'
require_relative 'blast_helpers'

RSpec.configure do |c|
Expand Down

0 comments on commit 07e32a3

Please sign in to comment.