Skip to content

Commit

Permalink
fixing bugs, changing gene list previews. refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
adkinsrs committed Nov 30, 2023
1 parent 417ef27 commit 0cf9ca4
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 392 deletions.
59 changes: 59 additions & 0 deletions www/cgi/get_unweighted_gene_cart_preview.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/opt/bin/python3

"""
"""

import cgi
import json
import os
import string
import sys

lib_path = os.path.abspath(os.path.join('..', '..', 'lib'))
sys.path.append(lib_path)
import geardb

def main():
print('Content-Type: application/json\n\n')

form = cgi.FieldStorage()
share_id = form.getvalue('share_id')
valid_chars = "%s%s" % (string.ascii_letters, string.digits)
share_id = ''.join(c for c in share_id if c in valid_chars)

result = { 'success': 0 }

# Get genes from the gene cart
if not share_id:
result['message'] = 'No share ID provided'
result["success"] = 0
print(json.dumps(result))
return

gene_cart = geardb.get_gene_cart_by_share_id(share_id)
if not gene_cart:
result['message'] = 'Invalid share ID'
result["success"] = 0
print(json.dumps(result))
return

genes = gene_cart.genes
organism_id = gene_cart.organism_id

# Get the Gene objects for this gene cart
gene_collection = geardb.GeneCollection()
gene_collection.get_by_gene_symbol(gene_symbol=' '.join(genes), organism_id=organism_id, exact=True)


gene_dict = {} # Key is ensembl ID, value is dict of gene symbol and product.
# Create an dict of gene symbol to gene object
for gene in gene_collection.genes:
gene_dict[gene.ensembl_id] = { 'gene_symbol': gene.gene_symbol, 'product': gene.product }

result["gene_info"] = gene_dict
result['success'] = 1
print(json.dumps(result))

if __name__ == '__main__':
main()
10 changes: 5 additions & 5 deletions www/cgi/get_weighted_gene_cart_preview.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import cgi
import json
import os
import string
import sys

import pandas as pd
import scanpy as sc

import os, sys

gene_cart_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'carts')
ROWS_TO_SHOW = 5
Expand All @@ -35,21 +35,21 @@ def main():
except OSError as e:
message = "Unable to open file for genecart {}".format(share_id)
success = -1
result = { 'preview_json':[], 'success': success, 'message': message }
result = { 'preview_json':[], 'num_genes':-1, 'weights':[], 'success': success, 'message': message }
print(json.dump(result))
sys.exit()

adata.var_names_make_unique()

df1 = pd.DataFrame(adata.X, adata.obs.index, adata.var.index).transpose()
# df1 = pd.DataFrame(adata.X, adata.obs.index, adata.var.index).transpose()
# Merge df1 into adata.var, using the index of df1 as the index of adata.var
# Reset index so that all column levels are the same. Numerical index is later dropped for displaying.
df = pd.concat([adata.var, df1], axis=1).reset_index()[:ROWS_TO_SHOW]
#df = pd.concat([adata.var, df1], axis=1).reset_index()[:ROWS_TO_SHOW]

result["num_genes"] = len(adata.var)
result["weights"] = adata.obs.index.tolist()

result['preview_json'] = df.to_html(classes=['weighted-list'], index=False)
#result['preview_json'] = df.to_html(classes=['weighted-list'], index=False)
result['success'] = 1
print(json.dumps(result))

Expand Down
12 changes: 10 additions & 2 deletions www/css/common.v2.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ p.menu-label {
background-color: lightgrey;
}

