Skip to content

Commit

Permalink
fixed testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalluri committed Sep 12, 2023
1 parent 75be8b8 commit 550614a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 63 deletions.
24 changes: 1 addition & 23 deletions src/interactome.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Author: Neha Talluri
07/19/23
Methods for converting/creating the universal input and universal output
Methods for converting from the universal input and recreating the universal output
"""

import pandas as pd
Expand All @@ -26,10 +26,6 @@ def convert_undirected_to_directed(df: pd.DataFrame) -> pd.DataFrame:
new_df['Direction'] = 'D'
df.loc[mask, 'Direction'] = 'D'
df = pd.concat([df, new_df], ignore_index=True)

print("convert_undirected_to_directed")
print(df)

return df


Expand All @@ -47,9 +43,6 @@ def convert_directed_to_undirected(df: pd.DataFrame) -> pd.DateOffset:

df["Direction"] = "U"

print("convert_directed_to_undirected")
print(df)

return df


Expand All @@ -65,9 +58,6 @@ def add_constant(df: pd.DataFrame, new_col_name: str, const: str) -> pd.DataFram

df.insert(df.shape[1], new_col_name, const)

print("add_constant")
print(df)

return df


Expand All @@ -87,9 +77,6 @@ def add_directionality_constant(df: pd.DataFrame, col_name: str, dir_const: str
mask = df['Direction'] == 'U'
df.loc[mask, col_name] = undir_const

print("add_directionality_constant")
print(df)

return df

def readd_direction_col_mixed(df: pd.DataFrame, existing_direction_column: str, dir_const: str, undir_const: str) -> pd.DataFrame:
Expand All @@ -114,9 +101,6 @@ def readd_direction_col_mixed(df: pd.DataFrame, existing_direction_column: str,
# mask_dir = df[existing_direction_column] == dir_const
# df.loc[mask_dir, "Direction"] = "D"

print("readd_direction_col_mixed")
print(df)

return df

def readd_direction_col_undirected(df: pd.DataFrame) -> pd.DataFrame:
Expand All @@ -128,9 +112,6 @@ def readd_direction_col_undirected(df: pd.DataFrame) -> pd.DataFrame:
"""
df.insert(df.shape[1], "Direction", "U")

print("readd_direction_col_undirected")
print(df)

return df

def readd_direction_col_directed(df: pd.DataFrame) -> pd.DataFrame:
Expand All @@ -142,7 +123,4 @@ def readd_direction_col_directed(df: pd.DataFrame) -> pd.DataFrame:
"""
df.insert(df.shape[1], "Direction", "D")

print("readd_direction_col_directed")
print(df)

return df
12 changes: 6 additions & 6 deletions test/interactome/expected/add_const.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
A - B 0.5 U
B - C 0.5 D
C - B 0.5 D
A - D 0.5 U
C - D 0.5 D
D - C 0.5 D
A B 0.5 U -
B C 0.5 D -
C B 0.5 D -
A D 0.5 U -
C D 0.5 D -
D C 0.5 D -
12 changes: 6 additions & 6 deletions test/interactome/expected/add_directionality_const.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
A pp B 0.5 U
B pd C 0.5 D
C pd B 0.5 D
A pp D 0.5 U
C pd D 0.5 D
D pd C 0.5 D
A B 0.5 U pp
B C 0.5 D pd
C B 0.5 D pd
A D 0.5 U pp
C D 0.5 D pd
D C 0.5 D pd
6 changes: 3 additions & 3 deletions test/interactome/expected/convert_u_to_d.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
A B 0.5 D
B A 0.5 D
B C 0.5 D
C B 0.5 D
A D 0.5 D
D A 0.5 D
C D 0.5 D
D C 0.5 D
D C 0.5 D
B A 0.5 D
D A 0.5 D
68 changes: 43 additions & 25 deletions test/interactome/test_interactome.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,63 @@ def setup_class(cls):
"""
Path(OUT_DIR).mkdir(parents=True, exist_ok=True)

def undirected_to_directed(self):
df = pd.read_csv(IN_DIR+ 'test-network.csv', sep='\t')
def test_undirected_to_directed(self):
columns = ['Interactor1','Interactor2','Weight','Direction']
df = pd.read_csv(IN_DIR+ '/test-network.csv', sep='\t', header=None, names=columns)
df = convert_undirected_to_directed(df)
expected_df = pd.read_csv(EXPECTED_DIR+ 'convert_u_to_d.csv', sep='\t')
df.to_csv(OUT_DIR+"/output_u_to_d.csv", sep='\t', index=False, header=False)
expected_df = pd.read_csv(EXPECTED_DIR+ '/convert_u_to_d.csv', sep='\t', header=None, names=columns)
assert df.equals(expected_df)

