<?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%2Fgenewiki%2Fexperimental</id>
	<title>Module:Sandbox/genewiki/experimental - 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%2Fgenewiki%2Fexperimental"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/genewiki/experimental&amp;action=history"/>
	<updated>2026-04-21T22:00:24Z</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/genewiki/experimental&amp;diff=146505&amp;oldid=prev</id>
		<title>imported&gt;I9606: have julias function working sort of, but can;t see where it tries to keep track of the coordinates.. don&#039;t think it does and don&#039;t think you can reverse the path the way it looks like she wants to.</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/genewiki/experimental&amp;diff=146505&amp;oldid=prev"/>
		<updated>2015-10-16T00:08:17Z</updated>

		<summary type="html">&lt;p&gt;have julias function working sort of, but can;t see where it tries to keep track of the coordinates.. don&amp;#039;t think it does and don&amp;#039;t think you can reverse the path the way it looks like she wants to.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--uncomment and add this to the debug console to run code.&lt;br /&gt;
--frame = mw.getCurrentFrame()&lt;br /&gt;
--frame.args = {&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, from =&amp;quot;Q14865053&amp;quot;}&lt;br /&gt;
--print(p.hello(frame))&lt;br /&gt;
&lt;br /&gt;
---require(&amp;#039;Module:Wikidata&amp;#039;)	&lt;br /&gt;
&lt;br /&gt;
-- All Lua modules on Wikipedia must begin by defining a variable that will hold their&lt;br /&gt;
-- externally accessible functions. They can have any name and may also hold data.&lt;br /&gt;
p = {&lt;br /&gt;
	devmode	 = false&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
p.getQualifierID = function(frame)&lt;br /&gt;
	local propertyID = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;) &lt;br /&gt;
	local qualifierID = mw.text.trim(frame.args[2] or &amp;quot;&amp;quot;)&lt;br /&gt;
	local input_parm = mw.text.trim(frame.args[3] or &amp;quot;&amp;quot;)&lt;br /&gt;
	local itemID = mw.text.trim(frame.args[4] or &amp;quot;&amp;quot;) --if direct link from wikidata item&lt;br /&gt;
	&lt;br /&gt;
	if input_parm == &amp;quot;FETCH_WIKIDATA&amp;quot; then&lt;br /&gt;
		local entity = &amp;quot;&amp;quot;&lt;br /&gt;
		if itemID ~= &amp;quot;&amp;quot; then&lt;br /&gt;
			entity = mw.wikibase.getEntityObject(itemID)&lt;br /&gt;
		else&lt;br /&gt;
			entity = mw.wikibase.getEntityObject()&lt;br /&gt;
		end&lt;br /&gt;
		if entity.claims[propertyID] ~= nil then&lt;br /&gt;
			local out = {}&lt;br /&gt;
			for k, v in pairs(entity.claims[propertyID]) do&lt;br /&gt;
				for k2, v2 in pairs(v.qualifiers[qualifierID]) do&lt;br /&gt;
					if v2.snaktype == &amp;#039;value&amp;#039; then&lt;br /&gt;
							out[#out + 1] = &amp;quot;Q&amp;quot; .. v2.datavalue.value[&amp;quot;numeric-id&amp;quot;]&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			return table.concat(out, &amp;quot;, &amp;quot;)&lt;br /&gt;
		else&lt;br /&gt;
			return &amp;quot;&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return input_parm&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Try to replace this with one function that fails gracefully&lt;br /&gt;
--- Get the image URL associated the current article&lt;br /&gt;
---{{#invoke:Wikidata|getValueFromID|{{#invoke:Sandbox/genewiki/geneboxdev |getQIDFromID |{{#invoke:Wikidata|pageId}} |P688}}|P18|FETCH_WIKIDATA}}&lt;br /&gt;
--- breaks apart to be &lt;br /&gt;
---{{#invoke:Wikidata|getValueFromID|&lt;br /&gt;
---	{{#invoke:Sandbox/genewiki/geneboxdev |getQIDFromID |&lt;br /&gt;
---		{{#invoke:Wikidata|pageId}} &lt;br /&gt;
---	|P688}}&lt;br /&gt;
---|P18|FETCH_WIKIDATA}}&lt;br /&gt;
--- testing on ARF6 Q14865053 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
p.testEntityId = function(wikidata_qid)&lt;br /&gt;
	--pcall pattern does not not work for this..&lt;br /&gt;
	--local entity = mw.wikibase.getEntity(wikidata_qid)&lt;br /&gt;
	--but it does for locally generated errors like this&lt;br /&gt;
	local entity = 2+&amp;quot;error&amp;quot;&lt;br /&gt;
	return entity&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- test entry point&lt;br /&gt;
-- local qid = mw.text.trim(frame.args[&amp;#039;from&amp;#039;])&lt;br /&gt;
p.hello = function( frame ) &lt;br /&gt;
	local qid = &amp;quot;1Q14865053&amp;quot;&lt;br /&gt;
	local out = &amp;quot;&amp;quot;&lt;br /&gt;
	--this is like a try statement&lt;br /&gt;
	local worked,value = pcall(p.testEntityId, qid) &lt;br /&gt;
	if(worked)&lt;br /&gt;
		then out = value &lt;br /&gt;
		else out = &amp;quot;error! &amp;quot;..value&lt;br /&gt;
	end&lt;br /&gt;
    return out    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--gets an image for a qif, doesn&amp;#039;t die if no qid is given to it. &lt;br /&gt;
--frame = mw.getCurrentFrame()&lt;br /&gt;
--frame.args = {QID=&amp;quot;Q14865053&amp;quot;}&lt;br /&gt;
--print(p.getDefaultImage(frame))&lt;br /&gt;
&lt;br /&gt;
p.getDefaultImage = function(frame)&lt;br /&gt;
	local wikidata_id = mw.text.trim(frame.args[&amp;#039;QID&amp;#039;] or &amp;quot;&amp;quot;)&lt;br /&gt;
	-- &amp;quot;nil&amp;quot; (a string, not the value nil), &amp;quot;number&amp;quot;, &amp;quot;string&amp;quot;, &amp;quot;boolean&amp;quot;, &amp;quot;table&amp;quot;, &amp;quot;function&amp;quot;, &amp;quot;thread&amp;quot;, and &amp;quot;userdata&amp;quot;.&lt;br /&gt;
	if wikidata_id == nil &lt;br /&gt;
		then return &amp;quot;&amp;quot;&lt;br /&gt;
	elseif string.len(wikidata_id) &amp;lt; 3  &lt;br /&gt;
		then return &amp;quot;&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local propertyID = &amp;quot;P18&amp;quot;&lt;br /&gt;
	local sep = mw.text.trim(&amp;quot; &amp;quot;)&lt;br /&gt;
	local imgsize = mw.text.trim(&amp;quot;220px&amp;quot;)&lt;br /&gt;
	local entity = mw.wikibase.getEntity(wikidata_id)&lt;br /&gt;
	local claims&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 (claims[1] and claims[1].mainsnak.datatype == &amp;quot;commonsMedia&amp;quot;) then&lt;br /&gt;
			local out = {}&lt;br /&gt;
			for k, v in pairs(claims) do&lt;br /&gt;
				local filename = v.mainsnak.datavalue.value&lt;br /&gt;
				out[#out + 1] = &amp;quot;[[File:&amp;quot; .. filename .. &amp;quot;|&amp;quot; .. imgsize .. &amp;quot;]]&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
				return table.concat(out, sep)&lt;br /&gt;
		else&lt;br /&gt;
			return &amp;quot;&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return input_parm&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.ViewSomething(frame)&lt;br /&gt;
	local itemID =&amp;quot;Q14865053&amp;quot;&lt;br /&gt;
	local data = mw.wikibase.getEntityObject(itemID)&lt;br /&gt;
	if not data then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
---	local f = frame.args[1] and frame or frame:getParent()&lt;br /&gt;
&lt;br /&gt;
	local i = 1&lt;br /&gt;
	while true do&lt;br /&gt;
---		local index = f.args[i]&lt;br /&gt;
---		if not index then&lt;br /&gt;
			if type(data) == &amp;quot;table&amp;quot; then&lt;br /&gt;
				return mw.text.jsonEncode(data, mw.text.JSON_PRESERVE_KEYS + mw.text.JSON_PRETTY)&lt;br /&gt;
			else&lt;br /&gt;
				return tostring(data)&lt;br /&gt;
			end&lt;br /&gt;
---		end&lt;br /&gt;
		&lt;br /&gt;
		data = data[index] or data[tonumber(index)]&lt;br /&gt;
		if not data then&lt;br /&gt;
			return&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		i = i + 1&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.getChromosomeLocJulia = function(frame)&lt;br /&gt;
	local propertyID = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;) &lt;br /&gt;
	local qualifierID = mw.text.trim(frame.args[2] or &amp;quot;&amp;quot;)&lt;br /&gt;
	local input_parm = mw.text.trim(frame.args[3] or &amp;quot;&amp;quot;)&lt;br /&gt;
	local qualifierIds = p.getQualifierID(frame)&lt;br /&gt;
	local newest_build = &amp;quot;&amp;quot;&lt;br /&gt;
	local preferred_value = &amp;quot;not set&amp;quot;&lt;br /&gt;
	if qualifierIds then&lt;br /&gt;
		local list_itemID = mw.text.split(qualifierIds,&amp;quot;,&amp;quot;)&lt;br /&gt;
		for index,value in ipairs(list_itemID) do&lt;br /&gt;
  			local entity = mw.wikibase.getEntityObject(value)&lt;br /&gt;
			local alias = &amp;quot;&amp;quot;&lt;br /&gt;
			if entity[&amp;#039;aliases&amp;#039;] ~= nil then&lt;br /&gt;
        		local test = entity[&amp;#039;aliases&amp;#039;][&amp;#039;en&amp;#039;]&lt;br /&gt;
				for key, value in ipairs(test) do&lt;br /&gt;
					if string.match(value[&amp;#039;value&amp;#039;], &amp;#039;^hg&amp;#039;) then&lt;br /&gt;
						alias = value[&amp;#039;value&amp;#039;]&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				local build_no = alias:gsub(&amp;quot;hg&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
				if newest_build &amp;lt; build_no or newest_build == &amp;quot;&amp;quot; then&lt;br /&gt;
					newest_build = build_no&lt;br /&gt;
					preferred_value = &amp;quot;path here&amp;quot;&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return preferred_value&lt;br /&gt;
	else&lt;br /&gt;
		return &amp;quot;nnn&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	return &amp;quot;mmm&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
---getChromosomeLoc &lt;br /&gt;
---input propertyID ie(Genomic start) P644&lt;br /&gt;
---      qualifierID (ie GenLoc Assembly) P659&lt;br /&gt;
---      input_parm (ie FETCH_WIKIDATA)  &lt;br /&gt;
---      {{#invoke:Sandbox/genewiki/geneboxdev|getChromosomeLoc|P644|P659|FETCH_WIKIDATA}}&lt;br /&gt;
---output preferred chromosome location start value in this case it would be 49893092&lt;br /&gt;
&lt;br /&gt;
--for debug window -- Q14865053&lt;br /&gt;
--frame = mw.getCurrentFrame()&lt;br /&gt;
--frame.args = {&amp;quot;P644&amp;quot;,&amp;quot;P659&amp;quot;,&amp;quot;FETCH_WIKIDATA&amp;quot;,&amp;quot;Q14865053&amp;quot;}&lt;br /&gt;
--print(p.getChromosomeLoc(frame))&lt;br /&gt;
&lt;br /&gt;
p.getChromosomeLoc = function(frame)&lt;br /&gt;
	-- will contain the numeric value for the requested coordinate&lt;br /&gt;
	local output = &amp;quot;&amp;quot;&lt;br /&gt;
	local sep = &amp;quot; &amp;quot;&lt;br /&gt;
	-- can only be P644 (genomic start) or P645 (genomic end) for this to work&lt;br /&gt;
	-- should probably try to catch that.  Might also increase legibility to use specific variable names when possible&lt;br /&gt;
	local propertyID = mw.text.trim(frame.args[1] or &amp;quot;&amp;quot;) &lt;br /&gt;
	-- this can really only be P659 right now.  I&amp;#039;m not sure of the value of including it as a parameter as other values will likely break this function&lt;br /&gt;
	local qualifierID = mw.text.trim(frame.args[2] or &amp;quot;&amp;quot;)&lt;br /&gt;
	-- Why do we include this here?  What should happen if FETCH_WIKIDATA is not included? &lt;br /&gt;
	local input_parm = mw.text.trim(frame.args[3] or &amp;quot;&amp;quot;)&lt;br /&gt;
	-- this can needs to be fed to the function either by a call to {{#invoke:Wikidata|pageId}} or by setting it directly (e.g. if the function was applied on a page other than the targeted gene)&lt;br /&gt;
	--alert if this id is not a valid thing in wikidata, a Lua error will occur that says&lt;br /&gt;
	--The ID entered is unknown to the system. Please use a valid entity ID.&lt;br /&gt;
	local itemID = mw.text.trim(frame.args[4] or &amp;quot;&amp;quot;)&lt;br /&gt;
	-- will track the different builds pulled from the qualifiers&lt;br /&gt;
	local newest_build = &amp;quot;0&amp;quot;&lt;br /&gt;
	-- starts the process&lt;br /&gt;
	local entity = mw.wikibase.getEntityObject(itemID)&lt;br /&gt;
	local claims&lt;br /&gt;
	--gets a table of claims on the (genomic start or end) property Q19847637&lt;br /&gt;
	if entity and entity.claims then&lt;br /&gt;
		claims = entity.claims[propertyID]&lt;br /&gt;
	end&lt;br /&gt;
	--will return nothing if no claims are found&lt;br /&gt;
	if claims then&lt;br /&gt;
		--checking to be sure claims is populated, not sure it its needed&lt;br /&gt;
		if (claims[1] ) then&lt;br /&gt;
			--useful for debugging&lt;br /&gt;
			--local out = {}&lt;br /&gt;
			--pulls the genome location from the claim&lt;br /&gt;
			for k, v in pairs(claims) do&lt;br /&gt;
				local location = v.mainsnak.datavalue.value&lt;br /&gt;
				--debugging&lt;br /&gt;
				--out[#out + 1] = k..&amp;quot; location:&amp;quot; .. location.. &amp;quot; || &amp;quot; &lt;br /&gt;
				--gets the qualifiers linked to the current claim&lt;br /&gt;
				local quals = v.qualifiers.P659 &lt;br /&gt;
				--if there are any&lt;br /&gt;
				if quals then&lt;br /&gt;
					for qk, qv in pairs(quals) do&lt;br /&gt;
						local qual_obj_id = &amp;quot;Q&amp;quot;..qv.datavalue.value[&amp;quot;numeric-id&amp;quot;]&lt;br /&gt;
						--get to the entity targeted by the qualifier property.  Genome builds are Items in wikidata&lt;br /&gt;
						local qual_obj = mw.wikibase.getEntityObject(qual_obj_id)&lt;br /&gt;
						local alias = &amp;quot;&amp;quot;&lt;br /&gt;
						--this uses the aliases to pull out version numbers&lt;br /&gt;
						--seems like there ought to be a better way to do this, but likely would need to change the data added by the bot&lt;br /&gt;
						if qual_obj[&amp;quot;aliases&amp;quot;] ~= nil then&lt;br /&gt;
							local test = qual_obj[&amp;quot;aliases&amp;quot;][&amp;quot;en&amp;quot;]&lt;br /&gt;
							for key, value in ipairs(test) do&lt;br /&gt;
								if string.match(value[&amp;#039;value&amp;#039;], &amp;#039;^hg&amp;#039;) then&lt;br /&gt;
									alias = value[&amp;#039;value&amp;#039;]&lt;br /&gt;
									local build_no = alias:gsub(&amp;quot;hg&amp;quot;,&amp;quot;&amp;quot;)&lt;br /&gt;
									--report only the most location associated with the most recent build&lt;br /&gt;
									--if there is more than one location per build, just give one back as that is not our problem right now.&lt;br /&gt;
									if build_no &amp;gt; newest_build then&lt;br /&gt;
										output = location&lt;br /&gt;
										newest_build = build_no&lt;br /&gt;
									end&lt;br /&gt;
								end&lt;br /&gt;
							end&lt;br /&gt;
						end&lt;br /&gt;
					end&lt;br /&gt;
				--in case there are no qualifiers, but there is a location, might as well return it&lt;br /&gt;
				else output = location &lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
				return output&lt;br /&gt;
		else&lt;br /&gt;
			return &amp;quot;&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		return &amp;quot;&amp;quot;&lt;br /&gt;
		--debug&lt;br /&gt;
		--&amp;quot;no claims for &amp;quot;..itemID..&amp;quot; prop &amp;quot;..propertyID&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- All modules end by returning the variable containing its functions to Wikipedia.&lt;br /&gt;
return p&lt;br /&gt;
&lt;br /&gt;
-- We can now use this module by calling {{#invoke: HelloWorld | hello }}.&lt;br /&gt;
-- The #invoke command begins with the module&amp;#039;s name, in this case &amp;quot;HelloWorld&amp;quot;,&lt;br /&gt;
-- then takes the name of one of its functions as an argument, in this case &amp;quot;hello&amp;quot;.&lt;/div&gt;</summary>
		<author><name>imported&gt;I9606</name></author>
	</entry>
</feed>