forked from Reed-CompBio/spras
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made updates to code and attempted to add testing for interactome
- Loading branch information
Showing
16 changed files
with
260 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
""" | ||
Author: Neha Talluri | ||
07/19/23 | ||
Methods for converting/creating the universal input and universal output | ||
""" | ||
|
||
import pandas as pd | ||
|
||
def convert_undirected_to_directed(df: pd.DataFrame) -> pd.DataFrame: | ||
""" | ||
turns a graph into a fully directed graph | ||
- turns every unidirected edges into a bi-directed edge | ||
- with bi-directed edges, we are not loosing too much information because the relationship of the undirected egde is still preserved | ||
*A user must keep the Direction column when using this function | ||
@param df: input network df of edges, weights, and directionality | ||
@return a dataframe with no undirected edges in Direction column | ||
""" | ||
|
||
mask = df['Direction'] == 'U' | ||
new_df = df[mask].copy(deep=True) | ||
new_df['Interactor1'], new_df['Interactor2'] = new_df['Interactor2'], new_df['Interactor1'] | ||
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 | ||
|
||
|
||
def convert_directed_to_undirected(df: pd.DataFrame) -> pd.DateOffset: | ||
""" | ||
turns a graph into a fully undirected graph | ||
- turns all the directed edges directly into undirected edges | ||
- we will loose any sense of directionality and the graph won't be inherently accurate, but the basic relationship between the two connected nodes will still remain intact. | ||
@param df: input network df of edges, weights, and directionality | ||
@return a dataframe with no directed edges in Direction column | ||
""" | ||
|
||
df["Direction"] = "U" | ||
|
||
print("convert_directed_to_undirected") | ||
print(df) | ||
|
||
return df | ||
|
||
|
||
def add_constant(df: pd.DataFrame, col_name: str, const: str) -> pd.DataFrame: | ||
""" | ||
adds a seperator somewhere into the input dataframe | ||
@param df: input network df of edges, weights, and directionality | ||
@param col_name: the name of the new column | ||
@param sep: some type of seperator needed in the df | ||
@return a df with a new seperator added to every row | ||
""" | ||
|
||
df.insert(df.shape[1], col_name, const) | ||
|
||
print("add_constant") | ||
print(df) | ||
|
||
return df | ||
|
||
|
||
def add_directionality_constant(df: pd.DataFrame, col_name: str, dir_const: str, undir_const: str) -> pd.DataFrame: | ||
""" | ||
deals with adding in directionality seperators for mixed graphs that isn't in the universal input | ||
*user must keep the Direction column when using the function | ||
@param df: input network df of edges, weights, and directionality | ||
@param col_name: the name of the new column | ||
@param dir_sep: the directed edge sep | ||
@param undir_sep: the undirected edge sep | ||
@return a df converted to show directionality differently | ||
""" | ||
df.insert(df.shape[1], col_name, dir_const) | ||
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: | ||
""" | ||
readds a 'Direction' column that puts a 'U' or 'D' at the end of provided dataframe | ||
based on the dir/undir seperators in the existing direction column | ||
*user must keep the existing direction column when using the function | ||
@param df: input network df that contains directionality | ||
@param existing_direction_column: the name of the existing directionality column | ||
@param dir_sep: the directed edge sep | ||
@param undir_sep: the undirected edge sep | ||
@return a df with Direction column added back | ||
""" | ||
|
||
df.insert(df.shape[1], "Direction", "D") | ||
|
||
mask_undir = df[existing_direction_column] == undir_const | ||
df.loc[mask_undir, "Direction"] = "U" | ||
|
||
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: | ||
""" | ||
readds a 'Direction' column that puts a 'U' at the end of the provided dataframe | ||
@param df: input network df that contains directionality | ||
@return a df with Direction column added back | ||
""" | ||
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: | ||
""" | ||
readds a 'Direction' column that puts a 'D' at the end of the provided dataframe | ||
@param df: input network df that contains directionality | ||
@return a df with Direction column added back | ||
""" | ||
df.insert(df.shape[1], "Direction", "D") | ||
|
||
print("readd_direction_col_directed") | ||
print(df) | ||
|
||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.