Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
36bafaf
use black to reformat the scripts
nilchia Apr 2, 2026
43605c9
use isort to fix the order
nilchia Apr 2, 2026
0e8feb8
remove unused modules
nilchia Apr 2, 2026
7ca24cd
run black again
nilchia Apr 2, 2026
aa8bb8c
use black to reformat lines to have length < 79
nilchia Apr 2, 2026
b3f9556
remove variables which were never used
nilchia Apr 2, 2026
c277a1b
fix too many blank lines
nilchia Apr 2, 2026
685a6ed
fix undefined modules
nilchia Apr 2, 2026
d579746
run black again
nilchia Apr 2, 2026
eaaf05e
run isort
nilchia Apr 2, 2026
d4d8ce2
fix module level import not at top of the file
nilchia Apr 2, 2026
ec76468
fix too many blank lines
nilchia Apr 2, 2026
f89f6f3
fix f-string is missing placeholders
nilchia Apr 2, 2026
2c0a87a
fix redefinition of unused
nilchia Apr 3, 2026
31197d1
fix isort
nilchia Apr 3, 2026
06155d7
fix do not assign a lambda expression, use a def
nilchia Apr 3, 2026
a70a745
remove unused
nilchia Apr 3, 2026
420aa87
fix may be undefined or defined from ...
nilchia Apr 3, 2026
5677fbf
fix remaining small fixes except length
nilchia Apr 3, 2026
5040f06
add flake8 lint check in CI
nilchia Apr 3, 2026
e185a99
fix max line length using claude
nilchia Apr 3, 2026
f686a8d
set max len of line to 120 in CI
nilchia Apr 3, 2026
db1cf9d
Update .github/workflows/lint.yml
nilchia Apr 3, 2026
99b272a
add removed libraries
nilchia Apr 9, 2026
1498d22
string is imported from data.py
nilchia Apr 9, 2026
afa6d77
isort fix
nilchia Apr 9, 2026
17edca9
fix mps memory test
nilchia Apr 9, 2026
51b862d
Merge branch 'BIMSBbioinfo:main' into lint_py
nilchia Apr 10, 2026
8c12ab0
use coad_cptac_2019
nilchia Apr 10, 2026
154bfbe
increase cbioportal timeout and check if the files are correctly down…
nilchia Apr 12, 2026
87631a9
bring back the removed extract.archive
nilchia Apr 13, 2026
f33b98b
Apply suggestion from @Copilot
borauyar Apr 19, 2026
4007e35
Apply suggestions from code review
borauyar Apr 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint Python scripts

on:
push:
paths:
- '**.py'
pull_request:
paths:
- '**.py'

jobs:
lint:
name: Lint Python scripts
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.11', '3.12']
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip
uses: actions/cache@v4
id: cache-pip
with:
path: ~/.cache/pip
key: pip_cache_py_${{ matrix.python-version }}_${{ hashFiles('**/pyproject.toml') }}

- name: Install linters
run: |
python -m pip install --upgrade pip
pip install isort flake8

- name: Run isort
run: isort --check-only --diff .

- name: Run flake8
run: flake8 . --max-line-length=120
30 changes: 24 additions & 6 deletions examples/tutorials/cbioportal.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"STUDY_ID = 'pancan_pcawg_2020'"
"STUDY_ID = 'coad_cptac_2019'"
]
},
{
Expand All @@ -37,6 +37,24 @@
"cbio.get_cbioportal_data(cbio.study_id)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b08670ec",
"metadata": {},
"outputs": [],
"source": [
"# Check the specific files the notebook needs are present\n",
"required_files = [\"data_cna.txt\", \"data_mutations.txt\", \"data_clinical_sample.txt\"]\n",
"missing = [f for f in required_files if not os.path.exists(os.path.join(STUDY_ID, f))]\n",
"assert not missing, f\"Missing required files in {STUDY_ID}: {missing}\"\n",
"\n",
"print(f\"All required files present in ./{STUDY_ID}/:\")\n",
"for f in required_files:\n",
" size = os.path.getsize(os.path.join(STUDY_ID, f))\n",
" print(f\" {f} ({size:,} bytes)\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -144,7 +162,7 @@
"metadata": {},
"outputs": [],
"source": [
"counts = np.unique(list(data['clin'].CANCER_TYPE), return_counts=True) "
"counts = np.unique(list(data['clin'].CANCER_TYPE), return_counts=True)"
]
},
{
Expand Down Expand Up @@ -274,8 +292,8 @@
"metadata": {},
"outputs": [],
"source": [
"data_importer = flexynesis.data.DataImporter(path=f'{STUDY_ID}/', \n",
" data_types = ['mut', 'cna'], \n",
"data_importer = flexynesis.data.DataImporter(path=f'{STUDY_ID}/',\n",
" data_types = ['mut', 'cna'],\n",
" concatenate=False, top_percentile=10, variance_threshold=0.8,\n",
" min_features=500)\n",
"train_dataset, test_dataset = data_importer.import_data()"
Expand Down Expand Up @@ -324,7 +342,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "flexy",
"language": "python",
"name": "python3"
},
Expand All @@ -338,7 +356,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down
50 changes: 30 additions & 20 deletions flexynesis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Lazy imports to avoid slow startup
# Only import essential components that are needed for basic functionality

from importlib.metadata import PackageNotFoundError, version

# Import core modules without heavy dependencies
from .config import search_spaces
from importlib.metadata import PackageNotFoundError, version

# Use the distribution name as published on PyPI (may differ from import name in some projects)
_DISTRIBUTION_NAME = "flexynesis"
Expand All @@ -13,72 +14,81 @@
except PackageNotFoundError:
# Happens in some dev scenarios before the package is installed
__version__ = "0+unknown"



class LazyModule:
"""Lazy module that only imports when accessed."""

def __init__(self, module_name):
self._module_name = module_name
self._module = None
self._import_error = None

def _import_module(self):
if self._module is None and self._import_error is None:
try:
import importlib
self._module = importlib.import_module(f'.{self._module_name}', package=__name__)

self._module = importlib.import_module(
f".{self._module_name}", package=__name__
)
except ImportError as e:
self._import_error = e
raise ImportError(f"Failed to import {self._module_name} module: {e}. "
f"This usually means some dependencies are missing. "
f"Try installing required packages or check your environment.")
raise ImportError(
f"Failed to import {self._module_name} module: {e}. "
f"This usually means some dependencies are missing. "
f"Try installing required packages or check your environment."
)
elif self._import_error is not None:
raise self._import_error
return self._module

def __getattr__(self, name):
module = self._import_module()
return getattr(module, name)

def __dir__(self):
if self._module is None:
return []
module = self._import_module()
return dir(module)

def __repr__(self):
if self._module is None:
return f"<LazyModule '{self._module_name}' (not yet imported)>"
else:
return f"<LazyModule '{self._module_name}' (imported)>"


# Create lazy module proxies - these are NOT imported yet
modules = LazyModule('modules')
data = LazyModule('data')
main = LazyModule('main')
models = LazyModule('models')
feature_selection = LazyModule('feature_selection')
utils = LazyModule('utils')
modules = LazyModule("modules")
data = LazyModule("data")
main = LazyModule("main")
models = LazyModule("models")
feature_selection = LazyModule("feature_selection")
utils = LazyModule("utils")


# Import commonly used classes directly for easy access
# These will be imported lazily when first accessed
def _get_data_importer():
"""Lazy getter for DataImporter class."""
return data.DataImporter


def _get_models():
"""Lazy getter for model classes."""
return models


# Export all modules and commonly used classes
__all__ = [
"search_spaces",
"modules",
"data",
"data",
"main",
"models",
"feature_selection",
"utils",
"DataImporter"
"DataImporter",
]

Loading
Loading