Skip to content

Commit

Permalink
Update publication codes and figures
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Jan 19, 2024
1 parent 9935409 commit 9bfcfb6
Show file tree
Hide file tree
Showing 13 changed files with 174,685 additions and 47 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/deploy_streamlit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy streamlit docker to Azure
on: [] # [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Build and push
uses: azure/docker-login@v1
with:
login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- run: |
docker build . -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/marsilea:${{ github.sha }}
docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/marsilea:${{ github.sha }}
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v2
with:
resource-group: ${{ secrets.RESOURCE_GROUP }}
dns-name-label: ${{ secrets.RESOURCE_GROUP }}${{ github.run_number }}
image: ${{ secrets.REGISTRY_LOGIN_SERVER }}/marsilea:${{ github.sha }}
registry-login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
registry-username: ${{ secrets.REGISTRY_USERNAME }}
registry-password: ${{ secrets.REGISTRY_PASSWORD }}
name: marsilea
location: 'west us'
105 changes: 78 additions & 27 deletions examples/plot_available_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,63 @@

from marsilea.layers import Rect, RightTri, FrameRect, FracRect

# sphinx_gallery_start_ignore
import mpl_fontkit as fk

fk.install("Lato", verbose=False)

# sphinx_gallery_end_ignore

def label_ax(ax, text):
ax.text(1.05, .5, text, transform=ax.transAxes,
ha="left", va="center")


# sphinx_gallery_start_ignore
from pathlib import Path

save_path = Path(__file__).parent / "imgs"
plt.rcParams['svg.fonttype'] = 'none'
# sphinx_gallery_end_ignore


# %%
# Mesh plotters
plt.ion()
rng = np.random.default_rng(0)
data = np.arange(5)
data2d = np.arange(5).reshape(1, 5)
pieces = {
0: FrameRect(color="g", label="2"),
1: Rect(color="g", label="2"),
2: RightTri(color="g", label="3"),
3: FracRect(color="b", label="3"),
4: RightTri(color="b", label="3", right_angle="upper right"),
0: FrameRect(color="#7E2E84", width=2),
1: Rect(color="#D14081"),
2: RightTri(color="#EF798A"),
3: FracRect(color="#F9F5E3", frac=(.5, .5)),
4: RightTri(color="#CCF5AC", right_angle="upper right"),
}

plotters = {
"Color Mesh": mp.ColorMesh(data2d, cmap="Blues"),
"Sized Mesh": mp.SizedMesh(data2d, sizes=(100, 500), cmap="Greens"),
"Marker Mesh": mp.MarkerMesh(data2d >= 2, size=300, marker="*", color="red"),
"Sized Mesh": mp.SizedMesh(data2d, sizes=(100, 500), color="#A05F96"),
"Marker Mesh": mp.MarkerMesh(data2d > 0, size=300, marker="x", color="#AAD9BB"),
"Layers Mesh": ma.layers.LayersMesh(data2d, pieces=pieces),
}

canvas = ma.Heatmap(data2d, width=5, height=0, cmap="Oranges", label="Color Mesh")
for title, plotter in plotters.items():
plotter.set_label(title, "right")
canvas.add_bottom(plotter)
canvas.add_bottom(plotter, name=title)

canvas.add_dendrogram("bottom", method="ward", colors="#FFDD95")
canvas.add_dendrogram("bottom", method="ward", colors="#1D2B53", name="Dendrogram")
canvas.render()

for ax in canvas.figure.get_axes():
for title in list(plotters.keys()) + ["Dendrogram"]:
ax = canvas.get_ax(title)
ax.set_axis_off()
label_ax(ax, title)

# sphinx_gallery_start_ignore
if '__file__' in globals():
plt.savefig(save_path / "all_plotters_mesh.svg", bbox_inches="tight")
# sphinx_gallery_end_ignore

# %%
# Label plotters
Expand All @@ -64,35 +90,44 @@
text_color.append(".1")
matrix = rng.standard_normal((1, 100))
canvas2 = ma.Heatmap(matrix, width=5, height=.1)
canvas2.add_top(mp.Labels(text, text_props={'color': text_color}, rotation=0, label="Labels"))
canvas2.add_bottom(mp.AnnoLabels(labels, mark=[3, 4, 5, 96, 97, 98], rotation=0))
canvas2.add_top(mp.Labels(text, text_props={'color': text_color}, rotation=0), name="Labels")
canvas2.add_bottom(mp.AnnoLabels(labels, mark=[3, 4, 5, 96, 97, 98], rotation=0), name="AnnoLabels")
canvas2.render()

for title in ["Labels", "AnnoLabels"]:
ax = canvas2.get_ax(title)
label_ax(ax, title)

# sphinx_gallery_start_ignore
if '__file__' in globals():
plt.savefig(save_path / "all_plotters_label.svg", bbox_inches="tight")
# sphinx_gallery_end_ignore

