Skip to content

Commit 4bfd119

Browse files
Merge pull request #408 from MannLabs/develop
Develop
2 parents a4a1155 + 72c5c00 commit 4bfd119

19 files changed

+4862
-4793
lines changed

.bumpversion.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.4.0
2+
current_version = 0.4.1
33
commit = True
44
tag = False
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?

alphapept/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.4.0"
1+
__version__ = "0.4.1"
22

33
__requirements__ = {
44
"": "requirements/requirements.txt",

alphapept/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
AUTHOR_EMAIL = "[email protected]"
3434
COPYRIGHT = "Mann Labs"
3535
BRANCH = "master"
36-
VERSION_NO = "0.4.0"
36+
VERSION_NO = "0.4.1"
3737
MIN_PYTHON = "3.6"
3838
MAX_PYTHON = "4"
3939
AUDIENCE = "Developers"

alphapept/interface.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1395,12 +1395,14 @@ def cli_database(settings_file):
13951395

13961396
@click.command(
13971397
"import",
1398-
help="Import and convert raw data from vendor to `.ms_data.hdf` file.",
1399-
short_help="Import and convert raw data from vendor to `.ms_data.hdf` file."
1398+
help="Import and convert raw data from vendor to `.ms_data.hdf` file with default settings.",
1399+
short_help="Import and convert raw data from vendor to `.ms_data.hdf` file with default settings."
14001400
)
14011401
@CLICK_SETTINGS_OPTION
14021402
def cli_import(settings_file):
1403-
settings = alphapept.settings.load_settings(settings_file)
1403+
from .paths import DEFAULT_SETTINGS_PATH
1404+
settings = alphapept.settings.load_settings_as_template(DEFAULT_SETTINGS_PATH)
1405+
settings['experiment']['file_paths'] = [settings_file]
14041406
import_raw_data(settings)
14051407

14061408

alphapept/quantification.py

+30-27
Original file line numberDiff line numberDiff line change
@@ -449,43 +449,49 @@ def protein_profile(files: list, minimum_ratios: int, chunk:tuple) -> (np.ndarra
449449
"""
450450
grouped, protein = chunk
451451

452-
column_combinations = List()
453-
[column_combinations.append(_) for _ in combinations(range(len(files)), 2)]
452+
files_ = grouped.index.get_level_values('filename').unique().tolist()
454453

455454
selection = grouped.unstack().T.copy()
456455
selection = selection.replace(0, np.nan)
457456

458-
if not selection.shape[1] == len(files):
459-
selection[[_ for _ in files if _ not in selection.columns]] = np.nan
457+
if len(files_) > 1:
458+
column_combinations = List()
459+
[column_combinations.append(_) for _ in combinations(range(len(files_)), 2)]
460460

461-
selection = selection[files]
461+
ratios = get_protein_ratios(selection.values, column_combinations, minimum_ratios)
462462

463-
ratios = get_protein_ratios(selection.values, column_combinations, minimum_ratios)
464-
465-
retry = False
466-
try:
467-
solution, success = solve_profile(ratios, 'L-BFGS-B')
468-
except ValueError:
469-
retry = True
463+
retry = False
464+
try:
465+
solution, success = solve_profile(ratios, 'L-BFGS-B')
466+
except ValueError:
467+
retry = True
470468

471-
if retry or not success:
472-
logging.info('Normalization with L-BFGS-B failed. Trying Powell')
473-
solution, success = solve_profile(ratios, 'Powell')
469+
if retry or not success:
470+
logging.info('Normalization with L-BFGS-B failed. Trying Powell')
471+
solution, success = solve_profile(ratios, 'Powell')
474472

475-
pre_lfq = selection.sum().values
473+
pre_lfq = selection.sum().values
476474

477-
if not success or np.sum(~np.isnan(ratios)) == 0: # or np.sum(solution) == len(pre_lfq):
478-
profile = np.zeros_like(pre_lfq)
479-
if np.sum(np.isnan(ratios)) != ratios.size:
480-
logging.info(f'Solver failed for protein {protein} despite available ratios:\n {ratios}')
475+
if not success or np.sum(~np.isnan(ratios)) == 0: # or np.sum(solution) == len(pre_lfq):
476+
profile = np.zeros(len(files_))
477+
if np.sum(np.isnan(ratios)) != ratios.size:
478+
logging.info(f'Solver failed for protein {protein} despite available ratios:\n {ratios}')
481479

480+
else:
481+
invalid = ((np.nansum(ratios, axis=1) == 0) & (np.nansum(ratios, axis=0) == 0))
482+
peptide_int_sum = pre_lfq.sum() * solution
483+
peptide_int_sum[invalid] = 0
484+
profile = peptide_int_sum * pre_lfq.sum() / np.sum(peptide_int_sum) #Normalize inensity again
482485
else:
483-
invalid = ((np.nansum(ratios, axis=1) == 0) & (np.nansum(ratios, axis=0) == 0))
484-
peptide_int_sum = pre_lfq.sum() * solution
485-
peptide_int_sum[invalid] = 0
486-
profile = peptide_int_sum * pre_lfq.sum() / np.sum(peptide_int_sum) #Normalize inensity again
486+
pre_lfq = profile = selection.values[0]
487487

488488

489+
#Rewrite ratios
490+
profile_dict = dict(zip(files_, profile))
491+
pre_dict = dict(zip(files_, pre_lfq))
492+
profile = np.array([0 if file not in profile_dict else profile_dict[file] for file in files])
493+
pre_lfq = np.array([0 if file not in pre_dict else pre_dict[file] for file in files])
494+
489495
return profile, pre_lfq, protein
490496

491497

@@ -519,9 +525,6 @@ def protein_profile_parallel(df: pd.DataFrame, minimum_ratios: int, field: str,
519525
#Take the best precursor for protein quantification. .max()
520526
grouped = df[[field, 'filename','precursor','protein_group']].groupby(['protein_group','filename','precursor']).max()
521527

522-
column_combinations = List()
523-
[column_combinations.append(_) for _ in combinations(range(len(files)), 2)]
524-
525528
files = df['filename'].unique().tolist()
526529
files.sort()
527530

alphapept/utils.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,18 @@ def assemble_df(settings, field = 'protein_fdr', callback=None):
296296

297297
def check_file(file):
298298
if not os.path.isfile(file):
299-
raise FileNotFoundError(f"{file}")
299+
base, ext = os.path.splitext(file)
300+
if not os.path.isfile(base+'.ms_data.hdf'):
301+
raise FileNotFoundError(f"{file}")
300302

301303
def get_size_mb(file):
302304
return os.path.getsize(file)/(1024**2)
303305

304306
def check_dir(dir):
305307
if not os.path.isdir(dir):
306-
raise FileNotFoundError(f"{dir}")
308+
base, ext = os.path.splitext(dir)
309+
if not os.path.isfile(base+'.ms_data.hdf'):
310+
raise FileNotFoundError(f"{dir}")
307311

308312
def delete_file(filename):
309313
if os.path.isfile(filename):

installer/one_click_windows/alphapept_innoinstaller.iss

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
33

44
#define MyAppName "AlphaPept"
5-
#define MyAppVersion "0.4.0"
5+
#define MyAppVersion "0.4.1"
66
#define MyAppPublisher "MannLabs"
77
#define MyAppURL "https://github.com/MannLabs/alphapept"
88
#define MyAppExeName "alphapept.exe"

installer/one_click_windows/create_installer_windows.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ call DEL /F/Q/S dist > NUL
1212
call RMDIR /Q/S build
1313
call RMDIR /Q/S dist
1414
call python setup.py sdist bdist_wheel
15-
call pip install dist/alphapept-0.4.0-py3-none-any.whl[stable,gui-stable]
15+
call pip install dist/alphapept-0.4.1-py3-none-any.whl[stable,gui-stable]
1616
call pip install pyinstaller==4.7
1717
call cd installer/one_click_windows
1818
call pyinstaller ../alphapept.spec -y

nbs/08_quantification.ipynb

+65-62
Original file line numberDiff line numberDiff line change
@@ -377,41 +377,41 @@
377377
" <tr>\n",
378378
" <th>0</th>\n",
379379
" <td>L-BFGS-B</td>\n",
380-
" <td>0.028414</td>\n",
381-
" <td>0.767214</td>\n",
382-
" <td>0.630689</td>\n",
380+
" <td>0.017857</td>\n",
381+
" <td>0.720272</td>\n",
382+
" <td>0.572021</td>\n",
383383
" </tr>\n",
384384
" <tr>\n",
385385
" <th>1</th>\n",
386386
" <td>TNC</td>\n",
387-
" <td>0.023116</td>\n",
388-
" <td>0.808149</td>\n",
389-
" <td>0.664340</td>\n",
387+
" <td>0.022109</td>\n",
388+
" <td>0.755240</td>\n",
389+
" <td>0.599792</td>\n",
390390
" </tr>\n",
391391
" <tr>\n",
392392
" <th>2</th>\n",
393393
" <td>SLSQP</td>\n",
394-
" <td>0.003840</td>\n",
395-
" <td>0.767214</td>\n",
396-
" <td>0.630689</td>\n",
394+
" <td>0.002948</td>\n",
395+
" <td>0.720272</td>\n",
396+
" <td>0.572021</td>\n",
397397
" </tr>\n",
398398
" <tr>\n",
399399
" <th>3</th>\n",
400400
" <td>trf</td>\n",
401-
" <td>0.232000</td>\n",
402-
" <td>0.771106</td>\n",
403-
" <td>0.633888</td>\n",
401+
" <td>0.235711</td>\n",
402+
" <td>0.721336</td>\n",
403+
" <td>0.572866</td>\n",
404404
" </tr>\n",
405405
" </tbody>\n",
406406
"</table>\n",
407407
"</div>"
408408
],
409409
"text/plain": [
410410
" Method Time Elapsed (min) Error / Baseline Error Error / Ground Truth\n",
411-
"0 L-BFGS-B 0.028414 0.767214 0.630689\n",
412-
"1 TNC 0.023116 0.808149 0.664340\n",
413-
"2 SLSQP 0.003840 0.767214 0.630689\n",
414-
"3 trf 0.232000 0.771106 0.633888"
411+
"0 L-BFGS-B 0.017857 0.720272 0.572021\n",
412+
"1 TNC 0.022109 0.755240 0.599792\n",
413+
"2 SLSQP 0.002948 0.720272 0.572021\n",
414+
"3 trf 0.235711 0.721336 0.572866"
415415
]
416416
},
417417
"execution_count": 13,
@@ -739,7 +739,7 @@
739739
" <th>fraction</th>\n",
740740
" <th>filename</th>\n",
741741
" <th>ms1_int_sum</th>\n",
742-
" <th>int_sum_dn</th>\n",
742+
" <th>ms1_int_sum_dn</th>\n",
743743
" </tr>\n",
744744
" </thead>\n",
745745
" <tbody>\n",
@@ -796,13 +796,13 @@
796796
"</div>"
797797
],
798798
"text/plain": [
799-
" precursor fraction filename ms1_int_sum int_sum_dn\n",
800-
"0 Prec_1 1 A 0.6 0.887676\n",
801-
"1 Prec_1 1 A 0.8 1.183568\n",
802-
"2 Prec_1 2 A 0.6 0.926809\n",
803-
"3 Prec_1 1 B 1.2 0.891552\n",
804-
"4 Prec_1 1 B 1.6 1.188736\n",
805-
"5 Prec_1 2 B 1.2 0.921659"
799+
" precursor fraction filename ms1_int_sum ms1_int_sum_dn\n",
800+
"0 Prec_1 1 A 0.6 0.887676\n",
801+
"1 Prec_1 1 A 0.8 1.183568\n",
802+
"2 Prec_1 2 A 0.6 0.926809\n",
803+
"3 Prec_1 1 B 1.2 0.891552\n",
804+
"4 Prec_1 1 B 1.6 1.188736\n",
805+
"5 Prec_1 2 B 1.2 0.921659"
806806
]
807807
},
808808
"metadata": {},
@@ -1217,43 +1217,49 @@
12171217
" \"\"\"\n",
12181218
" grouped, protein = chunk\n",
12191219
"\n",
1220-
" column_combinations = List()\n",
1221-
" [column_combinations.append(_) for _ in combinations(range(len(files)), 2)]\n",
1222-
" \n",
1220+
" files_ = grouped.index.get_level_values('filename').unique().tolist()\n",
1221+
"\n",
12231222
" selection = grouped.unstack().T.copy()\n",
12241223
" selection = selection.replace(0, np.nan)\n",
12251224
"\n",
1226-
" if not selection.shape[1] == len(files):\n",
1227-
" selection[[_ for _ in files if _ not in selection.columns]] = np.nan\n",
1225+
" if len(files_) > 1: \n",
1226+
" column_combinations = List()\n",
1227+
" [column_combinations.append(_) for _ in combinations(range(len(files_)), 2)]\n",
12281228
"\n",
1229-
" selection = selection[files]\n",
1230-
"\n",
1231-
" ratios = get_protein_ratios(selection.values, column_combinations, minimum_ratios)\n",
1232-
" \n",
1233-
" retry = False\n",
1234-
" try:\n",
1235-
" solution, success = solve_profile(ratios, 'L-BFGS-B')\n",
1236-
" except ValueError:\n",
1237-
" retry = True\n",
1238-
"\n",
1239-
" if retry or not success:\n",
1240-
" logging.info('Normalization with L-BFGS-B failed. Trying Powell')\n",
1241-
" solution, success = solve_profile(ratios, 'Powell')\n",
1229+
" ratios = get_protein_ratios(selection.values, column_combinations, minimum_ratios)\n",
12421230
" \n",
1243-
" pre_lfq = selection.sum().values\n",
1231+
" retry = False\n",
1232+
" try:\n",
1233+
" solution, success = solve_profile(ratios, 'L-BFGS-B')\n",
1234+
" except ValueError:\n",
1235+
" retry = True\n",
1236+
"\n",
1237+
" if retry or not success:\n",
1238+
" logging.info('Normalization with L-BFGS-B failed. Trying Powell')\n",
1239+
" solution, success = solve_profile(ratios, 'Powell')\n",
1240+
"\n",
1241+
" pre_lfq = selection.sum().values\n",
12441242
"\n",
1245-
" if not success or np.sum(~np.isnan(ratios)) == 0: # or np.sum(solution) == len(pre_lfq):\n",
1246-
" profile = np.zeros_like(pre_lfq)\n",
1247-
" if np.sum(np.isnan(ratios)) != ratios.size:\n",
1248-
" logging.info(f'Solver failed for protein {protein} despite available ratios:\\n {ratios}')\n",
1243+
" if not success or np.sum(~np.isnan(ratios)) == 0: # or np.sum(solution) == len(pre_lfq):\n",
1244+
" profile = np.zeros(len(files_))\n",
1245+
" if np.sum(np.isnan(ratios)) != ratios.size:\n",
1246+
" logging.info(f'Solver failed for protein {protein} despite available ratios:\\n {ratios}')\n",
12491247
"\n",
1248+
" else:\n",
1249+
" invalid = ((np.nansum(ratios, axis=1) == 0) & (np.nansum(ratios, axis=0) == 0))\n",
1250+
" peptide_int_sum = pre_lfq.sum() * solution \n",
1251+
" peptide_int_sum[invalid] = 0\n",
1252+
" profile = peptide_int_sum * pre_lfq.sum() / np.sum(peptide_int_sum) #Normalize inensity again\n",
12501253
" else:\n",
1251-
" invalid = ((np.nansum(ratios, axis=1) == 0) & (np.nansum(ratios, axis=0) == 0))\n",
1252-
" peptide_int_sum = pre_lfq.sum() * solution \n",
1253-
" peptide_int_sum[invalid] = 0\n",
1254-
" profile = peptide_int_sum * pre_lfq.sum() / np.sum(peptide_int_sum) #Normalize inensity again\n",
1255-
" \n",
1256-
" \n",
1254+
" pre_lfq = profile = selection.values[0]\n",
1255+
"\n",
1256+
"\n",
1257+
" #Rewrite ratios\n",
1258+
" profile_dict = dict(zip(files_, profile))\n",
1259+
" pre_dict = dict(zip(files_, pre_lfq))\n",
1260+
" profile = np.array([0 if file not in profile_dict else profile_dict[file] for file in files])\n",
1261+
" pre_lfq = np.array([0 if file not in pre_dict else pre_dict[file] for file in files])\n",
1262+
"\n",
12571263
" return profile, pre_lfq, protein \n"
12581264
]
12591265
},
@@ -1338,12 +1344,12 @@
13381344
],
13391345
"text/plain": [
13401346
" precursor filename protein_group ms1_int_sum\n",
1341-
"0 Prec_1 A X 0.6\n",
1342-
"1 Prec_1 B X 0.8\n",
1343-
"2 Prec_1 C X 1.0\n",
1344-
"3 Prec_2 A X 0.6\n",
1345-
"4 Prec_2 B X 1.2\n",
1346-
"5 Prec_2 C X 1.4"
1347+
"0 Prec_1 A X 0.6\n",
1348+
"1 Prec_1 B X 0.8\n",
1349+
"2 Prec_1 C X 1.0\n",
1350+
"3 Prec_2 A X 0.6\n",
1351+
"4 Prec_2 B X 1.2\n",
1352+
"5 Prec_2 C X 1.4"
13471353
]
13481354
},
13491355
"metadata": {},
@@ -1473,9 +1479,6 @@
14731479
"\n",
14741480
" #Take the best precursor for protein quantification. .max()\n",
14751481
" grouped = df[[field, 'filename','precursor','protein_group']].groupby(['protein_group','filename','precursor']).max()\n",
1476-
"\n",
1477-
" column_combinations = List()\n",
1478-
" [column_combinations.append(_) for _ in combinations(range(len(files)), 2)]\n",
14791482
" \n",
14801483
" files = df['filename'].unique().tolist()\n",
14811484
" files.sort()\n",

nbs/11_interface.ipynb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1600,12 +1600,14 @@
16001600
"\n",
16011601
"@click.command(\n",
16021602
" \"import\",\n",
1603-
" help=\"Import and convert raw data from vendor to `.ms_data.hdf` file.\",\n",
1604-
" short_help=\"Import and convert raw data from vendor to `.ms_data.hdf` file.\"\n",
1603+
" help=\"Import and convert raw data from vendor to `.ms_data.hdf` file with default settings.\",\n",
1604+
" short_help=\"Import and convert raw data from vendor to `.ms_data.hdf` file with default settings.\"\n",
16051605
")\n",
16061606
"@CLICK_SETTINGS_OPTION\n",
16071607
"def cli_import(settings_file):\n",
1608-
" settings = alphapept.settings.load_settings(settings_file)\n",
1608+
" from alphapept.paths import DEFAULT_SETTINGS_PATH\n",
1609+
" settings = alphapept.settings.load_settings_as_template(DEFAULT_SETTINGS_PATH)\n",
1610+
" settings['experiment']['file_paths'] = [settings_file]\n",
16091611
" import_raw_data(settings)\n",
16101612
"\n",
16111613
"\n",

release/one_click_linux_gui/control

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: alphapept
2-
Version: 0.4.0
2+
Version: 0.4.1
33
Architecture: all
44
Maintainer: Mann Labs <[email protected]>
55
Description: AlphaPept

release/one_click_linux_gui/create_installer_linux.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ python setup.py sdist bdist_wheel
1717
# Setting up the local package
1818
cd release/one_click_linux_gui
1919
# Make sure you include the required extra packages and always use the stable or very-stable options!
20-
pip install "../../dist/alphapept-0.4.0-py3-none-any.whl[stable,gui-stable]"
20+
pip install "../../dist/alphapept-0.4.1-py3-none-any.whl[stable,gui-stable]"
2121

2222
# Creating the stand-alone pyinstaller folder
2323
pip install pyinstaller==4.2

0 commit comments

Comments
 (0)