Module:BiologicalAgeBiomarkers: Difference between revisions

    From Longevity Wiki
    No edit summary
    No edit summary
     
    (42 intermediate revisions by the same user not shown)
    Line 1: Line 1:
    local p = {}
    local p = {}


    -- Define biomarkers with their long form and system
    local data = require('Module:BiologicalAgeBiomarkers/Data')
    local biomarkers = {
        SBP = {longForm = "Systolic Blood Pressure", system = "Cardiovascular System"},
        DBP = {longForm = "Diastolic Blood Pressure", system = "Cardiovascular System"},
        HDL = {longForm = "High-Density Lipoprotein", system = "Endocrine Metabolic System"},
        LDL = {longForm = "Low-Density Lipoprotein", system = "Endocrine Metabolic System"}
    }


    -- Incorporate data directly into studies identified by PMID
    local biomarkers = data.biomarkers
    local studies = {
    local rows = data.rows
        PMID12345 = {
    local studies = data.studies
            name = "Study1",
            data = {
                SBP = "120 mmHg",
                DBP = "80 mmHg",
                HDL = "55 mg/dL",
                LDL = "100 mg/dL"
            }
        },
        PMID67890 = {
            name = "Study2",
            data = {
                SBP = "130 mmHg",
                DBP = "85 mmHg",
                HDL = "60 mg/dL",
                LDL = "105 mg/dL"
            }
        },
        PMID13579 = {
            name = "Study3",
            data = {
                SBP = "125 mmHg",
                DBP = "82 mmHg",
                HDL = "57 mg/dL",
                LDL = "102 mg/dL"
            }
        }
    }


    function p.createCrossTable()
    function p.template(frame, name, arg)
    return frame:expandTemplate({title = name, args = { arg }})
    end
     
    function p.createCrossTable(frame)
        for _, study in ipairs(studies) do
        local count = 0
    for _ in pairs(study.biomarkers) do
    count = count + 1
    end
        study.count = count
    end
         -- Start of the wiki table
         -- Start of the wiki table
         local wikitable = '{| class="wikitable"\n!'
         local wikitable = '{| class="wikitable sortable"\n'
        local sep = ''
     
        for i, row in ipairs(rows) do
            wikitable = wikitable .. sep
            sep = '|-\n'
            wikitable = wikitable .. '! colspan="3" | ' .. row.name .. '\n'
            for _, study in ipairs(studies) do
                local cellValue = study[row.key] or ""
                if (row.rotate) then
    cellValue =  p.template(frame, "VerticalText", cellValue)
    else
    end
    wikitable = wikitable .. '! ' .. cellValue .. '\n'
            end
    end


         -- Column headers: Biomarker and System
         -- Column headers: Biomarker and System
         wikitable = wikitable .. ' !! Biomarker !! System'
        wikitable = wikitable .. '|-\n'
         wikitable = wikitable .. '! System !! Biomarker !! Count '
         for _, study in pairs(studies) do
         for _, study in pairs(studies) do
             wikitable = wikitable .. ' !! ' .. study.name
             wikitable = wikitable .. ' !! ' .. p.template(frame, "pmid", study.pmid)
        end
    end
    wikitable = wikitable .. '\n'


         -- Generate rows for each biomarker
         -- Generate rows for each biomarker
         for abbr, details in pairs(biomarkers) do
         for _, system in ipairs(biomarkers) do
            wikitable = wikitable .. '\n|-\n| ' .. details.longForm .. ' || ' .. details.system
        for _, bm in ipairs(system.data) do
            for _, study in pairs(studies) do
            wikitable = wikitable .. '|-\n'
                -- Retrieve data value for the current cell, using the nested structure
            wikitable = wikitable .. '| ' .. system.system .. ' || ' .. bm.name
                local cellValue = study.data[abbr] or "-"
           
                wikitable = wikitable .. ' || ' .. cellValue
            local count = 0
            end
            for _, study in ipairs(studies) do
            if study.biomarkers[bm.key] ~= nil then
        count = count + 1
            end
    end
            wikitable = wikitable .. string.format(' || %d', count)
           
            for _, study in ipairs(studies) do
                -- Retrieve data value for the current cell, using the nested structure
                local cellValue = study.biomarkers[bm.key] or ""
            if cellValue == "x" then
            cellValue = 'style="background-color:gray; color: transparent;" | ' .. cellValue
            elseif cellValue ~= "" then
            cellValue = 'style="background-color:gray;" | ' .. cellValue
                end
                wikitable = wikitable .. ' || ' .. cellValue
            end
    wikitable = wikitable .. '\n'
        end
         end
         end



    Latest revision as of 03:09, 21 February 2024

    Output the biological age biomarkers table.

    Data is stored in Module:BiologicalAgeBiomarkers/Data


    local p = {}
    
    local data = require('Module:BiologicalAgeBiomarkers/Data')
    
    local biomarkers = data.biomarkers
    local rows = data.rows
    local studies = data.studies
    
    function p.template(frame, name, arg)
    	return frame:expandTemplate({title = name, args = { arg }})
    end
    
    function p.createCrossTable(frame)
        for _, study in ipairs(studies) do
        	local count = 0
    		for _ in pairs(study.biomarkers) do
    			count = count + 1
    		end
        	study.count = count
    	end
    	
        -- Start of the wiki table
        local wikitable = '{| class="wikitable sortable"\n'
        local sep = ''
    
        for i, row in ipairs(rows) do
            wikitable = wikitable .. sep
            sep = '|-\n'
            wikitable = wikitable .. '! colspan="3" | ' .. row.name .. '\n'
            for _, study in ipairs(studies) do
                local cellValue = study[row.key] or ""
                if (row.rotate) then
    				cellValue =  p.template(frame, "VerticalText", cellValue)
    			else
    			end
    			wikitable = wikitable .. '! ' .. cellValue .. '\n'
            end
    	end
    
        -- Column headers: Biomarker and System
        wikitable = wikitable .. '|-\n'
        wikitable = wikitable .. '! System !! Biomarker !! Count '
        for _, study in pairs(studies) do
            wikitable = wikitable .. ' !! ' .. p.template(frame, "pmid", study.pmid)
    	end
    	wikitable = wikitable .. '\n'
    
        -- Generate rows for each biomarker
        for _, system in ipairs(biomarkers) do
    	    for _, bm in ipairs(system.data) do
    	        wikitable = wikitable .. '|-\n'
    	        wikitable = wikitable .. '| '  .. system.system .. ' || ' .. bm.name
    	        
    	        local count = 0
    	        for _, study in ipairs(studies) do
    	        	if study.biomarkers[bm.key] ~= nil then
        				count = count + 1
    	        	end
    			end
    	        wikitable = wikitable .. string.format(' || %d', count)
    	        
    	        for _, study in ipairs(studies) do
    	            -- Retrieve data value for the current cell, using the nested structure
    	            local cellValue = study.biomarkers[bm.key] or ""
    	        	if cellValue == "x" then
    	        		cellValue = 'style="background-color:gray; color: transparent;" | ' .. cellValue
    	        	elseif cellValue ~= "" then
    	        		cellValue = 'style="background-color:gray;" | ' .. cellValue
        	        end
     	            wikitable = wikitable .. ' || ' .. cellValue
    	        end
    			wikitable = wikitable .. '\n'
    	    end
        end
    
        -- End of the table
        wikitable = wikitable .. '\n|}'
    
        return wikitable
    end
    
    return p