Skip to content

Commit

Permalink
Merge pull request #42 from MannLabs/development
Browse files Browse the repository at this point in the history
Release 1.3.1
  • Loading branch information
GeorgWa authored Aug 17, 2023
2 parents 2851cee + 4030235 commit e1d0d62
Show file tree
Hide file tree
Showing 27 changed files with 278 additions and 160 deletions.
2 changes: 1 addition & 1 deletion alphadia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


__project__ = "alphadia"
__version__ = "1.3.0"
__version__ = "1.3.1"
__license__ = "Apache"
__description__ = "An open-source Python package of the AlphaPept ecosystem"
__author__ = "Mann Labs"
Expand Down
80 changes: 66 additions & 14 deletions alphadia/extraction/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,51 @@ def get_dense(
absolute_masses = absolute_masses
)

@nb.njit()
import numba as nb
@alphatims.utils.pjit()
def transpose_chunk(
chunk_idx,
chunks,
push_indices,
push_indptr,
tof_indices,
tof_indptr,
values,
new_values,
tof_indcount
):

tof_index_chunk_start = chunks[chunk_idx]
tof_index_chunk_stop = chunks[chunk_idx+1]

for push_idx in range(len(push_indptr)-1):
start_push_indptr = push_indptr[push_idx]
stop_push_indptr = push_indptr[push_idx + 1]

for idx in range(start_push_indptr, stop_push_indptr):
# new row
tof_index = tof_indices[idx]
if tof_index_chunk_start <= tof_index and tof_index < tof_index_chunk_stop:
push_indices[tof_indptr[tof_index] + tof_indcount[tof_index]] = push_idx
new_values[tof_indptr[tof_index] + tof_indcount[tof_index]] = values[idx]
tof_indcount[tof_index] += 1

@nb.njit
def build_chunks(number_of_elements, num_chunks):
# Calculate the number of chunks needed
chunk_size = (number_of_elements + num_chunks - 1) // num_chunks

chunks = [0]
start = 0

for _ in range(num_chunks):
stop = min(start + chunk_size, number_of_elements)
chunks.append(stop)
start = stop

return np.array(chunks)

@nb.njit
def transpose(
tof_indices,
push_indptr,
Expand All @@ -741,6 +785,9 @@ def transpose(
values : np.ndarray
values (n_values)
threads : int
number of threads to use
Returns
-------
Expand Down Expand Up @@ -774,18 +821,23 @@ def transpose(
# get new values
push_indices = np.zeros((len(tof_indices)), dtype=np.uint32)
new_values = np.zeros_like(values)

for push_idx in range(len(push_indptr)-1):
start_push_indptr = push_indptr[push_idx]
stop_push_indptr = push_indptr[push_idx + 1]

for idx in range(start_push_indptr, stop_push_indptr):

# new row
tof_index = tof_indices[idx]

push_indices[tof_indptr[tof_index] + tof_indcount[tof_index]] = push_idx
new_values[tof_indptr[tof_index] + tof_indcount[tof_index]] = values[idx]
tof_indcount[tof_index] += 1

chunks = build_chunks(max_tof_index+1, 20)

with nb.objmode:
alphatims.utils.set_threads(20)

transpose_chunk(
range(len(chunks)-1),
chunks,
push_indices,
push_indptr,
tof_indices,
tof_indptr,
values,
new_values,
tof_indcount,

)

return push_indices, tof_indptr, new_values
8 changes: 6 additions & 2 deletions alphadia/extraction/fdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ def fdr_to_q_values(
def get_q_values(
_df : pd.DataFrame,
score_column : str = 'proba',
decoy_column : str = '_decoy'
decoy_column : str = '_decoy',
qval_column : str = 'qval'
):
"""Calculates q-values for a dataframe containing PSMs.
Expand All @@ -189,6 +190,9 @@ def get_q_values(
The name of the column containing the decoy information.
Decoys are expected to be 1 and targets 0.
qval_column : str, default='qval'
The name of the column to store the q-values in.
Returns
-------
Expand All @@ -201,7 +205,7 @@ def get_q_values(
decoy_cumsum = np.cumsum(_df[decoy_column].values)
target_cumsum = np.cumsum(target_values)
fdr_values = decoy_cumsum/target_cumsum
_df['qval'] = fdr_to_q_values(fdr_values)
_df[qval_column] = fdr_to_q_values(fdr_values)
return _df

def plot_fdr(
Expand Down
3 changes: 2 additions & 1 deletion alphadia/extraction/hybridselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,8 +1308,9 @@ def append_precursor_information(

df['flat_frag_start_idx'] = self.precursors_flat['flat_frag_start_idx'].values[precursor_flat_lookup]
df['flat_frag_stop_idx'] = self.precursors_flat['flat_frag_stop_idx'].values[precursor_flat_lookup]

df['charge'] = self.precursors_flat['charge'].values[precursor_flat_lookup]
df['proteins'] = self.precursors_flat['proteins'].values[precursor_flat_lookup]
df['genes'] = self.precursors_flat['genes'].values[precursor_flat_lookup]

available_isotopes = utils.get_isotope_columns(self.precursors_flat.columns)
available_isotope_columns = [f'i_{i}' for i in available_isotopes]
Expand Down
4 changes: 4 additions & 0 deletions alphadia/extraction/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ def build_output(self):

for raw_name, dia_path, speclib in self.get_run_data():
run_path = os.path.join(temp_path, raw_name)
psm_path = os.path.join(run_path, 'psm.tsv')
if not os.path.exists(psm_path):
logger.warning(f'no psm file found for {raw_name}')
continue
run_df = pd.read_csv(os.path.join(run_path, 'psm.tsv'), sep='\t')

psm_df.append(run_df)
Expand Down
4 changes: 3 additions & 1 deletion alphadia/extraction/plexscoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,9 @@ def collect_candidates(
'decoy',
'channel',
'flat_frag_start_idx',
'flat_frag_stop_idx'
'flat_frag_stop_idx',
'proteins',
'genes'
] + utils.get_isotope_column_names(self.precursors_flat_df.columns)
df = utils.merge_missing_columns(
df,
Expand Down
2 changes: 1 addition & 1 deletion alphadia/extraction/workflow/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def get_classifier(self, available_columns):
classifier = self.classifier_store[classifier_hash]
else:
classifier = sklearn.base.clone(self.classifier_base)

return classifier
if isinstance(classifier, sklearn.pipeline.Pipeline):
for step in classifier.steps:
if hasattr(step[1], 'warm_start'):
Expand Down
12 changes: 6 additions & 6 deletions alphadia/extraction/workflow/peptidecentric.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,11 @@ def calibration(self):
self.recalibration(precursor_df, fragments_df)
break
else:
pass

# check if last step has been reached
if current_step == len(self.batch_plan) - 1:
logger.info('Searched all data without finding recalibration target')
raise RuntimeError('Searched all data without finding recalibration target')

self.end_of_epoch()

if 'final_full_calibration' in self.config['calibration']:
Expand Down Expand Up @@ -454,9 +457,6 @@ def check_recalibration(self, precursor_df):

if self.com.accumulated_precursors_001FDR > self.com.recalibration_target:
perform_recalibration = True

if self.com.current_step == len(self.batch_plan) -1:
perform_recalibration = True

return perform_recalibration

Expand Down Expand Up @@ -640,7 +640,7 @@ def requantify(
psm_df = self.fdr_manager.fit_predict(
multiplexed_features,
decoy_strategy='channel',
competetive = self.config['fdr']['competetive_scoring'],
competetive = self.config['multiplexing']['competetive_scoring'],
decoy_channel=decoy_channel,
)

Expand Down
2 changes: 1 addition & 1 deletion gui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alphadia",
"productName": "alphadia-gui",
"version": "1.3.0",
"version": "1.3.1",
"description": "Graphical user interface for DIA data analysis",
"main": "dist/electron.js",
"homepage": "./",
Expand Down
26 changes: 12 additions & 14 deletions gui/src/main/electron.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain, dialog, shell, nativeTheme } = require('electron')
const { app, BrowserWindow, Menu, ipcMain, dialog, shell, nativeTheme } = require('electron')
const osu = require('node-os-utils')
const path = require("path");
const writeYamlFile = require('write-yaml-file')
Expand All @@ -7,14 +7,17 @@ const os = require('os')

const { handleGetSingleFolder,handleGetMultipleFolders, handleGetSingleFile, handleGetMultipleFiles} = require('./modules/dialogHandler')
const { discoverWorkflows, workflowToConfig } = require('./modules/workflows')
const { getEnvironmentStatus, lineBreakTransform, CondaEnvironment} = require('./modules/cmd');
const { CondaEnvironment} = require('./modules/cmd');
const { buildMenu } = require('./modules/menu')
const { Profile } = require('./modules/profile')

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) app.quit();

let mainWindow;
let workflows;
let environment;
let profile;

function createWindow() {
// Create the browser window.
Expand All @@ -32,14 +35,18 @@ function createWindow() {
},
});
mainWindow.setTitle("alphaDIA");
mainWindow.removeMenu()
mainWindow.loadFile(path.join(__dirname, "../dist/index.html"));

profile = new Profile()

Menu.setApplicationMenu(buildMenu(mainWindow, profile));

// Open the DevTools if NODE_ENV=dev
if (process.env.NODE_ENV === "dev"){
mainWindow.webContents.openDevTools({ mode: "detach" });
}
environment = new CondaEnvironment("alpha")

environment = new CondaEnvironment(profile)
workflows = discoverWorkflows(mainWindow)
}

Expand Down Expand Up @@ -82,7 +89,7 @@ function handleStartWorkflow(workflow) {
// save config.yaml in workflow folder
writeYamlFile.sync(configPath, config, {lineWidth: -1})

return environment.spawn(`conda run -n ${environment.envName} --no-capture-output alphadia extract --config ${configPath}`)
return environment.spawn(`conda run -n ${profile.config.conda.envName} --no-capture-output alphadia extract --config ${configPath}`)
}

// This method will be called when Electron has finished
Expand Down Expand Up @@ -122,15 +129,6 @@ app.whenReady().then(() => {
powerMonitor.on("suspend", () => {
powerSaveBlocker.start("prevent-app-suspension");
});

mainWindow.webContents.on('render-process-gone', function (event, detailed) {
console.log("!crashed, reason: " + detailed.reason + ", exitCode = " + detailed.exitCode)
if (detailed.reason == "crashed"){
// relaunch app
app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) })
app.exit(0)
}
})
});

app.on('window-all-closed', () => {
Expand Down
Loading

0 comments on commit e1d0d62

Please sign in to comment.