Skip to content

Commit 60c725a

Browse files
authored
Fix imports (#3)
* :format: format with black * 🚚 move viz.py changes from phospho project version, lint w/ ruff * 🐛 fix import. network an wgcna analysis from acore, dendrogram * 🐛 missing function and start deconvoluting utils, add imports to pkg * 🎨 port interface adaptions - use plotly figures directly * 🐛 fix CDCI pipeline (missing imports and 3.13. incompability) * 🐛 do not allow pyton 3.13 for now * 🐛 add missing build dependency (for dynamic versioning based on tags)
1 parent df79e13 commit 60c725a

File tree

8 files changed

+497
-239
lines changed

8 files changed

+497
-239
lines changed

.github/workflows/cdci.yml

+15-16
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,27 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616
- uses: psf/black@stable
17-
# lint:
18-
# name: Lint with ruff
19-
# runs-on: ubuntu-latest
20-
# steps:
21-
# - uses: actions/checkout@v4
17+
lint:
18+
name: Lint with ruff
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
2222

23-
# - uses: actions/setup-python@v5
24-
# with:
25-
# python-version: "3.11"
26-
# - name: Install ruff
27-
# run: |
28-
# pip install ruff
29-
# - name: Lint with ruff
30-
# run: |
31-
# # stop the build if there are Python syntax errors or undefined names
32-
# ruff check .
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.11"
26+
- name: Install ruff
27+
run: |
28+
pip install ruff
29+
- name: Lint with ruff
30+
run: |
31+
ruff check .
3332
test:
3433
name: Test
3534
runs-on: ubuntu-latest
3635
strategy:
3736
matrix:
38-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
37+
python-version: ["3.9", "3.10", "3.11", "3.12"]
3938
steps:
4039
- uses: actions/checkout@v4
4140
- name: Set up Python ${{ matrix.python-version }}

pyproject.toml

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dynamic = ["version"]
66
description = "A Python package for plotting related to multimodal molecular data. Works with acore."
77
license = { text = "GNU General Public License v3" }
88
readme = "README.md"
9-
requires-python = ">=3.9"
9+
requires-python = ">=3.9,<3.13"
1010
classifiers = [
1111
"Development Status :: 2 - Pre-Alpha",
1212
"Intended Audience :: Developers",
@@ -27,12 +27,16 @@ dependencies = [
2727
"beautifulsoup4",
2828
"requests",
2929
"dash", # from dash import html
30-
# "networkx",
30+
"networkx",
3131
"matplotlib",
32-
# "cy-jupyterlab",
33-
# "nltk",
34-
# "webweb"
35-
# "acore",
32+
"kaleido",
33+
"pyvis",
34+
"wordcloud",
35+
"cyjupyter",
36+
"nltk",
37+
"webweb",
38+
"acore",
39+
"dash-cytoscape",
3640
]
3741

3842
[project.optional-dependencies]
@@ -64,5 +68,7 @@ Documentation = "https://analytics-core.readthedocs.io/"
6468

6569

6670
[build-system]
67-
requires = ["setuptools"]
71+
requires = ["setuptools", "setuptools_scm>=8"]
6872
build-backend = "setuptools.build_meta"
73+
74+
[tool.setuptools_scm]

src/vuecore/Dendrogram.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from collections import OrderedDict
2+
13
import numpy as np
24
import scipy as scp
3-
from collections import OrderedDict
4-
import plotly.graph_objs as go
55

66

77
def plot_dendrogram(
@@ -17,7 +17,8 @@ def plot_dendrogram(
1717
color_threshold=None,
1818
):
1919
"""
20-
Modified version of Plotly _dendrogram.py that returns a dendrogram Plotly figure object with cutoff line.
20+
Modified version of Plotly _dendrogram.py that
21+
returns a dendrogram Plotly figure object with cutoff line.
2122
2223
:param Z_dendrogram: Matrix of observations as array of arrays
2324
:type Z_dendrogram: ndarray
@@ -58,7 +59,7 @@ def plot_dendrogram(
5859
color_threshold=color_threshold,
5960
)
6061

61-
if cutoff_line == True:
62+
if cutoff_line:
6263
dendrogram.layout.update(
6364
{
6465
"shapes": [
@@ -221,7 +222,7 @@ def set_axis_layout(self, axis_key, hide_labels):
221222

222223
self.layout[axis_key].update(axis_defaults)
223224

224-
if hide_labels == True:
225+
if hide_labels:
225226
self.layout[axis_key].update({"showticklabels": False})
226227
else:
227228
pass
@@ -280,8 +281,8 @@ def get_dendrogram_traces(
280281
icoord = scp.array(Z_dendrogram["icoord"])
281282
dcoord = scp.array(Z_dendrogram["dcoord"])
282283
ordered_labels = scp.array(Z_dendrogram["ivl"])
283-
color_list = scp.array(Z_dendrogram["color_list"])
284-
colors = self.get_color_dict(colorscale)
284+
# color_list = scp.array(Z_dendrogram["color_list"])
285+
# colors = self.get_color_dict(colorscale)
285286

286287
trace_list = []
287288

@@ -295,7 +296,7 @@ def get_dendrogram_traces(
295296
ys = dcoord[i]
296297
else:
297298
ys = icoord[i]
298-
color_key = color_list[i]
299+
# color_key = color_list[i] # not used
299300
hovertext_label = None
300301
if hovertext:
301302
hovertext_label = hovertext[i]

src/vuecore/linkers.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from io import StringIO
2+
3+
import requests
4+
5+
6+
def get_clustergrammer_link(net, filename=None):
7+
clustergrammer_url = "http://amp.pharm.mssm.edu/clustergrammer/matrix_upload/"
8+
if filename is None:
9+
file_string = net.write_matrix_to_tsv()
10+
file_obj = StringIO(file_string)
11+
if "filename" not in net.dat or net.dat["filename"] is None:
12+
fake_filename = "Network.txt"
13+
else:
14+
fake_filename = net.dat["filename"]
15+
r = requests.post(clustergrammer_url, files={"file": (fake_filename, file_obj)})
16+
else:
17+
file_obj = open(filename, "r")
18+
r = requests.post(clustergrammer_url, files={"file": file_obj})
19+
link = r.text
20+
return link

src/vuecore/translate.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import base64
2+
import io
3+
4+
from dash import html
5+
6+
7+
def hex2rgb(color):
8+
_hex = color.lstrip("#")
9+
rgb = tuple(int(_hex[i : i + 2], 16) for i in (0, 2, 4))
10+
rgba = rgb + (0.6,)
11+
return rgba
12+
13+
14+
def mpl_to_html_image(plot, width=800):
15+
buf = io.BytesIO()
16+
plot.savefig(buf, format="png")
17+
data = base64.b64encode(buf.getbuffer()).decode("utf8")
18+
figure = html.Img(src="data:image/png;base64,{}".format(data), width=f"{width}")
19+
20+
return figure

src/vuecore/utils.py

+4-22
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import base64
2-
import io
31
import random
42
from collections import defaultdict
53
from urllib import error
64

75
import bs4 as bs
8-
import dash_html_components as html
96
import networkx as nx
107
import pandas as pd
118
import requests
129
from Bio import Entrez, Medline
10+
from dash import html
1311
from networkx.readwrite import json_graph
1412

1513
# TODO: This should probably be changed to the email of the person installing ckg?
@@ -23,15 +21,6 @@ def check_columns(df, cols):
2321
return True
2422

2523

26-
def mpl_to_html_image(plot, width=800):
27-
buf = io.BytesIO()
28-
plot.savefig(buf, format="png")
29-
data = base64.b64encode(buf.getbuffer()).decode("utf8")
30-
figure = html.Img(src="data:image/png;base64,{}".format(data), width="800")
31-
32-
return figure
33-
34-
3524
def generate_html(network):
3625
"""
3726
This method gets the data structures supporting the nodes, edges,
@@ -151,7 +140,7 @@ def networkx_to_neo4j_document(graph):
151140
rel_type = edge["type"]
152141
if "type" in graph.nodes()[r]:
153142
edge["type"] = graph.nodes()[r]["type"]
154-
if not (n, r, edge["type"]) in seen_rels:
143+
if (n, r, edge["type"]) not in seen_rels:
155144
rels[rel_type].append(edge)
156145
seen_rels.update({(n, r, edge["type"]), (r, n, edge["type"])})
157146
attr.update(rels)
@@ -268,9 +257,9 @@ def __extract_style(el):
268257
for k, v in [x.split(": ") for x in el.attrs["style"].split(";") if x != ""]
269258
}
270259

271-
if type(el) is str:
260+
if isinstance(el, str):
272261
return convert_html_to_dash(parse_html(el))
273-
if type(el) == bs.element.NavigableString:
262+
if isinstance(el, bs.element.NavigableString):
274263
return str(el)
275264
else:
276265
name = el.name
@@ -281,13 +270,6 @@ def __extract_style(el):
281270
return getattr(html, name.title())(contents, style=style)
282271

283272

284-
def hex2rgb(color):
285-
hex = color.lstrip("#")
286-
rgb = tuple(int(hex[i : i + 2], 16) for i in (0, 2, 4))
287-
rgba = rgb + (0.6,)
288-
return rgba
289-
290-
291273
def get_rgb_colors(n):
292274
colors = []
293275
r = int(random.random() * 256)

0 commit comments

Comments
 (0)