Skip to content

Commit 7b54512

Browse files
Update project files (from AAanalysis)
1 parent 92afee0 commit 7b54512

File tree

6 files changed

+146
-87
lines changed

6 files changed

+146
-87
lines changed

docs/project_cheat_sheet.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,18 @@ Testing frameworks validate that your code works as intended.
106106
1. `pytest`: Run all tests.
107107
2. `pytest <file>`: Run specific tests.
108108
3. `pytest -k <test_name>`: Run specific test.
109-
4. `pytest --cov=<module>`: Generate coverage.
110-
5. `pytest --fixtures`: Show fixtures.
109+
4. `pytest --durations=0`: Show all tests sorted by duration.
110+
5. `pytest -x`: Stop after the first failure.
111+
6. `pytest --maxfail=<num>`: Stop after the specified number of failures.
112+
7. `pytest --lf`: Run only the tests that failed at the last run.
113+
8. `pytest --ff`: Run the last failures first, then all tests.
114+
9. `pytest --cov`: Generate coverage report for the entire codebase.
115+
10. `pytest --cov=<module>`: Generate coverage.
116+
11. `pytest --cov-report=<type>`: Specify the type of coverage report (e.g., html, xml, term).
117+
12. `pytest -v`: Increase verbosity of the output.
118+
13. `pytest -q`: Decrease verbosity of the output.
119+
14. `pytest --tb=short`: Display a shorter traceback format.
120+
15. `pytest --disable-warnings`: Disable warnings display during test run
111121

112122
### unittest
113123

docs/source/conf.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
# Create notebooks rst and table rst first
1414
from create_tables_doc import generate_table_rst
15-
from create_notebooks_docs import export_notebooks_to_rst
16-
processed_notebooks = export_notebooks_to_rst()
15+
from create_notebooks_docs import export_example_notebooks_to_rst, export_tutorial_notebooks_to_rst
16+
17+
export_tutorial_notebooks_to_rst()
18+
export_example_notebooks_to_rst()
1719
generate_table_rst()
1820

1921
# -- Path and Platform setup --------------------------------------------------

docs/source/create_notebooks_docs.py

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Procedure:
99
1. Ensure the Jupyter tutorials you want to include in the documentation are fully executed and saved with their outputs.
1010
2. Run this script to convert these tutorials into RST format. (automatically in conf.py)
11-
3. Include the generated RST files in the Sphinx documentation's toctree.
11+
3. Include the generated RST files in the Sphinx documentation's toctree (Notebooks from examples are excluded).
1212
1313
Before running this script, ensure the project is in 'editable' mode to maintain consistency across documentation:
1414
- If using `poetry`:
@@ -31,21 +31,30 @@
3131
SEP = os.sep
3232
FOLDER_PROJECT = str(Path(__file__).parent.parent.parent) + SEP
3333
FOLDER_SOURCE = os.path.dirname(os.path.abspath(__file__)) + SEP
34-
FOLDER_NOTEBOOKS = FOLDER_PROJECT + "tutorials" + SEP
34+
FOLDER_TUTORIALS = FOLDER_PROJECT + "tutorials" + SEP
3535
FOLDER_GENERATED_RST = FOLDER_SOURCE + "generated" + SEP # Saving .rst directly in 'generated'
36+
FOLDER_EXAMPLES = FOLDER_PROJECT + "examples" + SEP
37+
FOLDER_EXAMPLES_RST = FOLDER_GENERATED_RST + "examples" + SEP
38+
FOLDER_IMAGE = FOLDER_GENERATED_RST + "images" + SEP
39+
3640
LIST_EXCLUDE = []
3741

3842

3943
# Helper functions
4044
class CustomPreprocessor(Preprocessor):
45+
"""Class for notebook preprocessing"""
46+
def __init__(self, notebook_name='default', in_examples=False, **kwargs):
47+
super().__init__(**kwargs)
48+
self.notebook_name = notebook_name
49+
self.in_examples=in_examples
50+
4151
def preprocess(self, nb, resources):
42-
"""
43-
Rename image resources and update the notebook cells accordingly.
44-
"""
52+
"""Rename image resources and update the notebook cells accordingly."""
53+
# Extract the base name of the notebook file
4554
output_items = list(resources['outputs'].items())
4655
for idx, (output_name, output_content) in enumerate(output_items):
47-
# Formulate the new name
48-
new_name = f"NOTEBOOK_{idx + 1}_{output_name}"
56+
# Formulate the new name using the notebook name
57+
new_name = f"{self.notebook_name}_{idx + 1}_{output_name}"
4958
# Modify resources['outputs']
5059
resources['outputs'][new_name] = resources['outputs'].pop(output_name)
5160
# Update the notebook cell outputs
@@ -60,26 +69,50 @@ def preprocess(self, nb, resources):
6069
# Prevent overriding
6170
old_name = filename["image/png"]
6271
if old_name.split("output")[1] == new_name.split("output")[1]:
63-
filename['image/png'] = str(new_name)
72+
new_file_name = "examples" + SEP + str(new_name) if self.in_examples else str(new_name)
73+
filename['image/png'] = new_file_name
6474
break
6575
return nb, resources
6676

