Skip to content
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ Once installed, you can call the CLI.
Example using demo files:

```bash
ecoffitter --input demo_files/censored.txt --params demo_files/params.txt --outfile demo_files/output.txt
ecoff-fitter --input demo_files/input.txt --params demo_files/params.txt --outfile demo_files/output.txt
```

Instead of using a parameter file, you can also specify parameters directly.

Usage:

```bash
ecoff_fitter [-h] --input INPUT [--params PARAMS]
ecoff-fitter [-h] --input INPUT [--params PARAMS]
[--dilution_factor DILUTION_FACTOR]
[--distributions ] [--boundary_support boundary_support]
[--distributions DISTRIBUTIONS] [--boundary_support BOUNDARY_SUPPORT]
[--percentile PERCENTILE] [--outfile OUTFILE] [--verbose]
```

Expand Down
Binary file modified demo_files/output.pdf
Binary file not shown.
Binary file removed demo_files/~$demo_input.xlsx
Binary file not shown.
53 changes: 19 additions & 34 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,56 +160,41 @@ def run_ecoff(self):
individual_results[col] = (fitter, result)


text = "ECOFF RESULTS\n"
text += "=====================================\n\n"
text = "ECOFF RESULTS\n=====================================\n\n"

if len(individual_results.keys())>1:
text += "GLOBAL FIT\n"
text += "-------------------------------------\n"
text += f" ECOFF: {global_result[0]:.4f}\n"
text += f" z-value: {global_result[1]:.4f}\n"
for i in range(global_fitter.distributions):
if global_fitter.distributions > 1:
text += f" Component {i+1}:\n"
text += f" mu = {dilution_factor**global_fitter.mus_[i]:.4f}\n"
text += f" sigma (folds) = {dilution_factor**global_fitter.sigmas_[i]:.4f}\n"
text += "\n"

text += "INDIVIDUAL FITS:\n"
text += "-------------------------------------\n"
global_report = GenerateReport.from_fitter(global_fitter, global_result)
if len(individual_results) > 1:

text += global_report.to_text("GLOBAL FIT")
text += "\nINDIVIDUAL FITS:\n-------------------------------------\n"


# Individual fits
for name, (fitter, result) in individual_results.items():
rep = GenerateReport.from_fitter(fitter, result)
text += rep.to_text(label=name)

for col, (fitter, result) in individual_results.items():
text += f"{col}\n"
text += f" ECOFF: {result[0]:.4f}\n"
text += f" z-value: {result[1]:.4f}\n"
for i in range(fitter.distributions):
if fitter.distributions>1:
text += f" Component {i+1}:\n"
text += f" mu = {dilution_factor**fitter.mus_[i]:.4f}\n"
text += f" sigma (folds) = {dilution_factor**fitter.sigmas_[i]:.4f}\n"
text += "\n"

if outfile:
validate_output_path(outfile)
if len(individual_results.keys())==1:
validate_output_path(outfile)
report = GenerateReport.from_fitter(global_fitter, global_result)
if outfile.endswith(".pdf"):
report.save_pdf(outfile)
global_report.save_pdf(outfile)
else:
report.write_out(outfile)
text += f"\nSaved global report to: {outfile}"
global_report.write_out(outfile)
elif (len(individual_results.keys()))>1:
# Build section reports
global_report = GenerateReport.from_fitter(global_fitter, global_result)

indiv_reports = {
name: GenerateReport.from_fitter(fitter, result)
for name, (fitter, result) in individual_results.items()
}

# Build combined PDF
combined = CombinedReport(outfile, global_report, indiv_reports)
combined.save_pdf()
if outfile.endswith(".pdf"):
combined.save_pdf()
else:
combined.write_out()


for widget in self.plot_frame.winfo_children():
Expand Down
96 changes: 72 additions & 24 deletions src/ecoff_fitter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import argparse
from typing import Any, List, Optional
from ecoff_fitter import ECOFFitter
from ecoff_fitter.report import GenerateReport
from ecoff_fitter.report import GenerateReport, CombinedReport
from ecoff_fitter.defence import validate_output_path
from ecoff_fitter.utils import read_multi_obs_input
from unittest.mock import MagicMock, patch



def build_parser() -> argparse.ArgumentParser:
"""Create and configure the command-line argument parser."""
parser = argparse.ArgumentParser(
Expand All @@ -27,7 +29,7 @@ def build_parser() -> argparse.ArgumentParser:
required=True,
help=(
"Path to the input MIC dataset (CSV, TSV, XLSX, or XLS) "
"with columns 'MIC' and 'observations'."
"with columns 'MIC' and assay name."
),
)
parser.add_argument(
Expand Down Expand Up @@ -80,28 +82,74 @@ def main(argv: Optional[List[str]] = None) -> None:
parser = build_parser()
args = parser.parse_args(argv)

fitter = ECOFFitter(
input=args.input,
params=args.params,
dilution_factor=args.dilution_factor,
distributions=args.distributions,
boundary_support=args.boundary_support,
)

result = fitter.generate(percentile=args.percentile)

report = GenerateReport.from_fitter(fitter, result)

report.print_stats(args.verbose)

if args.outfile:

validate_output_path(args.outfile)

if args.outfile.endswith(".pdf"):
report.save_pdf(args.outfile)
else:
report.write_out(args.outfile)
try:

data_dict = read_multi_obs_input(args.input)
df_global = data_dict['global']
df_individual = data_dict['individual']

global_fitter = ECOFFitter(
input=df_global,
params=args.params,
distributions=args.distributions,
boundary_support=args.boundary_support,
dilution_factor=args.dilution_factor
)

global_result = global_fitter.generate(percentile=args.percentile)

individual_results = {}
for col, subdf in df_individual.items():

fitter = ECOFFitter(
input=subdf,
params=args.params,
dilution_factor=args.dilution_factor,
distributions=args.distributions,
boundary_support=args.boundary_support,
)

result = fitter.generate(percentile=args.percentile)
individual_results[col] = (fitter, result)

text = "\n\nECOFF RESULTS\n=====================================\n\n"

global_report = GenerateReport.from_fitter(global_fitter, global_result)

if len(individual_results) > 1:
text += global_report.to_text("GLOBAL FIT")
text += "\nINDIVIDUAL FITS:\n-------------------------------------\n"

# Individual fits
for name, (fitter, result) in individual_results.items():
rep = GenerateReport.from_fitter(fitter, result)
text += rep.to_text(label=name)

if args.outfile:
validate_output_path(args.outfile)
if len(individual_results.keys())==1:

if args.outfile.endswith(".pdf"):
global_report.save_pdf(args.outfile)
else:
global_report.write_out(args.outfile)
elif (len(individual_results.keys()))>1:
# Build section reports
indiv_reports = {
name: GenerateReport.from_fitter(fitter, result)
for name, (fitter, result) in individual_results.items()
}
# Build combined PDF
combined = CombinedReport(args.outfile, global_report, indiv_reports)
if args.outfile.endswith(".pdf"):
combined.save_pdf()
else:
combined.write_out()

print (text)

except Exception as e:
print ('Error', str(e))


if __name__ == "__main__":
Expand Down
Loading
Loading