# %%
# Statistics plotters

data1d = np.arange(1, 6)
data2d = rng.integers(1, 10, size=(10, 5))
bar_width = .6
bar_width = .5

plotters = {
"Simple Bar": mp.Numbers(data1d, color="#756AB6", width=bar_width),
"Bar": mp.Bar(data2d, color="#5F8670", width=bar_width),
"Boxen": mp.Boxen(data2d, color="#FFB534", width=bar_width),
"Violin": mp.Violin(rng.standard_normal((20, 5)), color="#65B741"),
"Point": mp.Point(data2d, color="#4CB9E7"),
"Strip": mp.Strip(data2d, color="#FF004D"),
"Swarm": mp.Swarm(data2d, color="#647D87"),
"Point": mp.Point(data2d, color="#656176"),
"Strip": mp.Strip(rng.standard_normal((50, 5)), color="#FF004D"),
"Swarm": mp.Swarm(rng.standard_normal((50, 5)), color="#647D87"),
"Stacked Bar": mp.StackBar(rng.integers(1, 10, (5, 5)), items="abcde", width=bar_width),
"Center Bar": mp.CenterBar(rng.integers(1, 10, (5, 2)), colors=["#EE7214", "#527853"], width=bar_width),
}

canvas3 = ma.Heatmap(rng.standard_normal((10, 5)), width=4, height=0)
for title, plotter in plotters.items():
plotter.allow_labeling = True
plotter.set_label(title, "right")
canvas3.add_bottom(plotter, pad=.3, size=2, name=title)
size = 1
if title in ["Violin", "Strip", "Swarm"]:
size = 1.5
canvas3.add_bottom(plotter, pad=.1, size=size, name=title)

canvas3.vsplit(cut=[2])
canvas3.add_bottom(mp.Chunk(["Lower", "Upper"], ["#FFDD95", "#FFB000"], padding=10))
Expand All @@ -104,19 +139,35 @@
ax.spines[dir].set_visible(False)
ax.tick_params(left=False, labelleft=False)

# for title in plotters.keys():
# ax = canvas3.get_ax(title)[0]
# ax.text(-.1, .5, title, transform=ax.transAxes, fontsize=14, ha="right", va="center")
for title in plotters.keys():
ax = canvas3.get_ax(title)[-1]
label_ax(ax, title)

# sphinx_gallery_start_ignore
if '__file__' in globals():
plt.savefig(save_path / "all_plotters_stat.svg", bbox_inches="tight")
# sphinx_gallery_end_ignore


# %%
# Other plotters
matrix = pd.DataFrame(data=rng.integers(1, 10, (4, 5)), index=list("ACGT"))
colors = {"A": "r", "C": "b", "G": "g", "T": "black"}
colors = {"A": "#D81159", "C": "#218380", "G": "#FBB13C", "T": "#73D2DE"}
weights = rng.integers(1, 10, 4)
seqlogo = mp.SeqLogo(matrix, color_encode=colors)
arc = mp.Arc([1, 2, 3, 4, 5], [(1, 5), (2, 3), (1, 2), (4, 5)], width=1, colors="#FF004D")
arc = mp.Arc([1, 2, 3, 4, 5], [(1, 5), (2, 3), (1, 2), (4, 5)],
weights=weights, width=(2, 5), colors="#534D56")

canvas4 = ma.Heatmap(rng.standard_normal((10, 5)), width=4, height=0)
canvas4.add_top(seqlogo, size=2)
canvas4.add_top(arc, size=1, pad=.2)
canvas4.add_top(seqlogo, size=2, name="Sequence Logo")
canvas4.add_top(arc, size=1, pad=.2, name="Arc Diagram")
canvas4.render()

for title in ["Sequence Logo", "Arc Diagram"]:
ax = canvas4.get_ax(title)
label_ax(ax, title)

# sphinx_gallery_start_ignore
if '__file__' in globals():
plt.savefig(save_path / "all_plotters_other.svg", bbox_inches="tight")
# sphinx_gallery_end_ignore
99 changes: 97 additions & 2 deletions examples/plot_mouse_embryo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,98 @@

# sphinx_gallery_start_ignore
import mpl_fontkit as fk

fk.install("Lato", verbose=False)


class Transforms:
"""
Holds transformation matrices.
All the details for transformation matrices can be found at: https://arxiv.org/pdf/1711.10662.pdf.
"""

@staticmethod
def rgb_to_lms():
"""
Matrix for RGB color-space to LMS color-space transformation.
"""
return np.array([[17.8824, 43.5161, 4.11935],
[3.45565, 27.1554, 3.86714],
[0.0299566, 0.184309, 1.46709]]).T

@staticmethod
def lms_to_rgb() -> np.ndarray:
"""
Matrix for LMS colorspace to RGB colorspace transformation.
"""
return np.array([[0.0809, -0.1305, 0.1167],
[-0.0102, 0.0540, -0.1136],
[-0.0004, -0.0041, 0.6935]]).T