6777

6878
# Main function
69-
def export_notebooks_to_rst():
79+
def export_tutorial_notebooks_to_rst():
7080
"""Export Jupyter tutorials to RST without execution."""
71-
for filename in os.listdir(FOLDER_NOTEBOOKS):
81+
for filename in os.listdir(FOLDER_TUTORIALS):
7282
if filename.endswith('.ipynb') and filename not in LIST_EXCLUDE:
73-
full_path = os.path.join(FOLDER_NOTEBOOKS, filename)
83+
notebook_name = filename.replace('.ipynb', '')
84+
full_path = os.path.join(FOLDER_TUTORIALS, filename)
7485
# Load the notebook
7586
with open(full_path, 'r') as f:
7687
notebook = nbformat.read(f, as_version=4)
7788
# Convert to notebook to RST
78-
custom_preprocessor = CustomPreprocessor()
89+
custom_preprocessor = CustomPreprocessor(notebook_name=notebook_name)
7990
rst_exporter = nbconvert.RSTExporter(preprocessors=[custom_preprocessor])
8091
output, resources = rst_exporter.from_notebook_node(notebook)
8192
# Write the RST and any accompanying files (like images)
8293
writer = FilesWriter(build_directory=FOLDER_GENERATED_RST)
8394
writer.write(output, resources, notebook_name=filename.replace('.ipynb', ''))
8495

8596

97+
def export_example_notebooks_to_rst():
98+
"""Export Jupyter examples to RST without execution."""
99+
for root, dirs, files in os.walk(FOLDER_EXAMPLES):
100+
for filename in files:
101+
if filename.endswith('.ipynb') and filename not in LIST_EXCLUDE:
102+
notebook_name = filename.replace('.ipynb', '')
103+
full_path = os.path.join(root, filename)
104+
#print(f"Processing file: {full_path}") # Debug print
105+
try:
106+
# Load the notebook
107+
with open(full_path, 'r') as f:
108+
notebook = nbformat.read(f, as_version=4)
109+
# Convert to notebook to RST
110+
custom_preprocessor = CustomPreprocessor(notebook_name=notebook_name, in_examples=True)
111+
rst_exporter = nbconvert.RSTExporter(preprocessors=[custom_preprocessor])
112+
output, resources = rst_exporter.from_notebook_node(notebook)
113+
# Write the RST and any accompanying files (like images)
114+
writer = FilesWriter(build_directory=FOLDER_EXAMPLES_RST)
115+
writer.write(output, resources, notebook_name=notebook_name)
116+
except FileNotFoundError as e:
117+
print(f"Error processing file: {full_path}. Error: {e}")
118+

