Skip to content

Commit

Permalink
ml changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalluri committed Mar 12, 2024
1 parent f9e989e commit 278b761
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions spras/analysis/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ def summarize_networks(file_paths: Iterable[Union[str, PathLike]]) -> pd.DataFra
with open(file, 'r') as f:
lines = f.readlines()

if len(lines) > 0:
lines.pop(0) # process header line

edges = []
for line in lines:
parts = line.split('\t')
if len(parts) == 4:
if len(parts) == 4: # empty lines not allowed but empty files are allowed
node1 = parts[0]
node2 = parts[1]
direction = str(parts[3]).strip()
Expand All @@ -56,8 +59,9 @@ def summarize_networks(file_paths: Iterable[Union[str, PathLike]]) -> pd.DataFra
edges.append(DIR_CONST.join([node1, node2]))
elif direction != 'Direction' and direction != 'U' and direction != 'D':
raise ValueError(f"direction is {direction}, rather than U or D")
elif len(parts) > 4 or (len(parts) < 4 and len(parts) > 0): # empty line in file is okay
raise ValueError(f"A line in pathway file {file} contains {len(parts)} values. There should be 4 values per line")
elif len(parts) != 0:
raise ValueError(f"In file {file}, expected line {line} to have 4 values, but found {len(parts)} values.")

# getting the algorithm name
p = PurePath(file)
edge_tuples.append((p.parts[-2], edges))
Expand Down

0 comments on commit 278b761

Please sign in to comment.