Skip to content

Commit

Permalink
Merge pull request #97 from jvivian/jvivian/issue96
Browse files Browse the repository at this point in the history
Resolve factor analysis set collection now that `data.h5ad` isn't output
  • Loading branch information
jvivian authored Jul 22, 2024
2 parents 31a39c2 + 2371bcd commit c2807b3
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions dfmdash/streamlit/pages/1_Factor_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def normalize(df):
# raw = get_df()
# TEST_DIR = Path('dfmdash/data/example-output/')


# Parameter for results
def get_factors(res_dir):
factor_path = res_dir / "factors.csv"
Expand All @@ -47,6 +48,26 @@ def get_factors(res_dir):
return df


def parse_factor_blocks(file_path: Path) -> list[str]:
factor_blocks = []
start_collecting = False

with file_path.open("r") as file:
for line in file:
if "order" in line:
start_collecting = True
continue

if start_collecting:
if line.strip():
factor_name = line.split(",")[0].strip()
factor_blocks.append(factor_name)
else:
break

return factor_blocks


res_dir = Path(st.text_input("Path to results", value=EX_PATH))
if not res_dir:
st.warning("Please provide and hit <ENTER>")
Expand All @@ -67,11 +88,9 @@ def get_factors(res_dir):

# Normalize original data for state / valid variables
ad = ann.read_h5ad(res_dir / "data.h5ad")
factor_map = ad.var["factor"].to_frame()
factor_set = factor_map["factor"].unique().to_list() + [x for x in df.columns if "Global" in x]
factor_set = parse_factor_blocks(res_dir / state / "model.csv") + [x for x in df.columns if "Global" in x]
factor = st.sidebar.selectbox("Factor", factor_set)


# Normalize factors and add to new dataframe
if st.sidebar.checkbox("Invert Factor"):
df[factor] = df[factor] * -1
Expand Down

0 comments on commit c2807b3

Please sign in to comment.