Skip to content

Commit

Permalink
move mdutils methods to md writer
Browse files Browse the repository at this point in the history
  • Loading branch information
rugeli committed Jul 22, 2024
1 parent 47d9c6f commit bcab5b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
13 changes: 5 additions & 8 deletions cellpack/autopack/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
from cellpack.autopack.ldSequence import halton
from cellpack.autopack.plotly_result import PlotlyAnalysis
from cellpack.autopack.utils import check_paired_key, get_paired_key, get_seed_list
from cellpack.autopack.writers import Writer, MarkdownWriter
from cellpack.autopack.writers.ImageWriter import ImageWriter
from cellpack.autopack.writers import Writer, MarkdownWriter, ImageWriter


class Analysis:
Expand Down Expand Up @@ -294,20 +293,18 @@ def run_distance_analysis(
)

md_object.add_header(level=1, header="Distance analysis")
# TODO: add new method to add new line in markdown writer
md_object.report_md.new_line(
md_object.add_line(
f"Expected minimum distance: {expected_minimum_distance:.2f}"
)
md_object.report_md.new_line(
md_object.add_line(
f"Actual minimum distance: {packed_minimum_distance:.2f}\n"
)

if expected_minimum_distance > packed_minimum_distance:
# TODO: add new method to add new list in markdown writer, check `add_table_of_contents`
md_object.add_header(
level=2, header="Possible errors", add_table_of_contents="n"
)
md_object.report_md.new_list(
md_object.add_list(
[
f"Packed minimum distance {packed_minimum_distance:.2f}"
" is less than the "
Expand All @@ -325,7 +322,7 @@ def run_distance_analysis(
)
for img_path in ingr_distance_histo_path:
img_list.append(
md_object.report_md.new_inline_image(
md_object.add_inline_image(
text=f"Distance distribution {ingr_key}",
path=f"{output_image_location}/{img_path.name}",
)
Expand Down
15 changes: 12 additions & 3 deletions cellpack/autopack/writers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,6 @@ def add_table_from_csv(self, header, filepath, text_align="center"):
text_align=text_align,
)

def write_file(self):
self.report_md.create_md_file()

# Image text must be a list, if list is not same length as list of filepaths, only 1st item in image_text is used
def add_images(self, header, image_text, filepaths):
self.report_md.new_header(
Expand All @@ -524,3 +521,15 @@ def add_images(self, header, image_text, filepaths):
)
)
self.report_md.new_line()

def add_line(self, line):
self.report_md.new_line(line)

def add_list(self, list_items):
self.report_md.new_list(list_items)

def add_inline_image(self, text, filepath):
return self.report_md.new_inline_image(text=text, path=str(filepath))

def write_file(self):
self.report_md.create_md_file()

0 comments on commit bcab5b4

Please sign in to comment.