Module:Infobox gene: Difference between revisions

Content deleted Content added
updated ncbi links to use https
Changed how disease and drugs are displayed and referenced to eliminate bare urls and enable editing to reference in wikidata
Line 157:
local disease, dis_ref = ''
if p.getDisease(entity, "P2293") then disease, dis_ref = p.getDisease(entity, "P2293") else disease, dis_ref = {"'''VALUE_ERROR'''","'''VALUE_ERROR'''" } end
if p.getDrug(entity_protein, "P129") then drug, drug_ref, drug_pqid, drug_pname = p.getDrug(entity_protein, "P129") else drug, drug_ref, drug_pqid, drug_pname = {"'''VALUE_ERROR'''","'''VALUE_ERROR'''" } end
local drug = check_values(p.getDrug, {entity_protein, "P129"})
--local drug = check_values(p.getDrug, {entity_protein, "P129"})
--define Global Color Scheme
Line 171 ⟶ 172:
p.renderIdentifiers(aliases, hgnc_id, gene_symbol, homologene_id, omim_id, mgi_id, ChEMBL_id, IUPHAR_id, ec_no, entrez_gene)
if (disease ~= "" and dis_ref ~= "") then --removes section from those items without disease info
p.renderDiseases(frame, disease, dis_ref, name, root_qid)
end
if (drug ~= "" ) then --removes section from those items without drug info
p.renderDrug(frame,drug, drug_ref, drug_pqid, drug_pname)
end
if (mol_funct ~= "" and cell_comp ~= "" and bio_process ~= "") then
Line 188 ⟶ 189:
return tostring(root)
--return table.concat(drug_pqid)
 
 
else return "An Error has occurred retrieving Wikidata item for infobox"
end
Line 532 ⟶ 533:
end
 
p.renderDiseases = function(frame, disease, dis_ref, name, qid)
local title = "Genetically Related Diseases"
local disease_title = "Disease Name"
local source_title = "'''References'''"
 
--check first to see if any of the diseases have references
local ref_flagref_flag_all = {}false --check eachif any disease forhave references if not then don't render athe referenceheaders
local disease_name = ''
local ref_flag_all = "" --check if any disease have references if not then don't render the headers
for index,value in ipairs(disease) do
if (dis_ref[index] ~= nil and dis_ref[index] ~= '') then
ref_flag[index]if disease_name == '' truethen
disease_name = value
else
disease_name = disease_name..","..value
end
ref_flag_all = true
end
Line 564 ⟶ 566:
:done()
:newline()
:tag('tr')
:tag('th')
:css('background-color', sideTitleBGcolor)
:attr('colspan', '2')
:wikitext(disease_title)
:done()
:newline()
:tag('td')
:css('background-color', sideTitleBGcolor)
:attr('colspan', '2')
:wikitext(source_title)
:done()
:newline()
:done()
end
for index,value in ipairs(disease) do
local i = 0
--local ref_collapse = ""
local ref_default = ""
local ref_link = ""
local ref_link_list = ""
if ref_flag[index] then
if (dis_ref[index] ~= nil or dis_ref[index] ~= '') then
ref_link_list = mw.text.split(dis_ref[index], ",")
end
 
local br_count = 0
for i =1, table.getn(ref_link_list) do
ref_url = table.remove(ref_link_list, 1)
abbr_url = string.gsub(ref_url, "http://", '')
if i > 1 then --not sure why indexing off, but renders empty value if don't do this
ref_link = ref_link..frame:extensionTag("ref",frame:expandTemplate{ title = 'cite_web', args = { title = abbr_url, url = ref_url} })
else
br_count = br_count -1
end
if br_count < 3 then
br_count = br_count + 1
else
br_count = 0
ref_link = ref_link ..'<br>'
end
end
--local disease_name = table.concat(disease, ", ")
local ref_url = "https://www.wikidata.org/wiki/"..qid.."#P2293" --direct page to property genetically associated disease
local title = "Diseases that are genetically associated with "..name.." view/edit references on wikidata"
local ref_link = disease_name..frame:extensionTag("ref",frame:expandTemplate{ title = 'cite_web', args = { title = title, url = ref_url} })
 
 
root
:tag('tr')
Line 617 ⟶ 584:
:css('background-color', rowBGcolor)
:attr('scope', 'row')
:attr('colspan', '23')
:wikitext(valueref_link)
:done()
:newline()
:tag('td')
:tag('span')
:attr('colspan', '2')
:tag('table')
:css('padding', '0')
:css('border', 'none')
:css('margin', '0')
:css('width', '100%')
:css('text-align', 'right')
:tag('tr')
:tag('td')
:attr('colspan', '1')
:newline()
:tag('p')
:attr('class', 'plainlinks')
:wikitext(ref_link)
:newline()
:done()
:done()
:done()
:done()
:newline()
end end
end
end
 
--p.renderDrug = function(drug, drug_ref)
p.renderDrug = function(frame,drug, drug_ref, drug_pqid, drug_pname)
local title = "Targeted by Drug"
local drug_title = "Drug Name"
local source_title = "'''References'''"
 
--check first to see if any of the drugs have references
--check first to see if any of the drugs have references
--local ref_flag = {} --check each drug for a reference
local ref_flag_all = false --check if any drugs have references if not then don't render the headers
drug_list_per_protein = {} -- a list of lists of drugs to put in reference string each protein will have a list
 
--for i,v in ipairs(drug_pqid) do -- set all lists keys to empty so can append without key errors
for k,v in pairs(drug) do
ref_flag_all = true
--end
for index,value in ipairs(drug) do
if (drug_ref[index] ~= nil and drug_ref[index] ~= '') then
protein_qid = drug_pqid[index]
if drug_list_per_protein[protein_qid] == '' or drug_list_per_protein[protein_qid] == nil then
drug_list_per_protein[protein_qid] = value
else
drug_list_per_protein[protein_qid] = drug_list_per_protein[protein_qid]..','..value --each list of drugs keyed on protein qid
end
ref_flag_all = true
end
end
 
