taxa 0.1.0

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rubocop.yml +5 -0
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG.md +1 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +9 -0
  8. data/Gemfile.lock +50 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +42 -0
  11. data/Rakefile +12 -0
  12. data/bin/console +15 -0
  13. data/bin/setup +8 -0
  14. data/lib/taxa.rb +10 -0
  15. data/lib/taxa/open_tree_of_life/client.rb +27 -0
  16. data/lib/taxa/open_tree_of_life/label_format_helper.rb +22 -0
  17. data/lib/taxa/open_tree_of_life/studies/base.rb +26 -0
  18. data/lib/taxa/open_tree_of_life/studies/find_studies.rb +20 -0
  19. data/lib/taxa/open_tree_of_life/studies/find_trees.rb +20 -0
  20. data/lib/taxa/open_tree_of_life/studies/properties.rb +19 -0
  21. data/lib/taxa/open_tree_of_life/studies/study.rb +19 -0
  22. data/lib/taxa/open_tree_of_life/studies/tree.rb +19 -0
  23. data/lib/taxa/open_tree_of_life/taxonomy/about.rb +18 -0
  24. data/lib/taxa/open_tree_of_life/taxonomy/base.rb +26 -0
  25. data/lib/taxa/open_tree_of_life/taxonomy/mrca.rb +22 -0
  26. data/lib/taxa/open_tree_of_life/taxonomy/subtree.rb +25 -0
  27. data/lib/taxa/open_tree_of_life/taxonomy/taxon_info.rb +30 -0
  28. data/lib/taxa/open_tree_of_life/tnrs/autocomplete_name.rb +26 -0
  29. data/lib/taxa/open_tree_of_life/tnrs/base.rb +24 -0
  30. data/lib/taxa/open_tree_of_life/tnrs/contexts.rb +19 -0
  31. data/lib/taxa/open_tree_of_life/tnrs/infer_context.rb +23 -0
  32. data/lib/taxa/open_tree_of_life/tnrs/match_names.rb +32 -0
  33. data/lib/taxa/open_tree_of_life/tree_of_life/about.rb +18 -0
  34. data/lib/taxa/open_tree_of_life/tree_of_life/base.rb +30 -0
  35. data/lib/taxa/open_tree_of_life/tree_of_life/induced_subtree.rb +33 -0
  36. data/lib/taxa/open_tree_of_life/tree_of_life/mrca.rb +22 -0
  37. data/lib/taxa/open_tree_of_life/tree_of_life/node_info.rb +22 -0
  38. data/lib/taxa/open_tree_of_life/tree_of_life/subtree.rb +50 -0
  39. data/lib/taxa/version.rb +5 -0
  40. data/taxa.gemspec +32 -0
  41. metadata +127 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bc7d986ed381cdb8284eec26e8f84e85d0ef803c00faf6b4f89cd178524b099c
