Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Dec 11, 2023
1 parent a44eb06 commit 2a43b9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 45 deletions.
6 changes: 5 additions & 1 deletion server/lib/genome/groupers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def normalize_claim(primary_term, claim_aliases)
response = retrieve_normalizer_response(claim_alias.alias)
match_type = response['match_type']
if !response.nil? && match_type > 0
concept_id = response[@descriptor_name]['id'][15..]
concept_id = response['normalized_id']
if !claim_responses.key?(concept_id)
claim_responses[concept_id] = response
end
Expand Down Expand Up @@ -93,6 +93,10 @@ def normalize_claim(primary_term, claim_aliases)
response
end

def get_concept_id(response)
response['normalized_id'] unless response['match_type'].zero?
end

def retrieve_extension(descriptor, type, default = nil)
unless descriptor.fetch('extensions').blank?
descriptor['extensions'].each do |extension|
Expand Down
22 changes: 3 additions & 19 deletions server/lib/genome/groupers/drug_grouper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def initialize
if !url_base.ends_with? "/"
url_base += "/"
end
@normalizer_host = "#{url_base}/therapy/"
@normalizer_host = "#{url_base}therapy/"
@descriptor_name = 'therapy'

@term_to_match_dict = {}

Expand Down Expand Up @@ -52,19 +53,6 @@ def run(source_id = nil)
end
end

def set_response_structure
url = URI("#{@normalizer_host}search?q=")
body = fetch_json_response(url)
version = body['service_meta_']['version']
if version < '0.4.0'
@descriptor_name = 'therapy_descriptor'
@id_name = 'therapy_id'
else
@descriptor_name = 'therapeutic_descriptor'
@id_name = 'therapeutic'
end
end

def create_sources
drug_source_type = SourceType.find_by(type: 'drug')

Expand Down Expand Up @@ -168,10 +156,6 @@ def create_sources
}
end

def get_concept_id(response)
response[@descriptor_name][@id_name] unless response['match_type'].zero?
end

def produce_concept_id_nomenclature(concept_id)
case concept_id
when /rxcui:/
Expand Down Expand Up @@ -293,7 +277,7 @@ def add_grouper_claim_aliases(claim, record)
end

def add_grouper_data(drug, descriptor)
drug_data = retrieve_normalizer_data(descriptor[@id_name])
gene_data = retrieve_normalizer_data(descriptor['id'][15..])

drug_data.each do |source_name, source_data|
next if %w[DrugBank ChEMBL GuideToPHARMACOLOGY].include?(source_name)
Expand Down
33 changes: 8 additions & 25 deletions server/lib/genome/groupers/gene_grouper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,15 @@ def run(source_id = nil)
if normalized_gene.is_a? String
normalized_id = normalized_gene
else
normalized_id = normalized_gene['normalize_id']
create_new_gene normalized_gene['gene'] if Gene.find_by(concept_id: normalized_id).nil?
normalized_id = normalized_gene['normalized_id']
create_new_gene(normalized_gene['gene'], normalized_id) if Gene.find_by(concept_id: normalized_id).nil?
end
add_claim_to_gene(gene_claim, normalized_id)

pbar.progress += 1
end
end

# def set_response_structure
# @descriptor_name = 'gene_descriptor'
#
# url = URI("#{@normalizer_host}search?q=")
# body = fetch_json_response(url)
# version = body['service_meta_']['version']
# if version < '0.2.0'
# @id_name = 'gene_id'
# else
# @id_name = 'gene'
# end
# end
#
def create_sources
gene_source_type = SourceType.find_by(type: 'gene')

Expand Down Expand Up @@ -134,10 +121,6 @@ def create_sources
}
end

def get_concept_id(response)
response['normalized_id'] unless response['match_type'].zero?
end

def create_gene_claim(record, source)
GeneClaim.where(
name: record['symbol'],
Expand Down Expand Up @@ -212,8 +195,8 @@ def add_grouper_claim_attribute(claim, record)
)
end

def add_grouper_data(gene, descriptor)
gene_data = retrieve_normalizer_data(descriptor['id'][15..])
def add_grouper_data(gene, descriptor, normalized_id)
gene_data = retrieve_normalizer_data(normalized_id)
gene_data.each do |source_name, source_data|
source = @sources[source_name.to_sym]

Expand All @@ -227,19 +210,19 @@ def add_grouper_data(gene, descriptor)
end
end

def create_new_gene(gene_response)
def create_new_gene(gene_response, normalized_id)
name = if gene_response.fetch('label').blank?
gene_response['id'][15..]
normalized_id
else
gene_response['label']
end
gene = Gene.where(
concept_id: gene_response['id'][15..],
concept_id: normalized_id,
name: name,
long_name: retrieve_extension(gene_response, 'approved_name')
).first_or_create

add_grouper_data(gene, gene_response)
add_grouper_data(gene, gene_response, normalized_id)
end

def add_claim_attributes(claim, gene)
Expand Down

0 comments on commit 2a43b9f

Please sign in to comment.