From bd96a4a3ee6da951c77bc570a40ca3a07a764726 Mon Sep 17 00:00:00 2001 From: lorenasandoval88 <43822820+lorenasandoval88@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:33:29 -0400 Subject: [PATCH] limit variants to 500 in pgs --- sdk/get23.js | 2 +- sdk/getPgs.js | 34 +++++++++++++++++++++++----------- sdk/prs.js | 4 +--- sdk/ui.js | 13 +++++++------ 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/sdk/get23.js b/sdk/get23.js index c225e6c..878afa0 100644 --- a/sdk/get23.js +++ b/sdk/get23.js @@ -254,7 +254,7 @@ get23.userTxtsByPhenotypeId = async function (phenoId, keysLen, maxKeys) { if (combined.length < maxUsers) { cleanUsers = get23.usersByFileType("23andme", combined) } else { - cleanUsers = await (get23.usersByFileType("23andme", combined.slice(7, 15)))//.slice(0,maxUsers) + cleanUsers = await (get23.usersByFileType("23andme", combined.slice(7, 19)))//.slice(0,maxUsers) //console.log("Warning: user txts for phenotypeID", phenoId, "> 7. First 6 files used.") console.log("cleanUsers",cleanUsers) } diff --git a/sdk/getPgs.js b/sdk/getPgs.js index fa9d1be..6e1aebe 100644 --- a/sdk/getPgs.js +++ b/sdk/getPgs.js @@ -79,7 +79,7 @@ const timeout = (ms) => { getPgs.scoreFiles = async function(pgsIds) { // var scores = await scoreFilesTable.getItem("scoreFiles") - let scores = storage.saveData(scoreFilesTable,`https://www.pgscatalog.org/rest/score/`,pgsIds) + let scores = storage.saveData(scoreFilesTable,`https://www.pgscatalog.org/rest/score/`,[pgsIds]) return scores } @@ -99,6 +99,7 @@ getPgs.traitsData = async function(traits) { storeName: "traitsData" }) let dt + let traitFiles = getPgs.traitFiles() if ((await traitsData.getItem("traitsData")) === null) { dt = traits.map(trait => { @@ -131,18 +132,24 @@ getPgs.traitsData = async function(traits) { } //console.log("pgs",await getscoreFiles(["PGS002130"])) - +// get pgs text file filtered by variants number getPgs.loadScoreHm = async function(entry, build = 37, range) { - let txt = "" + const scoreFiles = await getPgs.scoreFiles(entry) + console.log("entry, scoreFiles",entry, scoreFiles) + const variants_number = scoreFiles[0].variants_number + console.log("variants_number",variants_number) + + let txt let dt dt = await pgsTxts.getItem(entry); // check for users in localstorage + if(variants_number<500){ + // console.log("variants_number<500",variants_number) if (entry == null){ - txt = "no pgs entry provided" - return txt + console.log("no pgs entry provided") + // return txt } else if (dt == null){ console.log("PGS entry: ",entry," PGS txt file not found in storage",dt) - txt = "" entry = "PGS000000".slice(0, -entry.length) + entry // https://ftp.ebi.ac.uk/pub/databases/spot/pgs/scores/PGS000004/ScoringFiles/Harmonized/PGS000004_hmPOS_GRCh37.txt.gz const url = `https://ftp.ebi.ac.uk/pub/databases/spot/pgs/scores/${entry}/ScoringFiles/Harmonized/${entry}_hmPOS_GRCh${build}.txt.gz` // @@ -169,17 +176,22 @@ getPgs.loadScoreHm = async function(entry, build = 37, range) { if (response?.ok) { ////console.log('Use the response here!'); } else { - txt = `:( Error loading PGS file. HTTP Response Code: ${response?.status}` + // txt = `:( Error loading PGS file. HTTP Response Code: ${response?.status}` + console.log(':( Error loading PGS file. HTTP Response Code: ${response?.status}') document.getElementById('pgsTextArea').value = txt } txt = await getPgs.parsePGS(entry, txt) pgsTxts.setItem(entry, txt) -} else if (dt != null){ - console.log("pgs txt file for",entry,"found in storage") - txt = dt + + } else if (dt != null){ + console.log("pgs txt file for",entry,"found in storage",dt) + txt = dt + }else{ + console.log(`pgs file too large: ${variants_number} variants`) } - return txt +} +return txt } // create PGS obj and data -------------------------- diff --git a/sdk/prs.js b/sdk/prs.js index 40d26b1..92cab62 100644 --- a/sdk/prs.js +++ b/sdk/prs.js @@ -105,7 +105,6 @@ PRS.Match2 = function (data) { data2.QC = true data2.QCtext = '' } - return data2 } @@ -114,8 +113,6 @@ PRS.Match2 = function (data) { PRS.calc = async function (matrix) { console.log("------------------------") console.log("Calculating PRS scores!") - console.log("matrix input data 2:", matrix) - let arr = [] const badIds = [] // todo remove qc from match2 function @@ -123,6 +120,7 @@ PRS.calc = async function (matrix) { for (let i = 0; i < matrix.users.txts.length; i++) { console.log("---------------------------") console.log("processing user #...", i) + console.log("matrix", matrix) for (let j = 0; j < matrix.pgs.txts.length; j++) { diff --git a/sdk/ui.js b/sdk/ui.js index 683049b..4a1e761 100644 --- a/sdk/ui.js +++ b/sdk/ui.js @@ -134,16 +134,17 @@ const ui = async function (targetDiv) { dt.pgs = {} const category = document.getElementById("pgsSelect").value console.log("PGS category selected: ", e.target.value) - // TODO filter ids by variant number using get scoreFIles - let pgsIds = (await (getPgs.idsFromCategory(category))).sort().slice(5, 8) + // TODO slice the pgs entries that are <500 + let pgsIds = (await (getPgs.idsFromCategory(category))).sort().slice(5, 12) console.log("pgsIds", pgsIds) - let pgsTxts = await Promise.all(pgsIds.map(async x => { + let pgsTxts = (await Promise.all(pgsIds.map(async x => { let res = await getPgs.loadScoreHm(x) return res - })) + }))).filter(item => item); + console.log("pgsTxts", pgsTxts) + dt.pgs.category = category - dt.pgs.ids = pgsIds dt.pgs.txts = pgsTxts //calculate prs @@ -191,7 +192,7 @@ const ui = async function (targetDiv) { x: traces[x].map(x => { let monthDay = x.users.meta.split(/\r?\n|\r|\n/g)[0].slice(-20, -14) let year = x.users.meta.split(/\r?\n|\r|\n/g)[0].slice(-4) - let xlabel = x.users.openSnp.variation +" , name: " + x.users.openSnp.name + " , Date: " + monthDay +" "+ year + let xlabel = x.users.openSnp.variation +", name: " + x.users.openSnp.name + " , Date: " + monthDay +" "+ year return xlabel }), mode: 'lines+markers',