kmer_analysis / app.py
Hack90's picture
Update app.py
8aba07b verified
from shiny import render
from shiny.express import input, ui
import plotly.express as px
import pandas as pd
import matplotlib.pyplot as plt
ui.page_opts(fillable=True)
ui.panel_title("Kmer Analysis")
with ui.layout_columns():
with ui.card():
ui.input_slider("kmer", "kmer", 0, 10, 5)
ui.input_slider("top_k", "top:", 0, 1000, 15)
ui.input_selectize(
"plot_type",
"Select Metric:",
["percentage", "count"],
multiple=False,
)
@render.plot
def plot():
df = pd.read_csv('kmers.csv')
k = input.kmer()
top_k = input.top_k()
fig = None
if input.plot_type() == "count":
df = df[df['k'] == k]
df = df.head(top_k)
fig, ax = plt.subplots()
ax.bar(df['kmer'], df['count'])
ax.set_title(f"Most common {k}-mers")
ax.set_xlabel("K-mer")
ax.set_ylabel("Count")
ax.set_xticklabels(df['kmer'], rotation=90)
if input.plot_type() == "percentage":
df = df[df['k'] == k]
df = df.head(top_k)
fig, ax = plt.subplots()
ax.bar(df['kmer'], df['percent']*100)
ax.set_title(f"Most common {k}-mers")
ax.set_xlabel("K-mer")
ax.set_ylabel("Percentage")
ax.set_xticklabels(df['kmer'], rotation=90)
return fig