Skip to content
Snippets Groups Projects
Commit 3602a940 authored by Bartosz Bartmanski's avatar Bartosz Bartmanski
Browse files

Added a bit more information in the output tables of InsertsDict class and streamlit app.

parent ee445b70
No related branches found
Tags 0.3.4
No related merge requests found
......@@ -321,6 +321,7 @@ class InsertsDict(object):
x.strand,
len(x),
x.coverage,
x.matched,
)
for x in self.get(
insert_type=insert_type, filter_threshold=filter_threshold
......@@ -328,13 +329,14 @@ class InsertsDict(object):
],
columns=(
"seq_id",
"NCBI_accession_number",
"hit_id",
"insert_idx",
"insert_start",
"insert_end",
"insert_strand",
"insert_length",
"insert_coverage",
"insert_matched",
),
)
......
......@@ -14,9 +14,6 @@ import plotting_on_genome as pog
if "stage" not in st.session_state:
st.session_state.stage = 0
if "insert_type" not in st.session_state:
st.session_state.insert_type = "both"
if "workdir" not in st.session_state:
st.session_state.workdir = None
......@@ -112,10 +109,6 @@ def get_main_inputs():
fwd_suf = st.text_input("Forward suffix:", "_F", key="fwd_suf")
rev_suf = st.text_input("Reverse suffix:", "_R", key="rev_suf")
st.session_state.insert_type = st.selectbox(
"insert types:", ["both", "matched", "unmatched"]
)
if args.workdir:
st.session_state.workdir = st.text_input("workdir", "Output")
......@@ -142,7 +135,7 @@ def convert_df(df, **kwargs):
def show_results():
inserts_all = st.session_state.pipeline
insert_type = st.session_state.insert_type
insert_type = st.selectbox("Insert type:", ["both", "matched", "unmatched"])
filter_threshold = st.slider("Filter threshold:", 0.0, 1.0, 0.7)
......@@ -155,32 +148,40 @@ def show_results():
)
params = dict(insert_type=insert_type, filter_threshold=filter_threshold)
df_inserts = inserts_all.to_dataframe(**params)
df_genes = inserts_all.genes_to_dataframe(**params, buffer=buffer)
if inserts_all is not None:
st.download_button(
label="Download all inserts as CSV",
data=df_inserts.pipe(convert_df, index=False),
file_name="inserts.csv",
mime="text/csv",
use_container_width=True,
)
df_inserts = inserts_all.to_dataframe(**params)
df_genes = inserts_all.genes_to_dataframe(**params, buffer=buffer)
st.download_button(
label="Download all genes as CSV",
data=df_genes.pipe(convert_df, index=False),
file_name="genes.csv",
mime="text/csv",
use_container_width=True,
)
counts = df_inserts.groupby("insert_matched").insert_matched.count().to_dict()
counts = {val: counts[val] if val in counts else 0 for val in (True, False)}
st.write(
f"Number of inserts:\n "
f"- matched: {counts[True]}\n "
f"- unmatched: {counts[False]}"
)
option = st.selectbox(
"plot type:",
["plot inserts", "plot genome", "plot insert dists"],
None,
)
st.download_button(
label="Download all inserts as CSV",
data=df_inserts.pipe(convert_df, index=False),
file_name="inserts.csv",
mime="text/csv",
use_container_width=True,
)
if inserts_all is not None:
st.download_button(
label="Download all genes as CSV",
data=df_genes.pipe(convert_df, index=False),
file_name="genes.csv",
mime="text/csv",
use_container_width=True,
)
option = st.selectbox(
"plot type:",
["plot inserts", "plot genome", "plot insert dists"],
None,
)
if option == "plot inserts":
......@@ -202,6 +203,11 @@ def show_results():
st.write(df_genes.query("seq_id == @seq_id"))
for insert in inserts:
st.write(
f"Insert {insert.idx}: "
f"coverage = {insert.coverage:.2f}, "
f"matched = {insert.matched}"
)
fig, axs = plt.subplots(2, 1, figsize=(10, 6), height_ratios=[3, 5])
fig.suptitle(f"Insert {insert.idx}")
axs = insert.plot(
......@@ -217,11 +223,11 @@ def show_results():
elif option == "plot genome":
st.write(df_inserts)
labels = st.toggle("Labels")
insert_idxs = None if st.toggle("Plot inserts", True) else []
st.write(df_inserts)
fig, ax = plt.subplots(figsize=(10, 10 * (1 + 2 * labels)))
ax = inserts_all.plot(insert_idxs, show_labels=labels, ax=ax, **params)
st.pyplot(fig, use_container_width=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment