supercat666 commited on
Commit
66c57f6
1 Parent(s): c0e089e

fixed cas9off

Browse files
Files changed (2) hide show
  1. app.py +6 -2
  2. cas9off.py +26 -24
app.py CHANGED
@@ -132,10 +132,10 @@ if selected_model == 'Cas9':
132
 
133
  # prediction button
134
  if st.button('Predict off-target effects'):
135
- if st.session_state.entry_method == 'manual':
136
  user_input = st.session_state.manual_entry
137
  predictions = cas9off.process_input_and_predict(user_input, input_type='manual')
138
- elif st.session_state.entry_method == 'txt':
139
  uploaded_file = st.session_state.txt_entry
140
  if uploaded_file is not None:
141
  # Read the uploaded file content
@@ -143,6 +143,10 @@ if selected_model == 'Cas9':
143
  predictions = cas9off.process_input_and_predict(file_content, input_type='manual')
144
 
145
  st.session_state.off_target_results = predictions
 
 
 
 
146
  progress = st.empty()
147
 
148
  # input error display
 
132
 
133
  # prediction button
134
  if st.button('Predict off-target effects'):
135
+ if st.session_state.entry_method == ENTRY_METHODS['manual']:
136
  user_input = st.session_state.manual_entry
137
  predictions = cas9off.process_input_and_predict(user_input, input_type='manual')
138
+ elif st.session_state.entry_method == ENTRY_METHODS['txt']:
139
  uploaded_file = st.session_state.txt_entry
140
  if uploaded_file is not None:
141
  # Read the uploaded file content
 
143
  predictions = cas9off.process_input_and_predict(file_content, input_type='manual')
144
 
145
  st.session_state.off_target_results = predictions
146
+ else:
147
+ # Ensure that 'predictions' is defined even if the button hasn't been clicked
148
+ predictions = None
149
+
150
  progress = st.empty()
151
 
152
  # input error display
cas9off.py CHANGED
@@ -82,9 +82,34 @@ class Encoder:
82
  self.on_off_code = np.array(on_off_dim7_codes)
83
 
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  def process_input_and_predict(input_data, input_type='manual'):
86
  """
87
- Process the user input and predict using the CRISPR-Net model.
88
 
89
  Args:
90
  input_data: A string of manual input or the path to an input file.
@@ -119,29 +144,6 @@ def process_input_and_predict(input_data, input_type='manual'):
119
 
120
  return inputs
121
 
122
- def encode_on_off_seq_pairs(input_file):
123
- inputs = pd.read_csv(input_file, delimiter=",", header=None, names=['on_seq', 'off_seq'])
124
- input_codes = []
125
- for idx, row in inputs.iterrows():
126
- on_seq = row['on_seq']
127
- off_seq = row['off_seq']
128
- en = Encoder(on_seq=on_seq, off_seq=off_seq)
129
- input_codes.append(en.on_off_code)
130
- input_codes = np.array(input_codes)
131
- input_codes = input_codes.reshape((len(input_codes), 1, 24, 7))
132
- y_pred = CRISPR_net_predict(input_codes)
133
- inputs['CRISPR_Net_score'] = y_pred
134
- inputs.to_csv("CRISPR_net_results.csv", index=False)
135
-
136
- def CRISPR_net_predict(X_test):
137
- json_file = open("cas9_model/CRISPR_Net_CIRCLE_elevation_SITE_structure.json", 'r')
138
- loaded_model_json = json_file.read()
139
- json_file.close()
140
- loaded_model = tf.keras.models.model_from_json(loaded_model_json) # Updated for TensorFlow 2
141
- loaded_model.load_weights("cas9_model/CRISPR_Net_CIRCLE_elevation_SITE_weights.h5")
142
- y_pred = loaded_model.predict(X_test).flatten()
143
- return y_pred
144
-
145
  if __name__ == '__main__':
146
  parser = argparse.ArgumentParser(description="CRISPR-Net v1.0 (Aug 10 2019)")
147
  parser.add_argument("input_file",
 
82
  self.on_off_code = np.array(on_off_dim7_codes)
83
 
84
 
85
+
86
+
87
+ def encode_on_off_seq_pairs(input_file):
88
+ inputs = pd.read_csv(input_file, delimiter=",", header=None, names=['on_seq', 'off_seq'])
89
+ input_codes = []
90
+ for idx, row in inputs.iterrows():
91
+ on_seq = row['on_seq']
92
+ off_seq = row['off_seq']
93
+ en = Encoder(on_seq=on_seq, off_seq=off_seq)
94
+ input_codes.append(en.on_off_code)
95
+ input_codes = np.array(input_codes)
96
+ input_codes = input_codes.reshape((len(input_codes), 1, 24, 7))
97
+ y_pred = CRISPR_net_predict(input_codes)
98
+ inputs['CRISPR_Net_score'] = y_pred
99
+ inputs.to_csv("CRISPR_net_results.csv", index=False)
100
+
101
+ def CRISPR_net_predict(X_test):
102
+ json_file = open("cas9_model/CRISPR_Net_CIRCLE_elevation_SITE_structure.json", 'r')
103
+ loaded_model_json = json_file.read()
104
+ json_file.close()
105
+ loaded_model = tf.keras.models.model_from_json(loaded_model_json) # Updated for TensorFlow 2
106
+ loaded_model.load_weights("cas9_model/CRISPR_Net_CIRCLE_elevation_SITE_weights.h5")
107
+ y_pred = loaded_model.predict(X_test).flatten()
108
+ return y_pred
109
+
110
  def process_input_and_predict(input_data, input_type='manual'):
111
  """
112
+ Process the user input and predict.
113
 
114
  Args:
115
  input_data: A string of manual input or the path to an input file.
 
144
 
145
  return inputs
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  if __name__ == '__main__':
148
  parser = argparse.ArgumentParser(description="CRISPR-Net v1.0 (Aug 10 2019)")
149
  parser.add_argument("input_file",