4
+ data.tar.gz: e6edb9b337a03a9cb3ecfb16b81022044029dcb753009fe9526dcae10e5ff21a
5
+ SHA512:
6
+ metadata.gz: c93fe05a6e816d72009f9c8178edb6d7a012fadcf309bdfee2cb37f886a1a0142a1245415eb620fadab6d057c55d3b342c5eddc0ce2e27763cac9ebfce9077fd
7
+ data.tar.gz: bf4b4afe570f496caf9b537b198223eb52a3fbc4e7cca4e36723bd019f817879f6ad0e877d647d63eff95f4dcb78acbd9b3222229b3b7e38210696efad95dcb2
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,5 @@
1
+ Metrics/MethodLength:
2
+ Max: 50
3
+
4
+ AllCops:
5
+ NewCops: enable
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1 @@
1
+ nothing yet
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at shane.sherman@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in taxa.gemspec
6
+ gemspec
7
+
8
+ gem 'minitest', '~> 5.0'
9
+ gem 'rake', '~> 12.0'
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ taxa (0.1.0)
5
+ faraday (~> 1.1)
6
+ json (~> 1.8)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.1)
12
+ faraday (1.1.0)
13
+ multipart-post (>= 1.2, < 3)
14
+ ruby2_keywords
15
+ json (1.8.6)
16
+ minitest (5.14.2)
17
+ multipart-post (2.1.1)
18
+ parallel (1.20.1)
19
+ parser (2.7.2.0)
20
+ ast (~> 2.4.1)
21
+ rainbow (3.0.0)
22
+ rake (12.3.3)
23
+ regexp_parser (2.0.0)
24
+ rexml (3.2.4)
25
+ rubocop (1.6.1)
26
+ parallel (~> 1.10)
27
+ parser (>= 2.7.1.5)
28
+ rainbow (>= 2.2.2, < 4.0)
29
+ regexp_parser (>= 1.8, < 3.0)
30
+ rexml
31
+ rubocop-ast (>= 1.2.0, < 2.0)
32
+ ruby-progressbar (~> 1.7)
33
+ unicode-display_width (>= 1.4.0, < 2.0)
34
+ rubocop-ast (1.3.0)
35
+ parser (>= 2.7.1.5)
36
+ ruby-progressbar (1.10.1)
37
+ ruby2_keywords (0.0.2)
38
+ unicode-display_width (1.7.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ minitest (~> 5.0)
45
+ rake (~> 12.0)
46
+ rubocop (~> 1.6)
47
+ taxa!
48
+
49
+ BUNDLED WITH
50
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Shane Sherman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # Taxa
2
+
3
+ Taxa allows users to search multiple taxonomic data sources. Currently only Open Tree of Life is implemented.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'taxa'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install taxa
20
+
21
+ ## Usage
22
+
23
+ client = Taxa::OpenTreeOfLife::Client.new
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ssherman/taxa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ssherman/taxa/blob/master/CODE_OF_CONDUCT.md).
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the Taxa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ssherman/taxa/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'taxa'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'taxa/version'
4
+ require_relative './taxa/open_tree_of_life/client'
5
+
6
+ module Taxa
7
+ # include OpenTreeOfLife
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './tnrs/base'
4
+ require_relative './tree_of_life/base'
5
+ require_relative './taxonomy/base'
6
+ require_relative './studies/base'
7
+ require 'faraday'
8
+
9
+ module Taxa
10
+ module OpenTreeOfLife
11
+ # API client for Open Tree of Life
12
+ class Client
13
+ attr_accessor :options
14
+ attr_reader :tnrs, :tree_of_life, :taxonomy, :studies
15
+
16
+ def initialize(**options)
17
+ @options = options
18
+
19
+ http_client = options[:http_client] || Faraday.new
20
+ @tnrs = TNRS.new(http_client)
21
+ @tree_of_life = TreeOfLife.new(http_client)
22
+ @taxonomy = Taxonomy.new(http_client)
23
+ @studies = Studies.new(http_client)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Taxa
4
+ module OpenTreeOfLife
5
+ # helper module to get label format from parameters
6
+ module LabelFormatHelper
7
+ SUBTREE_LABEL_FORMATS = %w[name id name_and_id].freeze
8
+
9
+ def get_label_format(format, **parameters)
10
+ if format == 'newick'
11
+ label_format = parameters[:label_format] || 'name_and_id'
12
+ unless SUBTREE_LABEL_FORMATS.include?(label_format)
13
+ raise ArgumentError, "label_format be one of the following #{SUBTREE_LABEL_FORMATS.join(', ')}"
14
+ end
15
+
16
+ return label_format
17
+ end
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './find_studies'
4
+ require_relative './find_trees'
5
+ require_relative './properties'
6
+ require_relative './study'
7
+ require_relative './tree'
8
+
9
+ module Taxa
10
+ module OpenTreeOfLife
11
+ # Studies api endpoints
12
+ class Studies
13
+ attr_reader :http_client
14
+
15
+ include FindStudies
16
+ include FindTrees
17
+ include Properties
18
+ include Study
19
+ include Tree
20
+
21
+ def initialize(http_client)
22
+ @http_client = http_client
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Studies
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module FindStudies
11
+ def find_studies(**parameters)
12
+ url = 'https://api.opentreeoflife.org/v3/studies/find_studies'
13
+ response = @http_client.post(url, JSON.generate(parameters),
14
+ 'Content-Type' => 'application/json')
15
+ JSON.parse(response.body)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Studies
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module FindTrees
11
+ def find_trees(**parameters)
12
+ url = 'https://api.opentreeoflife.org/v3/studies/find_trees'
13
+ response = @http_client.post(url, JSON.generate(parameters),
14
+ 'Content-Type' => 'application/json')
15
+ JSON.parse(response.body)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Studies
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module Properties
11
+ def properties
12
+ url = 'https://api.opentreeoflife.org/v3/studies/properties'
13
+ response = @http_client.post(url, nil, 'Content-Type' => 'application/json')
14
+ JSON.parse(response.body)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Studies
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module Study
11
+ def study(id)
12
+ url = "https://api.opentreeoflife.org/v3/study/#{id}"
13
+ response = @http_client.get(url, nil, 'Content-Type' => 'application/json')
14
+ JSON.parse(response.body)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Studies
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module Tree
11
+ def tree(study_id, tree_id)
12
+ url = "https://api.opentreeoflife.org/v3/study/#{study_id}/tree/#{tree_id}"
13
+ response = @http_client.get(url, nil, 'Content-Type' => 'application/json')
14
+ JSON.parse(response.body)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Taxonomy
9
+ # tree of life about api endpoint
10
+ module About
11
+ def about
12
+ response = @http_client.post('https://api.opentreeoflife.org/v3/taxonomy/about')
13
+ JSON.parse(response.body)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './about'
4
+ require_relative './taxon_info'
5
+ require_relative './mrca'
6
+ require_relative './subtree'
7
+ require_relative '../label_format_helper'
8
+
9
+ module Taxa
10
+ module OpenTreeOfLife
11
+ # Taxonomy api endpoints
12
+ class Taxonomy
13
+ include About
14
+ include TaxonInfo
15
+ include Mrca
16
+ include Subtree
17
+ include LabelFormatHelper
18
+
19
+ attr_reader :http_client
20
+
21
+ def initialize(http_client)
22
+ @http_client = http_client
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Taxonomy
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module Mrca
11
+ def mrca(ott_ids)
12
+ raise ArgumentError, 'ott_ids required' if ott_ids.nil?
13
+ raise ArgumentError, 'ott_ids expected to be an array' unless ott_ids.is_a?(Array)
14
+
15
+ url = 'https://api.opentreeoflife.org/v3/taxonomy/mrca'
16
+ response = @http_client.post(url, JSON.generate({ ott_ids: ott_ids }), 'Content-Type' => 'application/json')
17
+ JSON.parse(response.body)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Taxonomy
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module Subtree
11
+ def subtree(**parameters)
12
+ ott_id = parameters[:ott_id]
13
+ raise ArgumentError, 'ott_id required' if ott_id.nil?
14
+
15
+ label_format = get_label_format('newick', **parameters)
16
+
17
+ url = 'https://api.opentreeoflife.org/v3/taxonomy/subtree'
18
+ response = @http_client.post(url, JSON.generate({ ott_id: ott_id, label_format: label_format }),
19
+ 'Content-Type' => 'application/json')
20
+ JSON.parse(response.body)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class Taxonomy
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module TaxonInfo
11
+ def taxon_info(**parameters)
12
+ ott_id = parameters[:ott_id]
13
+ source_id = parameters[:source_id]
14
+ validate_ott_and_source_id(ott_id, source_id)
15
+
16
+ url = 'https://api.opentreeoflife.org/v3/taxonomy/taxon_info'
17
+ response = @http_client.post(url, JSON.generate(parameters), 'Content-Type' => 'application/json')
18
+ JSON.parse(response.body)
19
+ end
20
+
21
+ private
22
+
23
+ def validate_ott_and_source_id(ott_id, source_id)
24
+ raise ArgumentError, 'ott_id or source_id are required' if ott_id.nil? && source_id.nil?
25
+ raise ArgumentError, 'ott_id and source_id specified. Only 1 can be used' if !ott_id.nil? && !source_id.nil?
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TNRS
9
+ # tnrs autocomplete_name api endpoint
10
+ module AutocompleteName
11
+ def autocomplete_name(**parameters)
12
+ name = parameters[:name]
13
+ raise ArgumentError if name.nil?
14
+
15
+ context_name = parameters[:context_name]
16
+ include_suppressed = parameters[:include_suppressed]
17
+
18
+ payload = { name: name, context_name: context_name, include_suppressed: include_suppressed }.compact
19
+ url = 'https://api.opentreeoflife.org/v3/tnrs/autocomplete_name'
20
+ response = @http_client.post(url, JSON.generate(payload), 'Content-Type' => 'application/json')
21
+ JSON.parse(response.body)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './match_names'
4
+ require_relative './autocomplete_name'
5
+ require_relative './contexts'
6
+ require_relative './infer_context'
7
+
8
+ module Taxa
9
+ module OpenTreeOfLife
10
+ # TNRS api endpoints
11
+ class TNRS
12
+ include MatchNames
13
+ include AutocompleteName
14
+ include Contexts
15
+ include InferContext
16
+
17
+ attr_reader :http_client
18
+
19
+ def initialize(http_client)
20
+ @http_client = http_client
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TNRS
9
+ # tnrs contexts api endpoint
10
+ module Contexts
11
+ def contexts
12
+ url = 'https://api.opentreeoflife.org/v3/tnrs/contexts'
13
+ response = @http_client.post(url, nil, 'Content-Type' => 'application/json')
14
+ JSON.parse(response.body)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TNRS
9
+ # tnrs contexts api endpoint
10
+ module InferContext
11
+ def infer_context(**parameters)
12
+ names = parameters[:names]
13
+ raise ArgumentError if names.nil?
14
+
15
+ payload = { names: names }
16
+ url = 'https://api.opentreeoflife.org/v3/tnrs/infer_context'
17
+ response = @http_client.post(url, JSON.generate(payload), 'Content-Type' => 'application/json')
18
+ JSON.parse(response.body)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TNRS
9
+ # tnrs match_names api endpoint
10
+ module MatchNames
11
+ def match_names(**parameters)
12
+ names = parameters[:names]
13
+ raise ArgumentError if names.nil?
14
+
15
+ context_name = parameters[:context_name]
16
+ do_approximate_matching = parameters[:do_approximate_matching] || false
17
+ include_suppressed = parameters[:include_suppressed]
18
+
19
+ payload = {
20
+ names: names,
21
+ context_name: context_name,
22
+ do_approximate_matching: do_approximate_matching,
23
+ include_suppressed: include_suppressed
24
+ }
25
+ url = 'https://api.opentreeoflife.org/v3/tnrs/match_names'
26
+ response = @http_client.post(url, JSON.generate(payload), 'Content-Type' => 'application/json')
27
+ JSON.parse(response.body)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TreeOfLife
9
+ # tree of life about api endpoint
10
+ module About
11
+ def about
12
+ response = @http_client.post('https://api.opentreeoflife.org/v3/tree_of_life/about')
13
+ JSON.parse(response.body)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './about'
4
+ require_relative './node_info'
5
+ require_relative './mrca'
6
+ require_relative './subtree'
7
+ require_relative './induced_subtree'
8
+ require_relative '../label_format_helper'
9
+
10
+ module Taxa
11
+ module OpenTreeOfLife
12
+ # wraps the tree of life API from Open Tree of Life
13
+ class TreeOfLife
14
+ include About
15
+ include NodeInfo
16
+ include Mrca
17
+ include Subtree
18
+ include InducedSubtree
19
+ include LabelFormatHelper
20
+
21
+ SUBTREE_FORMATS = %w[newick arguson].freeze
22
+
23
+ attr_reader :http_client
24
+
25
+ def initialize(http_client)
26
+ @http_client = http_client
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TreeOfLife
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module InducedSubtree
11
+ def induced_subtree(**parameters)
12
+ ott_ids = parameters[:ott_ids]
13
+ node_ids = parameters[:node_ids]
14
+
15
+ validate_ott_and_node_ids(ott_ids, node_ids)
16
+
17
+ label_format = get_label_format('newick', **parameters)
18
+
19
+ payload = { node_ids: node_ids, ott_ids: ott_ids, label_format: label_format }.compact
20
+ url = 'https://api.opentreeoflife.org/v3/tree_of_life/induced_subtree'
21
+ response = @http_client.post(url, JSON.generate(payload), 'Content-Type' => 'application/json')
22
+ JSON.parse(response.body)
23
+ end
24
+
25
+ private
26
+
27
+ def validate_ott_and_node_ids(ott_ids, node_ids)
28
+ raise ArgumentError, 'ott_ids or node_ids are required' if ott_ids.nil? && node_ids.nil?
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TreeOfLife
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module Mrca
11
+ def mrca(**parameters)
12
+ valid = parameters[:ott_ids] || parameters[:node_ids]
13
+ raise ArgumentError unless valid
14
+
15
+ url = 'https://api.opentreeoflife.org/v3/tree_of_life/mrca'
16
+ response = @http_client.post(url, JSON.generate(parameters), 'Content-Type' => 'application/json')
17
+ JSON.parse(response.body)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TreeOfLife
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module NodeInfo
11
+ def node_info(**parameters)
12
+ valid = parameters[:ott_id] || parameters[:node_id] || parameters[:node_ids]
13
+ raise ArgumentError unless valid
14
+
15
+ url = 'https://api.opentreeoflife.org/v3/tree_of_life/node_info'
16
+ response = @http_client.post(url, JSON.generate(parameters), 'Content-Type' => 'application/json')
17
+ JSON.parse(response.body)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+
6
+ module Taxa
7
+ module OpenTreeOfLife
8
+ class TreeOfLife
9
+ # wrapper around the node_info tree of life endpoint for Open Tree of Life
10
+ module Subtree
11
+ def subtree(**parameters)
12
+ ott_id = parameters[:ott_id]
13
+ node_id = parameters[:node_id]
14
+
15
+ validate_ott_and_node_id(ott_id, node_id)
16
+
17
+ format = parameters[:format] || 'newick'
18
+ validate_format(format)
19
+
20
+ label_format = get_label_format(format, **parameters)
21
+
22
+ height_limit = get_height_limit(format, **parameters)
23
+ payload = { node_id: node_id, ott_id: ott_id, format: format, label_format: label_format,
24
+ height_limit: height_limit }.compact
25
+ url = 'https://api.opentreeoflife.org/v3/tree_of_life/subtree'
26
+ response = @http_client.post(url, JSON.generate(payload), 'Content-Type' => 'application/json')
27
+ JSON.parse(response.body)
28
+ end
29
+
30
+ private
31
+
32
+ def validate_ott_and_node_id(ott_id, node_id)
33
+ raise ArgumentError, 'ott_id or node_id are required' if ott_id.nil? && node_id.nil?
34
+ raise ArgumentError, 'ott_id and node_id specified. Only 1 can be specified' if !ott_id.nil? && !node_id.nil?
35
+ end
36
+
37
+ def validate_format(format)
38
+ return if SUBTREE_FORMATS.include?(format)
39
+
40
+ raise ArgumentError, "format be one of the following #{SUBTREE_FORMATS.join(', ')}"
41
+ end
42
+
43
+ def get_height_limit(format, **parameters)
44
+ height_limit = parameters[:height_limit]
45
+ (format == 'arguson' ? 3 : -1) if height_limit.nil?
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Taxa
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/taxa/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'taxa'
7
+ spec.version = Taxa::VERSION
8
+ spec.authors = ['Shane Sherman']
9
+ spec.email = ['shane.sherman@gmail.com']
10
+
11
+ spec.summary = 'Wrapper around a bunch of taxonomy databases.'
12
+ spec.description = 'Wrapper around a bunch of taxonomy databases.'
13
+ spec.homepage = 'https://github.com/ssherman/taxa'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/ssherman/taxa'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/ssherman/taxa/master/CHANGELOG.md'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+ spec.add_development_dependency 'rubocop', '~> 1.6'
30
+ spec.add_dependency 'faraday', '~> 1.1'
31
+ spec.add_dependency 'json', '~> 1.8'
32
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taxa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shane Sherman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ description: Wrapper around a bunch of taxonomy databases.
56
+ email:
57
+ - shane.sherman@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - ".travis.yml"
65
+ - CHANGELOG.md
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/taxa.rb
75
+ - lib/taxa/open_tree_of_life/client.rb
76
+ - lib/taxa/open_tree_of_life/label_format_helper.rb
77
+ - lib/taxa/open_tree_of_life/studies/base.rb
78
+ - lib/taxa/open_tree_of_life/studies/find_studies.rb
79
+ - lib/taxa/open_tree_of_life/studies/find_trees.rb
80
+ - lib/taxa/open_tree_of_life/studies/properties.rb
81
+ - lib/taxa/open_tree_of_life/studies/study.rb
82
+ - lib/taxa/open_tree_of_life/studies/tree.rb
83
+ - lib/taxa/open_tree_of_life/taxonomy/about.rb
84
+ - lib/taxa/open_tree_of_life/taxonomy/base.rb
85
+ - lib/taxa/open_tree_of_life/taxonomy/mrca.rb
86
+ - lib/taxa/open_tree_of_life/taxonomy/subtree.rb
87
+ - lib/taxa/open_tree_of_life/taxonomy/taxon_info.rb
88
+ - lib/taxa/open_tree_of_life/tnrs/autocomplete_name.rb
89
+ - lib/taxa/open_tree_of_life/tnrs/base.rb
90
+ - lib/taxa/open_tree_of_life/tnrs/contexts.rb
91
+ - lib/taxa/open_tree_of_life/tnrs/infer_context.rb
92
+ - lib/taxa/open_tree_of_life/tnrs/match_names.rb
93
+ - lib/taxa/open_tree_of_life/tree_of_life/about.rb
94
+ - lib/taxa/open_tree_of_life/tree_of_life/base.rb
95
+ - lib/taxa/open_tree_of_life/tree_of_life/induced_subtree.rb
96
+ - lib/taxa/open_tree_of_life/tree_of_life/mrca.rb
97
+ - lib/taxa/open_tree_of_life/tree_of_life/node_info.rb
98
+ - lib/taxa/open_tree_of_life/tree_of_life/subtree.rb
99
+ - lib/taxa/version.rb
100
+ - taxa.gemspec
101
+ homepage: https://github.com/ssherman/taxa
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ homepage_uri: https://github.com/ssherman/taxa
106
+ source_code_uri: https://github.com/ssherman/taxa
107
+ changelog_uri: https://github.com/ssherman/taxa/master/CHANGELOG.md
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '2.7'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.1.4
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Wrapper around a bunch of taxonomy databases.
127
+ test_files: []