def directed_to_undirected(self):
df = pd.read_csv(IN_DIR+ 'test-network.csv', sep='\t')
def test_directed_to_undirected(self):
columns = ['Interactor1','Interactor2','Weight','Direction']
df = pd.read_csv(IN_DIR+ '/test-network.csv', sep='\t', header=None, names=columns)
df = convert_directed_to_undirected(df)
expected_df = pd.read_csv(EXPECTED_DIR+'convert_d_to_u.csv', sep='\t')
df.to_csv(OUT_DIR+"/output_d_to_u.csv", sep='\t', index=False, header=False)
expected_df = pd.read_csv(EXPECTED_DIR+'/convert_d_to_u.csv', sep='\t', header=None, names=columns)
assert df.equals(expected_df)

def add_const(self):
df = pd.read_csv(IN_DIR+ 'test-network.csv', sep='\t')
df = add_constant(df, "const", "-")
expected_df = pd.read_csv(EXPECTED_DIR+"add_const.csv", sep='\t')
def test_add_const(self):
columns = ['Interactor1','Interactor2','Weight','Direction']
expected_columns = ['Interactor1','Interactor2','Weight','Direction', 'Const']
df = pd.read_csv(IN_DIR+ '/test-network.csv', sep='\t', header=None, names=columns)
df = add_constant(df, "Const", "-")
df.to_csv(OUT_DIR+"/output_add_const.csv", sep='\t', index=False, header=False)
expected_df = pd.read_csv(EXPECTED_DIR+"/add_const.csv", sep='\t', header=None, names=expected_columns)
assert df.equals(expected_df)

def add_directionality_const(self):
df = pd.read_csv(IN_DIR+ 'test-network.csv', sep='\t')
df = add_directionality_constant(df, "direct", "pd", "pp")
expected_df = pd.read_csv(EXPECTED_DIR+"add_directionality_const.csv", sep='\t')
def test_add_directionality_const(self):
columns = ['Interactor1','Interactor2','Weight','Direction']
expected_columns = ['Interactor1','Interactor2','Weight','Direction', 'Direct_Const']
df = pd.read_csv(IN_DIR+ '/test-network.csv', sep='\t', header=None, names=columns)
df = add_directionality_constant(df, "Direct_Const", "pd", "pp")
df.to_csv(OUT_DIR+"/output_add_directionality_const.csv", sep='\t', index=False, header=False)
expected_df = pd.read_csv(EXPECTED_DIR+"/add_directionality_const.csv", sep='\t', header=None, names=expected_columns)
assert df.equals(expected_df)

def readd_col_mixed(self):
df = pd.read_csv(IN_DIR+ "test-readd-network.csv", sep ='\t')
df.columns = ["Edge1", "InteractionType", "Edge2", "Weight"]
df = readd_direction_col_mixed(df, "InteractionType", "pd", "pp")
expected_df = pd.read_csv(EXPECTED_DIR+"readd_mixed.csv", sep = '\t')
def test_readd_col_mixed(self):
columns = ['Interactor1','Direct_Const','Interactor2','Weight']
expected_columns = ['Interactor1','Direct_Const','Interactor2','Weight', 'Direction']
df = pd.read_csv(IN_DIR+ '/test-readd-network.csv', sep='\t', header=None, names=columns)
df = readd_direction_col_mixed(df, "Direct_Const", "pd", "pp")
df.to_csv(OUT_DIR+"/output_readd_directiona_col_mixed.csv", sep='\t', index=False, header=False)
expected_df = pd.read_csv(EXPECTED_DIR+"/readd_mixed.csv", sep = '\t',header=None, names=expected_columns )
assert df.equals(expected_df)

def readd_col_undir(self):
df = pd.read_csv(IN_DIR+ "test-readd-network.csv", sep ='\t')
def test_readd_col_undir(self):
columns = ['Interactor1','Direct_Const','Interactor2','Weight']
expected_columns = ['Interactor1','Direct_Const','Interactor2','Weight', 'Direction']
df = pd.read_csv(IN_DIR+ '/test-readd-network.csv', sep='\t', header=None, names=columns)
df = readd_direction_col_undirected(df)
expected_df = pd.read_csv(EXPECTED_DIR+"readd_undir.csv", sep = '\t')
df.to_csv(OUT_DIR+"/output_readd_directiona_col_undir.csv", sep='\t', index=False, header=False)
expected_df = pd.read_csv(EXPECTED_DIR+"/readd_undir.csv", sep = '\t', header=None, names=expected_columns)
assert df.equals(expected_df)

def readd_col_dir(self):
df = pd.read_csv(IN_DIR+ "test-readd-network.csv", sep ='\t')
def test_readd_col_dir(self):
columns = ['Interactor1','Direct_Const','Interactor2','Weight']
expected_columns = ['Interactor1','Direct_Const','Interactor2','Weight', 'Direction']
df = pd.read_csv(IN_DIR+ '/test-readd-network.csv', sep='\t', header=None, names=columns)
df = readd_direction_col_directed(df)
expected_df = pd.read_csv(EXPECTED_DIR+"readd_dir.csv", sep = '\t')
df.to_csv(OUT_DIR+"/output_readd_directiona_col_dir.csv", sep='\t', index=False, header=False)
expected_df = pd.read_csv(EXPECTED_DIR+"/readd_dir.csv", sep = '\t', header=None, names=expected_columns)
assert df.equals(expected_df)

0 comments on commit 550614a

Please sign in to comment.