Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the OBO Foundry synchronization script #79

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ config/*.p12
config/*.json
data/
projectFilesBackup/
.bundle
.ruby-version
repo*
*.turtle
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ PATH
specs:
ncbo_cron (0.0.1)
dante
faraday (~> 2)
faraday-follow_redirects (~> 0)
goo
google-analytics-data
mlanett-redis-lock
Expand Down Expand Up @@ -98,6 +100,8 @@ GEM
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-net_http (3.0.2)
faraday-retry (2.2.1)
faraday (~> 2.0)
Expand Down
71 changes: 19 additions & 52 deletions lib/ncbo_cron/obofoundry_sync.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
require 'base64'
require 'json'
require 'net/http'
require 'uri'
require 'faraday'
require 'faraday/follow_redirects'
require 'multi_json'

module NcboCron
module Models
class OBOFoundrySync

def initialize
@logger = Logger.new(STDOUT)
@oauth_token = Base64.decode64(NcboCron.settings.git_repo_access_token)
@graphql_uri = URI.parse("https://api.github.com/graphql")
@request_options = { use_ssl: @graphql_uri.scheme == "https" }
end

def run
# Get a map of OBO ID spaces to BioPortal acronyms
map = get_ids_to_acronyms_map

onts = get_obofoundry_ontologies
@logger.info("Found #{onts.size} OBO Library ontologies")
@logger.info("Found #{onts.size} OBO Foundry ontologies")

# Are any OBO Library ontologies missing from BioPortal?
# Are any OBO Foundry ontologies missing from BioPortal?
missing_onts = []
active_onts = onts.reject { |ont| ont.key?("is_obsolete") }
active_onts = onts.reject { |ont| ont.key?('is_obsolete') }
@logger.info("#{active_onts.size} OBO Foundry ontologies are currently active")
active_onts.each do |ont|
if not map.key?(ont["id"])
if not map.key?(ont['id'])
missing_onts << ont
@logger.info("Missing OBO Library ontology: #{ont['title']} (#{ont['id']})")
@logger.info("Missing OBO Foundry ontology: #{ont['title']} (#{ont['id']})")
end
end

# Have any of the OBO Library ontologies that BioPortal hosts become obsolete?
# Have any of the OBO Foundry ontologies that BioPortal hosts become obsolete?
obsolete_onts = []
ids = active_onts.map{ |ont| ont["id"] }
ids = active_onts.map{ |ont| ont['id'] }
obsolete_ids = map.keys - ids
obsolete_ids.each do |id|
ont = onts.find{ |ont| ont["id"] == id }
ont = onts.find{ |ont| ont['id'] == id }
@logger.info("Deprecated OBO Library ontology: #{ont['title']} (#{ont['id']})")
obsolete_onts << ont
end
Expand All @@ -45,49 +42,19 @@ def run
end

def get_ids_to_acronyms_map
query = "query {
repository(name: \"ncbo.github.io\", owner: \"ncbo\") {
object(expression: \"master:oboids_to_bpacronyms.json\") {
... on Blob {
text
}
}
}
}"

response = issue_request(query)
JSON.parse(response)
response = Faraday.get('https://ncbo.github.io/oboids_to_bpacronyms.json')
MultiJson.load(response.body)
end

def get_obofoundry_ontologies
query = "query {
repository(name: \"OBOFoundry.github.io\", owner: \"OBOFoundry\") {
object(expression: \"master:registry/ontologies.jsonld\") {
... on Blob {
text
}
}
}
}"

response = issue_request(query)
ont_registry = JSON.parse(response)
ont_registry["ontologies"].to_a
end

def issue_request(query)
request = Net::HTTP::Post.new(@graphql_uri)
request["Authorization"] = "bearer #{@oauth_token}"
request.body = JSON.dump({"query" => query})

response = Net::HTTP.start(@graphql_uri.hostname, @graphql_uri.port, @request_options) do |http|
http.request(request)
conn = Faraday.new do |faraday|
faraday.response :follow_redirects
faraday.adapter Faraday.default_adapter
end
response = conn.get('http://purl.obolibrary.org/meta/ontologies.jsonld')

parsed = JSON.parse(response.body)
parsed.dig("data", "repository", "object", "text")
MultiJson.load(response.body)['ontologies']
end

end
end
end
2 changes: 2 additions & 0 deletions ncbo_cron.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]

gem.add_dependency("dante")
gem.add_dependency('faraday', '~> 2')
gem.add_dependency('faraday-follow_redirects', '~> 0')
gem.add_dependency("goo")
gem.add_dependency("google-analytics-data")
gem.add_dependency("mlanett-redis-lock")
Expand Down