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

Cleanup unused numba functions #273

Merged
merged 10 commits into from
Jul 15, 2024
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
450 changes: 0 additions & 450 deletions alphadia/features.py

Large diffs are not rendered by default.

38 changes: 0 additions & 38 deletions alphadia/numba/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,6 @@ def wrap1(
return values


@nb.njit
def get_mean0(dense, scan, cycle):
"""create a fixed window around the peak and extract the mean value"""
# window size around peak
w = 4

# extract mz
mz_window = dense[
max(scan - w, 0) : scan + w, max(cycle - w, 0) : cycle + w
].flatten()

return np.mean(mz_window)


@nb.njit
def get_mean_sparse0(dense, scan, cycle, threshold):
"""create a fixed window around the peak and extract the mean value"""
# window size around peak
w = 4

# extract mz
mz_window = dense[
max(scan - w, 0) : scan + w, max(cycle - w, 0) : cycle + w
].flatten()

mask = mz_window < threshold
fraction_nonzero = np.mean(mask.astype("int8"))

values = np.mean(mz_window[mask]) if fraction_nonzero > 0 else threshold

return values


@nb.njit
def symetric_limits_1d(
array_1d,
Expand Down Expand Up @@ -376,8 +343,3 @@ def fragment_correlation_different(x: np.ndarray, y: np.ndarray):
output[i_observations] = correlation_matrix

return output


@nb.njit(inline="always")
def amean(array, axis):
return np.sum(array, axis=axis) / array.shape[axis]
145 changes: 0 additions & 145 deletions alphadia/peakgroup/search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# native imports
import logging
import os

# alpha family imports
import alphatims
Expand Down Expand Up @@ -977,147 +976,3 @@ def assemble_precursor_df(self, precursors_flat):
precursors_flat[self.precursor_mz_column].values,
precursors_flat[available_isotope_columns].values.copy(),
)

def assemble_candidates(self, elution_group_container):
"""
Candidates are collected from the ElutionGroup objects and assembled into a pandas.DataFrame.

Parameters
----------
elution_group_container : ElutionGroupContainer
container object containing a list of ElutionGroup objects

Returns
-------
pandas.DataFrame
dataframe containing the extracted candidates

"""

candidates = []
for i in range(len(elution_group_container)):
for j in range(len(elution_group_container[i].candidates)):
candidates.append(elution_group_container[i].candidates[j])

candidate_attributes = [
"elution_group_idx",
"score_group_idx",
"precursor_idx",
"rank",
"score",
"precursor_mz",
"decoy",
"channel",
"scan_center",
"scan_start",
"scan_stop",
"frame_center",
"frame_start",
"frame_stop",
]
candidate_df = pd.DataFrame(
{
attr: [getattr(c, attr) for c in candidates]
for attr in candidate_attributes
}
)
candidate_df = candidate_df.sort_values(by="precursor_idx")

# add additiuonal columns for precursor information
precursor_attributes = ["mz_calibrated", "mz_library"]

precursor_pidx = self.precursors_flat["precursor_idx"].values
candidate_pidx = candidate_df["precursor_idx"].values
precursor_flat_lookup = np.searchsorted(
precursor_pidx, candidate_pidx, side="left"
)

for attr in precursor_attributes:
if attr in self.precursors_flat.columns:
candidate_df[attr] = self.precursors_flat[attr].values[
precursor_flat_lookup
]

# DEBUG: save features for training if desired.
if self.feature_path is not None:
feature_matrix = np.zeros(
(len(candidates), len(candidates[0].features)), dtype=np.float32
)
for i in range(len(candidates)):
feature_matrix[i, :] = candidates[i].features

np.save(os.path.join(self.feature_path, "features.npy"), feature_matrix)

sub_df = candidate_df[
[
"elution_group_idx",
"score_group_idx",
"precursor_idx",
"rank",
"score",
"decoy",
]
]
sub_df.to_csv(
os.path.join(self.feature_path, "candidates.tsv"), index=False, sep="\t"
)

return candidate_df

def append_precursor_information(self, df):
"""
Append relevant precursor information to the candidates dataframe.

Parameters
----------
df : pandas.DataFrame
dataframe containing the extracted candidates

Returns
-------
pandas.DataFrame
dataframe containing the extracted candidates with precursor information appended
"""

# precursor_flat_lookup has an element for every candidate and contains the index of the respective precursor
precursor_pidx = self.precursors_flat["precursor_idx"].values
candidate_pidx = df["precursor_idx"].values
precursor_flat_lookup = np.searchsorted(
precursor_pidx, candidate_pidx, side="left"
)

df["decoy"] = self.precursors_flat["decoy"].values[precursor_flat_lookup]

df["rt_library"] = self.precursors_flat["rt_library"].values[
precursor_flat_lookup
]
if self.rt_column == "rt_calibrated":
df["rt_calibrated"] = self.precursors_flat["rt_calibrated"].values[
precursor_flat_lookup
]

df["mobility_library"] = self.precursors_flat["mobility_library"].values[
precursor_flat_lookup
]
if self.mobility_column == "mobility_calibrated":
df["mobility_calibrated"] = self.precursors_flat[
"mobility_calibrated"
].values[precursor_flat_lookup]

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]

for col in available_isotope_columns:
df[col] = self.precursors_flat[col].values[precursor_flat_lookup]

return df
18 changes: 13 additions & 5 deletions gui/src/main/modules/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { exec, execFile, spawn } = require('child_process');
const StringDecoder = require('string_decoder').StringDecoder;
const Transform = require('stream').Transform;

const { app, dialog } = require('electron');
const { app, dialog, BrowserWindow } = require('electron');
const writeYamlFile = require('write-yaml-file')

const { workflowToConfig } = require('./workflows');
Expand Down Expand Up @@ -287,7 +287,9 @@ class CMDExecutionEngine extends BaseExecutionEngine {
return run
}).catch((err) => {
console.log(err)
dialog.showMessageBox({
dialog.showMessageBox(
BrowserWindow.getFocusedWindow(),
{
type: 'error',
title: 'Error while starting workflow',
message: `Could not start workflow. ${err}`,
Expand Down Expand Up @@ -358,7 +360,9 @@ class BundledExecutionEngine extends BaseExecutionEngine {
}).catch((err) => {
this.available = false
this.error = err
dialog.showMessageBox({
dialog.showMessageBox(
BrowserWindow.getFocusedWindow(),
{
type: 'error',
title: 'Error while checking availability of bundled alphaDIA',
message: `Could not start bundled alphaDIA. ${err}`,
Expand Down Expand Up @@ -449,7 +453,9 @@ class BundledExecutionEngine extends BaseExecutionEngine {
return run
}).catch((err) => {
console.log(err)
dialog.showMessageBox({
dialog.showMessageBox(
BrowserWindow.getFocusedWindow(),
{
type: 'error',
title: 'Error while starting workflow',
message: `Could not start workflow. ${err}`,
Expand Down Expand Up @@ -615,7 +621,9 @@ class WSLExecutionEngine extends BaseExecutionEngine {
return run
}).catch((err) => {
console.log(err)
dialog.showMessageBox({
dialog.showMessageBox(
BrowserWindow.getFocusedWindow(),
{
type: 'error',
title: 'Error while starting workflow',
message: `Could not start workflow. ${err}`,
Expand Down
19 changes: 13 additions & 6 deletions gui/src/main/modules/profile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs")
const path = require("path")
const { app, shell} = require("electron")
const { app, shell, BrowserWindow} = require("electron")
const { dialog } = require('electron')

const VERSION = "1.7.1"
Expand Down Expand Up @@ -42,10 +42,15 @@ const Profile = class {
}

loadProfile() {
let loaded_config = {}

try {
config = JSON.parse(fs.readFileSync(this.getProfilePath()))
loaded_config = JSON.parse(fs.readFileSync(this.getProfilePath()))
console.log(loaded_config)
} catch (err) {
dialog.showMessageBox({
dialog.showMessageBox(
BrowserWindow.getFocusedWindow(),
{
type: 'error',
title: 'Error while loading profile',
message: `Could not load profile. ${err}`,
Expand All @@ -55,8 +60,10 @@ const Profile = class {
return
}

if (config.version !== VERSION) {
dialog.showMessageBox({
if (loaded_config.version !== VERSION) {
dialog.showMessageBox(
BrowserWindow.getFocusedWindow(),
{
type: 'info',
title: 'Found old alphaDIA profile',
message: `Found old alphaDIA profile. Updating to version ${VERSION}`,
Expand All @@ -65,7 +72,7 @@ const Profile = class {
})
this.saveProfile()
} else {
this.config = config
this.config = loaded_config
}
}

Expand Down
42 changes: 41 additions & 1 deletion gui/src/renderer/components/ParameterInput.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
import * as React from 'react'
import styled from '@emotion/styled'

import { Box, Checkbox, FormControl, MenuItem, Select, Stack, Tooltip, Typography, TextField } from '@mui/material'
import { Box, Chip, Button, Checkbox, FormControl, MenuItem, Select, Stack, Tooltip, Typography, TextField } from '@mui/material'

const StyledCheckbox = styled(Checkbox)(({ theme }) => ({
padding: 0.5
}))

const SingleFolderSelection = ({parameter, onChange = () => {}}) => {

const handleSelect = () => {
window.electronAPI.getSingleFolder().then((folder) => {
onChange(folder);
}).catch((err) => {
console.log(err);
})
}

const folderName = parameter.replace(/^.*[\\\/]/, '')

return (
<>
{folderName == ''? '':
<Chip
label={folderName}
onDelete={() => {onChange("")}}
size="small"
/>
}
<Button
variant="outlined"
size="small"
sx={{width: "150px"}}
onClick={handleSelect}>
Select Folder
</Button>
</>

)
}

const ParameterInput = ({
parameter,
onChange = () => {},
Expand Down Expand Up @@ -132,6 +165,13 @@ const ParameterInput = ({
/>
</Box>)
break;
case "singleFolderSelection":
input = (
<SingleFolderSelection
parameter={parameter.value}
onChange={onChange}
/>)
break;

default:
input = (
Expand Down
6 changes: 3 additions & 3 deletions gui/src/renderer/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const Home = () => (
Documentation
</Typography>
<br/>
<StyledLink onClick={() => window.electronAPI.openLink("http://www.google.com")}>
<StyledLink onClick={() => window.electronAPI.openLink("https://alphadia.readthedocs.io/en/latest/")}>
Link
</StyledLink>
</Box>
Expand All @@ -122,7 +122,7 @@ const Home = () => (
GitHub
</Typography>
<br/>
<StyledLink onClick={() => window.electronAPI.openLink("http://www.google.com")}>
<StyledLink onClick={() => window.electronAPI.openLink("https://github.com/MannLabs/alphadia")}>
Link
</StyledLink>
</Box>
Expand All @@ -141,7 +141,7 @@ const Home = () => (
Universe
</Typography>
<br/>
<StyledLink onClick={() => window.electronAPI.openLink("http://www.google.com")} sx={{color: "white !important"}}>
<StyledLink onClick={() => window.electronAPI.openLink("https://github.com/MannLabs")} sx={{color: "white !important"}}>
Link
</StyledLink>
</Box>
Expand Down
Loading
Loading