Skip to content

Commit

Permalink
update code based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalluri committed Sep 4, 2024
1 parent d5c5865 commit ce47c28
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 4 additions & 4 deletions spras/analysis/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def summarize_networks(file_paths: Iterable[Union[str, PathLike]]) -> pd.DataFra

return concated_df

def df_error(dataframe: pd.DataFrame):
def validate_df(dataframe: pd.DataFrame):
"""
Raises an error if the dataframe is empty or contains one pathway (one row)
"""
Expand Down Expand Up @@ -123,7 +123,7 @@ def pca(dataframe: pd.DataFrame, output_png: str, output_var: str, output_coord:
@param components: the number of principal components to calculate (Default is 2)
@param labels: determines if labels will be included in the scatterplot (Default is True)
"""
df_error(dataframe)
validate_df(dataframe)
df = dataframe.reset_index(drop=True)
columns = dataframe.columns
column_names = [element.split('-')[-3] for element in columns] # assume algorithm names do not contain '-'
Expand Down Expand Up @@ -225,7 +225,7 @@ def hac_vertical(dataframe: pd.DataFrame, output_png: str, output_file: str, lin
@param linkage: methods for calculating the distance between clusters
@param metric: used for distance computation between instances of clusters
"""
df_error(dataframe)
validate_df(dataframe)
if linkage not in linkage_methods:
raise ValueError(f"linkage={linkage} must be one of {linkage_methods}")
if metric not in distance_metrics:
Expand Down Expand Up @@ -284,7 +284,7 @@ def hac_horizontal(dataframe: pd.DataFrame, output_png: str, output_file: str, l
@param linkage: methods for calculating the distance between clusters
@param metric: used for distance computation between instances of clusters
"""
df_error(dataframe)
validate_df(dataframe)
if linkage not in linkage_methods:
raise ValueError(f"linkage={linkage} must be one of {linkage_methods}")
if linkage == "ward":
Expand Down
1 change: 0 additions & 1 deletion test/ml/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def test_ensemble_network_empty(self):
ml.ensemble_network(dataframe, OUT_DIR + 'ensemble-network-empty.tsv')

en = pd.read_table(OUT_DIR + 'ensemble-network-empty.tsv')
en = en.round(5)
expected = pd.read_table(EXPECT_DIR + 'expected-ensemble-network-empty.tsv')
expected = expected.round(5)

Expand Down

0 comments on commit ce47c28

Please sign in to comment.