Module:BiologicalAgeBiomarkers: Difference between revisions

    From Longevity Wiki
    No edit summary
    No edit summary
     
    (25 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 = {
    {
    system = "Cardiovascular System",
    data = {
    {key = "SBP", name = "Systolic Blood Pressure (SBP)"},
    {key = "DBP", name = "Diastolic Blood Pressure (DBP)"},
    {key = "PP", name = "Pulse Pressure"},
    {key = "MAP", name = "Mean Arterial Pressure"},
    {key = "Pulse", name = "Pulse"},
    {key = "PWV", name = "Pulse Wave Velocity"},
    {key = "HR", name = "Heart Rate"},
    {key = "IMT", name = "Intima-Media Thickness"},
    {key = "MinIMT", name = "Minimum Intima-Media Thickness"},
    {key = "EDV", name = "End Diastolic Velocity"},
    {key = "MVEAP", name = "Mitral Valve E/A Peak"},
    {key = "MVEL_MVES_MVEA", name = "MVEL, MVES, MVEA"},
    {key = "AI", name = "Atherosclerosis Index"},
    {key = "NTproBNP", name = "NT-proBNP"},
    {key = "CTnI", name = "Cardiac Troponin I"},
    {key = "CPK", name = "Creatine Phosphokinase"},
    {key = "Homocysteine", name = "Homocysteine"},
    }
    },


    {
    local biomarkers = data.biomarkers
    system = "Respiratory System",
    local rows = data.rows
    data = {
    local studies = data.studies
    {key = "FVC", name = "Forced Vital Capacity (FVC)"},
    {key = "FEV1", name = "Forced Expiratory Volume in 1 Second (FEV1)"},
    {key = "VC", name = "Vital Capacity"},
    {key = "MMFR", name = "Maximal Midexpiratory Flow Rate 75/25"},
    {key = "VO2Max", name = "VO2 Max"},
    {key = "CR", name = "Chest Radiography"},
    }
    },


    {
    function p.template(frame, name, arg)
    system = "Nervous System",
    return frame:expandTemplate({title = name, args = { arg }})
    data = {
    end
    {key = "MMSE", name = "Mini-Mental State Examination (MMSE)"},
    {key = "DST", name = "Digital Symbol Test"},
    {key = "NM", name = "Numeric Memory"},
    {key = "AM", name = "Associated Memory"},
    {key = "TM", name = "Topological Memory"},
    {key = "STM", name = "Short-Time Memory"},
    {key = "Concentration", name = "Concentration"},
    {key = "IMD", name = "Intellectuality - Mental Defect"},
    {key = "TMT", name = "Trail Making Test"},
    }
    },
    {
    system = "Endocrine Metabolic System",
    data = {
    {key = "Glucose", name = "Glucose"},
    {key = "HBA1C", name = "HBA1C"},
    {key = "CPeptide", name = "C-peptide"},
    {key = "Insulin", name = "Insulin"},
    {key = "TG", name = "Triglyceride"},
    {key = "TC", name = "Total Cholesterol (TC)"},
    {key = "HDL", name = "High-Density Lipoprotein (HDL)"},
    {key = "LDL", name = "Low-Density Lipoprotein (LDL)"},
    {key = "ApoA1B", name = "Apolipoprotein A1 and B"},
    {key = "TSH", name = "Thyroid-Stimulating Hormone (TSH)"},
    {key = "Testosterone", name = "Testosterone"},
    {key = "VitaminD", name = "Vitamin D"},
    {key = "Calcium", name = "Calcium"},
    {key = "Potassium", name = "Potassium"},
    {key = "Sodium", name = "Sodium"},
    {key = "InorganicPhosphorus", name = "Inorganic Phosphorus"},
    {key = "Urea", name = "Urea"},
    {key = "Creatinine", name = "Creatinine"},
    {key = "eGFR", name = "Estimated Glomerular Filtration Rate (eGFR)"},
    {key = "UricAcid", name = "Uric Acid"},
    {key = "CystatinC", name = "Cystatin C"},
    {key = "CreatinineClearance", name = "Creatinine Clearance"},
    {key = "UrineSG", name = "Urine Specific Gravity"},
    {key = "UrinepH", name = "Urine pH"},
    }
    },
    {
    system = "Digestive System",
    data = {
    {key = "ALT", name = "Alanine Aminotransferase (ALT)"},
    {key = "AST", name = "Aspartate Aminotransferase (AST)"},
    {key = "ALP", name = "Alkaline Phosphatase (ALP)"},
    {key = "TotalProtein", name = "Total Protein"},
    {key = "Albumin", name = "Albumin"},
    {key = "AGRatio", name = "Albumin/Globulin Ratio (A/G)"},
    {key = "TotalBilirubin", name = "Total Bilirubin"},
    {key = "DirectBilirubin", name = "Direct Bilirubin"},
    {key = "Amylase", name = "Amylase"},
    {key = "LDH", name = "Lactate Dehydrogenase"},
    {key = "Alpha2Globulin", name = "Alpha 2 Globulin"},
    {key = "GGT", name = "Gamma Glutamyl Transpeptidase"},
    }
    },


    {
    function p.createCrossTable(frame)
    system = "Hematologic System",
        for _, study in ipairs(studies) do
    data = {
        local count = 0
    {key = "RBC", name = "Red Blood Cell"},
    for _ in pairs(study.biomarkers) do
    {key = "RDW", name = "Red Blood Cell Volume Distribution Width"},
    count = count + 1
    {key = "Hematocrit", name = "Hematocrit"},
    end
    {key = "MCV", name = "Mean Corpuscular Volume"},
        study.count = count
    {key = "MCH", name = "Mean Corpuscular Hemoglobin"},
    end
    {key = "MCHC", name = "Mean Corpuscular Hemoglobin Concentration"},
    {key = "Hemoglobin", name = "Hemoglobin"},
    {key = "WBC", name = "White Blood Cell"},
    {key = "Granulocytes", name = "Granulocytes"},
    {key = "Neutrophils", name = "Neutrophils"},
    {key = "BasophilsEosinophils", name = "Basophils, Eosinophils"},
    {key = "Lymphocytes", name = "Lymphocytes"},
    {key = "Monocytes", name = "Monocytes"},
    {key = "Platelet", name = "Platelet"},
    {key = "MPV", name = "Mean Platelet Volume"},
    {key = "PDW", name = "Platelet Distribution Width"},
    {key = "ESR", name = "Erythrocyte Sedimentation Rate"},
    {key = "DdimerFibrinogen", name = "D-dimer, Fibrinogen"},
    {key = "Ferritin", name = "Ferritin"},
    {key = "Transferrin", name = "Transferrin"},
    }
    },
    {
    system = "Sensory System",
    data = {
    {key = "VisualAcc", name = "Visual Accommodation"},
    {key = "VisualReactTime", name = "Visual Reaction Time"},
    {key = "VisualAcuity", name = "Visual Acuity"},
    {key = "Hearing", name = "Hearing"},
    {key = "Vibrotactile", name = "Vibrotactile"},
    {key = "RetinalPhotos", name = "Retinal Photos"},
    }
    },
    {
    system = "Inflammatory System",
    data = {
    {key = "CRP", name = "C-Reactive Protein (CRP)"},
    {key = "CMVOptDensity", name = "Cytomegalovirus Optical Density"},
    {key = "IL6", name = "Interleukin-6"},
    {key = "Pselectin", name = "P-selectin"},
    }
    },
    {
    system = "Motion Index",
    data = {
    {key = "GripStrength", name = "Grip Strength"},
    {key = "VerticalJump", name = "Vertical Jump"},
    {key = "TUGTest", name = "Timed Up and Go Test"},
    {key = "ChairRiseTime", name = "Chair Rise Time"},
    {key = "PhysicalActivityWeek", name = "1-Week Physical Activity"},
    }
    },
    {
    system = "Body Morphology Index",
    data = {
    {key = "WC", name = "Waist Circumference (WC)"},
    {key = "WaistHipRatio", name = "Waist-to-Hip Ratio"},
    {key = "WaistHeightRatio", name = "Waist-to-Height Ratio"},
    {key = "BMI", name = "Body Mass Index (BMI)"},
    {key = "Weight", name = "Weight"},
    {key = "Height", name = "Height"},
    {key = "BodyFat", name = "Body Fat"},
    {key = "LeanBodyMass", name = "Lean Body Mass"},
    {key = "SoftLeanMass", name = "Soft Lean Mass"},
    }
    },
    {
    system = "Genetic Index",
    data = {
    {key = "TelomereLength", name = "Terminal Telomere Restriction Fragment"},
    }
    },
    }
    local rows = {
    {key = "method", name = "Biological Age Estimation Method"},
    {key = "year", name = "Year"}
    }
    -- Incorporate data directly into studies identified by PMID
    local studies = {
    {
        pmid = "12634284",
        method = "PCA",
        biomarkers = { AGRatio = "x", Albumin = "x", FEV1 = "x", FVC = "x", Hematocrit = "x", Hemoglobin = "x", RBC = "x", SBP = "x", Urea = "x" }
    },
    {
        pmid = "12672981",
        method = "PCA",
        biomarkers = { AGRatio = "x", FEV1 = "x", Glucose = "x", MCH = "x", SBP = "x" }
    },
    {
        pmid = "17889950",
        method = "MLR",
        biomarkers = { BMI = "x", BodyFat = "x", Creatinine = "x", DBP = "x", ESR = "x", FEV1 = "x", FVC = "x", Glucose = "x", HDL = "x", LeanBodyMass = "x", SBP = "x", TC = "x", TG = "x", TSH = "x", Testosterone = "x", WaistHipRatio = "x" }
    },
    {
        pmid = "17921421",
        method = "PCA",
        biomarkers = { Albumin = "x", FEV1 = "x", Hematocrit = "x", SBP = "x", Urea = "x" }
    },
    {
        pmid = "18597867",
        method = "PCA",
        biomarkers = { Albumin = "x", BodyFat = "x", ESR = "x", FEV1 = "x", HBA1C = "x", Hearing = "x", LDL = "x", SBP = "x", Urea = "x", VO2Max = "x", WC = "x" }
    },
    {
        pmid = "18840798",
        method = "PCA",
        biomarkers = { Albumin = "x", FEV1 = "x", RBC = "x", SBP = "x", Urea = "x" }
    },
    {
        pmid = "19940465",
        method = "PCA",
        biomarkers = { CystatinC = "x", DdimerFibrinogen = "x", EDV = "x", IMT = "x", MVEAP = "x", MVEL_MVES_MVEA = "x", PP = "x" }
    },
    {
        pmid = "20005245",
        method = "KDM",
        biomarkers = { AM = "x", Concentration = "x", FVC = "x", GripStrength = "x", Hearing = "x", NM = "x", TM = "x", Vibrotactile = "x", VisualAcc = "x", VisualReactTime = "x" }
    },
    {
        pmid = "20005245",
        method = "MLR",
        biomarkers = { AM = "x", Concentration = "x", FVC = "x", GripStrength = "x", Hearing = "x", NM = "x", TM = "x", Vibrotactile = "x", VisualAcc = "x", VisualReactTime = "x" }
    },
    {
        pmid = "22433233",
        method = "PCA",
        biomarkers = { FEV1 = "x", GripStrength = "x", SBP = "x", SoftLeanMass = "x", VO2Max = "x", VerticalJump = "x", WC = "x" }
    },
    {
        pmid = "2282902",
        method = "PCA",
        biomarkers = { AI = "x", AST = "x", FVC = "x", HR = "x", Hemoglobin = "x", LDH = "x", SBP = "x", TG = "x", Urea = "x" }
    },
    {
        pmid = "23213031",
        method = "KDM",
        biomarkers = { ALP = "x", Albumin = "x", CMVOptDensity = "x", CRP = "x", Creatinine = "x", FEV1 = "x", HBA1C = "x", SBP = "x", TC = "x", Urea = "x" }
    },
    {
        pmid = "23213031",
        method = "MLR",
        biomarkers = { ALP = "x", Albumin = "x", CMVOptDensity = "x", CRP = "x", Creatinine = "x", FEV1 = "x", HBA1C = "x", SBP = "x", TC = "x", Urea = "x" }
    },
    {
        pmid = "23213031",
        method = "PCA",
        biomarkers = { ALP = "x", Albumin = "x", CMVOptDensity = "x", CRP = "x", FEV1 = "x", HBA1C = "x", SBP = "x", TC = "x", Urea = "x" }
    },
    {
        pmid = "23642770",
        method = "MLR",
        biomarkers = { AGRatio = "x", ALP = "x", ALT = "x", AST = "x", Albumin = "x", Amylase = "x", BMI = "x", BodyFat = "x", CPK = "x", Creatinine = "x", CreatinineClearance = "x", DBP = "x", DirectBilirubin = "x", FEV1 = "x", FVC = "x", GGT = "x", Glucose = "x", HBA1C = "x", Homocysteine = "x", LDH = "x", LDL = "x", LeanBodyMass = "x", PP = "x", SBP = "x", TC = "x", TG = "x", TotalBilirubin = "x", TotalProtein = "x", Urea = "x", UrineSG = "x", UrinepH = "x", WC = "x", WaistHipRatio = "x" }
    },
    {
        pmid = "24522464",
        method = "PCA",
        biomarkers = { CystatinC = "x", MMFR = "x", MVEL_MVES_MVEA = "x", MinIMT = "x", PP = "x", TMT = "x" }
    },
    {
        pmid = "24659482",
        method = "PCA",
        biomarkers = { CystatinC = "x", DST = "x", DdimerFibrinogen = "x", IMT = "x", MVEL_MVES_MVEA = "x", TelomereLength = "x" }
    },
    {
        pmid = "26150497",
        method = "KDM",
        biomarkers = { ALP = "x", Albumin = "x", CMVOptDensity = "x", CRP = "x", Creatinine = "x", FEV1 = "x", HBA1C = "x", SBP = "x", TC = "x", Urea = "x" }
    },
    {
        pmid = "27191382",
        method = "Deep learning",
        biomarkers = { ALP = "x", Albumin = "x", Alpha2Globulin = "x", Glucose = "x", Hematocrit = "x", Lymphocytes = "x", RBC = "x", RDW = "x", TC = "x", Urea = "x" }
    },
    {
        pmid = "27216811",
        method = "KDM",
        biomarkers = { ALP = "x", Albumin = "x", Calcium = "x", Creatinine = "x", DBP = "x", Hemoglobin = "x", InorganicPhosphorus = "x", TSH = "x", TotalProtein = "x", Urea = "x" }
    },
    {
        pmid = "2737197",
        method = "PCA",
        biomarkers = { AI = "x", AST = "x", FVC = "x", Hemoglobin = "x", Pulse = "x", SBP = "x", Urea = "x" }
    },
    {
        pmid = "28110151",
        method = "KDM",
        biomarkers = { AST = "x", FEV1 = "x", Ferritin = "x", SBP = "x", TC = "x", Urea = "x", WC = "x" }
    },
    {
        pmid = "28110151",
        method = "MLR",
        biomarkers = { AST = "x", Creatinine = "x", FEV1 = "x", Ferritin = "x", SBP = "x", TC = "x", Urea = "x", WC = "x" }
    },
    {
        pmid = "28110151",
        method = "PCA",
        biomarkers = { AST = "x", Creatinine = "x", FEV1 = "x", Ferritin = "x", SBP = "x", TC = "x", Urea = "x", WC = "x" }
    },
    {
        pmid = "28203066",
        method = "PCA",
        biomarkers = { Glucose = "x", HDL = "x", MAP = "x", TG = "x", WC = "x" }
    },
    {
        pmid = "28958059",
        method = "KDM",
        biomarkers = { ALP = "x", Albumin = "x", CRP = "x", Creatinine = "x", FEV1 = "x", HBA1C = "x", SBP = "x", TC = "x" }
    },
    {
        pmid = "28977464",
        method = "KDM",
        biomarkers = { CRP = "x", FEV1 = "x", Glucose = "x", IL6 = "x", Pselectin = "x", SBP = "x", TC = "x" }
    },
    {
        pmid = "29188884",
        method = "PCA",
        biomarkers = { CystatinC = "x", MVEAP = "x", MinIMT = "x", PP = "x", TMT = "x" }
    },
    {
        pmid = "29340580",
        method = "Deep learning",
        biomarkers = { Albumin = "x", Calcium = "x", Creatinine = "x", Glucose = "x", HDL = "x", Hematocrit = "x", Hemoglobin = "x", LDL = "x", MCHC = "x", MCV = "x", Platelet = "x", Potassium = "x", RBC = "x", Sodium = "x", TC = "x", TG = "x", TotalBilirubin = "x", TotalProtein = "x", Urea = "x" }
    },
    {
        pmid = "29581467",
        method = "Deep learning",
        biomarkers = { PhysicalActivityWeek = "x" }
    },
    {
        pmid = "30644411",
        method = "Deep learning",
        biomarkers = { Ferritin = "x", Glucose = "x", HBA1C = "x", Urea = "x" }
    },
    {
        pmid = "30899733",
        method = "KDM",
        biomarkers = { FEV1 = "x", RBC = "x", SBP = "x", VitaminD = "x", WaistHeightRatio = "x" }
    },
    {
        pmid = "30899733",
        method = "MLR",
        biomarkers = { Creatinine = "x", FEV1 = "x", RBC = "x", SBP = "x", VitaminD = "x", WaistHeightRatio = "x" }
    },
    {
        pmid = "30899733",
        method = "PCA",
        biomarkers = { Creatinine = "x", FEV1 = "x", RBC = "x", SBP = "x", VitaminD = "x", WaistHeightRatio = "x" }
    },
    {
        pmid = "30999227",
        method = "KDM",
        biomarkers = { ALP = "x", Albumin = "x", CRP = "x", Creatinine = "x", HBA1C = "x", Lymphocytes = "x", MCV = "x", RDW = "x", SBP = "x", Urea = "x", UricAcid = "x", WBC = "x" }
    },
    {
        pmid = "31179487",
        method = "KDM",
        biomarkers = { ChairRiseTime = "x", DBP = "x", FEV1 = "x", GripStrength = "x", Height = "x", Hemoglobin = "x", MMSE = "x", Monocytes = "x", TUGTest = "x", eGFR = "x" }
    },
    {
        pmid = "31179487",
        method = "MLR",
        biomarkers = { ChairRiseTime = "x", DBP = "x", FEV1 = "x", GripStrength = "x", Height = "x", Hemoglobin = "x", MMSE = "x", Monocytes = "x", TUGTest = "x", eGFR = "x" }
    },
    {
        pmid = "31179487",
        method = "PCA",
        biomarkers = { ChairRiseTime = "x", DBP = "x", FEV1 = "x", GripStrength = "x", Height = "x", Hemoglobin = "x", MMSE = "x", Monocytes = "x", TUGTest = "x", eGFR = "x" }
    },
    {
        pmid = "31388024",
        method = "Deep learning",
        biomarkers = { PhysicalActivityWeek = "x" }
    },
    {
        pmid = "31566204",
        method = "KDM",
        biomarkers = { Albumin = "x", CMVOptDensity = "x", CRP = "x", Creatinine = "x", HBA1C = "x", Lymphocytes = "x", MCV = "x", SBP = "x", TC = "x", Urea = "x", WBC = "x" }
    },
    {
        pmid = "31693736",
        method = "KDM",
        biomarkers = { ALP = "x", Albumin = "x", CRP = "x", Creatinine = "x", HBA1C = "x", Lymphocytes = "x", MCV = "x", Urea = "x", UricAcid = "x", WBC = "x" }
    },
    {
        pmid = "3226152",
        method = "MLR",
        biomarkers = { AGRatio = "x", AST = "x", Albumin = "x", FVC = "x", Hemoglobin = "x", Pulse = "x", SBP = "x", TC = "x", Urea = "x", VisualAcuity = "x" }
    },
    {
        pmid = "3226152",
        method = "PCA",
        biomarkers = { AGRatio = "x", AST = "x", Albumin = "x", FVC = "x", Hemoglobin = "x", Pulse = "x", SBP = "x", TC = "x", Urea = "x", VisualAcuity = "x" }
    },
    {
        pmid = "32946548",
        method = "KDM",
        biomarkers = { Albumin = "x", CRP = "x", Creatinine = "x", Ferritin = "x", HBA1C = "x", Platelet = "x", RBC = "x", SBP = "x", TC = "x", TG = "x", Transferrin = "x", Urea = "x" }
    },
    {
        pmid = "33744131",
        method = "Deep learning",
        biomarkers = { CR = "x" }
    },
    {
        pmid = "34038024",
        method = "KDM",
        biomarkers = { ALP = "x", Albumin = "x", CRP = "x", Creatinine = "x", HBA1C = "x", SBP = "x", TC = "x" }
    },
    {
        pmid = "34453631",
        method = "Deep learning",
        biomarkers = { ALT = "x", AST = "x", Albumin = "x", ApoA1B = "x", BasophilsEosinophils = "x", CPeptide = "x", CRP = "x", CTnI = "x", Creatinine = "x", CystatinC = "x", DdimerFibrinogen = "x", Glucose = "x", Granulocytes = "x", HDL = "x", Hemoglobin = "x", Insulin = "x", LDL = "x", Lymphocytes = "x", MCHC = "x", MCV = "x", MPV = "x", Monocytes = "x", NTproBNP = "x", Neutrophils = "x", PDW = "x", Platelet = "x", RBC = "x", RDW = "x", TG = "x", Testosterone = "x", UricAcid = "x", VitaminD = "x", WBC = "x" }
    },
    {
        pmid = "5841151",
        method = "MLR",
        biomarkers = { GripStrength = "x", Hearing = "x", SBP = "x", TC = "x", VC = "x", Vibrotactile = "x", VisualAcuity = "x" }
    },
    {
        pmid = "6610563",
        method = "MLR",
        biomarkers = { GripStrength = "x", STM = "x", Vibrotactile = "x" }
    },
    {
        pmid = "6667707",
        method = "MLR",
        biomarkers = { DST = "x", Hearing = "x", IMD = "x", PWV = "x", SBP = "x", VC = "x", VisualAcc = "x", Weight = "x" }
    },
    {
        pmid = "7162237",
        method = "MLR",
        biomarkers = { FEV1 = "x", Hearing = "x", LDH = "x", TC = "x" }
    },
    {
        pmid = "8803500",
        method = "PCA",
        biomarkers = { ALT = "x", FVC = "x", Glucose = "x", Hemoglobin = "x", LDH = "x", SBP = "x", TC = "x", Urea = "x" }
    },
    {
        pmid = "950448",
        method = "MLR",
        biomarkers = { ALP = "x", ESR = "x", FEV1 = "x", SBP = "x", TC = "x", TG = "x", Urea = "x" }
    },
    }
    function p.createCrossTable()
         -- Start of the wiki table
         -- Start of the wiki table
         local wikitable = '{| class="wikitable"\n!'
         local wikitable = '{| class="wikitable sortable"\n'
     
         local sep = ''
         -- Column headers: Biomarker and System
        wikitable = wikitable .. ' System !! Biomarker'
        for _, study in pairs(studies) do
            wikitable = wikitable .. ' !! {{pmid|' .. study.pmid .. '}}'
    end
    wikitable = wikitable .. '\n'


         for i, row in ipairs(rows) do
         for i, row in ipairs(rows) do
             wikitable = wikitable .. '|-\n'
             wikitable = wikitable .. sep
             wikitable = wikitable .. '| ' .. row.name .. ' || ' .. ''
            sep = '|-\n'
             wikitable = wikitable .. '! colspan="3" | ' .. row.name .. '\n'
             for _, study in ipairs(studies) do
             for _, study in ipairs(studies) do
                 local cellValue = study[row.key] or ""
                 local cellValue = study[row.key] or ""
    wikitable = wikitable .. ' || ' .. cellValue
                if (row.rotate) then
    cellValue =  p.template(frame, "VerticalText", cellValue)
    else
    end
    wikitable = wikitable .. '! ' .. cellValue .. '\n'
             end
             end
    wikitable = wikitable .. '\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
         -- Generate rows for each biomarker
    Line 483: Line 51:
            wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. '| '  .. system.system .. ' || ' .. bm.name
            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
            for _, study in ipairs(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.biomarkers[bm.key] or ""
                local cellValue = study.biomarkers[bm.key] or ""
                wikitable = wikitable .. ' || ' .. cellValue
            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
            end
    wikitable = wikitable .. '\n'
    wikitable = wikitable .. '\n'

    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