Skip to content

Commit

Permalink
clean up new util func, add new test, add to contributing guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalluri committed Mar 18, 2024
1 parent 01ad342 commit 129532c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ Use the `run_container` utility function to run the command in the container `<u
Implement the `parse_output` function.
The edges in the Local Neighborhood output have the same format as the input, `<vertex1>|<vertex2>`.
Convert these to be tab-separated vertex pairs followed by a tab and a `1` at the end of every line, which indicates all edges have the same rank.
See the `add_rank_column` function in `src.util.py`.
Make sure header = True when the file is created.
See the `add_rank_column` and `raw_pathway_df` function in `src.util.py`.
Make sure header = True with column names: ['Node1', 'Node2', 'Rank', 'Direction'] when the file is created
The output should have the format `<vertex1> <vertex2> 1 U`.

### Step 4: Make the Local Neighborhood wrapper accessible through SPRAS
Expand Down
4 changes: 2 additions & 2 deletions spras/omicsintegrator2.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def parse_output(raw_pathway_file, standardized_pathway_file):
df = pd.DataFrame(columns = ['Node1', 'Node2', 'Rank', 'Direction'])
else:
df = pd.read_csv(raw_pathway_file, sep='\t', header=0)
df = df[df['in_solution'] == True] # Check whether this column can be empty before revising this line
df = df[df['in_solution'] == True] # Check whether this column can be empty before revising this line
df = df.take([0, 1], axis=1)
df = add_rank_column(df)
df = reinsert_direction_col_undirected(df)
df.drop(columns=['cost', 'in_solution'], inplace = True)
df.columns = ['Node1', 'Node2', 'Rank', "Direction"]

df.to_csv(standardized_pathway_file, header=True, index=False, sep='\t')
Expand Down
7 changes: 4 additions & 3 deletions spras/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def add_rank_column(df: pd.DataFrame) -> pd.DataFrame:

def raw_pathway_df(raw_pathway_file: str, header:int= None) -> pd.DataFrame:
"""
creates df from contents in raw pathway file, otherwise returns an empty df
@param raw_pathway_file: the specific path to the raw_pathway_file to read from
@param header: what row the header is, otherwise None
Creates DF from contents in raw pathway file,
otherwise returns an empty DF with standard output column names
@param raw_pathway_file: path to raw_pathway_file
@param header: what row the header is in raw_pathway_file, otherwise None
"""
try:
Expand Down
1 change: 1 addition & 0 deletions test/parse-outputs/expected/empty-pathway-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Node1 Node2 Rank Direction
Empty file.
10 changes: 10 additions & 0 deletions test/parse-outputs/test_parse_outputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import filecmp
from pathlib import Path

import pandas as pd
import pytest

from spras import runner

INDIR = "test/parse-outputs/input/"
Expand Down Expand Up @@ -29,3 +32,10 @@ def test_parse_outputs(self):

runner.parse_output(algo, test_file, out_file)
assert filecmp.cmp(OUTDIR + f"{algo}-pathway.txt", EXPDIR + f"{algo}-pathway-expected.txt", shallow=False)

def test_empty_file(self):
for algo in algorithms:
test_file = INDIR + f"empty-raw-pathway.txt"
out_file = OUTDIR + f"{algo}-empty-pathway.txt"
runner.parse_output(algo, test_file, out_file)
assert filecmp.cmp(OUTDIR + f"{algo}-empty-pathway.txt", EXPDIR + f"empty-pathway-expected.txt", shallow=False)

0 comments on commit 129532c

Please sign in to comment.