if ref_flag_all then
root
Line 680 ⟶ 634:
:done()
:newline()
:tag('tr')
:tag('th')
:css('background-color', sideTitleBGcolor)
:attr('colspan', '2')
:wikitext(drug_title)
:done()
:newline()
:tag('td')
:css('background-color', sideTitleBGcolor)
:attr('colspan', '2')
:wikitext(source_title)
:done()
:newline()
:done()
end
for key,value in pairs(drug) do
local i = 0
--local ref_collapse = ""
local ref_default = ""
local ref_link = ""
local ref_link_list = {}
 
local ref_split = mw.text.split(value, ",")
 
local hash = {} --storage to look for duplicated values in case
--loop to create reference links from drug lists
for k,v in ipairs(ref_split) do
for k,v in pairs(drug_list_per_protein) do
if not hash[v] then --only add if not found previously
local drug_name = v
ref_link_list[#ref_link_list+1] = v
local ref_url = "https://www.wikidata.org/wiki/"..k.."#P129" --direct page to property genetically associated disease
hash[v] = true
local title = "Drugs that physically interact with "..drug_pname[k].." view/edit references on wikidata"
end
local ref_link = drug_name..frame:extensionTag("ref",frame:expandTemplate{ title = 'cite_web', args = { title = title, url = ref_url} })
end
local br_count = 0
for i =1, table.getn(ref_link_list) do
ref_url = table.remove(ref_link_list, 1)
abbr_url = string.gsub(ref_url, "http://", '')
if i > 1 then --not sure why indexing off, but renders empty value if don't do this
ref_link = ref_link..frame:extensionTag("ref",frame:expandTemplate{ title = 'cite_web', args = { title = abbr_url, url = ref_url} })
else
br_count = br_count -1
end
if br_count < 3 then
br_count = br_count + 1
else
br_count = 0
ref_link = ref_link ..'<br>'
end
end
root
Line 738 ⟶ 655:
:css('background-color', rowBGcolor)
:attr('scope', 'row')
:attr('colspan', '23')
--:wikitext(valueref_link)
:wikitext(key)
:done()
:newline()
:tag('td')
:tag('span')
:attr('colspan', '2')
:tag('table')
:attr('class', ref_collapse)
:css('padding', '0')
:css('border', 'none')
:css('margin', '0')
:css('width', '100%')
:css('text-align', 'right')
:tag('tr')
:tag('td')
:attr('colspan', '1')
:newline()
:tag('p')
:attr('class', 'plainlinks')
:wikitext(ref_link)
:newline()
:done()
:done()
:done()
:done()
:newline()
end
end
end
Line 2,324 ⟶ 2,219:
end
 
local function getReference(qID, index, entity, property_id, ref_index)
local f = {"claims",property_id,index ref_index, "references",ref_index,"snaks","P854",1,"datavalue","value"}
local id = qID
--if id and (#id == 0) then
Line 2,379 ⟶ 2,274:
local linkTarget = mw.wikibase.sitelink(id)
local refLink = ""
local iref = ""
ref = getReference("", entity, "P2293", k)
for i=1,100 do --limits to 100 references displayed
if (ref local~= nil and ref ~= ""'') then
--refLink = refLink..","..ref
ref = getReference("", k, entity, "P2293", i)
if (ref ~= nilrefLink and= ref ~= '') then
refLink = refLink..","..ref
end
end
--if refLink = "" then --skip if there isn't a reference found
datasource[#out + 1] = refLink
if linkTarget then
out[#out + 1] = "[["..datav.."|"..datav.."]]"
Line 2,394 ⟶ 2,288:
out[#out + 1] = "[[:d:" .. id .. "|" .. datav .. "]]"
end
datasource[#out] = refLink
--end
end
Line 2,411 ⟶ 2,306:
local out = {}
local datasource = {}
local pname = {}
local pqid = {}
 
 
for key, val in pairs(protein_entities) do
local claims
local entity = val
local name = check_values(p.getLabel,{entity})
if entity.claims then
claims = entity.claims[propertyID] -- ie physically interacts with
Line 2,429 ⟶ 2,328:
local linkTarget = mw.wikibase.sitelink(id)
local refLink = ""
local ref = getReference(protein_id, entity, "P129",k) --just check if anything returned
local i
forif i(ref ~=1,100 donil --limitsand toref 100~= references'') displayedthen
local ref refLink = ""ref
end
ref = getReference(protein_id, k, entity, "P129", i)
if (ref ~= nil and ref ~= '')linkTarget then
refLink out[#out + 1] = refLink"[["..datav..",|"..refdatav.."]]"
end else
out[#out + 1] = "[[:d:" .. id .. "|" .. datav .. "]]"
end
end
pname[protein_id] = name
local wikiLink = "[["..datav.."|"..datav.."]]"
pqid[#out] = protein_id
local wikidataLink = "[[:d:" .. id .. "|" .. datav .. "]]"
ifdatasource[#out] (refLink ~= nil and refLink ~= '') then
if linkTarget then
if out[wikiLink] then
out[wikiLink] = out[wikiLink]..","..refLink
else
out[wikiLink] = refLink
end
else
if out[wikidataLink] then
out[wikidataLink] = out[wikidataLink]..","..refLink
else
out[wikidataLink] = refLink
end
end--end if linkTarget
end -- end if refLink
end --end k,v claims loop
end --end claims[1]
end --if claims
end -- end protein_entities loop
return out, datasource, pqid, pname
end