.select.is-success select, .input.is-success{
.select.is-success select, .input.is-success, .textarea.is-success{
border-color: #539400; /* overwrite default success for .select */
}

.select.is-success:not(:hover)::after {
border-color: #539400; /* overwrite default success for .select */
}

.select.is-danger select, .input.is-danger{
.select.is-danger select, .input.is-danger, .textarea.is-danger{
border-color: #942400; /* overwrite default success for .select */
}

Expand All @@ -106,3 +106,11 @@ p.menu-label {
.js-tree {
max-height: 200px; /* a) addresses long lists and b) addresses https://github.com/mar10/wunderbaum/issues/57 */
}

/* Toast-style notifications for actual alerts */
.notification.js-toast {
position: fixed;
top: 30px;
right: 10px;
z-index:999;
}
8 changes: 0 additions & 8 deletions www/css/compare_datasets.v2.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ input[type=number] {
height:92vh;
}

/* Toast-style notifications for actual alerts */
.notification.js-toast {
position: fixed;
top: 30px;
right: 10px;
z-index:999;
}

/* override loader from the themed CSS */
.button.is-loading::after, .loader, .select.is-loading::after, .control.is-loading::after {
border-color: black;
Expand Down
8 changes: 0 additions & 8 deletions www/css/curator_common.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@
background-color: lightgrey;
}

/* Toast-style notifications for actual alerts */
.notification.js-toast {
position: fixed;
top: 30px;
right: 10px;
z-index:999;
}

#post_plot_adjustments select {
width: 100px;
white-space: nowrap;
Expand Down
9 changes: 0 additions & 9 deletions www/css/gene_collection_manager.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
}

hr.gc-list-element-divider {
width: 90%;
background-color: #000000;
margin-left: auto;
margin-right: auto;
Expand All @@ -20,14 +19,6 @@ hr.gc-list-element-divider {
border-radius: 4px;
}

/* Toast-style notifications for actual alerts */
.notification.js-toast {
position: fixed;
top: 30px;
right: 10px;
z-index:999;
}

/* CSS for Floating UI components */

#delete_gc_popover {
Expand Down
8 changes: 0 additions & 8 deletions www/css/user_profile.v2.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,3 @@ img#submit_wait_indicator {
width: 30px;
margin-right: 10px;
}

/* Toast-style notifications for actual alerts */
.notification.js-toast {
position: fixed;
top: 30px;
right: 10px;
z-index:999;
}
6 changes: 3 additions & 3 deletions www/gene_collection_manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
</header>
<div class="card-content is-flex-grow-1">
<div class="content has-text-dark">
Upload a gene list with associated weights, for example from a principal component analysis
Upload a gene list with associated weights. For example, from a dataset's principal component analysis
</div>
</div>
<footer class="card-footer">
Expand All @@ -178,7 +178,7 @@
<div class="card-content is-flex-grow-1">
<div class="content has-text-dark">
<p class="is-subtitle has-text-weight-semibold">COMING SOON</p>
Upload a file containing a list of genes and associated labels, for example marker genes for cell types
Upload a file containing a list of genes and associated labels. For example, marker genes for cell types
</div>
</div>
<footer class="card-footer">
Expand Down Expand Up @@ -279,7 +279,7 @@
</div>
<div class="field-body">
<div class="buttons has-addons" role="group" aria-label="Gene cart list view preference">
<button type="button" id="btn_list_view_compact" class="button is-small is-dark active" aria-label="Compact view" data-toggle="popover" data-toggle="tooltip" data-placement="top" title="Compact view">
<button type="button" id="btn_list_view_compact" class="button is-small is-gear-bg-secondary" aria-label="Compact view" data-toggle="popover" data-toggle="tooltip" data-placement="top" title="Compact view">
<span class="icon is-small">
<i class="mdi mdi-format-list-bulleted"></i>
</span>
Expand Down
50 changes: 50 additions & 0 deletions www/js/common.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,56 @@ const convertToFormData = (object) => {
return formData;
}

/**
* Creates a toast notification with the given message and level class.
* @param {string} msg - The message to display in the toast notification.
* @param {string} [levelClass="is-danger"] - The level class for the toast notification. Defaults to "is-danger".
*/
const createToast = (msg, levelClass="is-danger") => {
const template = `
<div class="notification js-toast ${levelClass} animate__animated animate__fadeInUp animate__faster">
<button class="delete"></button>
${msg}
</div>
`
const html = generateElements(template);

const numToasts = document.querySelectorAll(".js-toast.notification").length;

if (document.querySelector(".js-toast.notification")) {
// If .js-toast notifications are present, append under final notification
// This is to prevent overlapping toast notifications
document.querySelector(".js-toast.notification:last-of-type").insertAdjacentElement("afterend", html);
// Position new toast under previous toast with CSS
html.style.setProperty("top", `${(numToasts * 70) + 30}px`);
} else {
// Otherwise prepend to top of main content
document.getElementById("main_c").prepend(html);
}

// This should get the newly added notification since it is now the first
html.querySelector(".js-toast.notification .delete").addEventListener("click", (event) => {
const notification = event.target.closest(".js-toast.notification");
notification.remove(notification);
});

// For a success message, remove it after 3 seconds
if (levelClass === "is-success") {
const notification = document.querySelector(".js-toast.notification:last-of-type");
notification.classList.remove("animate__fadeInUp");
notification.classList.remove("animate__faster");
notification.classList.add("animate__fadeOutDown");
notification.classList.add("animate__slower");
}

// remove the toast
html.addEventListener("animationend", (event) => {
if (event.animationName === "fadeOutDown") {
event.target.remove();
}
});
}

/**
* Collapses a JS step element.
*
Expand Down
39 changes: 0 additions & 39 deletions www/js/compare_datasets.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,45 +300,6 @@ const createGeneSelectInstance = (idSelector, geneSelect=null) => {
});
}

/* Creates a Toast-style message in the upper-corner of the screen. */
const createToast = (msg, levelClass="is-danger") => {
const template = `
<div class="notification js-toast ${levelClass} animate__animated animate__fadeInUp animate__faster">
<button class="delete"></button>
${msg}
</div>
`
const html = generateElements(template);

const numToasts = document.querySelectorAll(".js-toast.notification").length;

if (document.querySelector(".js-toast.notification")) {
// If .js-toast notifications are present, append under final notification
// This is to prevent overlapping toast notifications
document.querySelector(".js-toast.notification:last-of-type").insertAdjacentElement("afterend", html);
// Position new toast under previous toast with CSS
html.style.setProperty("top", `${(numToasts * 70) + 30}px`);
} else {
// Otherwise prepend to top of main content
document.getElementById("main_c").prepend(html);
}

// This should get the newly added notification since it is now the first
document.querySelector(".js-toast.notification .delete").addEventListener("click", (event) => {
const notification = event.target.closest(".js-toast.notification");
notification.remove(notification);
});

// For a success message, remove it after 3 seconds
if (levelClass === "is-success") {
const notification = document.querySelector(".js-toast.notification:last-of-type");
notification.classList.remove("animate__fadeInUp");
notification.classList.remove("animate__faster");
notification.classList.add("animate__fadeOutDown");
notification.classList.add("animate__slower");
}
}

const downloadSelectedGenes = (event) => {
event.preventDefault();

Expand Down
44 changes: 0 additions & 44 deletions www/js/curator_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,50 +883,6 @@ const createPlot = async (event) => {

}

/**
* Creates a toast notification with the given message and level class.
* @param {string} msg - The message to display in the toast notification.
* @param {string} [levelClass="is-danger"] - The level class for the toast notification. Defaults to "is-danger".
*/
const createToast = (msg, levelClass="is-danger") => {
const template = `
<div class="notification js-toast ${levelClass} animate__animated animate__fadeInUp animate__faster">
<button class="delete"></button>
${msg}
</div>
`
const html = generateElements(template);

const numToasts = document.querySelectorAll(".js-toast.notification").length;

if (document.querySelector(".js-toast.notification")) {
// If .js-toast notifications are present, append under final notification
// This is to prevent overlapping toast notifications
document.querySelector(".js-toast.notification:last-of-type").insertAdjacentElement("afterend", html);
// Position new toast under previous toast with CSS
html.style.setProperty("top", `${(numToasts * 70) + 30}px`);
} else {
// Otherwise prepend to top of main content
document.getElementById("main_c").prepend(html);
}

// This should get the newly added notification since it is now the first
html.querySelector(".js-toast.notification .delete").addEventListener("click", (event) => {
console.log(event.target);
const notification = event.target.closest(".js-toast.notification");
notification.remove(notification);
});

// For a success message, remove it after 3 seconds
if (levelClass === "is-success") {
const notification = document.querySelector(".js-toast.notification:last-of-type");
notification.classList.remove("animate__fadeInUp");
notification.classList.remove("animate__faster");
notification.classList.add("animate__fadeOutDown");
notification.classList.add("animate__slower");
}
}

/**
* Disables or enables a checkbox and its associated label.
* If the parent element is a .checkbox class, it will also be disabled or enabled.
Expand Down
Loading

0 comments on commit 0cf9ca4

Please sign in to comment.