Skip to content

Commit

Permalink
HotFix for factor analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
jvivian committed Jun 10, 2024
1 parent 386cd72 commit a11f39e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 12 additions & 2 deletions covid19_drdfm/streamlit/pages/0_Dynamic_Factor_Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def additional_params():
if not out_dir:
st.warning("Specify output directory (in sidebar) to continue")
st.stop()
return global_multiplier, out_dir
return global_multiplier, Path(out_dir)


def run_model(ad, out_dir, batch, global_multiplier) -> ModelRunner:
Expand All @@ -175,4 +175,14 @@ def run_model(ad, out_dir, batch, global_multiplier) -> ModelRunner:
batch = None if ad.obs.empty else ad.obs.columns[0]
dfm = run_model(ad, out_dir, batch, global_multiplier)
st.balloons()
st.stop()

filt_paths = [subdir / "factors.csv" for subdir in out_dir.iterdir() if (subdir / "factors.csv").exists()]
dfs = [pd.read_csv(x) for x in filt_paths]
try:
filt_df = pd.concat([x for x in dfs if ~x.empty]).set_index("Time")
filt_df.to_csv(out_dir / "factors.csv")
st.dataframe(filt_df)
dfm.ad.write(out_dir / "data.h5ad")
st.balloons()
except ValueError:
st.error(f"No runs succeeded!! Check failures.txt in {out_dir}")
8 changes: 5 additions & 3 deletions covid19_drdfm/streamlit/pages/1_Factor_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def normalize(df):
center_title("Factor Analysis")

# Read in data
raw = get_df()
# raw = get_df()
# TEST_DIR = Path('covid19_drdfm/data/example-output/')

# Parameter for results
Expand Down Expand Up @@ -72,8 +72,10 @@ def normalize(df):


# Normalize original data for state / valid variables
new = normalize(raw[raw.State == state][cols])
# st.dataframe(new)
ad = ann.read_h5ad(res_dir / "data.h5ad")
new = ad.to_df().reset_index()
new["State"] = ad.obs["State"].to_list()


# Normalize factors and add to new dataframe
if st.sidebar.checkbox("Invert Factor"):
Expand Down

0 comments on commit a11f39e

Please sign in to comment.