Skip to content

Commit

Permalink
added trait totals call
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenasandoval88 committed Oct 5, 2023
1 parent e7a15a4 commit a159963
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions sdk/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,46 @@ import {PGS23} from "../main.js";

let plot = {}

async function fetchAll2(url, maxPolls = null) {
const allResults = []

if (maxPolls == null) maxPolls = Infinity

for (let i = 0; i < maxPolls; i++) {
const offset = i * 100
let queryUrl = `${url}?limit=100&offset=${offset}`

const results = (await (await fetch(queryUrl)).json()).results
results.forEach(result => allResults.push(result))

if (results.length < 100) {
break
}
}
return allResults
}

async function traitTotals() {
let traitFiles = fetchAll2('https://www.pgscatalog.org/rest/trait/all')
let traitTotals = []
let allTraits = Array.from(new Set( traitFiles.flatMap(x => x["trait_categories"]).sort().filter(e =>
e.length).map(JSON.stringify)), JSON.parse)
let allScores = traits.map( x => getPgsFiles(x))

allTraits.map(( x, i)=> {
let counts = {}
counts["trait"]= x
counts["count"]= allScores[i].length
traitTotals.push(counts)
})
return traitTotals.sort((a,b) => a.count - b.count)
}



plot.pgsCounts = async function(){
let div = document.getElementById("pgsBar")

data = traitTotals()
var layout = {
title: 'Counts of PGS Catalog Scoring Files by Trait',
margin: {
Expand All @@ -19,8 +56,8 @@ plot.pgsCounts = async function(){
var data =
[
{
x: traitTotals.map(x=>x.count),
y: traitTotals.map(x=>x.trait),
x: data.map(x=>x.count),
y: data.map(x=>x.trait),
type: 'bar',
orientation: 'h'
}
Expand All @@ -31,7 +68,7 @@ plot.pgsCounts = async function(){
//return myDiv

}
//plot.pgsCounts()
plot.pgsCounts()

plot.plotAllMatchByEffect4 = async function(data, errorDiv ,dv) {
//https://community.plotly.com/t/fill-shade-a-chart-above-a-specific-y-value-in-plotlyjs/5133
Expand Down

0 comments on commit a159963

Please sign in to comment.