-
Notifications
You must be signed in to change notification settings - Fork 1
Add Layout Components for TnT #12
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
Changes from all commits
612b994
9b2abe7
ed24cea
6dd4b12
e303aa1
7f3b164
0aa1fc4
85e829f
66d0b2e
8e45563
8e284bc
cf6123c
5def8b0
8a21c76
1b842d5
3b0ab94
8dc755a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from io import StringIO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pyopenms import AASequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from scipy.stats import gaussian_kde | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from src.parse.masstable import parseFLASHDeconvOutput, parseFLASHTaggerOutput | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from src.render.sequence import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -157,4 +158,31 @@ def parseTnT(file_manager, dataset_id, deconv_mzML, anno_mzML, tag_tsv, protein_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_manager.store_data( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dataset_id, 'settings', settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| density_target, density_decoy = fdr_density_distribution(protein_df, logger=logger) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_manager.store_data(dataset_id, 'density_id_target', density_target) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_manager.store_data(dataset_id, 'density_id_decoy', density_decoy) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def fdr_density_distribution(df, logger=None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| df = df[df['ProteoformLevelQvalue'] > 0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Find density targets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_qscores = df[~df['accession'].str.startswith('DECOY_')]['ProteoformLevelQvalue'].dropna() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if len(target_qscores) > 0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| x_target = np.linspace(target_qscores.min(), target_qscores.max(), 200) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| kde_target = gaussian_kde(target_qscores) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| density_target = pd.DataFrame({'x': x_target, 'y': kde_target(x_target)}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| density_target = pd.DataFrame(columns=['x', 'y']) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Find density decoys (if present) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| decoy_qscores = df[df['accession'].str.startswith('DECOY_')]['ProteoformLevelQvalue'].dropna() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if len(decoy_qscores) > 0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| x_decoy = np.linspace(decoy_qscores.min(), decoy_qscores.max(), 200) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| kde_decoy = gaussian_kde(decoy_qscores) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| density_decoy = pd.DataFrame({'x': x_decoy, 'y': kde_decoy(x_decoy)}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| density_decoy = pd.DataFrame(columns=['x', 'y']) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return density_target, density_decoy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+168
to
+188
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Implement error handling for the KDE computation. While the function correctly computes the kernel density estimates for target and decoy distributions, it could benefit from additional error handling. The def fdr_density_distribution(df, logger=None):
df = df[df['ProteoformLevelQvalue'] > 0]
# Find density targets
target_qscores = df[~df['accession'].str.startswith('DECOY_')]['ProteoformLevelQvalue'].dropna()
if len(target_qscores) > 0:
+ try:
x_target = np.linspace(target_qscores.min(), target_qscores.max(), 200)
kde_target = gaussian_kde(target_qscores)
density_target = pd.DataFrame({'x': x_target, 'y': kde_target(x_target)})
+ except Exception as e:
+ if logger:
+ logger.warning(f"Failed to compute KDE for target distribution: {str(e)}")
+ density_target = pd.DataFrame(columns=['x', 'y'])
else:
density_target = pd.DataFrame(columns=['x', 'y'])
# Find density decoys (if present)
decoy_qscores = df[df['accession'].str.startswith('DECOY_')]['ProteoformLevelQvalue'].dropna()
if len(decoy_qscores) > 0:
+ try:
x_decoy = np.linspace(decoy_qscores.min(), decoy_qscores.max(), 200)
kde_decoy = gaussian_kde(decoy_qscores)
density_decoy = pd.DataFrame({'x': x_decoy, 'y': kde_decoy(x_decoy)})
+ except Exception as e:
+ if logger:
+ logger.warning(f"Failed to compute KDE for decoy distribution: {str(e)}")
+ density_decoy = pd.DataFrame(columns=['x', 'y'])
else:
density_decoy = pd.DataFrame(columns=['x', 'y'])
return density_target, density_decoy📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -104,6 +104,12 @@ def initialize_data(comp_name, selected_data, file_manager, tool): | |||||||||||||||||||||||||||||||||||||||||||||
| data = file_manager.get_results(selected_data, ['density_decoy']) | ||||||||||||||||||||||||||||||||||||||||||||||
| data_to_send['density_decoy'] = data['density_decoy'] | ||||||||||||||||||||||||||||||||||||||||||||||
| component_arguments = FDRPlotly(title="FDR Plot") | ||||||||||||||||||||||||||||||||||||||||||||||
| elif comp_name == 'id_fdr_plot': | ||||||||||||||||||||||||||||||||||||||||||||||
| data = file_manager.get_results(selected_data, ['density_id_target']) | ||||||||||||||||||||||||||||||||||||||||||||||
| data_to_send['density_target'] = data['density_id_target'] | ||||||||||||||||||||||||||||||||||||||||||||||
| data = file_manager.get_results(selected_data, ['density_id_decoy']) | ||||||||||||||||||||||||||||||||||||||||||||||
| data_to_send['density_decoy'] = data['density_id_decoy'] | ||||||||||||||||||||||||||||||||||||||||||||||
| component_arguments = FDRPlotly(title="FDR Plot") | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+107
to
+112
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding error handling for missing density datasets. The code doesn't have explicit error handling for cases where elif comp_name == 'id_fdr_plot':
+ try:
data = file_manager.get_results(selected_data, ['density_id_target'])
data_to_send['density_target'] = data['density_id_target']
data = file_manager.get_results(selected_data, ['density_id_decoy'])
data_to_send['density_decoy'] = data['density_id_decoy']
component_arguments = FDRPlotly(title="FDR Plot")
+ except KeyError:
+ # Handle missing datasets
+ data_to_send['density_target'] = pd.DataFrame(columns=['x', 'y'])
+ data_to_send['density_decoy'] = pd.DataFrame(columns=['x', 'y'])
+ component_arguments = FDRPlotly(title="FDR Plot (No Data Available)")Alternatively, using the elif comp_name == 'id_fdr_plot':
- data = file_manager.get_results(selected_data, ['density_id_target'])
- data_to_send['density_target'] = data['density_id_target']
- data = file_manager.get_results(selected_data, ['density_id_decoy'])
- data_to_send['density_decoy'] = data['density_id_decoy']
+ data = file_manager.get_results(selected_data, ['density_id_target', 'density_id_decoy'], partial=True)
+ data_to_send['density_target'] = data.get('density_id_target', pd.DataFrame(columns=['x', 'y']))
+ data_to_send['density_decoy'] = data.get('density_id_decoy', pd.DataFrame(columns=['x', 'y']))
component_arguments = FDRPlotly(title="FDR Plot")📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| elif comp_name == 'protein_table': | ||||||||||||||||||||||||||||||||||||||||||||||
| # TODO: Unify lookup or remove in vue | ||||||||||||||||||||||||||||||||||||||||||||||
| data = file_manager.get_results(selected_data, ['scan_table']) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify component mapping between options and names.
The component name
'combined_spectrum'at line 25 appears to map to'Sequence tag view (Tag table needed)'in the options list based on position. Please verify this mapping is correct, as there seems to be a potential mismatch.🏁 Script executed:
Length of output: 556
🏁 Script executed:
Length of output: 12478
Fix misaligned COMPONENT_OPTIONS/COMPONENT_NAMES entries
The 5th and 6th elements in your arrays are currently swapped/misnamed:
'Sequence tag view (Tag table needed)'↔ COMPONENT_NAMES[4] ='combined_spectrum''Score Distribution Plot'↔ COMPONENT_NAMES[5] ='id_fdr_plot'These mappings don’t align semantically. Please update one or both lists so that:
'Sequence tag view (Tag table needed)'maps to a name like'sequence_tag_view''Score Distribution Plot'maps to something like'score_distribution_plot''combined_spectrum'pairs with its intended option label (e.g.'Combined spectrum')Locations:
Suggested diff sketch:
COMPONENT_OPTIONS = [ …, - 'Sequence tag view (Tag table needed)', + 'Combined spectrum', # new or corrected label + 'Sequence tag view (Tag table needed)', 'Score Distribution Plot', … ] COMPONENT_NAMES = [ …, - 'combined_spectrum', - 'id_fdr_plot', + 'combined_spectrum', # match new/renamed option above + 'sequence_tag_view', # maps to Sequence tag view + 'score_distribution_plot', # maps to Score Distribution Plot … ]