Jayesh13 commited on
Commit
01b258e
·
verified ·
1 Parent(s): 03aaa04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -18,9 +18,8 @@ results_collection = db['protein_results']
18
  def is_homo_repeat(s):
19
  return all(c == s[0] for c in s)
20
 
21
- def hash_sequence(sequence, analysis_type, overlap):
22
- key_string = sequence + analysis_type + str(overlap)
23
- return hashlib.md5(key_string.encode()).hexdigest()
24
 
25
  @st.cache_data(show_spinner=False)
26
  def fragment_protein_sequence(sequence, max_length=1000):
@@ -73,8 +72,8 @@ def find_new_boundary_repeats(fragments, final_repeats, overlap=50):
73
  return new_repeats
74
 
75
  def get_or_process_sequence(sequence, analysis_type, overlap=50):
76
- sequence_hash = hash_sequence(sequence, analysis_type, overlap)
77
- cached = results_collection.find_one({"_id": sequence_hash})
78
  if cached:
79
  return cached["repeats"]
80
 
@@ -115,6 +114,7 @@ def get_or_process_sequence(sequence, analysis_type, overlap=50):
115
  # Save to DB for caching
116
  results_collection.insert_one({
117
  "_id": sequence_hash,
 
118
  "repeats": dict(final_repeats)
119
  })
120
  return final_repeats
@@ -195,4 +195,4 @@ if uploaded_files:
195
  row.update({repeat: freq.get(repeat, 0) for repeat in sorted(all_repeats)})
196
  rows.append(row)
197
  result_df = pd.DataFrame(rows)
198
- st.dataframe(result_df)
 
18
  def is_homo_repeat(s):
19
  return all(c == s[0] for c in s)
20
 
21
+ def hash_sequence(sequence):
22
+ return hashlib.md5(sequence.encode()).hexdigest()
 
23
 
24
  @st.cache_data(show_spinner=False)
25
  def fragment_protein_sequence(sequence, max_length=1000):
 
72
  return new_repeats
73
 
74
  def get_or_process_sequence(sequence, analysis_type, overlap=50):
75
+ sequence_hash = hash_sequence(sequence)
76
+ cached = results_collection.find_one({"_id": sequence_hash, "analysis_type": analysis_type})
77
  if cached:
78
  return cached["repeats"]
79
 
 
114
  # Save to DB for caching
115
  results_collection.insert_one({
116
  "_id": sequence_hash,
117
+ "analysis_type": analysis_type,
118
  "repeats": dict(final_repeats)
119
  })
120
  return final_repeats
 
195
  row.update({repeat: freq.get(repeat, 0) for repeat in sorted(all_repeats)})
196
  rows.append(row)
197
  result_df = pd.DataFrame(rows)
198
+ st.dataframe(result_df)