Skip to content

Commit b70d3df

Browse files
committed
improved docs
1 parent 1e4fa64 commit b70d3df

File tree

6 files changed

+94
-48
lines changed

6 files changed

+94
-48
lines changed

docs/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ This module offers methods for calculating and analyzing biodiversity metrics fr
5252
:show-inheritance:
5353

5454
Galaxy integration
55-
==================
55+
===================
5656
This module enables integration with the Galaxy platform for workflow automation and reproducibility. We keep it minimalistic, because we expect to use direct install of Galaxy once demos are deployed in the final VRE.
5757

5858
.. automodule:: momics.galaxy
@@ -62,7 +62,7 @@ This module enables integration with the Galaxy platform for workflow automation
6262
Panel dashboard module
6363
========================
6464
This module provides some of the utilities for building interactive dashboards using the Panel library. These are Specific
65-
for FAIR-EASE use case and more methods and widgets can be found directly in the demo workflow notebooks [here](https://github.com/emo-bon/momics-demos).
65+
for FAIR-EASE use case and more methods and widgets can be found directly in the demo workflow notebooks `here <https://github.com/emo-bon/momics-demos>`_.
6666

6767
.. automodule:: momics.panel_utils
6868
:members:
@@ -85,7 +85,7 @@ This module provides tools for handling and analyzing taxonomic information in o
8585
:show-inheritance:
8686

8787
Utilities of all sorts
88-
==================
88+
=========================
8989
This module contains miscellaneous utility functions used throughout the momics package.
9090

9191
.. automodule:: momics.utils

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Marine omics methods
44

55
These package currently supports FAIR-EASE `pilot demos <https://github.com/emo-bon/momics-demos>`_, but eventually it can serve for general purpose manipulation of metagenomic data, locally and in VREs.
66

7-
The idea is to provide testable methods to allow as much flexibility and remixing of the functionalities provided
7+
The idea is to provide testable methods to allow as much flexibility and remixing of the functionalities provided.
88

9-
European Marine Omics Biodiversity Observation Network
9+
EMO-BON
1010
===========================================================
1111

12-
Specifically, we aim primarily to manipulate EMO-BON marine genomics sampling data and metadata from ENA project `PRJEB51688 <https://www.ebi.ac.uk/ena/browser/view/PRJEB51688>`_. The interactive dashboards and jupyter notebooks built on top of this repository can be found `here <https://github.com/emo-bon/momics-demos/tree/main>`_.
12+
Specifically, we aim primarily to manipulate European Marine Omics Biodiversity Observation Network (EMO-BON) sampling data and metadata from ENA project `PRJEB51688 <https://www.ebi.ac.uk/ena/browser/view/PRJEB51688>`_. The interactive dashboards and jupyter notebooks built on top of this repository can be found `here <https://github.com/emo-bon/momics-demos/tree/main>`_.
1313

1414
The methods are mixture of statistical methods, plotting functionalities, metadata and data handling utilities and generators of `holoviz panel` widgets and panes. Experimental integration to `Galaxy` uses a wrapper around `bioblend <https://bioblend.readthedocs.io/en/latest/>`_.
1515

momics/diversity.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,16 @@ def beta_diversity_parametrized(
232232
# helper functions #
233233
####################
234234
def update_subset_indicator(indicator, df):
235-
"""Update the subset indicator with the number of unique `index`_ids."""
235+
"""
236+
Update the subset indicator with the number of unique `index` ids.
237+
"""
236238
indicator.value = df.index.nunique()
237239

238240

239241
def update_taxa_count_indicator(indicator, df):
240-
"""Update the taxa count indicator with the number of unique taxa."""
242+
"""
243+
Update the taxa count indicator with the number of unique taxa.
244+
"""
241245
indicator.value = df.index.nunique()
242246

243247

momics/galaxy/gecco.py

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@
66

77

88
class Gecco:
9+
"""
10+
A class to interact with the GECCO tool in the Galaxy platform for comparative genomics.
11+
12+
This class manages user authentication, history and dataset selection, file uploads,
13+
and submission of jobs to the GECCO tool via the Galaxy API.
14+
15+
Args:
16+
params (dict): Dictionary of Panel widgets and parameters required for interaction.
17+
"""
18+
919
def __init__(self, params):
20+
"""
21+
Initialize the Gecco class with user parameters and Galaxy connection.
22+
23+
Args:
24+
params (dict): Dictionary containing Panel widgets and configuration parameters.
25+
"""
1026
self.exp = RemGalaxy("GALAXY_EARTH_URL", "GALAXY_EARTH_KEY")
1127
self.logger = self.exp.logger
1228
self.gecco_tool_id = "gecco"
@@ -31,19 +47,28 @@ def __init__(self, params):
3147
self.debug = False
3248

3349
def handle_login(self, clicks):
50+
"""
51+
Handles user login and retrieves relevant data.
52+
53+
Args:
54+
clicks (int): Number of times the login button has been clicked.
55+
"""
3456
pn.state.notifications.info(f"User logged in: {self.exp.cfg.whoami()}")
3557
self.logger.info(f"You have clicked me {clicks} times")
3658
self.handle_get_histories(clicks)
37-
38-
# get the datasets right upon login
3959
self.handle_get_datasets(clicks)
4060

4161
def handle_get_histories(self, clicks):
62+
"""
63+
Retrieves the user's Galaxy histories and updates the selection widget.
64+
65+
Args:
66+
clicks (int): Number of times the login button has been clicked.
67+
"""
4268
self.exp.get_histories()
4369

4470
# clean histories dict for display, remove deleted histories and select fust relevant fields
4571
clean_histories = self.exp.clean_histories_for_display()
46-
4772
self.select_history.options = clean_histories
4873
self.select_history.value = clean_histories[0]
4974
self.logger.info(f"{len(clean_histories)} histories found.")
@@ -53,7 +78,12 @@ def handle_get_histories(self, clicks):
5378
self.handle_update_current_history_id(self.select_history.value)
5479

5580
def handle_get_datasets(self, clicks):
56-
# filtering seems too narrow or too broad, not sure what to do about it, but broad is better
81+
"""
82+
Retrieves available datasets from Galaxy and updates the selection widget.
83+
84+
Args:
85+
clicks (int): Number of times the login button has been clicked.
86+
"""
5787
datasets, *_ = self.exp.get_datasets_by_key(
5888
"extension", ["fasta", "gbk", "embl", "genbank", "gb"]
5989
)
@@ -74,30 +104,46 @@ def handle_get_datasets(self, clicks):
74104
self.logger.info(
75105
f"Datasets selector value[1]: {self.select_dataset.value[1]}"
76106
)
77-
# this is the id of the dataset
78107
self.handle_update_current_file_name(self.select_dataset.value)
79-
80108
self.logger.info(f"{len(datasets)} datasets found.")
81109

82110
def handle_update_current_file_name(self, value):
111+
"""
112+
Updates the current file name and ID based on the selected dataset.
113+
114+
Args:
115+
value (tuple): Tuple containing the file name and file ID.
116+
"""
83117
self.current_file_name.value = value[0]
84118
self.current_file_id.value = value[1]
85119

86120
def handle_update_current_history_name(self, value):
121+
"""
122+
Updates the current history name based on the selected history.
123+
124+
Args:
125+
value (dict): Dictionary containing history information.
126+
"""
87127
self.current_history_name.value = value["name"]
88128

89129
def handle_update_current_history_id(self, value):
90-
self.current_history_id.value = value["id"]
130+
"""
131+
Updates the current history ID based on the selected history.
91132
92-
def handle_update_current_file_name(self, value):
93-
self.current_file_name.value = value[0]
94-
self.current_file_id.value = value[1]
133+
Args:
134+
value (dict): Dictionary containing history information.
135+
"""
136+
self.current_history_id.value = value["id"]
95137

96138
def handle_create_history(self, clicks):
97-
# this supresses history creation upon startup
139+
"""
140+
Creates a new history in Galaxy if requested by the user.
141+
142+
Args:
143+
clicks (int): Number of times the create history button has been clicked.
144+
"""
98145
if clicks == 0:
99146
return
100-
101147
if self.history_name.value != "":
102148
self.exp.set_history(hname=self.history_name.value)
103149
else:
@@ -107,6 +153,12 @@ def handle_create_history(self, clicks):
107153
self.handle_get_histories(clicks)
108154

109155
def handle_upload_dataset(self, clicks):
156+
"""
157+
Uploads a dataset to Galaxy if the user chooses to upload from local source.
158+
159+
Args:
160+
clicks (int): Number of times the upload button has been clicked.
161+
"""
110162
if self.file_source_checkbox.value:
111163
pn.state.notifications.warning("You selected Galaxy source and not upload.")
112164
else:
@@ -123,7 +175,6 @@ def handle_upload_dataset(self, clicks):
123175
!= "ok"
124176
):
125177
time.sleep(1)
126-
127178
self.logger.info(f"Upload data: {upload_data}")
128179
uploaded_dataset_id = upload_data["outputs"][0]["id"]
129180
self.current_file_name.value = upload_data["outputs"][0]["name"]
@@ -132,15 +183,19 @@ def handle_upload_dataset(self, clicks):
132183
self.logger.info(f"Dataset {uploaded_dataset_id} uploaded.")
133184

134185
def handle_submit_gecco(self, clicks):
186+
"""
187+
Submits a job to the GECCO tool in Galaxy with the selected parameters.
188+
189+
Args:
190+
clicks (int): Number of times the submit button has been clicked.
191+
"""
135192
if clicks == 0:
136193
pn.state.notifications.warning("You need to log in first.")
137194
return
138-
139195
if self.current_file_id.value == "":
140196
pn.state.notifications.warning("No dataset selected.")
141197
self.logger.warning("No dataset selected.")
142198
return
143-
144199
if self.current_history_id.value == "":
145200
pn.state.notifications.warning("No history selected.")
146201
self.logger.warning("No history selected.")

momics/plotting.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
"""
2-
This module contains functions for plotting alpha and beta diversity results.
3-
4-
Functions:
5-
- hvplot_alpha_diversity: Creates a horizontal bar plot for alpha diversity using hvplot.
6-
- plot_pcoa_black: Plots a PCoA plot with optional coloring.
7-
- mpl_alpha_diversity: Plots the Shannon index grouped by a factor.
8-
- mpl_average_per_factor: Plots the average Shannon index grouped by a factor.
9-
- mpl_bgcs_violin: Creates a violin plot for BGC probabilities by type.
10-
- alpha_plot: Creates an alpha diversity plot.
11-
- av_alpha_plot: Creates an average alpha diversity plot.
12-
- beta_plot: Creates a beta diversity heatmap plot.
13-
- beta_plot_pc: Creates a beta diversity PCoA plot.
14-
- beta_plot_pc_granular: Creates a beta diversity PCoA plot for granular data.
15-
- mpl_plot_heatmap: Creates a heatmap plot for beta diversity.
16-
- fold_legend_labels_from_series: Folds a list of labels to a maximum length from a Series.
17-
- change_legend_labels: Changes the labels of a legend on a given matplotlib axis.
18-
- cut_xaxis_labels: Changes the x-tick labels by cutting them short.
19-
- get_sankey: Creates a Sankey diagram using Plotly.
20-
21-
Constants:
22-
- PLOT_FACE_COLOR: The face color for the plot.
23-
24-
TODO: returns should be plt.figure and not pn.pane.Matplotlib, as already
25-
implemented for beta_plot_pc() function.
2+
3+
Constants
4+
---------
5+
- PLOT_FACE_COLOR : str
6+
The face color for the plot.
7+
8+
TODO:
9+
- Returns should be plt.figure and not pn.pane.Matplotlib, as already implemented for beta_plot_pc() function.
2610
"""
2711

2812
import logging

momics/taxonomy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,20 @@ def pivot_taxonomic_data(df: pd.DataFrame) -> pd.DataFrame:
9090

9191
def normalize_abundance(
9292
df: pd.DataFrame, method: str = "tss_sqrt", rarefy_depth: int = None
93-
):
93+
) -> pd.DataFrame:
9494
"""
9595
Normalize the abundance DataFrame using specified method.
96+
9697
Args:
9798
df (pd.DataFrame): The input DataFrame containing taxonomic information.
9899
method (str): Normalization method. Options: 'tss', 'tss_sqrt', 'rarefy'.
99100
Defaults to 'tss_sqrt'.
100101
rarefy_depth (int, optional): Depth for rarefaction. If None, uses min sample sum.
101102
Defaults to None.
103+
102104
Returns:
103105
pd.DataFrame: A DataFrame with normalized abundance values.
106+
104107
Raises:
105108
IndexError: If the DataFrame does not have a multiindex with 'taxonomic_concat' and 'ncbi_tax_id'.
106109
TypeError: If the DataFrame does not contain numeric values for normalization.

0 commit comments

Comments
 (0)