Skip to content

Commit

Permalink
limit variants to 500 in pgs
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenasandoval88 committed Sep 20, 2024
1 parent 49a886b commit bd96a4a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion sdk/get23.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
34 changes: 23 additions & 11 deletions sdk/getPgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 => {
Expand Down Expand Up @@ -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` //
Expand All @@ -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 --------------------------
Expand Down
4 changes: 1 addition & 3 deletions sdk/prs.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ PRS.Match2 = function (data) {
data2.QC = true
data2.QCtext = ''
}

return data2
}

Expand All @@ -114,15 +113,14 @@ 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
// todo remove users with old chips
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++) {

Expand Down
13 changes: 7 additions & 6 deletions sdk/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit bd96a4a

Please sign in to comment.