supercat666 commited on
Commit
c0e089e
1 Parent(s): 0d0c645

fixed cas9off

Browse files
Files changed (2) hide show
  1. app.py +13 -2
  2. cas9off.py +38 -0
app.py CHANGED
@@ -95,6 +95,7 @@ if selected_model == 'Cas9':
95
 
96
  pass
97
  elif target_selection == 'off-target':
 
98
  ENTRY_METHODS = dict(
99
  manual='Manual entry of target sequence',
100
  txt="txt file upload"
@@ -130,8 +131,18 @@ if selected_model == 'Cas9':
130
  )
131
 
132
  # prediction button
133
- st.button(label='Predict off-target effects', on_click=cas9off.CRISPR_net_predict,
134
- disabled=st.session_state.target_sequence is not None)
 
 
 
 
 
 
 
 
 
 
135
  progress = st.empty()
136
 
137
  # input error display
 
95
 
96
  pass
97
  elif target_selection == 'off-target':
98
+
99
  ENTRY_METHODS = dict(
100
  manual='Manual entry of target sequence',
101
  txt="txt file upload"
 
131
  )
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
142
+ file_content = uploaded_file.getvalue().decode("utf-8")
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
cas9off.py CHANGED
@@ -81,6 +81,44 @@ class Encoder:
81
  on_off_dim7_codes.append(np.concatenate((diff_code, dir_code)))
82
  self.on_off_code = np.array(on_off_dim7_codes)
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  def encode_on_off_seq_pairs(input_file):
85
  inputs = pd.read_csv(input_file, delimiter=",", header=None, names=['on_seq', 'off_seq'])
86
  input_codes = []
 
81
  on_off_dim7_codes.append(np.concatenate((diff_code, dir_code)))
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.
91
+ input_type: 'manual' for manual input, 'file' for file input.
92
+
93
+ Returns:
94
+ A DataFrame with the off-target predictions.
95
+ """
96
+
97
+ if input_type == 'manual':
98
+ # Process manual input string into DataFrame
99
+ sequences = [seq.split(',') for seq in input_data.split('\n')]
100
+ inputs = pd.DataFrame(sequences, columns=['on_seq', 'off_seq'])
101
+ elif input_type == 'file':
102
+ # Read sequences from a file into DataFrame
103
+ inputs = pd.read_csv(input_data, delimiter=",", header=None, names=['on_seq', 'off_seq'])
104
+
105
+ # Encode the sequences
106
+ input_codes = []
107
+ for idx, row in inputs.iterrows():
108
+ on_seq = row['on_seq']
109
+ off_seq = row['off_seq']
110
+ en = Encoder(on_seq=on_seq, off_seq=off_seq)
111
+ input_codes.append(en.on_off_code)
112
+
113
+ # Convert to numpy array and reshape for the model
114
+ input_codes = np.array(input_codes)
115
+ input_codes = input_codes.reshape((len(input_codes), 1, 24, 7))
116
+
117
+ # Predict with CRISPR-Net model
118
+ inputs['CRISPR_Net_score'] = CRISPR_net_predict(input_codes)
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 = []