Skip to content

Commit

Permalink
Merge pull request #23 from MannLabs/development
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
ammarcsj authored Dec 8, 2023
2 parents 56e9080 + 6a2b8c8 commit 608a804
Show file tree
Hide file tree
Showing 11 changed files with 1,568 additions and 4,122 deletions.
10 changes: 5 additions & 5 deletions directlfq/dashboard_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,19 @@ def __init__(self):
self.path_protein_groups_file = pn.widgets.TextInput(
name='(optional) If you are using MaxQuant evidence.txt or peptides.txt files, you can add the link to the corresponding proteinGroups.txt file (will improve peptide-to-protein mapping)',
placeholder='(optional) Enter the whole path to the MaxQuant proteinGroups.txt file',
default = None,
value = None,
width=900,
sizing_mode='stretch_width',
margin=(15, 15, 0, 15)
)

## optional files

self.additional_headers_title = pn.pane.Markdown('* Add the names of columns that you want to keep in the directLFQ output file, separated by semicolons. Note that some basic additional columns such as gene names are always added to the output table by default.\nWARNING: Take care that columns you add are not ambigous. For example, adding the peptide sequence column will not work, because there are multiple peptide sequences per protein.')
self.additional_headers_title = pn.pane.Markdown('* Add the names of columns that you want to keep in the directLFQ output file, separated by semicolons. Note that some basic additional columns such as gene names are always added to the output table by value.\nWARNING: Take care that columns you add are not ambigous. For example, adding the peptide sequence column will not work, because there are multiple peptide sequences per protein.')
self.additional_headers = pn.widgets.TextInput(
name='',
placeholder='(optional) Enter the names of columns that you want to keep',
default = None,
value = None,
#width=900,
#sizing_mode='stretch_width',
#margin=(15, 15, 0, 15)
Expand All @@ -169,7 +169,7 @@ def __init__(self):
self.protein_subset_for_normalization_title = pn.pane.Markdown('* Specify a list of proteins (no header, seperated by linebreaks) that you want to use for normalization. This could for example be a list of housekeeping proteins:')
self.protein_subset_for_normalization_file = pn.widgets.TextInput(
name='',
default = None,
value = None,
placeholder='(optional) Enter the whole path to the protein list file',
width=900,
sizing_mode='stretch_width',
Expand All @@ -179,7 +179,7 @@ def __init__(self):
self.yaml_filt_dict_title = pn.pane.Markdown('* In case you want to define specific filters in addition to the standard filters, you can add a yaml file where the filters are defined (see GitHub docs).')
self.yaml_filt_dict_path = pn.widgets.TextInput(
name='',
default = None,
value = None,
placeholder='(optional) Enter the whole path to the yaml file with the filters',
width=900,
sizing_mode='stretch_width',
Expand Down
60 changes: 60 additions & 0 deletions directlfq/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import numpy as np
import pandas as pd

from numpy.random import MT19937
from numpy.random import RandomState, SeedSequence

class ProteinProfileGenerator():
def __init__(self, peptide_profiles):
self._peptide_profiles = peptide_profiles

self.protein_profile_dataframe = None
self._generate_protein_profile_dataframe()

def _generate_protein_profile_dataframe(self):
collected_profiles = [x.peptide_profile_vector for x in self._peptide_profiles]
protnames_for_index = [x.protein_name for x in self._peptide_profiles]
pepnames_for_index = [f'{idx}' for idx in range(len(self._peptide_profiles))]
self.protein_profile_dataframe = pd.DataFrame(collected_profiles,index=[protnames_for_index, pepnames_for_index])
self.protein_profile_dataframe.index.names = ['protein', 'ion']
self.protein_profile_dataframe = np.log2(self.protein_profile_dataframe.replace(0, np.nan))



class PeptideProfile():
def __init__(self, protein_name, fraction_zeros_in_profile, systematic_peptide_shift, add_noise, num_samples = 20, min_intensity = 1e6, max_intensity = 1e10):


self._fraction_zeros_in_profile = fraction_zeros_in_profile
self._systematic_peptide_shift = systematic_peptide_shift
self._add_noise = add_noise
self._min_intensity = min_intensity
self._max_intensity = max_intensity
self._num_samples = num_samples

self.protein_name = protein_name
self.peptide_profile_vector = []
self._define_peptide_profile_vector()

def _define_peptide_profile_vector(self):
self.peptide_profile_vector = self._get_single_peptide_profile_template()
self._scale_profile_vector()
if self._add_noise:
self._apply_poisson_noise_to_profilevector()
self._add_zeros_to_profilevector()

def _get_single_peptide_profile_template(self):
rs = RandomState(MT19937(SeedSequence(42312)))
return rs.randint(low=self._min_intensity, high=self._max_intensity,size=self._num_samples)

def _scale_profile_vector(self):
self.peptide_profile_vector = self.peptide_profile_vector*self._systematic_peptide_shift

def _apply_poisson_noise_to_profilevector(self):
self.peptide_profile_vector = np.random.poisson(lam=self.peptide_profile_vector, size=len(self.peptide_profile_vector))

def _add_zeros_to_profilevector(self):
num_elements_to_set_zero = int(self._num_samples*self._fraction_zeros_in_profile)
idxs_to_set_zero = np.random.choice(self._num_samples,size=num_elements_to_set_zero, replace=False)
self.peptide_profile_vector[idxs_to_set_zero] = 0

2 changes: 1 addition & 1 deletion misc/loose_pip_install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
conda create -n directlfq python=3.8 -y
conda activate directlfq
pip install -e '../.[development, gui]'
pip install -e '../.[development-stable, gui]'
directlfq
conda deactivate
120 changes: 0 additions & 120 deletions nbdev_nbs/01_lfq_manager.ipynb

This file was deleted.

1,187 changes: 1,030 additions & 157 deletions nbdev_nbs/02_normalization.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 608a804

Please sign in to comment.