Skip to content

Commit

Permalink
Merge pull request #22 from cbib/help-menu-byhydra
Browse files Browse the repository at this point in the history
Help menu byhydra
  • Loading branch information
johaGL authored Jan 26, 2024
2 parents 20bda79 + a5e6d63 commit 595dff6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ requirements: test_environment

## Make Dataset
data: requirements
$(PYTHON_INTERPRETER) src/data/make_dataset.py data/raw data/processed
$(PYTHON_INTERPRETER) src/data/make_dataset.py data/

## Delete all compiled Python files
clean:
Expand Down
24 changes: 11 additions & 13 deletions src/dimet/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

import hydra

from dimet.method import Method
from omegaconf import DictConfig, OmegaConf

from dimet.data import Dataset
from dimet.method import Method

import click

logger = logging.getLogger(__name__)

Expand All @@ -34,18 +33,17 @@ def main_run_analysis(cfg: DictConfig) -> None:
method.run(cfg, dataset)


@click.command(context_settings=dict(
help_option_names=['-h', '--help']) # needed to recognize -h as well
def fully_empty_args_custom_message() -> None:
custom_message: str = (
"\nDIMet is a tool for the Differential analysis of "
"targeted Isotope-labeled Metabolomics data. \n\n Please type "
"'python -m dimet --help' or 'python -m dimet -h' for usage.\n"
)
@click.option('-cd', type=str, required=True,
help="Directory containing the general configuration "
"(see -cn)")
@click.option('-cn', type=str, required=True,
help="File name of the general configuration "
"(only one .yaml file name)")
def main_run_analysis__or_display_help(cd, cn) -> None:
main_run_analysis() # run: hydra handles further arguments validation
print(custom_message)


if __name__ == "__main__":
main_run_analysis__or_display_help()
if len(sys.argv) <= 1:
fully_empty_args_custom_message()
else:
main_run_analysis()
12 changes: 6 additions & 6 deletions src/dimet/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ hydra:
chdir: true
run:
dir: ../outputs/${now:%Y-%m-%d}/${now:%H-%M-%S}/${analysis.dataset.label}-${analysis.method.label}

# Notes:
# This config.yaml file is never used by the code, but remains here as template.
# All the method/*.yaml files YES THEY ARE USED by the code


# This config.yaml file is used by the code when calling --help

defaults:
- analysis: abundance_plot
- _self_
- override hydra/help: dimet_help


figure_path: figures
table_path: tables

# check https://hydra.cc/docs/patterns/specializing_config/ for more info about this
# check https://hydra.cc/docs/patterns/specializing_config/ for more info about this
38 changes: 38 additions & 0 deletions src/dimet/config/hydra/help/dimet_help.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# App name, override to match the name your app is known by
app_name: DIMet

# Help header, customize to describe your app to your users
header: Welcome to ${hydra.help.app_name}!

footer: |-
Powered by Hydra (https://hydra.cc)
Use --hydra-help to view Hydra specific help
template: |-
${hydra.help.header}
DIMet is a tool for the Differential analysis of targeted Isotope-labeled Metabolomics data
Usage: python -m dimet [options]
optional arguments:
-cd, --config-dir Directory name where the general configuration is located (see -cn)
-cn, --config-name File name of the general configuration, only one .yaml file name
-h, --help Show this help message and exit
== Available analyses ==
$APP_CONFIG_GROUPS
${hydra.help.footer}
# Basic Hydra flags:
# $FLAGS_HELP
#
# Config groups, choose one of:
# $APP_CONFIG_GROUPS: All config groups that does not start with hydra/.
# $HYDRA_CONFIG_GROUPS: All the Hydra config groups (starts with hydra/)
#
# Configuration generated with overrides:
# $CONFIG : Generated config
24 changes: 10 additions & 14 deletions src/dimet/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def build(self) -> "Dataset":

class Dataset(BaseModel):
config: DatasetConfig
raw_data_folder: str = None
sub_folder_absolute: str = None
metadata_df: Optional[pd.DataFrame] = None
abundances_df: Optional[pd.DataFrame] = None
Expand Down Expand Up @@ -75,22 +74,23 @@ def preload(self):
logger.info("looking for data in %s", self.sub_folder_absolute)
else:
self.sub_folder_absolute = self.config.subfolder
self.raw_data_folder = os.path.join(self.sub_folder_absolute, "raw")


# start loading the dataframes
file_paths = [
("metadata", os.path.join(self.raw_data_folder,
("metadata", os.path.join(self.sub_folder_absolute,
self.config.metadata + ".csv")),
("abundances", os.path.join(self.raw_data_folder,
("abundances", os.path.join(self.sub_folder_absolute,
self.config.abundances + ".csv")),
("mean_enrichment", os.path.join(
self.raw_data_folder,
self.sub_folder_absolute,
self.config.mean_enrichment + ".csv")),
("isotopologue_proportions", os.path.join(
self.raw_data_folder,
self.sub_folder_absolute,
self.config.isotopologue_proportions + ".csv")),
("isotopologues", os.path.join(
self.raw_data_folder, self.config.isotopologues + ".csv")),
self.sub_folder_absolute,
self.config.isotopologues + ".csv")),
]
dfs = []
for label, file_path in file_paths:
Expand Down Expand Up @@ -130,7 +130,7 @@ def preload(self):
# log the first 5 rows of the metadata
logger.info("Loaded metadata: \n%s", self.metadata_df.head())
logger.info(
"Finished loading raw dataset %s, available dataframes are : %s",
"Finished loading dataset %s, available dataframes are : %s",
self.config.label, self.available_datasets
)
self.check_expectations()
Expand Down Expand Up @@ -191,17 +191,13 @@ class DataIntegrationConfig(DatasetConfig):

class DataIntegration(Dataset):
config: DataIntegrationConfig
integration_files_folder_absolute: str = None # absolute path directory
deg_dfs: Dict[int, pd.DataFrame] = {}
pathways_dfs: Dict[str, pd.DataFrame] = {}

def set_dataset_integration_config(self):
self.preload()
self.split_datafiles_by_compartment()

self.integration_files_folder_absolute = os.path.join(
self.sub_folder_absolute, "integration_files")

self.check_expectations() # of the Dataset class
self.check_expectations_integration_data() # of this child class

Expand Down Expand Up @@ -231,7 +227,7 @@ def load_deg_dfs(self):
for i, file_name in enumerate(self.config.transcripts):
try:
path_deg_file = os.path.join(
self.integration_files_folder_absolute,
self.sub_folder_absolute,
f"{file_name}.csv")
deg_df = pd.read_csv(path_deg_file, sep='\t', header=0)
self.deg_dfs[i] = deg_df
Expand All @@ -247,7 +243,7 @@ def load_pathways_dfs(self):
for k in self.config.pathways.keys():
try:
path_file = os.path.join(
self.integration_files_folder_absolute,
self.sub_folder_absolute,
f"{self.config.pathways[k]}.csv")
pathway_df = pd.read_csv(path_file, sep='\t', header=0)
self.pathways_dfs[k] = pathway_df
Expand Down

0 comments on commit 595dff6

Please sign in to comment.