This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing.
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
local p = {} local localSeparatorStr = "," -- **lclz** Correct it if your wiki has different setting, like zhwiki uses "、" for now local localNotApplicableStr = "n/a" -- **lclz** local root --define Global Color Scheme local rowBGcolor = '#eee' local titleBGcolor = '#ddd' local sideTitleBGcolor = '#c3fdb8' -- wrapped "protected call", return "value error" with error info on error local function check_values(f,args) --local u= table.upack(args) local exist, val = pcall(f, unpack(args)) if exist and val ~= nil then return(val) else -- Leaking some debugging info won't hurt.... return("'''VALUE_ERROR''' (" .. tostring(val) .. ")") end end --texts relevant to localization are tagged with --**lclz** and/or *lclz* --on a page {{#invoke:Sandbox/genewiki/alllua getTemplateData QID=Q14865053}} --in debug window --frame = mw.getCurrentFrame() --frame.args = {QID="Q14865053"} Q18031325 --print(p.getTemplateData(frame)) function p.getTemplateData(frame) --make some guesses about whether the provided QID is a good one --could expand here if we had some kind of error handling framework --did we get it from the page local root_qid = mw.text.trim(frame.args['QID'] or "") --try to get it from the args local mm_qid = "" --pull all the entity objects that we will need local entity = {} local entity_protein = {} local entity_mouse = {} local entity_mouse_protein = {} local checkOrtholog = "" --flag used to see if mouse data avaliable local mouse_propertyID = "P684" --actually ortholog property additional orthologs can exist local protein_propertyID = "P688" --get root gene entity if root_qid == "" then entity = mw.wikibase.getEntity() if entity then root_qid = entity.id else root_qid = "" end else --assuming we think its good make one call to retrieve and store its wikidata representation entity = mw.wikibase.getEntity(root_qid) end --need to figure out if it is protein or gene here local subclass = p.getValue(entity, "P31") or "" if string.find(subclass, 'protein') then --if protein switch entity to gene **lclz** local claims if entity.claims then claims = entity.claims["P702"] --encoded by end if claims then --go through each index and reassign entity entity = {} if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") then for k, v in pairs(claims) do --this would be problematic if multiple genes for the protein local itemID = "Q" .. claims[#entity + 1].mainsnak.datavalue.value["numeric-id"] entity[#entity + 1] = mw.wikibase.getEntity(itemID) root_qid = itemID end end --will return nothing if no claims are found end entity = mw.wikibase.getEntity(root_qid) end --get the other related entities if entity then local claims --get protein entity object if entity.claims then claims = entity.claims[protein_propertyID] end if claims then --go through each index and then make entity_protein indexed if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") then for k, v in pairs(claims) do local protein_itemID = "Q" .. claims[#entity_protein + 1].mainsnak.datavalue.value["numeric-id"] entity_protein[#entity_protein + 1] = mw.wikibase.getEntity(protein_itemID) end end --will return nothing if no claims are found end --get mouse entity object if entity.claims then claims = entity.claims[mouse_propertyID] end local qualifierID = "P703" --found in taxon local mouse_qual = "Q83310" if claims then if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") then for k, v in pairs(claims) do if checkOrtholog == 1 then -- Don't have to go on if we already got it break end local mouse_itemID = "Q" .. v.mainsnak.datavalue.value["numeric-id"] local quals if v.qualifiers then quals = v.qualifiers.P703 end if quals then for qk, qv in pairs(quals) do --get the taxon qualifier id local qual_obj_id = "Q"..qv.datavalue.value["numeric-id"] if qual_obj_id == mouse_qual then --check if this is mouse or other mm_qid = mouse_itemID entity_mouse = mw.wikibase.getEntity(mouse_itemID) checkOrtholog = 1 break end end end end end --will return nothing if no claims are found else checkOrtholog = 0 end --get mouse protein entity object if entity_mouse and entity_mouse.claims then claims = entity_mouse.claims[protein_propertyID] end if claims then if (claims[1] and claims[1].mainsnak.snaktype == "value" and claims[1].mainsnak.datavalue.type == "wikibase-entityid") then for k, v in pairs(claims) do local protein_itemID = "Q" .. claims[#entity_mouse_protein + 1].mainsnak.datavalue.value["numeric-id"] entity_mouse_protein[#entity_mouse_protein + 1] = mw.wikibase.getEntity(protein_itemID) end end --will return nothing if no claims are found end end if entity then --only require the main gene entity --a list variables of all the data in the info box local name = check_values(p.getLabel,{entity}) local bgee_wikidata_id = 'Q54985720' local expressed_in_tissues = check_values(p.getValue, {entity, "P5572", localNotApplicableStr, localSeparatorStr, bgee_wikidata_id}) --P5572: expressed in local expressed_in_mouse_tissues = check_values(p.getValue, {entity_mouse, "P5572", localNotApplicableStr, localSeparatorStr, bgee_wikidata_id}) --P5572: expressed in local entrez_gene = check_values(p.getValue, {entity, "P351", localNotApplicableStr} ) local entrez_gene_mm = check_values(p.getValue, {entity_mouse, "P351", localNotApplicableStr}) local image = check_values( p.getImage, {entity, "P18", " ", "250px"}) --need to set size local uniprotID_hs = check_values(p.getValueProtein, {entity_protein, "P352", localNotApplicableStr}) local uniprotID_mm = check_values(p.getValueProtein, {entity_mouse_protein, "P352", localNotApplicableStr}) local pdbIDs = check_values(p.getPDB, {entity_protein}) --makes a list with links to RCSB local aliases = check_values(p.getAliases, {entity}) local gene_symbol = check_values(p.getValue, {entity, "P353"}) local hgnc_id = check_values(p.getValue, {entity, "P354"}) local homologene_id = check_values(p.getValue, {entity, "P593"}) local omim_id = check_values(p.getValue, {entity, "P492"}) local mgi_id = check_values(p.getValue, {entity_mouse, "P671"}) local ChEMBL_id = check_values(p.getValue, {entity_protein, "P592"}) local IUPHAR_id = check_values(p.getValue, {entity_protein, "P595"}) local ec_no = check_values(p.getValueProtein, {entity_protein, "P591"}) local mol_funct = check_values(p.getGO, {entity_protein, "P680"}) local cell_comp = check_values(p.getGO, {entity_protein, "P681"}) local bio_process = check_values(p.getGO, {entity_protein, "P682"}) local expression_images = check_values(p.getImage, {entity,"P692","<br><br>","250px"}) local ensembl = check_values(p.getValue, {entity, "P594", localNotApplicableStr}) local ensembl_mm = check_values(p.getValue, {entity_mouse, "P594", localNotApplicableStr}) local refseq_mRNA = check_values(p.getRefseq_mRNA, {entity, "P639", localNotApplicableStr}) local refseq_mRNA_mm = check_values(p.getRefseq_mRNA, {entity_mouse, "P639", localNotApplicableStr}) local refseq_prot = check_values(p.getRefseq_protein, {entity_protein, "P637", localNotApplicableStr}) local refseq_prot_mm = check_values(p.getRefseq_protein, {entity_mouse_protein, "P637", localNotApplicableStr}) local gstart = check_values(p.getChromosomeLoc, {entity, "P644", "hg"}) local gend = check_values(p.getChromosomeLoc, {entity, "P645", "hg"}) local chr = check_values(p.trimChromosome, {entity}) local cytoband = check_values(p.getValue, {entity, "P4196", localNotApplicableStr}) local db = check_values(p.getAliasFromGenomeAssembly, {entity,"hg"}) local gstart_mm = check_values(p.getChromosomeLoc, {entity_mouse, "P644", "mm"}) local gend_mm = check_values(p.getChromosomeLoc, {entity_mouse, "P645", "mm"}) local chr_mm = check_values( p.trimChromosome, {entity_mouse}) local db_mm = check_values(p.getAliasFromGenomeAssembly, {entity_mouse,"mm"}) local cytoband_mm = check_values(p.getValue, {entity_mouse, "P4196", localNotApplicableStr}) local disease, dis_ref = p.getDisease(entity, "P2293") local drug, drug_ref, drug_pqid, drug_pname = p.getDrug(entity_protein, "P129") --local drug = check_values(p.getDrug, {entity_protein, "P129"}) p.createTable() p.renderUpperTitle(name) --p.renderCaption() p.renderImage(image) p.renderAvailableStructures(uniprotID_hs, uniprotID_mm, checkOrtholog, pdbIDs) --PDB info p.renderIdentifiers(aliases, hgnc_id, gene_symbol, homologene_id, omim_id, mgi_id, ChEMBL_id, IUPHAR_id, ec_no, entrez_gene) --uncomment here to add a section of the infobox about genetically related diseases, with references --if (disease ~= "" and dis_ref ~= "") then --removes section from those items without disease info -- p.renderDiseases(frame, disease, dis_ref, name, root_qid) --end --uncomment here to add a section of the infobox about drugs that target the protein product of this gene, with references --if (drug ~= "" ) then --removes section from those items without drug info -- p.renderDrug(frame,drug, drug_ref, drug_pqid, drug_pname) --end if (chr ~= "" and gstart ~= "" and gend ~= "") or (chr_mm ~= "" and gstart_mm ~= "" and gend_mm ~= "") then p.renderGeneLocation(frame, chr, gstart, gend, db, cytoband, ensembl, chr_mm, gstart_mm, gend_mm, db_mm, cytoband_mm, ensembl_mm, name) end if expression_images ~= "" or expressed_in_tissues ~= localNotApplicableStr then p.renderRNAexpression(expression_images, entrez_gene, ensembl, expressed_in_tissues, ensembl_mm, expressed_in_mouse_tissues) end if (mol_funct ~= "" and cell_comp ~= "" and bio_process ~= "") then p.renderGeneOntology(mol_funct, cell_comp, bio_process, uniprotID_hs) end p.renderOrthologs(frame, entrez_gene, entrez_gene_mm, ensembl, ensembl_mm, uniprotID_hs, uniprotID_mm, refseq_mRNA, refseq_mRNA_mm, refseq_prot, refseq_prot_mm, db, chr, gstart, gend, db_mm, chr_mm, gstart_mm, gend_mm) p.renderFooter(root_qid, mm_qid) return tostring(root) --return table.concat(drug_pqid) else return "An Error has occurred retrieving Wikidata item for infobox" end end function p.createTable(subbox) if subbox == 'sub' then --doesn't work root :tag('table') :css('padding', '0') :css('border', 'none') :css('margin', '0') :css('width', 'auto') :css('min-width', '100%') :css('font-size', '100%') :css('clear', 'none') :css('float', 'none') :css('background-color', 'transparent') else root = mw.html.create('table') root -- *lclz*: Some projects, like zhwiki (again), use inline styles on -- infobox modules in addition to the class. Be sure to check them out. :addClass('infobox') :css('width', '26.4em') end end --Title above image function p.renderUpperTitle(name) local title = name if not title then return "error: failed to get label"; end root :tag('tr') :tag('th') :attr('colspan', 4) :css('text-align', 'center') :css('font-size', '125%') :css('font-weight', 'bold') :wikitext(title) :done() --end th :done() --end tr end --This is a place holder for the image caption, which is stored in wikicommons comments unsure how to access function p.renderCaption(entity) --caption end --gets default image function p.renderImage(image) root :tag('tr') :tag('td') :attr('colspan', 4) :css('text-align', 'center') :wikitext(image) :done() --end td :done() --end tr end function p.renderAvailableStructures(uniprotID_hs, uniprotID_mm, checkOrtholog, pdbIDs) local title = 'Available structures' --**lclz** local pdb_link = "[[Protein_Data_Bank PDB]]" --**lclz** local searchTitle = "" local listTitle = "List of PDB id codes" --**lclz** local PDBe_base = 'https://www.ebi.ac.uk/pdbe/searchResults.html?display=both&term=' local RCSB_base = 'https://www.rcsb.org/search?q=' ..'rcsb_polymer_entity_container_identifiers.reference_sequence_identifiers.database_name:UniProt%20AND%20' ..'rcsb_polymer_entity_container_identifiers.reference_sequence_identifiers.database_accession:' local url_uniprot = " " if checkOrtholog == 1 and uniprotID_mm ~= 'n/a' then searchTitle = 'Ortholog search: ' --**lclz** url_uniprot = uniprotID_mm..','..uniprotID_hs else searchTitle = 'Human UniProt search: ' --**lclz** url_uniprot = uniprotID_hs end local PDBe_list = " " --create a list with " or " if there is more than one uniprot --get first uniprot in a list if url_uniprot:match("([^,]+),") then--first check if there is a list if not just assume one value PDBe_list = string.gsub(url_uniprot, ",", "%%20or%%20") --add or's inststead of commas else PDBe_list = url_uniprot end local PDBe = "["..PDBe_base..PDBe_list.." PDBe] " local RCSB = "["..RCSB_base..url_uniprot.." RCSB] " if string.match(pdbIDs, '%w+') then --if there aren't any PDB_ID don't display this part of the infobox --p.formatRow(title)---how to not close the tags is a mystery and I could condense code once I figure out root :tag('tr') :tag('td') :attr('colspan', 4) :css('text-align', 'center') :css('background-color', rowBGcolor) :tag('table') :css('padding', '0') :css('border', 'none') :css('margin', '0') :css('width', '100%') :css('text-align', 'left') :tag('tr') --create title header :tag('th') :attr('colspan', '4') :css('text-align', 'center') :css('background-color', titleBGcolor) :wikitext(title) :done() --end th :done() --end tr :tag('tr') :tag('th') :attr('rowspan', '2') :css('background-color', sideTitleBGcolor) :css('width', '43px') :wikitext(pdb_link) :done() --end th :tag('td') :attr('colspan', '2') :css('background-color', rowBGcolor) :wikitext(searchTitle) :tag('span') :attr('class', 'plainlinks') :wikitext(PDBe) :wikitext(RCSB) :done() --end span :done() --end td :done() --end tr :tag('tr') --new row for collapsible list of PDB codes :tag('td') :tag('table') :attr('class', 'collapsible collapsed') :css('padding', '0') :css('border', 'none') :css('margin', '0') :css('width', '100%') :css('text-align', 'left') :tag('tr') :css('background-color', titleBGcolor) :css('text-align', 'center') :tag('th') :attr('colspan', '2') :wikitext(listTitle) :done() --end th :done() --end tr :tag('tr') :tag('td') :attr('colspan', '2') :css('background-color', rowBGcolor) :tag('p') :tag('span') :attr('class', 'plainlinks') :wikitext(pdbIDs) :done() --end span :done() --end p :done() --end td :done() --end tr :done() --end table :done() --end td :done() --end tr :done() --end table :done() --end td :done() --end tr else return "" end end function p.renderIdentifiers(aliases, hgnc_id, gene_symbol, homologene_id, omim_id, mgi_id, ChEMBL_id, IUPHAR_id, ec_no, entrez_gene) local title = "Identifiers" --**lclz** local label_aliases = "[[Gene nomenclature Aliases]]" --**lclz** local symbol_url if gene_symbol == "" or gene_symbol == nil then symbol_url = "" else if hgnc_id == "" or hgnc_id == nil then symbol_url = gene_symbol else symbol_url = "[https://www.genenames.org/data/gene-symbol-report/#!/hgnc_id/"..hgnc_id.." "..gene_symbol.."]" end end -- *lclz*: see getAliases. You can, say, use another punctuation for your language. aliases = string.gsub(aliases, ', '..gene_symbol..'