Skip to content

Commit

Permalink
remove pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
febielin committed Aug 19, 2023
1 parent 65845fe commit 3fd50c1
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions ersilia/publish/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import shutil
import time
import re
import pandas as pd
from ..cli import echo

from fuzzywuzzy import fuzz
Expand Down Expand Up @@ -439,6 +438,16 @@ def _compare_tolerance(self, value1, value2, tolerance_percentage):
def _compare_string_similarity(self, str1, str2, similarity_threshold):
similarity = fuzz.ratio(str1, str2)
return similarity >= similarity_threshold

def read_csv(self, file_path):
data = []
with open(file_path, 'r') as file:
lines = file.readlines()
header = lines[0].strip().split(',')
for line in lines[1:]:
values = line.strip().split(',')
data.append(dict(zip(header, values)))
return data

@throw_ersilia_exception
def run_bash(self):
Expand Down Expand Up @@ -525,20 +534,31 @@ def run_bash(self):
result = mdl.run(input=ex_file, output=output_file, batch_size=100)
print("Ersilia run completed!\n")

ersilia_run = pd.read_csv(output_file)
ersilia_run = self.read_csv(output_file)
remove_cols = ['key', 'input']
ersilia_run = ersilia_run.drop(columns=remove_cols)
bash_run = pd.read_csv(arg1)
for row in ersilia_run:
for col in remove_cols:
if col in row:
del row[col]
bash_run = self.read_csv(arg1)
print("Bash output:\n", bash_run)
print("\nErsilia output:\n", ersilia_run)

# Select common columns for comparison
common_columns = ersilia_run.columns.intersection(bash_run.columns)
ersilia_columns = set()
for row in ersilia_run:
ersilia_columns.update(row.keys())

bash_columns = set()
for row in bash_run:
bash_columns.update(row.keys())

common_columns = ersilia_columns & bash_columns

# Compare values in the common columns within a 5% tolerance`
for column in common_columns:
if isinstance(ersilia_run[column][1], (float, int)) and isinstance(ersilia_run[column][1], (float, int)):
if not all(self._compare_tolerance(a, b, 5) for a, b in zip(ersilia_run[column], bash_run[column])):
if not all(self._compare_tolerance(a, b, DIFFERENCE_THRESHOLD) for a, b in zip(ersilia_run[column], bash_run[column])):
click.echo(BOLD + "\nBash run and Ersilia run produce inconsistent results." + RESET)
print("Error in the following column: ", column)
print(ersilia_run[column])
Expand Down

0 comments on commit 3fd50c1

Please sign in to comment.