Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve factor analysis set collection now that data.h5ad isn't output #97

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading