From d1e80b06db9ed2593cdd402e85ec718fae2469ba Mon Sep 17 00:00:00 2001 From: pgarrett Date: Mon, 27 Nov 2023 10:27:06 -0800 Subject: [PATCH] fixed accession issue, where sequence wouldn't reset properly, and throw an error. --- app.py | 349 +++++++++++++++++++++++++++++++++------------------ constants.py | 13 +- util.py | 141 ++++++++++++++++++++- 3 files changed, 379 insertions(+), 124 deletions(-) diff --git a/app.py b/app.py index d2246ce..60cf42d 100644 --- a/app.py +++ b/app.py @@ -1,34 +1,54 @@ -import pickle +import uuid from collections import Counter +import random import pandas as pd import streamlit as st -import numpy as np -import requests from peptacular.sequence import strip_modifications, calculate_sequence_length from peptacular.digest import identify_cleavage_sites from peptacular.mass import valid_mass_sequence from peptacular.constants import AMINO_ACIDS from peptacular.spans import calculate_span_coverage import matplotlib as mpl +import regex as reg from constants import * from wiki import * -from util import make_clickable, generate_peptide_df, bin_aa_counts, coverage_string, create_colorbar - - -def fetch_sequence_from_uniprot(accession_number): - url = f"https://www.uniprot.org/uniprot/{accession_number}.fasta" - response = requests.get(url) - if response.status_code != 200: - st.error(f"Error fetching sequence from UniProt: {response.status_code}") - st.stop() - return None - return ''.join(response.text.split('\n')[1:]) # Remove the header line - +from util import make_clickable, generate_peptide_df, coverage_string, create_colorbar, generate_app_url, \ + fetch_sequence_from_uniprot st.set_page_config(page_title="proteincleaver", page_icon=":knife:", layout="wide") +# Parse query parameters +params = st.experimental_get_query_params() +query_peptide_sequence = params.get('protein_sequence', [DEFAULT_PROTEIN_SEQUENCE])[0] +query_proteases = params.get('proteases', [';'.join(DEFAULT_PROTEASES)])[0].split(',') +query_custom_regex = params.get('custom_regex', [''])[0] +query_missed_cleavages = int(params.get('missed_cleavages', [DEFAULT_MISSED_CLEAVAGES])[0]) +query_mass_type = params.get('mass_type', [DEFAULT_MASS_TYPE])[0] +query_min_peptide_len = int(params.get('min_peptide_len', [DEFAULT_MIN_PEPTIDE_LEN])[0]) +query_max_peptide_len = int(params.get('max_peptide_len', [DEFAULT_MAX_PEPTIDE_LEN])[0]) +query_min_mass = float(params.get('min_mass', [DEFAULT_MIN_PEPTIDE_MASS])[0]) +query_max_mass = float(params.get('max_mass', [DEFAULT_MAX_PEPTIDE_MASS])[0]) +query_semi_enzymatic = params.get('semi_enzymatic', ['False'])[0].lower() == 'true' +query_infer_charge = params.get('infer_charge', ['True'])[0].lower() == 'true' +query_min_charge = int(params.get('min_charge', [DEFAULT_MIN_CHARGE])[0]) +query_max_charge = int(params.get('max_charge', [DEFAULT_MAX_CHARGE])[0]) +query_min_mz = float(params.get('min_mz', [DEFAULT_MIN_MZ])[0]) +query_max_mz = float(params.get('max_mz', [DEFAULT_MAX_MZ])[0]) +query_remove_non_proteotypic = params.get('remove_non_proteotypic', ['False'])[0].lower() == 'true' +query_n_term_static_mod = float(params.get('n_term_static_mod', [0.0])[0]) +query_c_term_static_mod = float(params.get('c_term_static_mod', [0.0])[0]) +query_num_static_mods = int(params.get('num_static_mods', [DEFAULT_STATIC_MODS])[0]) +query_n_term_var_mod = float(params.get('n_term_var_mod', [0.0])[0]) +query_c_term_var_mod = float(params.get('c_term_var_mod', [0.0])[0]) +query_max_var_mods = int(params.get('max_var_mods', [DEFAULT_MAX_VAR_MODS])[0]) +query_num_variable_mods = int(params.get('num_variable_mods', [DEFAULT_VAR_MODS])[0]) +query_static_mods_str = params.get('static_mods', ['C:57.02146'])[0] +query_static_mods = [(s.split(':')[0], float(s.split(':')[1])) for s in query_static_mods_str.split(';') if s] +query_variable_mods_str = params.get('variable_mods', [''])[0] +query_variable_mods = [(s.split(':')[0], float(s.split(':')[1])) for s in query_variable_mods_str.split(';') if s] + # CSS to inject contained in a string hide_table_row_index = """