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

Fetch taxonomic and functional information for UniProt id's #20

Merged
merged 4 commits into from
Jun 14, 2023
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
26 changes: 24 additions & 2 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class Api::ApiController < ApplicationController
respond_to :json

before_action :set_headers, only: %i[pept2taxa pept2lca pept2prot pept2funct pept2ec pept2go pept2interpro peptinfo taxa2lca taxonomy taxa2tree]
before_action :set_params, only: %i[pept2taxa pept2lca pept2prot pept2funct pept2ec pept2go pept2interpro peptinfo taxa2lca taxonomy taxa2tree]
before_action :set_headers, only: %i[pept2taxa pept2lca pept2prot pept2funct pept2ec pept2go pept2interpro peptinfo taxa2lca taxonomy taxa2tree protinfo]
before_action :set_params, only: %i[pept2taxa pept2lca pept2prot pept2funct pept2ec pept2go pept2interpro peptinfo taxa2lca taxonomy taxa2tree protinfo]
before_action :set_query, only: %i[pept2taxa pept2lca peptinfo taxonomy]
before_action :set_sequences, only: %i[pept2prot]

Expand Down Expand Up @@ -270,6 +270,28 @@ def taxonomy
respond_with(@result)
end

# Returns the taxonomic and functional information for given uniprot id's
# param[input]: Array, required, List of input uniprot id's
def protinfo
@result = {}

UniprotEntry
.includes(:taxon, :ec_numbers, :go_terms, :interpro_entries)
.where(uniprot_accession_number: @input_order)
.find_in_batches do |batch|
batch.each do |uniprot_id|
@result[uniprot_id.uniprot_accession_number] = {
taxon: uniprot_id.taxon,
ec: uniprot_id.ec_numbers.map { |ec| { ec_number: ec.code } },
go: uniprot_id.go_terms.map { |go| { go_term: go.code } },
ipr: uniprot_id.interpro_entries.map { |interpro| { code: interpro.code } }
}
end
end

respond_with(@result)
end

private

# log all api calls to stathat
Expand Down
13 changes: 13 additions & 0 deletions app/views/api/api/protinfo.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
json.array! @input_order do |uniprot_id|
if @result.key? uniprot_id
json.protein uniprot_id

json.ec @result[uniprot_id][:ec]
json.go @result[uniprot_id][:go]
json.ipr @result[uniprot_id][:ipr]

json.taxon_id @result[uniprot_id][:taxon][:id]
json.taxon_name @result[uniprot_id][:taxon][:name]
json.taxon_rank @result[uniprot_id][:taxon][:rank]
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
match 'peptinfo' => 'api#peptinfo', via: %i[get post]
match 'taxonomy' => 'api#taxonomy', via: %i[get post]
match 'messages' => 'api#messages', via: %i[get post]
match 'protinfo' => 'api#protinfo', via: %i[get post]
end

namespace :api, path: 'api/v2' do
Expand All @@ -49,5 +50,6 @@
match 'peptinfo' => 'api#peptinfo', via: %i[get post]
match 'taxonomy' => 'api#taxonomy', via: %i[get post]
match 'messages' => 'api#messages', via: %i[get post]
match 'protinfo' => 'api#protinfo', via: %i[get post]
end
end
Loading