-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8" /> | ||
<title>LIS Web-Components - <lis-gene-search-element></title> | ||
<!-- CSS framework --> | ||
<link rel="stylesheet" type="text/css" href="../node_modules/uikit/dist/css/uikit.min.css"> | ||
<script src="../node_modules/uikit/dist/js/uikit.min.js"></script> | ||
<!-- web components polyfills --> | ||
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> | ||
<script src="../node_modules/lit/polyfill-support.js"></script> | ||
<!-- GraphQL --> | ||
<script type="text/javascript" src="./services-dscensor.js"></script> | ||
<!-- web components --> | ||
<script type="module" src="../lib/index.js"></script> | ||
</head> | ||
|
||
<body> | ||
|
||
<div class="uk-container uk-margin-bottom"> | ||
<h1><dscensor-element></h1> | ||
<p> | ||
The <code><dscensor-element></code> is developmental and serves to eventually replace the existing multiQC view. | ||
</p> | ||
<hr> | ||
</div> | ||
|
||
<div class="uk-container uk-container-expand"> | ||
<div class="uk-container uk-container-expand"> | ||
<form id="dscensor-form"> | ||
<label for="genera">Genera:</label> | ||
<select id="genera" name="genera"> | ||
</select> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
</div> | ||
<lis-simple-table-element id="dscensor-table"></lis-simple-table-element> | ||
<lis-histogram-element id="dscensor-histogram"></lis-histogram-element> | ||
</div> | ||
|
||
<!-- set the search function by property because functions can't be set as attributes --> | ||
<script type="text/javascript"> | ||
// get the simple table element | ||
window.onload = (event) => { | ||
const form = document.getElementById('dscensor-form'); | ||
form.addEventListener('submit', (event) => dscensorSubmit(event)); | ||
|
||
const dropdown = document.getElementById('genera'); | ||
|
||
const genera = dscensorQuery(getGenus); | ||
genera.then((g) => { g.forEach((genera) => { | ||
const option = document.createElement('option'); | ||
option.value = genera; | ||
option.text = genera; | ||
dropdown.appendChild(option); | ||
}); | ||
}); | ||
} | ||
|
||
function dscensorSubmit(event){ | ||
const genera = document.getElementById('genera'); | ||
const query = 'genomes?genus=' + genera.options[genera.selectedIndex].value; | ||
const customUrl = uri + query; | ||
const data = dscensorFormQuery(event, customUrl); | ||
data.then((ds) => { | ||
const formatted = ds.map(d => (flatten(d))); | ||
console.log(formatted); | ||
const dataAttributes = Object.keys(formatted[0]); | ||
|
||
let index = dataAttributes.indexOf('url'); | ||
if (index > -1) { // only splice array when item is found | ||
dataAttributes.splice(index, 1); // 2nd parameter means remove one item only | ||
} | ||
index = dataAttributes.indexOf('derived_from'); | ||
if (index > -1) { // only splice array when item is found | ||
dataAttributes.splice(index, 1); // 2nd parameter means remove one item only | ||
} | ||
|
||
const labels = {} | ||
dataAttributes.map((d) => labels[[d]] = d); | ||
console.log(dataAttributes, labels); | ||
const tableElement = document.getElementById('dscensor-table'); | ||
// set the element's properties | ||
tableElement.caption = 'DSCensor Test'; | ||
tableElement.dataAttributes = dataAttributes; | ||
tableElement.header = labels; | ||
tableElement.data = formatted; | ||
const histoElement = document.getElementById('dscensor-histogram'); | ||
histoElement.width = 1000; | ||
histoElement.height = 1000; | ||
histoElement.ylabel = 'Complete BUSCOs'; | ||
histoElement.xlabel = 'Genome'; | ||
histoElement.data = tableElement.data.map((d) => ({"name": d.filename, "count": d.complete_buscos})); | ||
}); | ||
} | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// query a local instance of the LIS GraphQL server: | ||
// https://github.com/legumeinfo/graphql-server | ||
|
||
// Note: using port 4444 since port 4000 is default for jekyll site | ||
const uri = 'https://services.lis.ncgr.org/dscensor/'; | ||
const exampleQuery = 'genomes?genus=arachis' | ||
const url = uri + exampleQuery | ||
const getGenus = 'https://services.lis.ncgr.org/dscensor/genera' | ||
// A function that gets data from a GraphQL server via a POST request. | ||
// Adapted from https://graphql.org/graphql-js/graphql-clients/ | ||
function dscensorQuery(url) { | ||
return fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json', | ||
}, | ||
}) | ||
.then(r => r.json()) | ||
.then((response) => { | ||
if (response.errors) { | ||
response.errors.forEach(console.error); | ||
} | ||
return response; | ||
}); | ||
} | ||
|
||
function dscensorFormQuery(event, url) { | ||
event.preventDefault(); // prevent the form from submitting normally | ||
// your custom code here | ||
console.log('Form submitted'); | ||
console.log('URL:', url); | ||
return fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Accept': 'application/json', | ||
}, | ||
}) | ||
.then(r => r.json()) | ||
.then((response) => { | ||
if (response.errors) { | ||
response.errors.forEach(console.error); | ||
} | ||
return response; | ||
}); | ||
} | ||
|
||
// Flatten GraphQL results that contain objects | ||
const flatten = (obj, out={}, prefixes=[]) => { | ||
if (obj != null) { | ||
Object.keys(obj).forEach(key => { | ||
const key_prefixes = [...prefixes, key]; | ||
if (typeof obj[key] == 'object' && !Array.isArray(obj[key])) { | ||
out = flatten(obj[key], out, key_prefixes); | ||
} else { | ||
// const prefix_key = key_prefixes.join('_'); | ||
out[key] = obj[key]; | ||
} | ||
}); | ||
} | ||
return out; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters