lederhosen 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lederhosen.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lederhosen"
8
- s.version = "0.3.4"
8
+ s.version = "0.3.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Austin G. Davis-Richardson"]
@@ -12,21 +12,26 @@ module Lederhosen
12
12
  input = options[:input]
13
13
  output = options[:output]
14
14
  reads = options[:reads]
15
- samples = options[:samples]
15
+ min_samples = options[:samples]
16
16
 
17
- ohai "filtering otu file #{input} (reads = #{reads}, samples = #{samples}), saving to #{output}"
17
+ ohai "filtering otu file #{input} (reads = #{reads}, samples = #{min_samples}), saving to #{output}"
18
18
 
19
19
  ##
20
20
  # Iterate over otu table line by line.
21
21
  # Only print if cluster meets criteria
22
22
  #
23
- kept = 0
23
+ kept_clusters = 0
24
+ total_reads = 0
25
+ kept_reads = 0
26
+
27
+ out = File.open(output, 'w')
28
+
24
29
  File.open(input) do |handle|
25
30
  header = handle.gets.strip
26
31
  header = header.split(',')
27
32
  samples = header[1..-1]
28
33
 
29
- puts header.join(',')
34
+ out.puts header.join(',')
30
35
 
31
36
  handle.each do |line|
32
37
  line = line.strip.split(',')
@@ -34,13 +39,17 @@ module Lederhosen
34
39
  counts = line[1..-1].collect { |x| x.to_i }
35
40
 
36
41
  # should be the same as uc_filter
37
- if counts.reject { |x| x < reads }.length > samples
38
- puts line.join(',')
39
- kept += 1
42
+ if counts.reject { |x| x < reads }.length > min_samples
43
+ out.puts line.join(',')
44
+ kept_clusters += 1
45
+ kept_reads += counts.inject(:+)
40
46
  end
47
+ total_reads += counts.inject(:+)
41
48
  end
42
49
  end
43
- ohai "kept #{kept} clusters."
50
+
51
+ ohai "kept #{kept_reads} reads (#{kept_reads/total_reads.to_f})."
52
+ ohai "kept #{kept_clusters} clusters."
44
53
  end
45
54
 
46
55
  end
@@ -2,7 +2,7 @@ module Lederhosen
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 4
5
+ PATCH = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].join('.')
8
8
  end
data/spec/cli_spec.rb CHANGED
@@ -37,10 +37,14 @@ describe Lederhosen::CLI do
37
37
  end
38
38
 
39
39
  it 'should build OTU abundance matrices' do
40
- `./bin/lederhosen otu_table --clusters=#{$test_dir}/clusters.uc --output=#{$test_dir}/test_tables`
40
+ `./bin/lederhosen otu_table --clusters=#{$test_dir}/clusters.uc --output=#{$test_dir}/otu_table.csv`
41
41
  $?.success?.should be_true
42
42
  end
43
43
 
44
+ it 'should filter OTU abundance matrices' do
45
+ `./bin/lederhosen otu_filter --input=#{$test_dir}/otu_table.csv --output=#{$test_dir}/otu_table.filtered.csv --reads 1 --samples 1`
46
+ end
47
+
44
48
  it 'should split joined.fasta into reads for each cluster' do
45
49
  `./bin/lederhosen split --reads=#{$test_dir}/joined.fasta --clusters=#{$test_dir}/clusters.uc --out-dir=#{$test_dir}/split --min-clst-size=1`
46
50
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lederhosen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Austin G. Davis-Richardson