Skip to content

Commit

Permalink
Merge pull request #31 from MannLabs/development
Browse files Browse the repository at this point in the history
Python >3.9 compatibility and some refactoring for expressiveness
  • Loading branch information
ammarcsj authored Feb 21, 2024
2 parents 27be825 + c733813 commit 468ed03
Show file tree
Hide file tree
Showing 19 changed files with 1,760 additions and 980 deletions.
4 changes: 2 additions & 2 deletions directlfq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


__project__ = "directlfq"
__version__ = "0.2.17"
__version__ = "0.2.18"
__license__ = "Apache"
__description__ = "An open-source Python package of the AlphaPept ecosystem"
__author__ = "Mann Labs"
Expand All @@ -13,7 +13,7 @@
"software",
"AlphaPept ecosystem",
]
__python_version__ = ">=3.8,<3.10"
__python_version__ = ">=3.8"
__classifiers__ = [
# "Development Status :: 1 - Planning",
# "Development Status :: 2 - Pre-Alpha",
Expand Down
2 changes: 2 additions & 0 deletions directlfq/lfq_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def run_lfq(input_file, columns_to_add = [], selected_proteins_file :str = None
filter_dict = load_filter_dict_if_given_as_yaml(filter_dict)
input_file = lfqutils.add_mq_protein_group_ids_if_applicable_and_obtain_annotated_file(input_file, input_type_to_use,mq_protein_groups_txt, columns_to_add)
input_df = lfqutils.import_data(input_file=input_file, input_type_to_use=input_type_to_use, filter_dict=filter_dict)

input_df = lfqutils.sort_input_df_by_protein_id(input_df)
input_df = lfqutils.index_and_log_transform_input_df(input_df)
input_df = lfqutils.remove_allnan_rows_input_df(input_df)

Expand Down
6 changes: 3 additions & 3 deletions directlfq/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ def _shift_to_reference_sample(self, row_idx):
@staticmethod
def _calc_distance(samples_1, samples_2):
distrib = get_fcdistrib(samples_1, samples_2)
distance = np.nanmedian(distrib)
if np.isnan(distance):
is_all_nan = np.all(np.isnan(distrib))
if is_all_nan:
return np.nan
else:
return distance
return np.nanmedian(distrib)


def _update_ion_dataframe(self):
Expand Down
12 changes: 11 additions & 1 deletion directlfq/protein_intensity_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@


def estimate_protein_intensities(normed_df, min_nonan, num_samples_quadratic, num_cores):
"derives protein pseudointensities from between-sample normalized data"
""""Performs the LFQ protein intensity estimation. The input is a normalized ion intensity dataframe. The output is the lfq protein intensity dataframe and the lfq ion intensity dataframe.
Args:
normed_df (pd.DataFrame): A pandas dataframe that contains the multi-index of [config.PROTEIN_ID, config.QUANT_ID]. The columns are the sample names and the values are the ion intensities. Zero value are replaced with NaNs and the dataframe is subsequently log-transformed. The dataframe needs to be sorted by the protein IDs, as the subsequent functions assume this.
min_nonan (int): minimum number of NaNs
num_samples_quadratic (int): minimum number of samples to use for the quadratic normalization
num_cores (int): number of cores to use for the multiprocessing. If set to 1, the processing is done sequentially.
Returns:
tuple[protein_intensity_df, ion_intensity_df]: protein intensity dataframe and an ion intensity dataframe. The ion intensity dataframe is only compiled if the config.COMPILE_NORMALIZED_ION_TABLE is set to True.
"""

allprots = list(normed_df.index.get_level_values(0).unique())
LOGGER.info(f"{len(allprots)} lfq-groups total")
Expand Down
3 changes: 3 additions & 0 deletions directlfq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ def index_and_log_transform_input_df(data_df):
def remove_allnan_rows_input_df(data_df):
return data_df.dropna(axis = 0, how = 'all')

def sort_input_df_by_protein_id(data_df):
return data_df.sort_values(by = config.PROTEIN_ID,ignore_index=True)




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 = 0.2.17
current_version = 0.2.18
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
78 changes: 78 additions & 0 deletions nbdev_nbs/02_normalization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,72 @@
"test_that_profiles_with_noise_are_close()\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Test 2: One array is entirely NaN\n",
"Test 1: Both arrays are non-NaN and identical\n",
"Test 3: Arrays with some NaN values\n",
"Test 4: Arrays with different values but no NaNs\n",
"Test 5: Empty arrays\n",
"All tests passed!\n"
]
}
],
"source": [
"import directlfq.normalization as lfq_norm\n",
"import numpy as np\n",
"\n",
"def _calc_distance(samples_1, samples_2):\n",
" distrib = lfq_norm.get_fcdistrib(samples_1, samples_2)\n",
" is_all_nan = np.all(np.isnan(distrib))\n",
" if is_all_nan:\n",
" return np.nan\n",
" else:\n",
" return np.nanmedian(distrib)\n",
"\n",
"def test_calc_distance():\n",
" print(\"Test 2: One array is entirely NaN\")\n",
" samples_1 = np.array([np.nan, np.nan, np.nan])\n",
" samples_2 = np.array([1, 2, 3])\n",
" assert np.isnan(lfq_norm.SampleShifterLinear._calc_distance(samples_1, samples_2)) == True, \"Test 2 failed: Expected NaN for an array entirely of NaNs\"\n",
" \n",
"\n",
" print(\"Test 1: Both arrays are non-NaN and identical\")\n",
" samples_1 = np.array([1, 2, 3])\n",
" samples_2 = np.array([1, 2, 3])\n",
" assert np.isnan(_calc_distance(samples_1, samples_2)) == False, \"Test 1 failed: Expected a non-NaN result for identical arrays\"\n",
" assert lfq_norm.SampleShifterLinear._calc_distance(samples_1, samples_2) == 0, \"Test 1 failed: Expected a distance of 0 for identical arrays\"\n",
" \n",
"\n",
" print(\"Test 3: Arrays with some NaN values\")\n",
" samples_1 = np.array([1, np.nan, 3])\n",
" samples_2 = np.array([13, 2, np.nan])\n",
" assert np.isnan(_calc_distance(samples_1, samples_2)) == False, \"Test 3 failed: Expected a valid number even with some NaNs\"\n",
" assert lfq_norm.SampleShifterLinear._calc_distance(samples_1, samples_2) == -12 , \"Test 3 failed: Expected a distance of -12\"\n",
" \n",
" print(\"Test 4: Arrays with different values but no NaNs\")\n",
" samples_1 = np.array([1, 4, 7])\n",
" samples_2 = np.array([2, 5, 8])\n",
" assert lfq_norm.SampleShifterLinear._calc_distance(samples_1, samples_2) != 0, \"Test 4 failed: Expected a non-zero distance for different values\"\n",
" \n",
" print(\"Test 5: Empty arrays\")\n",
" samples_1 = np.array([])\n",
" samples_2 = np.array([])\n",
" assert np.isnan(lfq_norm.SampleShifterLinear._calc_distance(samples_1, samples_2)) == True, \"Test 5 failed: Expected NaN for empty arrays\"\n",
"\n",
" print(\"All tests passed!\")\n",
"\n",
"# Run the test function\n",
"test_calc_distance()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1422,6 +1488,18 @@
"display_name": "directlfq",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.17"
}
},
"nbformat": 4,
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: directlfq
Version: 0.2.17
Version: 0.2.18
Architecture: all
Maintainer: Mann Labs <opensource@alphapept.com>
Description: directlfq
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/directlfq-0.2.17-py3-none-any.whl[stable, gui]"
pip install "../../dist/directlfq-0.2.18-py3-none-any.whl[stable, gui]"

# Creating the stand-alone pyinstaller folder
pip install pyinstaller==4.10
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>directlfq.0.2.17</string>
<string>directlfq.0.2.18</string>
<key>CFBundleShortVersionString</key>
<string>0.2.17</string>
<string>0.2.18</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/directlfq-0.2.17-py3-none-any.whl[stable, gui]"
pip install "../../dist/directlfq-0.2.18-py3-none-any.whl[stable, gui]"

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

pkgbuild --root dist/directlfq --identifier de.mpg.biochem.directlfq.app --version 0.2.17 --install-location /Applications/directlfq.app --scripts scripts directlfq.pkg
pkgbuild --root dist/directlfq --identifier de.mpg.biochem.directlfq.app --version 0.2.18 --install-location /Applications/directlfq.app --scripts scripts directlfq.pkg
productbuild --distribution distribution.xml --resources Resources --package-path directlfq.pkg dist/directlfq_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>directlfq 0.2.17</title>
<title>directlfq 0.2.18</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/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/directlfq-0.2.17-py3-none-any.whl[stable, gui]"
pip install "../../dist/directlfq-0.2.18-py3-none-any.whl[stable, gui]"

# Creating the stand-alone pyinstaller folder
pip install pyinstaller==4.10
Expand Down
2 changes: 1 addition & 1 deletion release/one_click_windows_gui/directlfq_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 "directlfq"
#define MyAppVersion "0.2.17"
#define MyAppVersion "0.2.18"
#define MyAppPublisher "Max Planck Institute of Biochemistry and the University of Copenhagen, Mann Labs"
#define MyAppURL "https://github.com/MannLabs/directlfq"
#define MyAppExeName "directlfq_gui.exe"
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ author = Constantin Ammar
author_email = constantin.ammar@gmail.com
copyright = fast.ai
branch = master
version = 0.2.17
version = 0.2.18
min_python = 3.6
audience = Developers
language = English
Expand Down
Binary file removed test_data/.sync_journal.db-shm
Binary file not shown.
Loading

0 comments on commit 468ed03

Please sign in to comment.