Skip to content

Commit

Permalink
added opensnp data
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenasandoval88 committed Mar 26, 2024
1 parent 471dd5d commit c6a7182
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ <h4 class="hero_title">Diseasome</h3>
</div>

</section>
<!-- 23 and me -->
<h5>OpenSNP</h5>
<div id = snp></div>
<br>

<!-- pgs scoring counts bar plot ----------------------------->
<h5>The Polygenic Score (PGS) Catalog</h5>
<p>The PGS Catalog is an open database of published polygenic scores (PGS). Each PGS in the Catalog is consistently annotated with relevant metadata; including scoring files (variants, effect alleles/weights), annotations of how the PGS was developed and applied, and evaluations of their predictive performance.</p>
<br>
<h6 style="color: rgb(6, 137, 231);">Select from the bar chart below, to display variant sizes for entries in a category</h6>

Expand Down
133 changes: 133 additions & 0 deletions sdk/allTraits.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,141 @@ let fetchAll = localforage.createInstance({
name: "fetchAll",
storeName: "urls"
})
let openSnpDbUrls = localforage.createInstance({
name: "openSnpDbUrls",
storeName: "userUrls"
})
let openSnpDbUsers = localforage.createInstance({
name: "openSnpDbUsers",
storeName: "usersTxt"
})
let output = []
// 23andMe ///////////////////////////////////////////////////////////////////////////////////
// get all users with genotype data (23andMe, illumina, ancestry etc)-------------------------------
async function getUserUrls() { // opensnp user data includes ancestry, familtyTree, and 23and me genotype data
const newLocal = 'usersFull';
let dt
dt = await openSnpDbUrls.getItem(newLocal); // check for users in localstorage
if (dt == null) {
let url = 'https://corsproxy.io/?https://opensnp.org/users.json'
let users = (await (await fetch(url)).json())
let dt2 = users.sort((a, b) => a.id - b.id)
dt = openSnpDbUrls.setItem('usersFull', dt2)
}
// console.log("getUrls, dt:", dt)
return dt
}

// filter users without 23andme/ancestry data---------------------------------------------------------
async function filterUsers(type) {
let users = await getUserUrls()
let dt
let arr = []
dt = await openSnpDbUrls.getItem('usersFiltered'); // check local storage for user data
if (dt == null) {
users.filter(row => row.genotypes.length > 0).map(dt => {

// keep user with one or more 23andme files
dt.genotypes.map(i => {
if (dt.genotypes.length > 0 && i.filetype == type) {
let innerObj = {};
innerObj["name"] = dt["name"];
innerObj["id"] = dt["id"];
innerObj["genotype.id"] = i.id;
innerObj["genotype.filetype"] = i.filetype;
innerObj["genotype.download_url"] = i.download_url.replace("http", "https")
arr.push(innerObj)

}
})
})
dt = arr //.filter(x=> x.genotypes.length != 0)
openSnpDbUrls.setItem('usersFiltered', dt)
}
//console.log("fiter, dt:", dt)
return dt
}
let users2 = await filterUsers("23andme")
console.log("users2",users2)

async function get23(urls) {
let arr23Txts = []
for (let i = 0; i < urls.length; i++) {
let user = await openSnpDbUsers.getItem(urls[i]);

if (user == null) {
let url2 = 'https://corsproxy.io/?' + urls[i]
user = (await (await fetch(url2)).text())
openSnpDbUsers.setItem(urls[i], user);
}
if (user.substring(0, 37) == '# This data file generated by 23andMe') {
//console.log("This is a valid 23andMe file:", user.substring(0, 37))
let parsedUser = await parse23(user, urls[i])
arr23Txts.push(parsedUser)
} else {
console.log("ERROR:This is NOT a valid 23andMe file:", user.substring(0, 37))
}
}

return arr23Txts
}

// plot opensnp data types --------------
let users = (await getUserUrls())
let usersFlat = users.flatMap(x=>x.genotypes)
let datatypes = [...new Set(users.flatMap(x=>x.genotypes.flatMap(e=>e.filetype)))]
console.log("usersFlat",usersFlat)
var obj = {};
var counter = {}

for (var i = 0, len = usersFlat.length; i < len; i++) {
obj[usersFlat[i]['filetype']] = usersFlat[i];
counter[usersFlat[i]['filetype']] = (counter[usersFlat[i]['filetype']] || 0) + 1
}
let newArr = new Array();
for (var key in obj){
newArr.push(extend( obj[key], {count:counter[key]}));
}

function extend(a, b){
for(var key in b)
if(b.hasOwnProperty(key))
a[key] = b[key];
return a;
}
console.log(newArr)


let snpDiv = document.getElementById("snp")
var layout = {

autosize: true,
title: `Counts of OpenSNP datatypes`,
margin: {l:150},
xaxis: {
autorange: false,
range: [0, 1000],
type: 'linear'
},
}
var dt = [{
x: newArr.map(x => x.count),
y: newArr.map(x => x.filetype),
type: 'bar',
orientation: 'h',
marker: {
color: Array(newArr.length).fill(['orange', 'green', 'red',
'#1f77b4', //muted blue
'#ff7f0e', // safety orange
'#2ca02c', // cooked asparagus green
'#d62728', //brick red
]).flat().splice(0, newArr.length)
}
}]
plotly.newPlot(snpDiv, dt, layout);

// top bar plot
// PGS ///////////////////////////////////////////////////////////////////////////////////
const traitFiles = (await fetchAll2('https://www.pgscatalog.org/rest/trait/all')).flatMap(x => x)
const traits = Array.from(new Set(traitFiles.flatMap(x => x["trait_categories"])
.sort().filter(e => e.length).map(JSON.stringify)), JSON.parse)
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}
/* hero background image */
.bgimage {
height:45vh;
height:35vh;
background: url('dna2.jpg');
background-size:cover;
position:relative;
Expand Down

0 comments on commit c6a7182

Please sign in to comment.