Skip to content

Commit 2be1994

Browse files
authored
Merge pull request #35 from Multiomics-Analytics-Group/st-autorun
St autorun argument and updated README
2 parents c582ae2 + 5beede2 commit 2be1994

File tree

10 files changed

+88
-68
lines changed

10 files changed

+88
-68
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ pip install -e path/to/vuegen # specify location
4444
pip install -e . # in case you pwd is in the vuegen directory
4545
```
4646

47-
### Quatro installation
47+
### Quarto installation
4848

49-
Install quatro with vueguen if you don't have it globally installed.
49+
Install quarto with vueguen if you don't have it globally installed.
5050

5151
```bash
5252
pip install -e ".[quarto]" # specify location
@@ -65,12 +65,20 @@ Test your quarto installation by running the following command:
6565
quarto check
6666
```
6767

68-
6968
## Execution
7069

70+
Run VueGen using a configuration file with the following command:
71+
72+
```bash
73+
python vuegen/main.py --config docs/example_data/MicW2Graph/report_config_micw2graph.yaml --report_type streamlit
74+
```
75+
76+
By default, the `streamlit_autorun` argument is set to False, but you can use it in case you want to automatically run the streamlit app.
77+
78+
It's also possible to provide a directory instead of a configuration file:
79+
7180
```bash
72-
cd docs
73-
python vuegen/main.py --config example_data/MicW2Graph/report_config_micw2graph.yaml --report_type streamlit
81+
python vuegen/main.py --directory docs/example_data/MicW2Graph/ --report_type streamlit
7482
```
7583

7684
The current report types are streamlit, html, pdf, docx, odt, revealjs, pptx, and jupyter.

docs/example_data/MicW2Graph/MicW2Graph_config.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,59 @@ sections:
1313
- component_type: plot
1414
plot_type: plotly
1515
title: Top Species Plot Biome Plotly
16-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/1_top_species_plot_biome_plotly.json
16+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/1_top_species_plot_biome_plotly.json
1717
description: ''
1818
- component_type: plot
1919
plot_type: altair
2020
title: Multilineplot Altair
21-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/2_multilineplot_altair.json
21+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/2_multilineplot_altair.json
2222
description: ''
2323
- component_type: dataframe
2424
file_format: csv
2525
delimiter: ','
2626
title: Abundance Data Allbiomes
27-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/3_abundance_data_allbiomes.csv
27+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/3_abundance_data_allbiomes.csv
2828
description: ''
2929
- component_type: dataframe
3030
file_format: xls
3131
title: Abundance Data Allbiomes
32-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/4_abundance_data_allbiomes.xls
32+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/1_Abundance_data/4_abundance_data_allbiomes.xls
3333
description: ''
3434
- title: Sample Data
3535
description: ''
3636
components:
3737
- component_type: plot
3838
plot_type: plotly
3939
title: Pie Plot Countries Plotly
40-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/1_pie_plot_countries_plotly.json
40+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/1_pie_plot_countries_plotly.json
4141
description: ''
4242
- component_type: plot
4343
plot_type: plotly
4444
title: Pie Plots Biomes Plotly
45-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/2_pie_plots_biomes_plotly.json
45+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/2_pie_plots_biomes_plotly.json
4646
description: ''
4747
- component_type: plot
4848
plot_type: static
4949
title: Number Samples Per Study
50-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/3_number_samples_per_study.png
50+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/3_number_samples_per_study.png
5151
description: ''
5252
- component_type: dataframe
5353
file_format: parquet
5454
title: Sample Info Allbiomes
55-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/4_sample_info_allbiomes.parquet
55+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/4_sample_info_allbiomes.parquet
5656
description: ''
5757
- component_type: dataframe
5858
file_format: txt
5959
delimiter: \t
6060
title: Sample Info Allbiomes
61-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/5_sample_info_allbiomes.txt
61+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/2_Sample_data/5_sample_info_allbiomes.txt
6262
description: ''
6363
- title: Extra Info
6464
description: ''
6565
components:
6666
- component_type: markdown
6767
title: Test Md
68-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/1_Exploratory_Data_Analysis/3_Extra_info/1_test_md.md
68+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/1_Exploratory_Data_Analysis/3_Extra_info/1_test_md.md
6969
description: ''
7070
- title: Microbial Association Networks
7171
description: ''
@@ -76,7 +76,7 @@ sections:
7676
- component_type: plot
7777
plot_type: interactive_network
7878
title: Man Example
79-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/2_Microbial_Association_Networks/1_Network_visualization1/1_man_example.graphml
79+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/2_Microbial_Association_Networks/1_Network_visualization1/1_man_example.graphml
8080
description: ''
8181
- title: Network Visualization2
8282
description: ''
@@ -85,21 +85,21 @@ sections:
8585
plot_type: interactive_network
8686
csv_network_format: edgelist
8787
title: Man Example Edgelist
88-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/2_Microbial_Association_Networks/2_Network_visualization2/1_man_example_edgelist.csv
88+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/2_Microbial_Association_Networks/2_Network_visualization2/1_man_example_edgelist.csv
8989
description: ''
9090
- title: Network Visualization3
9191
description: ''
9292
components:
9393
- component_type: plot
9494
plot_type: interactive_network
9595
title: Man Example
96-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/2_Microbial_Association_Networks/3_Network_visualization3/1_man_example.cyjs
96+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/2_Microbial_Association_Networks/3_Network_visualization3/1_man_example.cyjs
9797
description: ''
9898
- title: Network Visualization4
9999
description: ''
100100
components:
101101
- component_type: plot
102102
plot_type: interactive_network
103103
title: Ckg Network
104-
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/example_data/MicW2Graph/2_Microbial_Association_Networks/4_Network_visualization4/1_ckg_network.html
104+
file_path: /Users/asaru/Documents/DTU/MoNA/vuegen/docs/example_data/MicW2Graph/2_Microbial_Association_Networks/4_Network_visualization4/1_ckg_network.html
105105
description: ''

docs/images/vuegen_logo.png

-827 KB
Loading

docs/images/vuegen_logo.svg

Lines changed: 11 additions & 11 deletions
Loading

vuegen/config_manager.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ def _create_sect_config_fromdir(self, section_dir_path: Path) -> Dict[str, Union
211211

212212
return section_config
213213

214-
215214
def _resolve_base_dir(self, base_dir: str) -> Path:
216215
"""
217216
Resolves the provided base directory to an absolute path from the root, accounting for relative paths.
@@ -234,11 +233,10 @@ def _resolve_base_dir(self, base_dir: str) -> Path:
234233

235234
# Make sure the resolved base directory exists
236235
if not base_dir_path.is_dir():
237-
raise ValueError(f"Base directory '{base_dir}' does not exist or is not a directory.")
236+
raise ValueError(f"Base directory '{base_dir}' does not exist or is not a directory. {project_dir} {base_dir_path}")
238237

239238
return base_dir_path
240239

241-
242240
def create_yamlconfig_fromdir(self, base_dir: str) -> Tuple[Dict[str, Union[str, List[Dict]]], Path]:
243241
"""
244242
Generates a YAML-compatible config file from a directory. It also returns the resolved folder path.

vuegen/main.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
# Parse command-line arguments
88
args = get_args(prog_name="VueGen")
99

10-
# Determine the configuration file path or directory
10+
# Determine the vuegen arguments
1111
config_path = args.config
1212
dir_path = args.directory
13-
14-
# Report type
1513
report_type = args.report_type
14+
streamlit_autorun = args.streamlit_autorun
1615

1716
# Determine the report name for logger suffix
1817
if config_path:
@@ -21,14 +20,14 @@
2120
report_name = Path(dir_path).name
2221

2322
# Define logger suffix based on report type and name
24-
logger_suffix = f"{report_type}_report_{report_name}"
23+
logger_suffix = f"{report_type}_report_{str(report_name)}"
2524

2625
# Initialize logger
2726
logger = get_logger(f"{logger_suffix}")
2827

2928
# Generate the report
30-
report_generator.get_report(config_path = config_path,
29+
report_generator.get_report(report_type = report_type,
30+
logger = logger,
31+
config_path = config_path,
3132
dir_path = dir_path,
32-
report_type = report_type,
33-
logger = logger)
34-
33+
streamlit_autorun = streamlit_autorun)

vuegen/quarto_reportview.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import subprocess
33
from typing import List
4+
from pathlib import Path
45

56
import networkx as nx
67
import pandas as pd
@@ -498,18 +499,15 @@ def _generate_image_content(self, image_path: str, alt_text: str = "", width: in
498499
Returns
499500
-------
500501
str
501-
The formatted HTML image content.
502+
The formatted image content.
502503
"""
503504
if is_url(image_path):
504505
src = image_path
505506
else:
506-
src = os.path.abspath(image_path)
507+
src = Path(image_path).resolve()
507508

508-
# Return the HTML content
509-
return f"""
510-
<div style="text-align: center;">
511-
<img src="{src}" alt="{alt_text}" width="{width}" height="{height}" />
512-
</div>\n"""
509+
# Return the image content
510+
return f"""![](/{src}){{fig-alt={alt_text} width={width} height={height}}}\n"""
513511

514512
def _show_dataframe(self, dataframe, is_report_static, static_dir: str = STATIC_FILES_DIR) -> List[str]:
515513
"""

vuegen/report_generator.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .utils import assert_enum_value, load_yaml_config, write_yaml_config
88

99

10-
def get_report(report_type: str, logger: logging.Logger, config_path: str = None, dir_path: str = None) -> None:
10+
def get_report(report_type: str, logger: logging.Logger, config_path: str = None, dir_path: str = None, streamlit_autorun: bool = False) -> None:
1111
"""
1212
Generate and run a report based on the specified engine.
1313
@@ -21,6 +21,8 @@ def get_report(report_type: str, logger: logging.Logger, config_path: str = None
2121
Path to the YAML configuration file.
2222
dir_path : str, optional
2323
Path to the directory from which to generate the configuration file.
24+
streamlit_autorun : bool, optional
25+
Whether to automatically run the Streamlit report after generation (default is False).
2426
2527
Raises
2628
------
@@ -47,16 +49,17 @@ def get_report(report_type: str, logger: logging.Logger, config_path: str = None
4749
# Create and run ReportView object based on its type
4850
if report_type == ReportType.STREAMLIT:
4951
st_report = StreamlitReportView(
50-
report=report,
51-
report_type=report_type
52+
report = report,
53+
report_type = report_type,
54+
streamlit_autorun = streamlit_autorun
5255
)
5356
st_report.generate_report()
5457
st_report.run_report()
5558

5659
else:
5760
quarto_report = QuartoReportView(
58-
report=report,
59-
report_type=report_type
61+
report = report,
62+
report_type = report_type
6063
)
6164
quarto_report.generate_report()
6265
quarto_report.run_report()

vuegen/streamlit_reportview.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class StreamlitReportView(r.WebAppReportView):
1818
STATIC_FILES_DIR = os.path.join(BASE_DIR, 'static')
1919
REPORT_MANAG_SCRIPT = 'report_manager.py'
2020

21-
def __init__(self, report: r.Report, report_type: r.ReportType):
21+
def __init__(self, report: r.Report, report_type: r.ReportType, streamlit_autorun: bool = False):
2222
super().__init__(report = report, report_type = report_type)
23+
self.streamlit_autorun = streamlit_autorun
2324

2425
def generate_report(self, output_dir: str = SECTIONS_DIR, static_dir: str = STATIC_FILES_DIR) -> None:
2526
"""
@@ -113,14 +114,20 @@ def run_report(self, output_dir: str = SECTIONS_DIR) -> None:
113114
output_dir : str, optional
114115
The folder where the report was generated (default is SECTIONS_DIR).
115116
"""
116-
self.report.logger.info(f"Running '{self.report.title}' {self.report_type} report.")
117-
try:
118-
subprocess.run(["streamlit", "run", os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)], check=True)
119-
except KeyboardInterrupt:
120-
print("Streamlit process interrupted.")
121-
except subprocess.CalledProcessError as e:
122-
self.report.logger.error(f"Error running Streamlit report: {str(e)}")
123-
raise
117+
if self.streamlit_autorun:
118+
self.report.logger.info(f"Running '{self.report.title}' {self.report_type} report.")
119+
try:
120+
subprocess.run(["streamlit", "run", os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)], check=True)
121+
except KeyboardInterrupt:
122+
print("Streamlit process interrupted.")
123+
except subprocess.CalledProcessError as e:
124+
self.report.logger.error(f"Error running Streamlit report: {str(e)}")
125+
raise
126+
else:
127+
# If autorun is False, print instructions for manual execution
128+
self.report.logger.info(f"All the scripts to build the Streamlit app are available at {output_dir}")
129+
self.report.logger.info(f"To run the Streamlit app, use the following command:")
130+
self.report.logger.info(f"streamlit run {os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)}")
124131

125132
def _format_text(self, text: str, type: str, level: int = 1, color: str = '#000000', text_align: str = 'center') -> str:
126133
"""

vuegen/utils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,23 @@ def get_args(prog_name: str, others: dict = {}) -> argparse.Namespace:
185185
parser.add_argument(
186186
"-dir",
187187
"--directory",
188-
type=str,
189-
default=None,
190-
help="Path to the directory from which the YAML config will be inferred."
188+
type = str,
189+
default = None,
190+
help = "Path to the directory from which the YAML config will be inferred."
191191
)
192192
parser.add_argument(
193193
"-rt",
194194
"--report_type",
195-
type=str,
196-
default='streamlit', # this is not a valid default
197-
help="Type of the report to generate (streamlit, html, pdf, docx, odt, revealjs, pptx, or jupyter)."
195+
type = str,
196+
default = None,
197+
help = "Type of the report to generate (streamlit, html, pdf, docx, odt, revealjs, pptx, or jupyter)."
198+
)
199+
parser.add_argument(
200+
"-st_autorun",
201+
"--streamlit_autorun",
202+
action = "store_true", # Automatically sets True if the flag is passed
203+
default = False,
204+
help = "Automatically run the Streamlit app after report generation."
198205
)
199206

200207
# Parse arguments

0 commit comments

Comments
 (0)