Module:BiologicalAgeBiomarkers: Difference between revisions

    From Longevity Wiki
    No edit summary
    No edit summary
    Line 7: Line 7:
         HDL = {name = "High-Density Lipoprotein (HDL)", system = "Endocrine Metabolic System"},
         HDL = {name = "High-Density Lipoprotein (HDL)", system = "Endocrine Metabolic System"},
         LDL = {name = "Low-Density Lipoprotein (LDL)", system = "Endocrine Metabolic System"}
         LDL = {name = "Low-Density Lipoprotein (LDL)", system = "Endocrine Metabolic System"}
    }
    local rows = {
    method = "Biological Age Estimation Method",
    year = "Year"
    }
    }


    Line 12: Line 17:
    local studies = {
    local studies = {
         PMID12345 = {
         PMID12345 = {
        pmid = 12345,
             name = "Study1",
             name = "Study1",
            method = "MLR",
            year = "1995",
             data = {
             data = {
                 SBP = "120 mmHg",
                 SBP = "x",
                 DBP = "80 mmHg",
                 DBP = "x",
                 HDL = "55 mg/dL",
                 HDL = "x",
                 LDL = "100 mg/dL"
                 LDL = "x"
             }
             }
         },
         },
         PMID67890 = {
         PMID67890 = {
             name = "Study2",
             name = 67890,
            method = "MLR",
            year = "1995",
             data = {
             data = {
                 SBP = "130 mmHg",
                 SBP = "x",
                 DBP = "85 mmHg",
                 DBP = "x",
                 HDL = "60 mg/dL",
                 HDL = "x",
                 LDL = "105 mg/dL"
                 LDL = "x"
             }
             }
         },
         },
         PMID13579 = {
         PMID13579 = {
             name = "Study3",
             pmid = 13579,
            method = "MLR",
            year = "1995",
             data = {
             data = {
                 SBP = "125 mmHg",
                 SBP = "x",
                 DBP = "82 mmHg",
                 DBP = "x",
                 HDL = "57 mg/dL",
                 HDL = "x",
                 LDL = "102 mg/dL"
                 LDL = "x"
             }
             }
         }
         }
    Line 47: Line 59:
         wikitable = wikitable .. ' System !! Biomarker'
         wikitable = wikitable .. ' System !! Biomarker'
         for _, study in pairs(studies) do
         for _, study in pairs(studies) do
             wikitable = wikitable .. ' !! '  .. study.name
             wikitable = wikitable .. ' !! '  .. study.pmid
        end
    end
    wikitable = wikitable .. '\n'
     
        for key, name in pairs(rows) do
            wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. '| ' .. name .. ' || ' .. ''
            for _, study in pairs(studies) do
                local cellValue = study[key] or ""
    wikitable = wikitable .. ' || ' .. cellValue
            end
    wikitable = wikitable .. '\n'
    end


         -- Generate rows for each biomarker
         -- Generate rows for each biomarker
         for abbr, details in pairs(biomarkers) do
         for abbr, details in pairs(biomarkers) do
             wikitable = wikitable .. '\n|-\n| ' .. details.system .. ' || ' .. details.name
             wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. details.system .. ' || ' .. details.name
             for _, study in pairs(studies) do
             for _, study in pairs(studies) do
                 -- Retrieve data value for the current cell, using the nested structure
                 -- Retrieve data value for the current cell, using the nested structure
                 local cellValue = study.data[abbr] or "-"
                 local cellValue = study.data[abbr] or ""
                 wikitable = wikitable .. ' || ' .. cellValue
                 wikitable = wikitable .. ' || ' .. cellValue
             end
             end
    wikitable = wikitable .. '\n'
         end
         end



    Revision as of 01:34, 19 February 2024

    Output the biological age biomarkers table.

    Data is stored in Module:BiologicalAgeBiomarkers/Data


    local p = {}
    
    -- Define biomarkers with their long form and system
    local biomarkers = {
        SBP = {name = "Systolic Blood Pressure (SBP)", system = "Cardiovascular System"},
        DBP = {name = "Diastolic Blood Pressure (DBP)", system = "Cardiovascular System"},
        HDL = {name = "High-Density Lipoprotein (HDL)", system = "Endocrine Metabolic System"},
        LDL = {name = "Low-Density Lipoprotein (LDL)", system = "Endocrine Metabolic System"}
    }
    
    local rows = {
    	method = "Biological Age Estimation Method",
    	year = "Year"
    }
    
    -- Incorporate data directly into studies identified by PMID
    local studies = {
        PMID12345 = {
        	pmid = 12345,
            name = "Study1",
            method = "MLR",
            year = "1995",
            data = {
                SBP = "x",
                DBP = "x",
                HDL = "x",
                LDL = "x"
            }
        },
        PMID67890 = {
            name = 67890,
            method = "MLR",
            year = "1995",
            data = {
                SBP = "x",
                DBP = "x",
                HDL = "x",
                LDL = "x"
            }
        },
        PMID13579 = {
            pmid = 13579,
            method = "MLR",
            year = "1995",
            data = {
                SBP = "x",
                DBP = "x",
                HDL = "x",
                LDL = "x"
            }
        }
    }
    
    function p.createCrossTable()
        -- Start of the wiki table
        local wikitable = '{| class="wikitable"\n!'
    
        -- Column headers: Biomarker and System
        wikitable = wikitable .. ' System !! Biomarker'
        for _, study in pairs(studies) do
            wikitable = wikitable .. ' !! '  .. study.pmid
    	end
    	wikitable = wikitable .. '\n'
    
        for key, name in pairs(rows) do
            wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. '| ' .. name .. ' || ' .. ''
            for _, study in pairs(studies) do
                local cellValue = study[key] or ""
    			wikitable = wikitable .. ' || ' .. cellValue
            end
    		wikitable = wikitable .. '\n'
    	end
    
        -- Generate rows for each biomarker
        for abbr, details in pairs(biomarkers) do
            wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. details.system .. ' || ' .. details.name
            for _, study in pairs(studies) do
                -- Retrieve data value for the current cell, using the nested structure
                local cellValue = study.data[abbr] or ""
                wikitable = wikitable .. ' || ' .. cellValue
            end
    		wikitable = wikitable .. '\n'
        end
    
        -- End of the table
        wikitable = wikitable .. '\n|}'
    
        return wikitable
    end
    
    return p