Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
long_description_content_type="text/markdown",
url="https://github.com/harveycas/project_spring_2020",
packages=setuptools.find_packages(),
install_requires = ['xlsxwriter'],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down
48 changes: 26 additions & 22 deletions tests/test_tetrad_analysis.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest
from tetrad_analysis import dataframe_functions
from tetrad_analysis import dataframe_functions as ddf
import pandas as pd
import numpy as np
from pathlib import Path
import os.path


SAMPLE_XLSX = Path(__file__)/ "data"/"python_test_list.xlsx"
SAMPLE_XLSX = Path(__file__).parent / "data"/"python_test_list.xlsx"
SAMPLE_DF_TAIL = pd.DataFrame(
data={
"Plate": [1,1,1],
Expand All @@ -18,13 +18,13 @@
"URA": [0,1,0],
}
)
COL = "URA"

def test_read_excel_file():

expected_tail = SAMPLE_DF_TAIL.set_index("Plate")

result = dataframe_functions.read_excel_file(SAMPLE_XLSX)
result = ddf.read_excel_file(SAMPLE_XLSX)

assert result.tail(3) == expected_tail

Expand All @@ -33,15 +33,15 @@ def test_sort_and_filter_by_col():

#For sorting input by col

expected_df = dataframe_functions.read_excel_file(SAMPLE_XLSX)
expected_df_sorted = dataframe_functions_in.sort_values([col], ascending = False)
expected_df = ddf.read_excel_file(SAMPLE_XLSX)
expected_df_sorted = expected_df.sort_values(["URA"], ascending = False)

#test for isolating positive values:

expected_pos_vals = expected_df_sorted[expected_df_sorted[col]>0]
expected_pos_vals = expected_df_sorted[expected_df_sorted[COL]>0]
expected_df_filtered = pd.DataFrame(expected_pos_vals)

result = dataframe_functions.sort_and_filter_by_col(expected_df,col)
result = ddf.sort_and_filter_by_col(expected_df,"URA")

assert result == expected_df_filtered

Expand All @@ -53,15 +53,15 @@ def test_sort_and_filter_by_col():

def test_combine_antibiotics():

expected_df = dataframe_functions.read_excel_file(SAMPLE_XLSX)

expected_df = ddf.read_excel_file(SAMPLE_XLSX)
markers = ['NAT','HYG','URA']
expected_all_positive = {}
for marker in markers:
expected_marker = dataframe_functions.sort_and_filter_by_col(marker)
expected_marker = ddf.sort_and_filter_by_col(expected_df,marker)
expected_all_positive[marker + '_plus'] = expected_marker
return expected_all_positive

result = dataframe_functions.test_combine_antibiotics(expected_df,markers)
result = ddf.test_combine_antibiotics(expected_df,markers)

assert result == expected_all_positive

Expand All @@ -70,13 +70,16 @@ def test_combine_antibiotics():


def test_write_marker_dict_to_disk():

file_out = "test.xlsx"
marker = "URA"
writer = pd.ExcelWriter(file_out, engine='xlsxwriter')
for sheet_name in markers.keys():
markers[sheet_name].to_excel(writer, sheet_name=sheet_name, index=False)

anti_bs = { "a": pd.DataFrame({ "Plate": [1,1,1], "Tetrad":[12,12,12],})}
for sheet_name in anti_bs.keys():
anti_bs[sheet_name].to_excel(writer, sheet_name=sheet_name, index=False)
expected_result = writer.save()

result = write_marker_dict_to_disk(marker,file_out)
result = ddf.write_marker_dict_to_disk(anti_bs,file_out)

assert result == expected_result

Expand All @@ -85,14 +88,15 @@ def test_write_marker_dict_to_disk():


def test_antibiotic_analysis():
file_out = "test.xlsx"
markers = ['NAT','HYG','URA']
expected_df = ddf.read_excel_file(SAMPLE_XLSX)

expected_df = dataframe_functions.read_excel_file(SAMPLE_XLSX)

expected_df_tetrad = read_excel_file(file_in)
expected_output_dict = combine_antibiotics(expected_df_tetrad, markers)
expected_result = writer_marker_dict_to_disk(expected_output_dict,file_out)
expected_df_tetrad = ddf.read_excel_file(SAMPLE_XLSX)
expected_output_dict = ddf.combine_antibiotics(expected_df_tetrad, markers)
expected_result = ddf.write_marker_dict_to_disk(expected_output_dict,file_out)

result = dataFrame_functions.test_antibiotic_analysis(file_in,file_out="Antibiotic_markers.xlsx",markers=['NAT','HYG','URA'])
result = ddf.antibiotic_analysis(SAMPLE_XLSX,file_out="Antibiotic_markers.xlsx",markers=markers)

assert result == expected_result

Expand Down
8 changes: 4 additions & 4 deletions tetrad_analysis/dataframe_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def combine_antibiotics(df_in,markers):
#create one dataframe containing all of the positive markers
all_positive = {}
for marker in markers:
df_marker = sort_and_filter_by_col(marker)
df_marker = sort_and_filter_by_col(df_in,marker)
all_positive[marker + '_plus'] = df_marker

return all_positive
Expand All @@ -58,7 +58,7 @@ def combine_antibiotics(df_in,markers):



def write_marker_dict_to_disk(marker,file_out):
def write_marker_dict_to_disk(marker_dict,file_out):
"""
Given a dict of dataframes, writes out an excel file in which each
dataframe occupies its own sheet
Expand All @@ -67,8 +67,8 @@ def write_marker_dict_to_disk(marker,file_out):
#turn the dataframes stored in a dict into an excel document
writer = pd.ExcelWriter(file_out, engine='xlsxwriter')

for sheet_name in markers.keys():
markers[sheet_name].to_excel(writer, sheet_name=sheet_name, index=False)
for sheet_name in marker_dict.keys():
marker_dict[sheet_name].to_excel(writer, sheet_name=sheet_name, index=False)

writer.save()

Expand Down