-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
44 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,18 @@ | ||
class Api::Pept2taxaController < Api::ApiController | ||
include TaxonomyHelper | ||
|
||
before_action :set_cors_headers | ||
before_action :set_params | ||
before_action :set_query | ||
before_action :search_input | ||
|
||
# Returns a list of taxa retrieved from the Uniprot entries containing a given tryptic peptide | ||
# param[input]: Array, required, List of input peptides | ||
# param[equate_il]: "true" or "false", Indicate if you want to equate I and L | ||
# param[extra]: "true" or "false", Include lineage | ||
# param[names]: "true" or "false", Include the lineage names | ||
def pept2taxa | ||
@result = {} | ||
lookup = Hash.new { |h, k| h[k] = Set.new } | ||
ids = Set.new | ||
|
||
seqid2seq = {} | ||
Sequence.where(sequence: @input).select(:id, :sequence).each do |seq| | ||
seqid2seq[seq[:id]] = seq[:sequence] | ||
@result[seq[:sequence]] = Set.new | ||
end | ||
|
||
rel_name = @equate_il ? :sequence_id : :original_sequence_id | ||
Peptide.where(rel_name => seqid2seq.keys).select(:id, rel_name, :uniprot_entry_id).find_in_batches do |items| | ||
uniprot2seqids = Hash.new { |h, k| h[k] = [] } | ||
items.each { |i| uniprot2seqids[i[:uniprot_entry_id]] << i[rel_name] } | ||
|
||
UniprotEntry.where(id: uniprot2seqids.keys).select(:id, :taxon_id).each do |entry| | ||
uniprot2seqids[entry[:id]].each do |seqid| | ||
sequence = seqid2seq[seqid] | ||
lookup[entry[:taxon_id]] << sequence | ||
ids << entry[:taxon_id] | ||
end | ||
end | ||
end | ||
|
||
ids.delete nil | ||
ids = ids.to_a.sort | ||
|
||
@query.where(id: ids).find_in_batches do |group| | ||
group.each do |t| | ||
lookup[t.id].each { |s| @result[s] << t } | ||
end | ||
end | ||
|
||
@result = pept2taxa_helper | ||
filter_input_order | ||
|
||
respond_with(@result) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,5 @@ def protinfo | |
} | ||
end | ||
end | ||
|
||
respond_with(@result) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
json.array! @input_order do |peptide| | ||
json.peptide peptide | ||
json.uniprot_id @result[peptide][:uniprot_id] | ||
json.protein_name @result[peptide][:name] | ||
json.taxon_id @result[peptide][:taxon_id] | ||
json.protein @result[peptide][:protein] | ||
if @extra_info | ||
json.taxon_name @result[peptide][:taxon][:name] | ||
json.ec_references @result[peptide][:ec_cross_references] | ||
json.go_references @result[peptide][:go_cross_references] | ||
json.interpro_references @result[peptide][:interpro_cross_references] | ||
@input_order.map do |peptide| | ||
json.array! @result[peptide].map do |prot| | ||
json.peptide peptide | ||
json.uniprot_id prot[:uniprot_id] | ||
json.protein_name prot[:name] | ||
json.taxon_id prot[:taxon_id] | ||
json.protein prot[:protein] | ||
if @extra_info | ||
json.taxon_name prot[:taxon][:name] | ||
json.ec_references prot[:ec_cross_references] | ||
json.go_references prot[:go_cross_references] | ||
json.interpro_references prot[:interpro_cross_references] | ||
end | ||
end | ||
end |