docs/source/create_tables_doc.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""This is a script to convert csv/excel files into RST files """
2+
13
import os
24
import pandas as pd
35
import re
@@ -23,16 +25,11 @@
2325
STR_REMOVE = "_XXX" # Check with tables_template.rst for consistency
2426
STR_ADD_TABLE = "ADD-TABLE"
2527

26-
EXCLUDE_FROM_REF_CHECK = ["t1_omics_fields",
27-
"t2_quantification_methods",
28-
"t4_omics_analysis_tools",
29-
"t5_omics_post_analysis_tools",
30-
"t6_enrichment_tools"]
31-
28+
EXCLUDE_FROM_REF_CHECK = ["t3a_aaontology_categories",
29+
"t3b_aaontology_subcategories"]
3230

3331
# Helper Functions
3432
def _f_xlsx(on=True, file=None, ending=".xlsx"):
35-
""""""
3633
if on:
3734
if ending not in file:
3835
return file.split(".")[0] + ending
@@ -52,7 +49,6 @@ def _check_references(table_name=None, table_refs=None, list_refs=None):
5249

5350

5451
def _check_tables(list_tables):
55-
""""""
5652
f = lambda x: _f_xlsx(on=False, file=x)
5753
if list_tables != LIST_TABLES:
5854
list_missing_map = [f(x) for x in list_tables if x not in list_tables]
@@ -78,11 +74,13 @@ def _convert_excel_to_rst(df):
7874
else:
7975
new_row.append(str(val))
8076
rst_output += " * - " + "\n - ".join(new_row) + "\n"
77+
rst_output += "\n" # Add a blank line after each table for better spacing.
8178
return rst_output
8279

8380

8481
# Main Functionality
8582
def generate_table_rst():
83+
"""Generate rst tables from csv and excel"""
8684
# Read the existing references
8785
with open(FILE_REF, 'r') as f:
8886
list_refs = f.read()

docs/source/index/badges.rst

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,63 @@
1-
.. Developer Notes:
2-
Comments explain how to set up each badge and its purpose. Please update badges in README.rst and vice versa
3-
4-
.. Group 1: Build and Test Status
5-
.. --------------------------------
6-
.. Build Status Badge
7-
.. To set up this badge, go to your GitHub Actions tab and find the relevant workflow.
8-
.. Click on "Create status badge" and copy the Markdown or RST code.
9-
.. image:: https://github.com/breimanntools/xomics/workflows/Build/badge.svg
10-
:target: https://github.com/breimanntools/xomics/actions
11-
:alt: Build Status
12-
13-
.. Python-check Badge
14-
.. This badge reflects the status of your Python code checks if set up in GitHub Actions.
15-
.. image:: https://github.com/breimanntools/xomics/workflows/Python-check/badge.svg
16-
:target: https://github.com/breimanntools/xomics/actions
17-
:alt: Python-check
18-
19-
.. Group 2: Package and Version Information
20-
.. ----------------------------------------
21-
.. PyPI - Status Badge
22-
.. This badge automatically reflects the package status on PyPI.
23-
.. image:: https://img.shields.io/pypi/status/xomics.svg
1+
..
2+
Developer Notes:
3+
Please make sure that badges in badges.rst (Read The Docs)
4+
and README.rst (GitHub) are the same.
5+
6+
7+
.. Group 1: Package badges
8+
.. |PyPI Status| image:: https://img.shields.io/pypi/status/xomicss.svg
249
:target: https://pypi.org/project/xomics/
2510
:alt: PyPI - Status
2611

27-
.. Supported Python Versions Badge
28-
.. This badge shows the Python versions your package supports.
29-
.. Update the badge URL to reflect the Python versions specified in your `pyproject.toml`.
30-
.. image:: https://img.shields.io/pypi/pyversions/xomics.svg
12+
.. |PyPI Version| image:: https://img.shields.io/pypi/v/xomicss.svg
3113
:target: https://pypi.python.org/pypi/xomics
32-
:alt: Supported Python Versions
14+
:alt: PyPI - Package Version
3315

34-
.. PyPI - Package Version Badge
35-
.. This badge automatically shows the latest package version available on PyPI.
36-
.. image:: https://img.shields.io/pypi/v/xomics.svg
16+
.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/xomicss.svg
3717
:target: https://pypi.python.org/pypi/xomics
38-
:alt: PyPI - Package Version
18+
:alt: Supported Python Versions
3919

40-
.. Conda - Package Version Badge
41-
.. This badge shows the latest package version available on conda-forge.
42-
.. image:: https://anaconda.org/conda-forge/xomics/badges/version.svg
43-
:target: https://anaconda.org/conda-forge/xomics
44-
:alt: Conda - Package Version
20+
.. |Downloads| image:: https://pepy.tech/badge/xomicss
21+
:target: https://pepy.tech/project/xomicss
22+
:alt: Downloads
23+
24+
.. |License| image:: https://img.shields.io/github/license/breimanntools/xomicss.svg
25+
:target: https://github.com/breimanntools/xomicss/blob/master/LICENSE
26+
:alt: License
4527

46-
.. Group 3: Documentation and Code Quality
47-
.. ---------------------------------------
48-
.. Documentation Status Badge
49-
.. This badge reflects the build status of your latest documentation on ReadTheDocs.
50-
.. image:: https://readthedocs.org/projects/xomics/badge/?version=latest
51-
:target: https://xomics.readthedocs.io/en/latest/?badge=latest
28+
.. Group 2: Testing badges
29+
.. |Unit Tests| image:: https://github.com/breimanntools/xomicss/actions/workflows/main.yml/badge.svg
30+
:target: https://github.com/breimanntools/xomicss/actions/workflows/main.yml
31+
:alt: CI/CD Pipeline
32+
33+
.. |CodeQL| image:: https://github.com/breimanntools/xomicss/actions/workflows/codeql_analysis.yml/badge.svg
34+
:target: https://github.com/breimanntools/xomicss/actions/workflows/codeql_analysis.yml
35+
:alt: CodeQL
36+
37+
.. |Codecov| image:: https://codecov.io/gh/breimanntools/xomicss/branch/master/graph/badge.svg
38+
:target: https://codecov.io/gh/breimanntools/xomicss
39+
:alt: Codecov
40+
41+
.. |Documentation Status| image:: https://readthedocs.org/projects/xomicss/badge/?version=latest
42+
:target: https://xomicss.readthedocs.io/en/latest/?badge=latest
5243
:alt: Documentation Status
5344

54-
.. Group 4: License and Downloads
55-
.. ------------------------------
56-
.. License Badge
57-
.. This badge shows the license type of your project.
58-
.. image:: https://img.shields.io/github/license/breimanntools/xomics.svg
59-
:target: https://github.com/breimanntools/xomics/blob/master/LICENSE
60-
:alt: License
6145

62-
.. Downloads Badge
63-
.. This badge shows the number of downloads from PyPI.
64-
.. image:: https://pepy.tech/badge/xomics
65-
:target: https://pepy.tech/project/xomics
66-
:alt: Downloads
46+
.. Group 3: Potential badges for future
47+
.. |Conda Version| image:: https://anaconda.org/conda-forge/xomicss/badges/version.svg
48+
:target: https://anaconda.org/conda-forge/xomicss
49+
:alt: Conda - Package Version
50+
51+
52+
..
53+
Missing badges
54+
|Conda Version|
55+
56+
.. list-table::
57+
:widths: 20 80
58+
:header-rows: 1
59+
60+
* - **Package**
61+
- |PyPI Status| |PyPI Version| |Supported Python Versions| |Downloads| |License|
62+
* - **Testing**
63+
- |Unit Tests| |CodeQL| |Codecov| |Documentation Status|

pyproject.toml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
[build-system]
2-
requires = ["poetry-core"]
2+
requires = ["poetry-core>=1.0.0"]
33
build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "xomics"
77
version = "0.2.0"
88
description = "Python framework for eXplainable Omics analysis"
9-
authors = [
10-
"Stephan Breimann <stephanbreimann@gmail.de>",
11-
"Clarissa Rienaecker <clarissa.rienaecker@web.de>"]
12-
license = "MIT"
9+
authors = ["Stephan Breimann <stephanbreimann@gmail.de>"]
10+
license = "BSD-3-Clause"
1311
readme = "README.rst"
12+
homepage = "https://xomics.readthedocs.io"
1413

1514
# Add classifiers to provide more details about the package (used by PyPI)
1615
classifiers = [
1716
"Operating System :: OS Independent",
1817
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
2019
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
2121
"Natural Language :: English",
2222
"Intended Audience :: Science/Research",
2323
"Intended Audience :: Developers",
@@ -26,6 +26,9 @@ classifiers = [
2626
"Topic :: Scientific/Engineering :: Bio-Informatics",
2727
"License :: OSI Approved :: MIT License",
2828
"Development Status :: 3 - Alpha",
29+
# 1 - Planning (The project is still in the planning phase)
30+
# 2 - Pre-Alpha (Initial development, not yet functional)
31+
# 3 - Alpha (Early development stage, not feature-complete, may be unstable, intended for early adopters and testers)
2932
# 4 - Beta (feature complete, may need minor improvements
3033
# 5 - Prodcution/Stable (softaware is stable & deployed)
3134
# 6 - Mature (Stable & in production for long time)
@@ -93,8 +96,8 @@ adjustText = "0.8"
9396
"Repository" = "https://github.com/breimanntools/xomics"
9497
"Documentation" = "https://xomics.readthedocs.io"
9598

96-
# If you use a tool for linting or formatting, you can add its configurations here.
97-
# For example, if you use `black` for formatting:
99+
100+
# Configuration for black (code formatter)
98101
[tool.black]
99102
line-length = 88
100103
exclude = '''
@@ -104,8 +107,24 @@ exclude = '''
104107
| \.eggs
105108
| \.mypy_cache
106109
| \.pytest_cache
107-
| \__pycache__
110+
| __pycache__
108111
| build
109112
| dist
110113
)/
111114
'''
115+
116+
# Configuration for isort (import sorting)
117+
[tool.isort]
118+
profile = "black"
119+
line_length = 88
120+
121+
# Configuration for flake8 (linting)
122+
[tool.flake8]
123+
max-line-length = 88
124+
exclude = '''
125+
.git,
126+
__pycache__,
127+
build,
128+
dist,
129+
venv
130+
'''

0 commit comments

Comments
 (0)