<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FMensis_Mirabilis%2Fgene</id>
	<title>Module:Sandbox/Mensis Mirabilis/gene - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FMensis_Mirabilis%2Fgene"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Mensis_Mirabilis/gene&amp;action=history"/>
	<updated>2026-04-21T06:20:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/Mensis_Mirabilis/gene&amp;diff=145828&amp;oldid=prev</id>
		<title>imported&gt;Mensis Mirabilis: ←Created page with &#039;local p = { }  local function check_values(f,args) 	    --local u= table.upack(args) 		local exist, val = pcall(f, unpack(args)) 		if exist and val ~= nil then...&#039;</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Mensis_Mirabilis/gene&amp;diff=145828&amp;oldid=prev"/>
		<updated>2018-11-20T14:16:41Z</updated>

		<summary type="html">&lt;p&gt;&lt;a href=&quot;/index.php?title=WP:AES&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;WP:AES (page does not exist)&quot;&gt;←&lt;/a&gt;Created page with &amp;#039;local p = { }  local function check_values(f,args) 	    --local u= table.upack(args) 		local exist, val = pcall(f, unpack(args)) 		if exist and val ~= nil then...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = { }&lt;br /&gt;
&lt;br /&gt;
local function check_values(f,args)&lt;br /&gt;
	    --local u= table.upack(args)&lt;br /&gt;
		local exist, val = pcall(f, unpack(args))&lt;br /&gt;
		if exist and val ~= nil then&lt;br /&gt;
			return(val)&lt;br /&gt;
		else&lt;br /&gt;
			-- Leaking some debugging info won&amp;#039;t hurt....&lt;br /&gt;
			return(&amp;quot;&amp;#039;&amp;#039;&amp;#039;VALUE_ERROR&amp;#039;&amp;#039;&amp;#039; (&amp;quot; .. tostring(val) .. &amp;quot;)&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.getTemplateData = function(frame)&lt;br /&gt;
&lt;br /&gt;
	--make some guesses about whether the provided QID is a good one&lt;br /&gt;
	--could expand here if we had some kind of error handling framework&lt;br /&gt;
	--did we get it from the page&lt;br /&gt;
	local root_qid = mw.text.trim(frame.args[&amp;#039;QID&amp;#039;]  or &amp;quot;&amp;quot;) --try to get it from the args&lt;br /&gt;
	local mm_qid = &amp;quot;&amp;quot;&lt;br /&gt;
	--pull all the entity objects that we will need&lt;br /&gt;
	local	entity = {} &lt;br /&gt;
	local	entity_protein = {}&lt;br /&gt;
	local	entity_mouse = {}&lt;br /&gt;
	local	entity_mouse_protein = {}&lt;br /&gt;
	local	checkOrtholog = &amp;quot;&amp;quot; --flag used to see if mouse data avaliable&lt;br /&gt;
	&lt;br /&gt;
	local mouse_propertyID = &amp;quot;P684&amp;quot; --actually ortholog property additional orthologs can exist&lt;br /&gt;
	local protein_propertyID = &amp;quot;P688&amp;quot; &lt;br /&gt;
&lt;br /&gt;
	--get root gene entity&lt;br /&gt;
	if root_qid == &amp;quot;&amp;quot; then&lt;br /&gt;
		entity = mw.wikibase.getEntityObject()&lt;br /&gt;
		if entity then root_qid = entity.id else root_qid = &amp;quot;&amp;quot; end&lt;br /&gt;
			&lt;br /&gt;
	else&lt;br /&gt;
		--assuming we think its good make one call to retrieve and store its wikidata representation&lt;br /&gt;
		entity = mw.wikibase.getEntity(root_qid)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
  	--need to figure out if it is protein or gene here&lt;br /&gt;
	local subclass = p.getValue(entity, &amp;quot;P31&amp;quot;) or &amp;quot;&amp;quot;&lt;br /&gt;
	if string.find(subclass, &amp;#039;protein&amp;#039;) then --if protein switch entity to gene&lt;br /&gt;
		if entity.claims then&lt;br /&gt;
	 		claims = entity.claims[&amp;quot;P702&amp;quot;] --encoded by&lt;br /&gt;
	 	end&lt;br /&gt;
		if claims then&lt;br /&gt;
			--go through each index and reassign entity&lt;br /&gt;
			entity = {}&lt;br /&gt;
			if (claims[1] and claims[1].mainsnak.snaktype == &amp;quot;value&amp;quot; and claims[1].mainsnak.datavalue.type == &amp;quot;wikibase-entityid&amp;quot;) then&lt;br /&gt;
				for k, v in pairs(claims) do --this would be problematic if multiple genes for the protein&lt;br /&gt;
					local itemID = &amp;quot;Q&amp;quot; .. claims[#entity + 1].mainsnak.datavalue.value[&amp;quot;numeric-id&amp;quot;]&lt;br /&gt;
					entity[#entity + 1] = mw.wikibase.getEntity(itemID)&lt;br /&gt;
					root_qid = itemID&lt;br /&gt;
				end&lt;br /&gt;
				&lt;br /&gt;
			end --will return nothing if no claims are found&lt;br /&gt;
		end&lt;br /&gt;
		 entity = mw.wikibase.getEntity(root_qid) 	&lt;br /&gt;
	 end&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	--get the other related entities&lt;br /&gt;
	if entity then&lt;br /&gt;
		local claims = &amp;quot;&amp;quot;&lt;br /&gt;
	 	--get protein entity object&lt;br /&gt;
	 	if entity.claims then&lt;br /&gt;
	 		claims = entity.claims[protein_propertyID]&lt;br /&gt;
	 	end&lt;br /&gt;
		if claims then&lt;br /&gt;
			--go through each index and then make entity_protein indexed&lt;br /&gt;
			if (claims[1] and claims[1].mainsnak.snaktype == &amp;quot;value&amp;quot; and claims[1].mainsnak.datavalue.type == &amp;quot;wikibase-entityid&amp;quot;) then&lt;br /&gt;
				for k, v in pairs(claims) do&lt;br /&gt;
					local protein_itemID = &amp;quot;Q&amp;quot; .. claims[#entity_protein + 1].mainsnak.datavalue.value[&amp;quot;numeric-id&amp;quot;]&lt;br /&gt;
					entity_protein[#entity_protein + 1] = mw.wikibase.getEntity(protein_itemID)&lt;br /&gt;
				end&lt;br /&gt;
				&lt;br /&gt;
			end --will return nothing if no claims are found&lt;br /&gt;
		end&lt;br /&gt;
	&lt;br /&gt;
	 	--get mouse entity object&lt;br /&gt;
	 	if entity.claims then&lt;br /&gt;
			claims = entity.claims[mouse_propertyID]&lt;br /&gt;
		end&lt;br /&gt;
		local qualifierID = &amp;quot;P703&amp;quot; --found in taxon&lt;br /&gt;
		local mouse_qual = &amp;quot;Q83310&amp;quot;&lt;br /&gt;
		if claims then&lt;br /&gt;
			if (claims[1] and claims[1].mainsnak.snaktype == &amp;quot;value&amp;quot; and claims[1].mainsnak.datavalue.type == &amp;quot;wikibase-entityid&amp;quot;) then&lt;br /&gt;
				for k, v in pairs(claims) do&lt;br /&gt;
					if checkOrtholog == 1 then -- Don&amp;#039;t have to go on if we already got it&lt;br /&gt;
						break&lt;br /&gt;
					end&lt;br /&gt;
&lt;br /&gt;
				  	local mouse_itemID = &amp;quot;Q&amp;quot; .. v.mainsnak.datavalue.value[&amp;quot;numeric-id&amp;quot;]&lt;br /&gt;
					local quals &lt;br /&gt;
					if v.qualifiers then&lt;br /&gt;
						quals = v.qualifiers.P703&lt;br /&gt;
					end&lt;br /&gt;
					if quals then&lt;br /&gt;
						for qk, qv in pairs(quals) do&lt;br /&gt;
							--get the taxon qualifier id&lt;br /&gt;
							local qual_obj_id = &amp;quot;Q&amp;quot;..qv.datavalue.value[&amp;quot;numeric-id&amp;quot;]&lt;br /&gt;
							if qual_obj_id == mouse_qual then --check if this is mouse or other&lt;br /&gt;
								mm_qid = mouse_itemID &lt;br /&gt;
								entity_mouse = mw.wikibase.getEntity(mouse_itemID)&lt;br /&gt;
								checkOrtholog = 1&lt;br /&gt;
								break&lt;br /&gt;
							end&lt;br /&gt;
						end&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end --will return nothing if no claims are found&lt;br /&gt;
		else&lt;br /&gt;
			checkOrtholog = 0&lt;br /&gt;
		end&lt;br /&gt;
	&lt;br /&gt;
	 	--get mouse protein entity object&lt;br /&gt;
	 	if entity_mouse and entity_mouse.claims then&lt;br /&gt;
			claims = entity_mouse.claims[protein_propertyID]&lt;br /&gt;
		end&lt;br /&gt;
	 	if claims then&lt;br /&gt;
	 		if (claims[1] and claims[1].mainsnak.snaktype == &amp;quot;value&amp;quot; and claims[1].mainsnak.datavalue.type == &amp;quot;wikibase-entityid&amp;quot;) then&lt;br /&gt;
				for k, v in pairs(claims) do&lt;br /&gt;
					local protein_itemID = &amp;quot;Q&amp;quot; .. claims[#entity_mouse_protein + 1].mainsnak.datavalue.value[&amp;quot;numeric-id&amp;quot;]&lt;br /&gt;
					entity_mouse_protein[#entity_mouse_protein + 1] = mw.wikibase.getEntity(protein_itemID)&lt;br /&gt;
				end&lt;br /&gt;
			end --will return nothing if no claims are found&lt;br /&gt;
	 	end	&lt;br /&gt;
	&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	if entity then --only require the main gene entity&lt;br /&gt;
		--a list variables of all the data in the info box&lt;br /&gt;
		local chr = check_values(p.trimChromosome, {entity})&lt;br /&gt;
		--local drug = check_values(p.getDrug, {entity_protein, &amp;quot;P129&amp;quot;})&lt;br /&gt;
		&lt;br /&gt;
		--define Global Color Scheme&lt;br /&gt;
		rowBGcolor = &amp;#039;#eee&amp;#039;&lt;br /&gt;
		titleBGcolor = &amp;#039;#ddd&amp;#039;&lt;br /&gt;
		sideTitleBGcolor = &amp;#039;#c3fdb8&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
		return tostring(root)&lt;br /&gt;
        --return table.concat(drug_pqid)&lt;br /&gt;
        &lt;br /&gt;
	else return &amp;quot;An Error has occurred retrieving Wikidata item for infobox&amp;quot;&lt;br /&gt;
	end	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--general function to get value given an entity and property&lt;br /&gt;
p.getValue = function(entity, propertyID, return_val)&lt;br /&gt;
&lt;br /&gt;
	local claims&lt;br /&gt;
	if return_val == nil then return_val = &amp;quot;&amp;quot; end&lt;br /&gt;
    local sep = &amp;quot; &amp;quot; --could ad as input parameter if need be&lt;br /&gt;
	if entity and entity.claims then&lt;br /&gt;
		claims = entity.claims[propertyID]&lt;br /&gt;
	end&lt;br /&gt;
	if claims then&lt;br /&gt;
		-- if wiki-linked value output as link if possible&lt;br /&gt;
		if (claims[1] and claims[1].mainsnak.snaktype == &amp;quot;value&amp;quot; and claims[1].mainsnak.datavalue.type == &amp;quot;wikibase-entityid&amp;quot;) then&lt;br /&gt;
			local out = {}&lt;br /&gt;
			for k, v in pairs(claims) do&lt;br /&gt;
				local datav = mw.wikibase.label(&amp;quot;Q&amp;quot; .. v.mainsnak.datavalue.value[&amp;quot;numeric-id&amp;quot;])&lt;br /&gt;
				if datav == nil then datav = &amp;quot; &amp;quot; end &lt;br /&gt;
				out[#out + 1] = datav			&lt;br /&gt;
			end&lt;br /&gt;
			return table.concat(out, sep)&lt;br /&gt;
		else&lt;br /&gt;
		-- just return best values&lt;br /&gt;
			return entity:formatPropertyValues(propertyID).value&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return return_val&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.trimChromosome = function(entity)&lt;br /&gt;
	local string_to_trim = p.getValue(entity, &amp;quot;P1057&amp;quot;)&lt;br /&gt;
	local out = &amp;#039;&amp;#039;&lt;br /&gt;
	&lt;br /&gt;
	--&amp;quot;mitochondrion&amp;quot; and &amp;quot;chromosome MT&amp;quot; is used for mitochondrial DNA.&lt;br /&gt;
	--See [[d:Special:WhatLinksHere/Q18694495]]&lt;br /&gt;
	if string.find(string_to_trim, &amp;#039;chromosome MT&amp;#039;) or string.find(string_to_trim, &amp;#039;mitochondri&amp;#039;) then --match both &amp;#039;mitochondrio&amp;#039;/&amp;#039;mitochondrial&amp;#039;&lt;br /&gt;
		out = &amp;quot;MT&amp;quot;&lt;br /&gt;
	elseif string.find(string_to_trim, &amp;#039;chromosome&amp;#039;) then&lt;br /&gt;
		out = string.match(string_to_trim, &amp;quot;%d+&amp;quot;)--extract number from string&lt;br /&gt;
		if out == nil then&lt;br /&gt;
			out = string.match(string_to_trim, &amp;quot;X&amp;quot;) or string.match(string_to_trim, &amp;quot;Y&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return out	&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local chr = check_values(p.trimChromosome, {entity})&lt;br /&gt;
local category_chromosome = &amp;#039;[[Category:Genes on human chromosome &amp;#039;..chr..&amp;#039;]]&amp;#039;&lt;br /&gt;
&lt;br /&gt;
function p._main(args)&lt;br /&gt;
&lt;br /&gt;
	return chr&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Mensis Mirabilis</name></author>
	</entry>
</feed>