@staticmethod
def lms_protanopia_sim(degree: float = 1.0) -> np.ndarray:
"""
Matrix for Simulating Protanopia colorblindness from LMS color-space.
:param degree: Protanopia degree.
"""
return np.array([[1 - degree, 2.02344 * degree, -2.52581 * degree],
[0, 1, 0],
[0, 0, 1]]).T

@staticmethod
def lms_deutranopia_sim(degree: float = 1.0) -> np.ndarray:
"""
Matrix for Simulating Deutranopia colorblindness from LMS color-space.
:param degree: Deutranopia degree.
"""
return np.array([[1, 0, 0],
[0.494207 * degree, 1 - degree, 1.24827 * degree],
[0, 0, 1]]).T

@staticmethod
def lms_tritanopia_sim(degree: float = 1.0) -> np.ndarray:
"""
Matrix for Simulating Tritanopia colorblindness from LMS color-space.
:param degree: Tritanopia degree.
"""
return np.array([[1, 0, 0],
[0, 1, 0],
[-0.395913 * degree, 0.801109 * degree, 1 - degree]]).T

@staticmethod
def hybrid_protanomaly_deuteranomaly_sim(degree_p: float = 1.0, degree_d: float = 1.0) -> np.ndarray:
"""
Matrix for Simulating Hybrid Colorblindness (protanomaly + deuteranomaly) from LMS color-space.
:param degree_p: protanomaly degree.
:param degree_d: deuteranomaly degree.
"""
return np.array([[1 - degree_p, 2.02344 * degree_p, -2.52581 * degree_p],
[0.494207 * degree_d, 1 - degree_d, 1.24827 * degree_d],
[0, 0, 1]]).T


def simulate_colorblind(
image_rgb: np.ndarray,
sim_type='protan',
degree: float | tuple = 1.0
) -> np.ndarray:
img_lms = np.dot(image_rgb[:, :, :3], Transforms.rgb_to_lms())

if sim_type == 'protan':
transform = Transforms.lms_protanopia_sim(degree)
elif sim_type == 'deutan':
transform = Transforms.lms_deutranopia_sim(degree)
elif sim_type == 'tritan':
transform = Transforms.lms_tritanopia_sim(degree)
else:
transform = Transforms.hybrid_protanomaly_deuteranomaly_sim(degree, degree)

img_lms_sim = np.dot(img_lms, transform)
img_rgb_sim = np.uint8(np.dot(img_lms_sim, Transforms.lms_to_rgb()) * 255)

return img_rgb_sim


# sphinx_gallery_end_ignore

embryo = ma.load_data('mouse_embryo')
Expand Down Expand Up @@ -83,7 +174,8 @@ def get_xy_hist(ct):

# Draw cell
ax = b.get_main_ax()
ax.scatter(embryo['cell_x'], embryo['cell_y'], s=1, c=embryo['colors'])
points = ax.scatter(embryo['cell_x'], embryo['cell_y'], s=1, c=embryo['colors'])
points.set_rasterized(True)
ax.set_xlim(xstart, xend)
ax.set_ylim(ystart, yend)
ax.set_title("Mouse Embryo E12.5")
Expand All @@ -106,12 +198,15 @@ def get_xy_hist(ct):
y_ax.set_axis_off()
y_ax.text(0.5, 0, n, va="top", ha="center", rotation=90, transform=y_ax.transAxes)


#%%
# sphinx_gallery_start_ignore
if '__file__' in globals():
from pathlib import Path
import matplotlib.pyplot as plt

plt.rcParams['svg.fonttype'] = 'none'
save_path = Path(__file__).parent / "imgs"
plt.savefig(save_path / "mouse_embryo.svg", bbox_inches="tight")
plt.savefig(save_path / "mouse_embryo.png", dpi=300, bbox_inches="tight")
# sphinx_gallery_end_ignore

1 change: 1 addition & 0 deletions examples/plot_oil_well.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
from pathlib import Path
import matplotlib.pyplot as plt

plt.rcParams['svg.fonttype'] = 'none'
save_path = Path(__file__).parent / "imgs"
plt.savefig(save_path / "oil_well.svg", bbox_inches="tight")
# sphinx_gallery_end_ignore
1 change: 1 addition & 0 deletions examples/plot_oncoprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
if '__file__' in globals():
from pathlib import Path
import matplotlib.pyplot as plt
plt.rcParams['svg.fonttype'] = 'none'
save_path = Path(__file__).parent / "imgs"
plt.savefig(save_path / "oncoprint.svg", bbox_inches="tight")
# sphinx_gallery_end_ignore
Binary file added img/publication/web-app-screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/publication/web-app-screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9bfcfb6

Please sign in to comment.