Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop sw #271

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AlphaTims is an open-source Python package that provides fast accession and visu
* [**Installation issues**](#installation-issues)
* [**Test data**](#test-data)
* [**Test sample**](#test-sample)
* [**LC**](#lc)
* [**LC**](#lc)
* [**DDA**](#dda)
* [**DIA**](#dia)
* [**Usage**](#usage)
Expand Down Expand Up @@ -318,6 +318,7 @@ Common installation/usage issues include:
* **GUI does not open.** In some cases this can be simply because of using an incompatible (default) browser. AlphaTims has been tested with Google Chrome and Mozilla Firefox. Windows IE and Windows Edge compatibility is not guaranteed.
* **When older Bruker files need to be processed as well,** the [legacy dependencies](requirements/requirements_legacy.txt) are also needed. However, note that this requires [Microsoft Visual C++](https://visualstudio.microsoft.com/visual-cpp-build-tools) to be manually installed (on Windows machines) prior to AlphaTims installation! To include the legacy dependencies, install AlphaTims with `pip install "alphatims[legacy]"` or `pip install "alphatims[legacy]" --upgrade` if already pre-installed.
* **When installed through `pip`, the GUI cannot be started.** Make sure you install AlphaTims with `pip install "alphatims[plotting-stable]"` to include the GUI with stable dependancies. If this was done and it still fails to run the GUI, a possible fix might be to run `pip install panel==0.10.3` after AlphaTims was installed.
* **Some external libraries are missing.** On some OS, there might be libraries missing. As an exmaple, the following error message might pop up: `OSError: libgomp.so.1: cannot open shared object file: No such file or directory`. This can be solved by installing those manually, e.g. on Linux: `apt-get install libgomp1`.

---
## How it works
Expand Down
2 changes: 1 addition & 1 deletion alphatims/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


__project__ = "alphatims"
__version__ = "1.0.7"
__version__ = "1.0.8"
__license__ = "Apache"
__description__ = "A Python package to index Bruker TimsTOF raw data for fast and easy accession and visualization"
__author__ = "Sander Willems, Eugenia Voytik"
Expand Down
135 changes: 104 additions & 31 deletions alphatims/bruker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ def index_precursors(
precursor_offsets[-1] = len(precursor_order)
offset = precursor_offsets[1]
offsets = precursor_order[offset:]
counts = np.empty(len(offsets) + 1, dtype=np.int)
counts = np.empty(len(offsets) + 1, dtype=np.int64)
counts[0] = 0
counts[1:] = np.cumsum(
self.quad_indptr[offsets + 1] - self.quad_indptr[offsets]
Expand Down Expand Up @@ -2058,22 +2058,23 @@ def index_precursors(
trimmed_spectrum_intensity_values
)

def save_as_mgf(
def save_as_spectra(
self,
directory: str,
file_name: str,
overwrite: bool = False,
centroiding_window: int = 5,
keep_n_most_abundant_peaks: int = -1,
mgf: bool = True
):
"""Save profile spectra from this TimsTOF object as an mgf file.
"""Save profile spectra from this TimsTOF object as an spectrum file.

Parameters
----------
directory : str
The directory where to save the mgf file.
The directory where to save the spectrum file.
file_name : str
The file name of the mgf file.
The file name of the spectrum file.
overwrite : bool
If True, an existing file is truncated.
If False, nothing happens if a file already exists.
Expand All @@ -2090,7 +2091,7 @@ def save_as_mgf(
Returns
-------
str
The full file name of the mgf file.
The full file name of the spectrum file.
"""
full_file_name = os.path.join(
directory,
Expand Down Expand Up @@ -2127,30 +2128,36 @@ def save_as_mgf(
mobilities = self.mobility_values[
self.precursors.ScanNumber.values.astype(np.int64)
]
with open(full_file_name, "w") as infile:
logging.info(f"Exporting profile spectra to {full_file_name}...")
for index in alphatims.utils.progress_callback(
range(1, self.precursor_max_index)
):
start = spectrum_indptr[index]
end = spectrum_indptr[index + 1]
title = (
f"index: {index}, "
f"intensity: {intensities[index - 1]:.1f}, "
f"mobility: {mobilities[index - 1]:.3f}, "
f"average_mz: {average_mzs[index - 1]:.3f}"
)
infile.write("BEGIN IONS\n")
infile.write(f'TITLE="{title}"\n')
infile.write(f"PEPMASS={mono_mzs[index - 1]:.6f}\n")
infile.write(f"CHARGE={charges[index - 1]}\n")
infile.write(f"RTINSECONDS={rtinseconds[index - 1]:.2f}\n")
for mz, intensity in zip(
self.mz_values[spectrum_tof_indices[start: end]],
spectrum_intensity_values[start: end],
):
infile.write(f"{mz:.6f} {intensity}\n")
infile.write("END IONS\n")
logging.info(f"Exporting profile spectra to {full_file_name}...")
if mgf:
save_as_mgf(
full_file_name,
spectrum_indptr,
intensities,
mobilities,
average_mzs,
mono_mzs,
charges,
rtinseconds,
spectrum_tof_indices,
spectrum_intensity_values,
self.precursor_max_index,
self.mz_values,
)
else:
save_as_spectra(
full_file_name,
spectrum_indptr,
intensities,
mobilities,
average_mzs,
mono_mzs,
charges,
rtinseconds,
spectrum_tof_indices,
spectrum_intensity_values,
self.mz_values,
)
logging.info(
f"Succesfully wrote {self.precursor_max_index - 1:,} "
f"spectra to {full_file_name}."
Expand Down Expand Up @@ -2326,7 +2333,7 @@ class PrecursorFloatError(TypeError):


@alphatims.utils.pjit(
signature_or_function="void(i8,i8[:],i8[:],i8[:],u4[:],u2[:],u4[:],f8[:],i8[:],i8[:])"
# signature_or_function="void(i8,i8[:],i8[:],i8[:],u4[:],u2[:],u4[:],f8[:],i8[:],i8[:])"
)
def set_precursor(
precursor_index: int,
Expand Down Expand Up @@ -3291,3 +3298,69 @@ def filter_tof_to_csr(
tof_value = tof_indices[idx]
indptr.append(len(values))
return np.array(indptr), np.array(values), np.array(columns)


def save_as_mgf(
full_file_name,
spectrum_indptr,
intensities,
mobilities,
average_mzs,
mono_mzs,
charges,
rtinseconds,
spectrum_tof_indices,
spectrum_intensity_values,
precursor_max_index,
mz_values,
):
with open(full_file_name, "w") as infile:
for index in alphatims.utils.progress_callback(
range(1, precursor_max_index)
):
start = spectrum_indptr[index]
end = spectrum_indptr[index + 1]
title = (
f"index: {index}, "
f"intensity: {intensities[index - 1]:.1f}, "
f"mobility: {mobilities[index - 1]:.3f}, "
f"average_mz: {average_mzs[index - 1]:.3f}"
)
infile.write("BEGIN IONS\n")
infile.write(f'TITLE="{title}"\n')
infile.write(f"PEPMASS={mono_mzs[index - 1]:.6f}\n")
infile.write(f"CHARGE={charges[index - 1]}\n")
infile.write(f"RTINSECONDS={rtinseconds[index - 1]:.2f}\n")
for mz, intensity in zip(
mz_values[spectrum_tof_indices[start: end]],
spectrum_intensity_values[start: end],
):
infile.write(f"{mz:.6f} {intensity}\n")
infile.write("END IONS\n")


def save_as_spectra(
full_file_name,
spectrum_indptr,
intensities,
mobilities,
average_mzs,
mono_mzs,
charges,
rtinseconds,
spectrum_tof_indices,
spectrum_intensity_values,
mz_values,
):
with h5py.File(full_file_name, "w") as infile:
infile["indptr"] = spectrum_indptr[1:]
infile["fragment_mzs"] = mz_values[
spectrum_tof_indices
]
infile["fragment_intensities"] = spectrum_intensity_values
infile["precursor_rt"] = rtinseconds
infile["precursor_charge"] = charges
infile["precursor_intensity"] = intensities
infile["precursor_mobility"] = mobilities
infile["precursor_average_mz"] = average_mzs
infile["precursor_monoisotopic_mz"] = mono_mzs
38 changes: 36 additions & 2 deletions alphatims/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,46 @@ def export_mgf(**kwargs):
directory = data.directory
else:
directory = parameters["output_folder"]
data.save_as_mgf(
data.save_as_spectra(
overwrite=not parameters["disable_overwrite"],
directory=directory,
file_name=f"{data.sample_name}.mgf",
centroiding_window=parameters["centroiding_window"],
keep_n_most_abundant_peaks=parameters["keep_n_most_abundant_peaks"]
keep_n_most_abundant_peaks=parameters["keep_n_most_abundant_peaks"],
mgf=True,
)


@export.command(
"spectra",
help="Export BRUKER_RAW_DATA as (profile) spectra file.",
no_args_is_help=True,
)
@cli_option("bruker_raw_data", as_argument=True)
@cli_option("keep_n_most_abundant_peaks")
@cli_option("centroiding_window")
@cli_option("disable_overwrite")
@cli_option("output_folder")
@cli_option("log_file")
@cli_option("threads")
@cli_option("disable_log_stream")
@cli_option("parameter_file")
@cli_option("export_parameters")
def export_spectra(**kwargs):
with parse_cli_settings("export spectra", **kwargs) as parameters:
import alphatims.bruker
data = alphatims.bruker.TimsTOF(parameters["bruker_raw_data"])
if "output_folder" not in parameters:
directory = data.directory
else:
directory = parameters["output_folder"]
data.save_as_spectra(
overwrite=not parameters["disable_overwrite"],
directory=directory,
file_name=f"{data.sample_name}.spectra.hdf",
centroiding_window=parameters["centroiding_window"],
keep_n_most_abundant_peaks=parameters["keep_n_most_abundant_peaks"],
mgf=False,
)


Expand Down
2 changes: 1 addition & 1 deletion misc/bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.7
current_version = 1.0.8
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion misc/one_click_linux/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: AlphaTims
Version: 1.0.7
Version: 1.0.8
Architecture: all
Maintainer: Mann Labs <opensource@alphapept.com>
Description: AlphaTims GUI
Expand Down
2 changes: 1 addition & 1 deletion misc/one_click_linux/create_installer_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rm -rf dist
rm -rf build
python setup.py sdist bdist_wheel
cd misc/one_click_linux
pip install "../../dist/alphatims-1.0.7-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install "../../dist/alphatims-1.0.8-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install pyinstaller==5.6.2
pyinstaller ../pyinstaller/alphatims.spec -y
conda deactivate
Expand Down
4 changes: 2 additions & 2 deletions misc/one_click_macos/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>alphatims.1.0.7</string>
<string>alphatims.1.0.8</string>
<key>CFBundleShortVersionString</key>
<string>1.0.7</string>
<string>1.0.8</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
6 changes: 3 additions & 3 deletions misc/one_click_macos/create_installer_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rm -rf build
python setup.py sdist bdist_wheel
cd misc/one_click_macos
pip install pyinstaller==5.6.2
pip install "../../dist/alphatims-1.0.7-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install "../../dist/alphatims-1.0.8-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
conda list
pyinstaller ../pyinstaller/alphatims.spec -y
conda deactivate
Expand All @@ -34,7 +34,7 @@ if false; then
# https://scriptingosx.com/2019/09/notarize-a-command-line-tool/
for f in $(find dist/alphatims -name '*.so' -or -name '*.dylib'); do codesign --sign "Developer ID Application: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)" $f; done
codesign --sign "Developer ID Application: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)" dist/alphatims/Contents/MacOS/alphatims_gui --force --options=runtime --entitlements entitlements.xml
pkgbuild --root dist/alphatims --identifier de.mpg.biochem.alphatims.app --version 1.0.7 --install-location /Applications/AlphaTims.app --scripts scripts alphatims.pkg --sign "Developer ID Installer: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)"
pkgbuild --root dist/alphatims --identifier de.mpg.biochem.alphatims.app --version 1.0.8 --install-location /Applications/AlphaTims.app --scripts scripts alphatims.pkg --sign "Developer ID Installer: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)"
productbuild --distribution distribution.xml --resources Resources --package-path alphatims.pkg dist/alphatims_gui_installer_macos.pkg --sign "Developer ID Installer: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)"
requestUUID=$(xcrun altool --notarize-app --primary-bundle-id "de.mpg.biochem.alphatims.app" --username "willems@biochem.mpg.de" --password "@keychain:Alphatims-develop" --asc-provider 7QSY5527AQ --file dist/alphatims_gui_installer_macos.pkg 2>&1 | awk '/RequestUUID/ { print $NF; }')
request_status="in progress"
Expand All @@ -46,6 +46,6 @@ if false; then
xcrun altool --notarization-info "$requestUUID" --username "willems@biochem.mpg.de" --password "@keychain:Alphatims-develop"
xcrun stapler staple dist/alphatims_gui_installer_macos.pkg
else
pkgbuild --root dist/alphatims --identifier de.mpg.biochem.alphatims.app --version 1.0.7 --install-location /Applications/AlphaTims.app --scripts scripts alphatims.pkg
pkgbuild --root dist/alphatims --identifier de.mpg.biochem.alphatims.app --version 1.0.8 --install-location /Applications/AlphaTims.app --scripts scripts alphatims.pkg
productbuild --distribution distribution.xml --resources Resources --package-path alphatims.pkg dist/alphatims_gui_installer_macos.pkg
fi
2 changes: 1 addition & 1 deletion misc/one_click_macos/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>AlphaTims 1.0.7</title>
<title>AlphaTims 1.0.8</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 misc/one_click_windows/alphatims_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 "AlphaTims"
#define MyAppVersion "1.0.7"
#define MyAppVersion "1.0.8"
#define MyAppPublisher "Max Planck Institute of Biochemistry, Mann department"
#define MyAppURL "https://github.com/MannLabs/alphatims"
#define MyAppExeName "alphatims_gui.exe"
Expand Down
2 changes: 1 addition & 1 deletion misc/one_click_windows/create_installer_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ call rmdir dist /s /q
call rmdir build /s /q
call python setup.py sdist bdist_wheel
call cd misc/one_click_windows
call pip install "../../dist/alphatims-1.0.7-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
call pip install "../../dist/alphatims-1.0.8-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
call pip install pyinstaller==4.10
call pyinstaller ../pyinstaller/alphatims.spec -y
call conda deactivate
Expand Down
2 changes: 1 addition & 1 deletion misc/one_click_windows/create_installer_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rm -rf dist
rm -rf build
python setup.py sdist bdist_wheel
cd misc/one_click_windows
pip install "../../dist/alphatims-1.0.7-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install "../../dist/alphatims-1.0.8-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install pyinstaller==5.6.2
# TODO https://stackoverflow.com/questions/54175042/python-3-7-anaconda-environment-import-ssl-dll-load-fail-error/60405693#60405693
pyinstaller ../pyinstaller/alphatims.spec -y
Expand Down