lederhosen 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
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 = "1.2.5"
8
+ s.version = "1.3.0"
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"]
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  "spec/data/ILT_L_9_B_002_3.txt.gz",
46
46
  "spec/data/test.uc",
47
47
  "spec/misc_spec.rb",
48
+ "spec/no_tasks_spec.rb",
48
49
  "spec/spec_helper.rb"
49
50
  ]
50
51
  s.homepage = "http://audy.github.com/lederhosen"
@@ -23,9 +23,61 @@ module Lederhosen
23
23
  { :identity => identity }.merge(taxonomies)
24
24
  end
25
25
 
26
+ # detect whether the taxonomy is one of the following
27
+ # possible formats:
28
+ #
29
+ # - :taxcollector
30
+ # - :greengenes
31
+ #
32
+ def detect_taxonomy_format(taxonomy)
33
+ # greengenes has a number as the first item in the header
34
+ # so let's just go with that
35
+ if taxonomy.split.first =~ /^[\d*]/
36
+ :greengenes
37
+ else
38
+ :taxcollector
39
+ end
40
+ end
41
+
42
+ def parse_taxonomy(taxonomy)
43
+ format = detect_taxonomy_format(taxonomy)
44
+
45
+ case format
46
+ when :greengenes
47
+ parse_taxonomy_greengenes(taxonomy)
48
+ when :taxcollector
49
+ parse_taxonomy_taxcollector(taxonomy)
50
+ else
51
+ fail 'unknown format!'
52
+ end
53
+ end
54
+
55
+ def parse_taxonomy_greengenes(taxonomy)
56
+
57
+ levels = { 'domain' => /k__(\w*)/,
58
+ 'kingdom' => /k__(\w*)/,
59
+ 'phylum' => /p__(\w*)/,
60
+ 'class' => /c__(\w*)/,
61
+ 'order' => /o__(\w*)/,
62
+ 'family' => /f__(\w*)/,
63
+ 'genus' => /g__(\w*)/,
64
+ 'species' => /s__(\w*)/
65
+ }
66
+
67
+ names = Hash.new
68
+
69
+ levels.each_pair do |level, regexp|
70
+ names[level] = taxonomy.match(regexp)[1] rescue nil
71
+ end
72
+
73
+ names['original'] = taxonomy
74
+
75
+ names
76
+ end
77
+
26
78
  # parse a taxonomic description using the
27
79
  # taxcollector format returning name at each level (genus, etc...)
28
- def parse_taxonomy(taxonomy)
80
+ def parse_taxonomy_taxcollector(taxonomy)
29
81
 
30
82
  levels = { 'domain' => 0,
31
83
  'kingdom' => 0,
@@ -44,7 +96,7 @@ module Lederhosen
44
96
  end
45
97
 
46
98
  # keep original taxonomic description
47
- names[:original] = taxonomy
99
+ names['original'] = taxonomy
48
100
 
49
101
  names
50
102
  end
@@ -26,7 +26,7 @@ module Lederhosen
26
26
  pbar.inc
27
27
  handle.each do |line|
28
28
  header = parse_usearch_line(line.strip)
29
- taxa << header[:original] rescue nil
29
+ taxa << header['original'] rescue nil
30
30
  end
31
31
  end
32
32
  end
@@ -1,9 +1,9 @@
1
1
  module Lederhosen
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 2
5
- CODENAME = 'Regenmantel' # changes for minor versions
6
- PATCH = 5
4
+ MINOR = 3
5
+ CODENAME = 'Dirndl' # changes for minor versions
6
+ PATCH = 0
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH].join('.')
9
9
  end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ lederhosen = Lederhosen::CLI.new
4
+
5
+ describe 'no_tasks' do
6
+
7
+ let(:greengenes_taxonomy) { '124 U55236.1 Methanobrevibacter thaueri str. CW k__Archaea; p__Euryarchaeota; c__Methanobacteria; o__Methanobacteriales; f__Methanobacteriaceae; g__Methanobrevibacter; Unclassified; otu_127' }
8
+ let(:taxcollector_taxonomy) { '[0]Bacteria;[1]Actinobacteria;[2]Actinobacteria;[3]null;[4]null;[5]null;[6]bacterium_TH3;[7]bacterium_TH3;[8]bacterium_TH3|M79434|8 ' }
9
+
10
+ it '#detect_taxonomy_format should recognize GreenGenes' do
11
+ lederhosen.detect_taxonomy_format(greengenes_taxonomy).should == :greengenes
12
+ end
13
+
14
+ it '#detect_taxonomy_format should recognize TaxCollector' do
15
+ lederhosen.detect_taxonomy_format(taxcollector_taxonomy).should == :taxcollector
16
+ end
17
+
18
+ it '#detect_taxonomy_format should fail on unknown formats' do
19
+ lederhosen.detect_taxonomy_format('this is not a taxonomic description').should raise_error
20
+ end
21
+
22
+ it '#parse_taxonomy_taxcollector should parse taxcollector taxonomy' do
23
+ taxonomy = lederhosen.parse_taxonomy_taxcollector(taxcollector_taxonomy)
24
+ taxonomy['original'].should == taxcollector_taxonomy
25
+
26
+ levels = %w{domain phylum class order family genus species kingdom original}
27
+
28
+ taxonomy.keys.each do |v|
29
+ levels.should include v
30
+ end
31
+ end
32
+
33
+ it '#parse_taxonomy_greengenes should parse greengenes taxonomy' do
34
+ taxonomy = lederhosen.parse_taxonomy_greengenes(greengenes_taxonomy)
35
+ levels = %w{domain phylum class order family genus species kingdom original}
36
+
37
+ taxonomy.keys.each do |v|
38
+ levels.should include v
39
+ end
40
+ end
41
+
42
+ it '#parse_taxonomy should automatically detect and parse greengenes taxonomy' do
43
+ lederhosen.parse_taxonomy(greengenes_taxonomy).should_not be_nil
44
+ end
45
+
46
+ it '#parse_taxonomy should automatically detect and parse taxcollector taxonomy' do
47
+ lederhosen.parse_taxonomy(taxcollector_taxonomy).should_not be_nil
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lederhosen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -143,6 +143,7 @@ files:
143
143
  - spec/data/ILT_L_9_B_002_3.txt.gz
144
144
  - spec/data/test.uc
145
145
  - spec/misc_spec.rb
146
+ - spec/no_tasks_spec.rb
146
147
  - spec/spec_helper.rb
147
148
  homepage: http://audy.github.com/lederhosen
148
149
  licenses:
@@ -159,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
160
  version: '0'
160
161
  segments:
161
162
  - 0
162
- hash: -656727926212445001
163
+ hash: -3539547832258076669
163
164
  required_rubygems_version: !ruby/object:Gem::Requirement
164
165
  none: false
165
166
  requirements: