Skip to content

Commit

Permalink
Merge pull request #183 from MannLabs/development
Browse files Browse the repository at this point in the history
Development 1.2.5
  • Loading branch information
jalew188 authored Jun 14, 2024
2 parents 00ba37b + 0272da9 commit 737f25c
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 40 deletions.
3 changes: 1 addition & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.2.4
current_version = 1.2.5
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down Expand Up @@ -28,6 +28,5 @@ serialize =
[bumpversion:file:./release/one_click_windows_gui/create_installer_windows.sh]

[bumpversion:file:./release/one_click_windows_gui/alphabase_innoinstaller.iss]

search = {current_version}
replace = {new_version}
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ repos:
hooks:
- id: ruff-format
- id: ruff

exclude: .bumpversion.cfg
2 changes: 1 addition & 1 deletion alphabase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


__project__ = "alphabase"
__version__ = "1.2.4"
__version__ = "1.2.5"
__license__ = "Apache"
__description__ = "An infrastructure Python package of the AlphaX ecosystem"
__author__ = "Mann Labs"
Expand Down
134 changes: 108 additions & 26 deletions alphabase/io/tempmmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,71 @@ def _log_cleanup_info_once() -> None:
is_cleanup_info_logged = True


def _change_temp_dir_location(abs_path: str) -> str:
"""
Check if the directory to which the temp arrays should be written exists, if so defines this as the new temp dir location. If not raise a value error.
Parameters
----------
abs_path : str
The absolute path to the new temporary directory.
"""

global TEMP_DIR_NAME

# ensure that the path exists
if os.path.exists(abs_path):
# ensure that the path points to a directory
if os.path.isdir(abs_path):
TEMP_DIR_NAME = abs_path
else:
raise ValueError(f"The path {abs_path} does not point to a directory.")
else:
raise ValueError(
f"The directory {abs_path} in which the file should be created does not exist."
)


def _get_file_location(abs_file_path: str, overwrite=False) -> str:
"""
Check if the path specified for the new temporary file is valid. If not raise a value error.
Valid file paths need to:
1. be contained in directories that exist
2. end in .hdf
3. not exist if overwrite is set to False
Parameters
----------
abs_path : str
The absolute path to the new temporary file.
Returns
------
str
The file path if it is valid.
"""
# check overwrite status and existence of file
if not overwrite:
if os.path.exists(abs_file_path):
raise ValueError(
"The file already exists. Set overwrite to True to overwrite the file or choose a different name."
)

# ensure that the filename conforms to the naming convention
if not os.path.basename.endswith(".hdf"):
raise ValueError("The chosen file name needs to end with .hdf")

# ensure that the directory in which the file should be created exists
if os.path.isdir(os.path.commonpath(abs_file_path)):
return abs_file_path
else:
raise ValueError(
f"The directory {os.path.commonpath(abs_file_path)} in which the file should be created does not exist."
)


def redefine_temp_location(path):
"""
Redfine the location where the temp arrays are written to.
Expand All @@ -46,25 +111,27 @@ def redefine_temp_location(path):
"""

global _TEMP_DIR, _TEMP_DIR, TEMP_DIR_NAME
global _TEMP_DIR, TEMP_DIR_NAME

logging.warning(
f"""Folder {TEMP_DIR_NAME} with temp mmap arrays is being deleted.All existing temp mmapp arrays will be unusable!"""
f"""Folder {TEMP_DIR_NAME} with temp mmap arrays is being deleted. All existing temp mmapp arrays will be unusable!"""
)

# cleaup old temporary directory
shutil.rmtree(TEMP_DIR_NAME, ignore_errors=True)
del _TEMP_DIR

# create new tempfile at desired location
_TEMP_DIR = tempfile.TemporaryDirectory(prefix=os.path.join(path, "temp_mmap"))
_TEMP_DIR = tempfile.TemporaryDirectory(prefix=os.path.join(path, "temp_mmap_"))
TEMP_DIR_NAME = _TEMP_DIR.name

logging.warning(
f"""New temp folder location. Temp mmap arrays are written to {TEMP_DIR_NAME}. Cleanup of this folder is OS dependant, and might need to be triggered manually!"""
)

return TEMP_DIR_NAME


def array(shape: tuple, dtype: np.dtype) -> np.ndarray:
def array(shape: tuple, dtype: np.dtype, tmp_dir_abs_path: str = None) -> np.ndarray:
"""Create a writable temporary mmapped array.
Parameters
Expand All @@ -73,14 +140,25 @@ def array(shape: tuple, dtype: np.dtype) -> np.ndarray:
A tuple with the shape of the array.
dtype : type
The np.dtype of the array.
tmp_dir_abs_path : str, optional
If specified the memory mapped array will be created in this directory.
An absolute path is expected.
Defaults to None. If not specified the global TEMP_DIR_NAME location will be used.
Returns
-------
type
A writable temporary mmapped array.
"""
global TEMP_DIR_NAME

_log_cleanup_info_once()

# redefine the temporary directory if a new location is given otherwise read from global variable
# this allows you to ensure that the correct temp directory location is used when working with multiple threads
if tmp_dir_abs_path is not None:
_change_temp_dir_location(tmp_dir_abs_path)

temp_file_name = os.path.join(
TEMP_DIR_NAME, f"temp_mmap_{np.random.randint(2**63)}.hdf"
)
Expand All @@ -97,7 +175,13 @@ def array(shape: tuple, dtype: np.dtype) -> np.ndarray:
).reshape(shape)


def create_empty_mmap(shape: tuple, dtype: np.dtype, path: str = None, overwrite=False):
def create_empty_mmap(
shape: tuple,
dtype: np.dtype,
file_path: str = None,
overwrite: bool = False,
tmp_dir_abs_path: str = None,
):
"""Initialize a new HDF5 file compatible with mmap. Returns the path to the initialized file.
File can be mapped using the mmap_array_from_path function.
Expand All @@ -107,41 +191,37 @@ def create_empty_mmap(shape: tuple, dtype: np.dtype, path: str = None, overwrite
A tuple with the shape of the array.
dtype : type
The np.dtype of the array.
path : str, optional
The path to the file that should be created.
file_path : str, optional
The absolute path to the file that should be created. This includes the file name.
Defaults to None.
If None a random file name will be generated.
If None a random file name will be generated in the default tempdir location.
overwrite : bool , optional
If True the file will be overwritten if it already exists.
Defaults to False.
tmp_dir_abs_path : str, optional
If specified the default tempdir location will be updated to this path. Defaults to None. An absolute path to a directory is expected.
Returns
-------
str
path to the newly created file.
"""
global TEMP_DIR_NAME

_log_cleanup_info_once()

# redefine the temporary directory if a new location is given otherwise read from global variable
# this allows you to ensure that the correct temp directory location is used when working with multiple threads
if tmp_dir_abs_path is not None:
_change_temp_dir_location(tmp_dir_abs_path)

# if path does not exist generate a random file name in the TEMP directory
if path is None:
if file_path is None:
temp_file_name = os.path.join(
TEMP_DIR_NAME, f"temp_mmap_{np.random.randint(2**63)}.hdf"
)
else:
# check that if overwrite is false the file does not already exist
if not overwrite:
if os.path.exists(path):
raise ValueError(
"The file already exists. Set overwrite to True to overwrite the file or choose a different name."
)
if not os.path.basename.endswith(".hdf"):
raise ValueError("The chosen file name needs to end with .hdf")
if os.path.isdir(os.path.commonpath(path)):
temp_file_name = path
else:
raise ValueError(
"The directory in which the file should be created does not exist."
)
temp_file_name = _get_file_location(file_path, overwrite=False)

with h5py.File(temp_file_name, "w") as hdf_file:
array = hdf_file.create_dataset("array", shape=shape, dtype=dtype)
Expand Down Expand Up @@ -233,13 +313,15 @@ def clear() -> str:
str
The name of the new temporary folder.
"""
global _TEMP_DIR
global TEMP_DIR_NAME
global _TEMP_DIR, TEMP_DIR_NAME

logging.warning(
f"Folder {TEMP_DIR_NAME} with temp mmap arrays is being deleted. "
"All existing temp mmapp arrays will be unusable!"
)

del _TEMP_DIR

_TEMP_DIR = tempfile.TemporaryDirectory(prefix="temp_mmap_")
TEMP_DIR_NAME = _TEMP_DIR.name
return TEMP_DIR_NAME
2 changes: 1 addition & 1 deletion alphabase/protein/fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def read_fasta_file(fasta_filename: str = ""):
protein information,
{protein_id:str, full_name:str, gene_name:str, description:str, sequence:str}
"""
with open(fasta_filename, "rt") as handle:
with open(fasta_filename, "rt", encoding="utf-8") as handle:
iterator = SeqIO.parse(handle, "fasta")
while iterator:
try:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
copyright = "2022, Mann Labs, MPIB"
author = "Mann Labs, MPIB"

release = "1.2.4"
release = "1.2.5"

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion release/one_click_linux_gui/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: AlphaBase
Version: 1.2.4
Version: 1.2.5
Architecture: all
Maintainer: Mann Labs <[email protected]>
Description: AlphaBase
Expand Down
2 changes: 1 addition & 1 deletion release/one_click_linux_gui/create_installer_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python setup.py sdist bdist_wheel
# Setting up the local package
cd release/one_click_linux_gui
# Make sure you include the required extra packages and always use the stable or very-stable options!
pip install "../../dist/alphabase-1.2.4-py3-none-any.whl[stable]"
pip install "../../dist/alphabase-1.2.5-py3-none-any.whl[stable]"

# Creating the stand-alone pyinstaller folder
pip install pyinstaller
Expand Down
4 changes: 2 additions & 2 deletions release/one_click_macos_gui/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<key>CFBundleIconFile</key>
<string>alpha_logo.icns</string>
<key>CFBundleIdentifier</key>
<string>alphabase.1.2.4</string>
<string>alphabase.1.2.5</string>
<key>CFBundleShortVersionString</key>
<string>1.2.4</string>
<string>1.2.5</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
4 changes: 2 additions & 2 deletions release/one_click_macos_gui/create_installer_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ python setup.py sdist bdist_wheel

# Setting up the local package
cd release/one_click_macos_gui
pip install "../../dist/alphabase-1.2.4-py3-none-any.whl[stable]"
pip install "../../dist/alphabase-1.2.5-py3-none-any.whl[stable]"

# Creating the stand-alone pyinstaller folder
pip install pyinstaller
Expand All @@ -40,5 +40,5 @@ cp ../../LICENSE.txt Resources/LICENSE.txt
cp ../logos/alpha_logo.png Resources/alpha_logo.png
chmod 777 scripts/*

pkgbuild --root dist/alphabase --identifier de.mpg.biochem.alphabase.app --version 1.2.4 --install-location /Applications/AlphaBase.app --scripts scripts AlphaBase.pkg
pkgbuild --root dist/alphabase --identifier de.mpg.biochem.alphabase.app --version 1.2.5 --install-location /Applications/AlphaBase.app --scripts scripts AlphaBase.pkg
productbuild --distribution distribution.xml --resources Resources --package-path AlphaBase.pkg dist/alphabase_gui_installer_macos.pkg
2 changes: 1 addition & 1 deletion release/one_click_macos_gui/distribution.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<installer-script minSpecVersion="1.000000">
<title>AlphaBase 1.2.4</title>
<title>AlphaBase 1.2.5</title>
<background mime-type="image/png" file="alpha_logo.png" scaling="proportional"/>
<welcome file="welcome.html" mime-type="text/html" />
<conclusion file="conclusion.html" mime-type="text/html" />
Expand Down
2 changes: 1 addition & 1 deletion release/one_click_windows_gui/alphabase_innoinstaller.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "AlphaBase"
#define MyAppVersion "1.2.4"
#define MyAppVersion "1.2.5"
#define MyAppPublisher "Max Planck Institute of Biochemistry and the University of Copenhagen, Mann Labs"
#define MyAppURL "https://github.com/MannLabs/alphabase"
#define MyAppExeName "alphabase_gui.exe"
Expand Down
2 changes: 1 addition & 1 deletion release/one_click_windows_gui/create_installer_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python setup.py sdist bdist_wheel
# Setting up the local package
cd release/one_click_windows_gui
# Make sure you include the required extra packages and always use the stable or very-stable options!
pip install "../../dist/alphabase-1.2.4-py3-none-any.whl[stable]"
pip install "../../dist/alphabase-1.2.5-py3-none-any.whl[stable]"

# Creating the stand-alone pyinstaller folder
pip install pyinstaller
Expand Down

0 comments on commit 737f25c

Please sign in to comment.