Module:Analysis
More actions
Analysis pages: one measurement or study of one accession's material, on its own page titled
Analysis:<accession ID>/<type> <n>. The fields are described on Template:Analysis.
Entry points
page- Template:Analysis. Reads the template's arguments, checks them, stores them with
#set(and each measurement with#subobject), and shows the page: an infobox, a first sentence, the finding, the reference material and the measurements. A field error is listed at the top and files the page in Category:Pages with analysis errors.
measurement- Template:Analysis measurement. Hands its fields over as a hidden token; the
pageentry point reads the tokens in themeasurementsfield and stores one subobject per measurement (m-1,m-2…), each naming the page through Property:Is measurement of.
list- Template:Accession,analyses: the analyses whose
Property:Is analysis of names the accession, as list items for Template:Infobox accession: type and year, then the tissue and the generation.
pagename-{{#invoke:Analysis|pagename|accession=…|type=…}}: the
next free title for that accession and type.
What it stores
On the page: Property:Is analysis of, Property:Has sampled lot, Property:Has analysis type, Property:Has analysis label (type and year, for links to the page), Property:Has sample identifier, Property:Has sample tissue, Property:Has sample generation, Property:Has analysing laboratory, Property:Has analysis date, Property:Has analysis source, Property:Has data repository URL, Property:Has reference place, Property:Has reference set, Property:Has analysis finding, and the sample point as Property:Has coordinates, Property:Has coordinate uncertainty and Property:Has georeference basis.
On each measurement: Property:Is measurement of, Property:Has measured quantity, Property:Has measured value, Property:Has measurement unit, Property:Has reference standard, Property:Has measurement uncertainty, Property:Has measurement note.
Values from a fixed list (type, tissue, reference standard, georeference basis) are matched without regard to case and stored in the list's own spelling; a value outside the list is not stored and is reported. Keep the lists at the top of the module in step with the properties' allowed values.
What it does not do
It compares nothing. It works out no match, score, probability or level of provenance evidence from the figures: an analysis counts at a level only through the study's own comparison, entered on the accession (see Property:Has identity confirmation).
Tests
p._build(args, title) returns the cleaned fields, the #set and #subobject
arguments and the errors without a frame, for tests run in the console. With p._asText = true,
page returns the #set and #subobject calls as wikitext, so a parse of the
output shows any warning SMW gives. p._listRows replaces the list query with given rows.
-- Module:Analysis
-- An analysis page: one measurement or study of one accession's material (genotyping, genome sequencing,
-- stable isotope ratios, an infrared spectrum, a cannabinoid assay, a measurement of the achenes), on its
-- own page titled Analysis:<accession>/<type> <n>, through Template:Analysis (entry point `page`).
-- Measurements are given as {{Analysis measurement}} calls in the page's `measurements` field. Each call only
-- hands its fields to this module (entry point `measurement`); this module stores every measurement as a
-- subobject naming its analysis page (Is measurement of), so the page and its measurements are written in one
-- place.
-- Template:Accession lists an accession's analyses in its infobox (entry point `list`).
-- The module records what a study reports. It compares nothing, scores nothing and works out no level of
-- provenance evidence: that is set on the accession, from the rules on Property:Has identity confirmation.
local p = {}
------------------------------------------------------------------------------------------
-- Vocabularies (the Allows values of the properties; keep both in step)
------------------------------------------------------------------------------------------
local TYPES = { 'Genotyping', 'Genome sequencing', 'Stable isotope ratios', 'Infrared spectrum',
'Cannabinoid assay', 'Achene measurement' }
local TISSUES = { 'Seed', 'Seed coat', 'Embryo', 'Leaf', 'Bract', 'Flower', 'Stem', 'Root' }
local STANDARDS = { 'VPDB', 'AIR', 'VSMOW', 'NIST SRM 987' }
local BASES = { "holder's georeference", 'collection point from label', 'settlement point', 'district point',
'province point', 'obfuscated field point' }
-- How each type opens the page's first sentence.
local LEAD = {
['Genotyping'] = 'Genotyping',
['Genome sequencing'] = 'Genome sequencing',
['Stable isotope ratios'] = 'Stable isotope ratios',
['Infrared spectrum'] = 'An infrared spectrum',
['Cannabinoid assay'] = 'A cannabinoid assay',
['Achene measurement'] = 'A measurement of the achenes',
}
p._TYPES, p._TISSUES, p._STANDARDS = TYPES, TISSUES, STANDARDS
local PREFIX = 'Analysis:'
local CATEGORY = 'Analyses'
local ERROR_CATEGORY = 'Pages with analysis errors'
local PRIMARY_LOT = 'lot' -- Module:Seed lot's subobject name for an accession's main lot
------------------------------------------------------------------------------------------
-- Helpers
------------------------------------------------------------------------------------------
local function trim(s)
if s == nil then return nil end
s = mw.text.trim(tostring(s))
if s == '' then return nil end
return s
end
local function splitList(s)
local out = {}
if not trim(s) then return out end
for _, v in ipairs(mw.text.split(s, ',', true)) do
v = trim(v)
if v then out[#out + 1] = v end
end
return out
end
-- A value in a fixed list, matched without regard to case; returns the list's own spelling.
local function canonical(list, v)
v = trim(v)
if not v then return nil end
local lv = mw.ustring.lower(v)
for _, c in ipairs(list) do
if mw.ustring.lower(c) == lv then return c end
end
return nil
end
p._canonical = canonical
-- A number as papers print it: a Unicode minus, a leading ±, thousands commas.
local function number(v)
v = trim(v)
if not v then return nil end
v = mw.ustring.gsub(v, '[−–]', '-')
v = mw.ustring.gsub(v, '^±%s*', '')
v = v:gsub(',', '')
local n = tonumber(v)
if n == nil then return nil end
return n, v
end
p._number = number
-- Generation of the plant the sampled tissue grew on: 0 = it grew at the collection site.
-- Returns the stored number (or false for "unknown") and its words.
local function generation(v)
v = trim(v)
if not v then return nil end
local lv = mw.ustring.lower(v)
if lv == 'unknown' or lv == 'not known' then return false, 'not known' end
if lv == 'field' then v = '0' end
local r = lv:match('^r(%d+)$')
if r then v = r end
local n = tonumber(v)
if not n or n < 0 or n ~= math.floor(n) then return nil end
if n == 0 then return 0, 'field: grew at the collection site' end
return n, 'grow-out ' .. n .. ' (R' .. n .. '): grew away from the collection site'
end
p._generation = generation
local function isoDate(v)
v = trim(v)
if not v then return nil end
if v:match('^%d%d%d%d$') or v:match('^%d%d%d%d%-[01]%d$') or v:match('^%d%d%d%d%-[01]%d%-[0-3]%d$') then return v end
return nil
end
local function coordinates(v)
v = trim(v)
if not v then return nil end
local a, b = v:match('^(%-?%d+%.?%d*)%s*,%s*(%-?%d+%.?%d*)$')
a, b = tonumber(a), tonumber(b)
if not a or not b or a < -90 or a > 90 or b < -180 or b > 180 then return nil end
return v
end
-- A lot named in the `lot` field: a Lot: page, a lot subobject (Page#lot), or an accession page, which
-- means that accession's main lot (as in Module:Seed lot).
local function lotRef(v)
v = trim(v)
if not v then return nil end
v = trim((v:gsub('^%[%[', ''):gsub('%]%]$', ''):gsub('|.*$', '')))
if not v then return nil end
if v:find('#', 1, true) or v:match('^[Ll]ot:') then return v end
return v .. '#' .. PRIMARY_LOT
end
local function plainTitle(v)
v = trim(v)
if not v then return nil end
return trim((v:gsub('^%[%[:?', ''):gsub('%]%]$', ''):gsub('|.*$', '')))
end
local function exists(title)
local ok, t = pcall(mw.title.new, title)
return ok and t and t.exists
end
local function link(title, label)
if exists(title) then return '[[:' .. title .. (label and ('|' .. label) or '') .. ']]' end
return label or title
end
-- δ13C as δ<sup>13</sup>C, 87Sr/86Sr as <sup>87</sup>Sr/<sup>86</sup>Sr; anything else as written.
local function quantityLabel(q)
q = mw.ustring.gsub(q, 'δ(%d+)(%u%l?)', 'δ<sup>%1</sup>%2')
q = mw.ustring.gsub(q, '^(%d+)(%u%l?)/(%d+)(%u%l?)$', '<sup>%1</sup>%2/<sup>%3</sup>%4')
return q
end
p._quantityLabel = quantityLabel
-- The parts of a title Analysis:<accession>/<type> <n>.
local function titleParts(title)
if not title or title:sub(1, #PREFIX) ~= PREFIX then return nil end
local rest = title:sub(#PREFIX + 1)
local acc, tail = rest:match('^(.*)/([^/]+)$')
if not acc then return nil end
local typ, n = tail:match('^(.-)%s+(%d+)$')
return { accession = acc, type = typ or tail, n = n and tonumber(n) }
end
p._titleParts = titleParts
------------------------------------------------------------------------------------------
-- Measurements: {{Analysis measurement}} hands its fields over as a hidden token
------------------------------------------------------------------------------------------
local MEASUREMENT_FIELDS = { 'quantity', 'value', 'unit', 'standard', 'uncertainty', 'note' }
-- {{#invoke:Analysis|measurement}}; the fields come from the calling template's arguments.
function p.measurement(frame)
local parent = frame:getParent()
local args = parent and parent.args or frame.args
local data = {}
for _, k in ipairs(MEASUREMENT_FIELDS) do data[k] = trim(args[k]) end
local enc = mw.text.encode(mw.text.jsonEncode(data))
return '<span class="lw-analysis-measurement" style="display:none" data-analysis-measurement="' .. enc .. '"></span>'
end
local function readMeasurements(text)
local out = {}
if not trim(text) then return out end
for enc in tostring(text):gmatch('data%-analysis%-measurement="([^"]*)"') do
local ok, data = pcall(mw.text.jsonDecode, mw.text.decode(enc))
if ok and type(data) == 'table' then out[#out + 1] = data end
end
return out
end
p._readMeasurements = readMeasurements
------------------------------------------------------------------------------------------
-- Building an analysis from its arguments (pure: no store, no frame; the fixtures call it)
------------------------------------------------------------------------------------------
-- args: the page's parameters; title: the page title. Returns
-- { a = cleaned fields, set = {Prop=value ...}, subobjects = { {name, Prop=value ...} ... }, errors = {...} }
function p._build(args, title)
local a, errors = { measurements = {} }, {}
local function err(s) errors[#errors + 1] = s end
local tp = titleParts(title)
a.accession = plainTitle(args.accession) or (tp and tp.accession)
if not a.accession then
err('no accession named (accession=)')
elseif tp and tp.accession ~= a.accession then
err('the title names ' .. tp.accession .. ' but accession= names ' .. a.accession)
end
local typeIn = trim(args.type) or (tp and tp.type)
a.type = canonical(TYPES, typeIn)
if not typeIn then
err('no type given (type=)')
elseif not a.type then
err('type "' .. typeIn .. '" is not one of: ' .. table.concat(TYPES, ', '))
elseif tp and canonical(TYPES, tp.type) ~= a.type then
err('the title names the type ' .. tp.type .. ' but type= is ' .. a.type)
end
if tp and not tp.n then err('the title must end in a number: ' .. PREFIX .. '<accession>/<type> <n>') end
a.lot = lotRef(args.lot)
a.sample_id = trim(args.sample_id)
a.tissue = {}
for _, t in ipairs(splitList(args.tissue)) do
local c = canonical(TISSUES, t)
if c then a.tissue[#a.tissue + 1] = c else err('tissue "' .. t .. '" is not one of: ' .. table.concat(TISSUES, ', ')) end
end
local gIn = trim(args.generation)
if not gIn then
err('no generation given (generation=: 0 for tissue that grew at the collection site, 1 for a first grow-out, … or unknown)')
else
local g, words = generation(gIn)
if g == nil then
err('generation "' .. gIn .. '" is not a whole number, field, R1 … or unknown')
else
a.generation, a.generation_words = g, words
end
end
a.laboratory = {}
for _, l in ipairs(splitList(args.laboratory)) do a.laboratory[#a.laboratory + 1] = plainTitle(l) end
if trim(args.date) then
a.date = isoDate(args.date)
if not a.date then err('date "' .. trim(args.date) .. '" is not yyyy, yyyy-mm or yyyy-mm-dd') end
end
a.source = plainTitle(args.source)
a.data_url = {}
for _, u in ipairs(splitList(args.data_url)) do
if u:match('^https?://[^%s]+$') then a.data_url[#a.data_url + 1] = u else err('data_url "' .. u .. '" is not a web address') end
end
a.reference_place = {}
for _, r in ipairs(splitList(args.reference_place)) do a.reference_place[#a.reference_place + 1] = plainTitle(r) end
a.reference_set = trim(args.reference_set)
a.finding = trim(args.finding)
if trim(args.coordinates) then
a.coordinates = coordinates(args.coordinates)
if not a.coordinates then
err('coordinates "' .. trim(args.coordinates) .. '" are not decimal latitude, longitude')
else
-- The sample point is entered through the team's displaced pin, like an accession's point (Privacy policy).
local basisIn = trim(args.georeference_basis)
a.georeference_basis = basisIn and canonical(BASES, basisIn) or (not basisIn and 'obfuscated field point') or nil
if basisIn and not a.georeference_basis then
err('georeference_basis "' .. basisIn .. '" is not one of the values on Property:Has georeference basis')
end
local uIn = trim(args.coordinate_uncertainty)
if uIn then
local u = number(uIn)
if u and u >= 0 then a.coordinate_uncertainty = tostring(u) else err('coordinate_uncertainty "' .. uIn .. '" is not a number of metres') end
elseif a.georeference_basis == 'obfuscated field point' then
a.coordinate_uncertainty = '500'
end
end
end
-- Measurements.
for i, m in ipairs(readMeasurements(args.measurements)) do
local e = { quantity = trim(m.quantity), unit = trim(m.unit), note = trim(m.note) }
if not e.quantity then err('measurement ' .. i .. ' names no quantity') end
local v = number(m.value)
if trim(m.value) and v == nil then
err('measurement ' .. i .. ': value "' .. m.value .. '" is not a number (put a range or a limit such as "below detection" in note=)')
end
if v ~= nil then e.value = select(2, number(m.value)) end
if not trim(m.value) and not e.note then err('measurement ' .. i .. ' gives no value') end
if trim(m.standard) then
e.standard = canonical(STANDARDS, m.standard)
if not e.standard then err('measurement ' .. i .. ': standard "' .. m.standard .. '" is not one of: ' .. table.concat(STANDARDS, ', ')) end
end
if trim(m.uncertainty) then
local u, us = number(m.uncertainty)
if u then e.uncertainty = us else err('measurement ' .. i .. ': uncertainty "' .. m.uncertainty .. '" is not a number') end
end
a.measurements[#a.measurements + 1] = e
end
-- The label other pages show for this analysis: its type and year.
a.year = a.date and a.date:sub(1, 4) or nil
a.label = a.type and (a.type .. (a.year and (', ' .. a.year) or '')) or nil
-- What is stored.
local set = {}
local function put(prop, v)
if type(v) == 'table' then
if #v > 0 then
set[#set + 1] = prop .. '=' .. table.concat(v, ';')
set[#set + 1] = '+sep=;'
end
elseif v ~= nil and v ~= false and tostring(v) ~= '' then
set[#set + 1] = prop .. '=' .. tostring(v)
end
end
put('Is analysis of', a.accession)
put('Has sampled lot', a.lot)
put('Has analysis type', a.type)
put('Has analysis label', a.label)
put('Has sample identifier', a.sample_id)
put('Has sample tissue', a.tissue)
put('Has sample generation', a.generation)
put('Has analysing laboratory', a.laboratory)
put('Has analysis date', a.date)
put('Has analysis source', a.source)
put('Has data repository URL', a.data_url)
put('Has reference place', a.reference_place)
put('Has reference set', a.reference_set)
put('Has analysis finding', a.finding)
put('Has coordinates', a.coordinates)
put('Has coordinate uncertainty', a.coordinate_uncertainty)
put('Has georeference basis', a.georeference_basis)
local subs = {}
for i, e in ipairs(a.measurements) do
local s = { 'm-' .. i, 'Is measurement of=' .. (title or '') }
if e.quantity then s[#s + 1] = 'Has measured quantity=' .. e.quantity end
if e.value then s[#s + 1] = 'Has measured value=' .. e.value end
if e.unit then s[#s + 1] = 'Has measurement unit=' .. e.unit end
if e.standard then s[#s + 1] = 'Has reference standard=' .. e.standard end
if e.uncertainty then s[#s + 1] = 'Has measurement uncertainty=' .. e.uncertainty end
if e.note then s[#s + 1] = 'Has measurement note=' .. e.note end
subs[#subs + 1] = s
end
return { a = a, set = set, subobjects = subs, errors = errors }
end
------------------------------------------------------------------------------------------
-- Display
------------------------------------------------------------------------------------------
-- p._asText: the fixtures and the render check set it, so #set and #subobject come back as wikitext
-- that action=parse evaluates (and warns on) instead of being consumed by the console.
p._asText = false
local function emit(frame, fn, args)
if p._asText then
local parts = {}
for _, v in ipairs(args) do parts[#parts + 1] = (tostring(v):gsub('|', '{{!}}')) end
return '{{' .. fn .. ':' .. table.concat(parts, '|') .. '}}'
end
return frame:callParserFunction(fn, args)
end
local function showValue(frame, page, prop)
if not page or not exists(page) then return nil end
return trim(frame:preprocess('{{#show:' .. page .. '|?' .. prop .. '|link=none}}'))
end
local function accessionLink(frame, acc)
if not acc then return "''not named''" end
local name = showValue(frame, acc, 'Has descriptive name')
if name and name ~= acc then return link(acc, name) .. ' <small>(' .. acc .. ')</small>' end
return link(acc)
end
local function lotLink(ref)
if not ref then return nil end
local page, sub = ref:match('^(.-)#(.*)$')
if page and sub == PRIMARY_LOT then return link(page) .. ' (main lot)' end
return link(ref)
end
local function sourceLink(frame, src)
if not src then return nil end
return trim(frame:expandTemplate{ title = 'Provenance evidence link', args = { src } })
end
local function hostOf(u)
return (u:match('^https?://([^/%?#]+)') or u):gsub('^www%.', '')
end
local function infoboxRows(frame, a)
local o = {}
local function row(label, value)
if value and value ~= '' then
o[#o + 1] = '|-\n! class="lw-infobox__label" | ' .. label .. '\n| class="lw-infobox__value" | ' .. value
end
end
local function section(label)
o[#o + 1] = '|-\n! colspan="2" class="lw-infobox__section-header" | ' .. label
end
row('Type', a.type)
row('Accession', accessionLink(frame, a.accession))
row('Seed lot', lotLink(a.lot))
section('Sample')
row('Sample code', a.sample_id)
row('Tissue', #a.tissue > 0 and table.concat(a.tissue, ', ') or nil)
row('Generation', a.generation_words or "''not stated''")
if a.coordinates then
local bits = {}
if a.georeference_basis then bits[#bits + 1] = a.georeference_basis end
if a.coordinate_uncertainty then bits[#bits + 1] = '± ' .. a.coordinate_uncertainty .. ' m' end
row('Point', a.coordinates .. (#bits > 0 and ('<br /><small>' .. table.concat(bits, ', ') .. '</small>') or ''))
end
section('Study')
local labs = {}
for _, l in ipairs(a.laboratory) do labs[#labs + 1] = link(l) end
row('Laboratory', #labs > 0 and table.concat(labs, '<br />') or nil)
row('Date', a.date)
row('Published in', sourceLink(frame, a.source) or "''no publication named''")
local places = {}
for _, r in ipairs(a.reference_place) do places[#places + 1] = link(r) end
row('Reference material from', #places > 0 and table.concat(places, ', ') or nil)
local data = {}
for _, u in ipairs(a.data_url) do data[#data + 1] = '<span class="plainlinks">[' .. u .. ' ' .. hostOf(u) .. ']</span>' end
row('Data', #data > 0 and table.concat(data, '<br />') or nil)
return table.concat(o, '\n')
end
local function measurementTable(a)
if #a.measurements == 0 then return nil end
local t = { '{| class="wikitable"', '! Quantity !! Value !! Unit !! Reference standard !! Uncertainty !! Note' }
for _, e in ipairs(a.measurements) do
t[#t + 1] = '|-\n| ' .. (e.quantity and quantityLabel(e.quantity) or '') .. ' || ' .. (e.value and mw.ustring.gsub(e.value, '^%-', '−') or '')
.. ' || ' .. (e.unit or '') .. ' || ' .. (e.standard or '') .. ' || ' .. (e.uncertainty and ('± ' .. e.uncertainty) or '')
.. ' || ' .. (e.note or '')
end
t[#t + 1] = '|}'
return table.concat(t, '\n')
end
local function lead(frame, a)
if not a.type then return nil end
local s = LEAD[a.type] .. ' of material from the accession ' .. accessionLink(frame, a.accession)
local src = sourceLink(frame, a.source)
if src then s = s .. ', published in ' .. src end
return s .. '.'
end
-- The page itself: {{Analysis|accession=|type=|…}} (Template:Analysis).
function p.page(frame)
local parent = frame:getParent()
local args = parent and parent.args or frame.args
local title = trim(frame.args.page) or mw.title.getCurrentTitle().prefixedText
local b = p._build(args, title)
local a = b.a
local out = {}
out[#out + 1] = emit(frame, '#set', b.set)
for _, s in ipairs(b.subobjects) do out[#out + 1] = emit(frame, '#subobject', s) end
if #b.errors > 0 then
local e = {}
for _, s in ipairs(b.errors) do e[#e + 1] = '<li>' .. s .. '</li>' end
out[#out + 1] = '<div class="error">Template:Analysis: <ul>' .. table.concat(e) .. '</ul></div>[[Category:' .. ERROR_CATEGORY .. ']]'
end
out[#out + 1] = '{| class="infobox lw-infobox lw-analysis-infobox"\n|+ class="lw-infobox__title" | '
.. (a.label or 'Analysis') .. '\n' .. infoboxRows(frame, a) .. '\n|}'
local l = lead(frame, a)
if l then out[#out + 1] = l end
if a.finding then
-- The study's finding, in its own terms, attributed to it.
out[#out + 1] = '\n== Finding ==\n' .. (a.source and 'The study reports: ' or 'Reported, with no publication named: ') .. a.finding
end
if a.reference_set then
out[#out + 1] = '\n== Reference material ==\n' .. a.reference_set
end
local mt = measurementTable(a)
if mt then out[#out + 1] = '\n== Measurements ==\n' .. mt end
out[#out + 1] = '\n[[Category:' .. CATEGORY .. ']]'
return table.concat(out, '\n')
end
------------------------------------------------------------------------------------------
-- The accession's list of analyses (Template:Accession → Template:Infobox accession)
------------------------------------------------------------------------------------------
local SEP_R, SEP_P, SEP_V = '⟦R⟧', '⟦P⟧', '⟦V⟧'
local function split(s, sep)
local out, i = {}, 1
if s == '' then return out end
while true do
local a, b = string.find(s, sep, i, true)
if not a then out[#out + 1] = string.sub(s, i); break end
out[#out + 1] = string.sub(s, i, a - 1)
i = b + 1
end
return out
end
local LIST_PRINTOUTS = {
{ 'label', 'Has analysis label' },
{ 'type', 'Has analysis type' },
{ 'tissue', 'Has sample tissue' },
{ 'generation', 'Has sample generation' },
}
-- Rows {subject, fields = {key = {values}}} for the analyses of `page`. No sort in the query: a sort on a
-- property drops every row that lacks it.
local function askAnalyses(frame, page)
local parts = { '{{#ask:[[Is analysis of::' .. page .. ']]' }
for _, po in ipairs(LIST_PRINTOUTS) do parts[#parts + 1] = '|?' .. po[2] .. '#-=⟪' .. po[1] .. '⟫' end
parts[#parts + 1] = '|format=plainlist|headers=plain|link=none|searchlabel=|default='
parts[#parts + 1] = '|sep=' .. SEP_R .. '|propsep=' .. SEP_P .. '|valuesep=' .. SEP_V .. '|limit=200}}'
local out = trim(frame:preprocess(table.concat(parts))) or ''
local rows = {}
if out == '' then return rows end
for _, row in ipairs(split(out, SEP_R)) do
local subject, rest = row:match('^(.-) %((⟪.*)%)%s*$')
if not subject then subject, rest = trim(row), '' end
local fields = {}
for _, part in ipairs(split(rest, SEP_P)) do
local k, v = part:match('^⟪([%w_]+)⟫: (.*)$')
if k then fields[k] = split(v, SEP_V) end
end
rows[#rows + 1] = { subject = trim(subject), fields = fields }
end
return rows
end
p._askAnalyses = askAnalyses
-- One <li> per analysis, ordered by title: "Genotyping, 2021 · leaf, field".
function p._renderList(rows)
table.sort(rows, function(x, y) return x.subject < y.subject end)
local items = {}
for _, r in ipairs(rows) do
local f = r.fields or {}
local label = (f.label and trim(f.label[1])) or (f.type and trim(f.type[1])) or r.subject
local bits = {}
if f.tissue and #f.tissue > 0 then
local t = {}
for _, v in ipairs(f.tissue) do if trim(v) then t[#t + 1] = mw.ustring.lower(trim(v)) end end
if #t > 0 then bits[#bits + 1] = table.concat(t, ', ') end
end
local g = f.generation and tonumber(trim(f.generation[1] or ''))
if g == 0 then bits[#bits + 1] = 'field' elseif g then bits[#bits + 1] = 'grow-out ' .. g end
items[#items + 1] = '<li class="lw-lineage-item">[[:' .. r.subject .. '|' .. label .. ']]'
.. (#bits > 0 and ('<span class="lw-lineage-unwritten"> · ' .. table.concat(bits, ', ') .. '</span>') or '') .. '</li>'
end
return table.concat(items)
end
-- {{#invoke:Analysis|list|page={{FULLPAGENAME}}}}: the <li> items, or nothing.
-- p._listRows (the render check only) replaces the query with given rows.
p._listRows = nil
function p.list(frame)
local page = trim(frame.args.page) or mw.title.getCurrentTitle().prefixedText
local rows = p._listRows or askAnalyses(frame, page)
return p._renderList(rows)
end
------------------------------------------------------------------------------------------
-- Page name: the next free Analysis:<accession>/<type> <n>
------------------------------------------------------------------------------------------
-- {{#invoke:Analysis|pagename|accession=…|type=…}}
function p.pagename(frame)
local acc, typ = plainTitle(frame.args.accession), canonical(TYPES, frame.args.type)
if not acc or not typ then return '' end
for n = 1, 99 do
local name = PREFIX .. acc .. '/' .. typ .. ' ' .. n
if not exists(name) then return name end
end
return ''
end
return p