Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
9f169cd
1
Parent(s):
d3204b1
Cleaning up previous fasta files
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import streamlit as st
|
| 3 |
-
import os
|
| 4 |
from tiger import tiger_exhibit, load_transcripts, TARGET_LEN, NUCLEOTIDE_TOKENS
|
| 5 |
|
| 6 |
|
|
@@ -38,11 +38,15 @@ status_bar_textform = text_form.progress(0)
|
|
| 38 |
fasta_form = st.form("fasta")
|
| 39 |
fasta = fasta_form.file_uploader(label="upload fasta file")
|
| 40 |
if fasta:
|
|
|
|
|
|
|
|
|
|
| 41 |
fname = fasta.name
|
| 42 |
st.write(fname)
|
| 43 |
-
|
|
|
|
| 44 |
f.write(fasta.getvalue().decode("utf-8"))
|
| 45 |
-
transcript_tbl = load_transcripts([
|
| 46 |
fasta_form.text("fasta file contents")
|
| 47 |
fasta_form.write(transcript_tbl)
|
| 48 |
seq = transcript_tbl['seq'][0]
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import streamlit as st
|
| 3 |
+
import os, shutil
|
| 4 |
from tiger import tiger_exhibit, load_transcripts, TARGET_LEN, NUCLEOTIDE_TOKENS
|
| 5 |
|
| 6 |
|
|
|
|
| 38 |
fasta_form = st.form("fasta")
|
| 39 |
fasta = fasta_form.file_uploader(label="upload fasta file")
|
| 40 |
if fasta:
|
| 41 |
+
if os.path.exists("temp"):
|
| 42 |
+
shutil.rmtree("temp")
|
| 43 |
+
os.makedirs("temp")
|
| 44 |
fname = fasta.name
|
| 45 |
st.write(fname)
|
| 46 |
+
fpath = os.path.join("temp", fname)
|
| 47 |
+
with open(fpath, "w") as f:
|
| 48 |
f.write(fasta.getvalue().decode("utf-8"))
|
| 49 |
+
transcript_tbl = load_transcripts([fpath])
|
| 50 |
fasta_form.text("fasta file contents")
|
| 51 |
fasta_form.write(transcript_tbl)
|
| 52 |
seq = transcript_tbl['seq'][0]
|
tiger.py
CHANGED
|
@@ -24,7 +24,6 @@ for gpu in tf.config.list_physical_devices('GPU'):
|
|
| 24 |
if len(tf.config.list_physical_devices('GPU')) > 0:
|
| 25 |
tf.config.experimental.set_visible_devices(tf.config.list_physical_devices('GPU')[0], 'GPU')
|
| 26 |
|
| 27 |
-
|
| 28 |
def load_transcripts(fasta_files):
|
| 29 |
|
| 30 |
# load all transcripts from fasta files into a DataFrame
|
|
@@ -95,7 +94,7 @@ def process_data(transcript_seq: str):
|
|
| 95 |
tf.reshape(one_hot_encode_sequence(target_seq, add_context_padding=False), [len(target_seq), -1]),
|
| 96 |
tf.reshape(one_hot_encode_sequence(guide_seq, add_context_padding=True), [len(guide_seq), -1]),
|
| 97 |
], axis=-1)
|
| 98 |
-
|
| 99 |
return target_seq, guide_seq, model_inputs
|
| 100 |
|
| 101 |
|
|
@@ -166,8 +165,9 @@ def find_off_targets(top_guides: pd.DataFrame, status_bar, status_text):
|
|
| 166 |
off_targets = pd.concat([off_targets, pd.DataFrame(dict_off_targets)])
|
| 167 |
|
| 168 |
# progress update
|
| 169 |
-
|
| 170 |
-
|
|
|
|
| 171 |
print('\rPercent complete: {:.2f}%'.format(100 * min(i / len(reference_transcripts), 1)), end='')
|
| 172 |
print('')
|
| 173 |
|
|
@@ -188,7 +188,7 @@ def predict_off_target(off_targets: pd.DataFrame, model: tf.keras.Model):
|
|
| 188 |
return off_targets.sort_values('Normalized LFC')
|
| 189 |
|
| 190 |
|
| 191 |
-
def tiger_exhibit(transcripts: pd.DataFrame, status_bar, status_text):
|
| 192 |
|
| 193 |
# load model
|
| 194 |
if os.path.exists('model'):
|
|
@@ -206,8 +206,9 @@ def tiger_exhibit(transcripts: pd.DataFrame, status_bar, status_text):
|
|
| 206 |
on_target_predictions = pd.concat([on_target_predictions, df.iloc[:NUM_TOP_GUIDES]])
|
| 207 |
|
| 208 |
# progress update
|
| 209 |
-
|
| 210 |
-
|
|
|
|
| 211 |
print('\rPercent complete: {:.2f}%'.format(100 * min((i + 1) / len(transcripts), 1)), end='')
|
| 212 |
print('')
|
| 213 |
|
|
|
|
| 24 |
if len(tf.config.list_physical_devices('GPU')) > 0:
|
| 25 |
tf.config.experimental.set_visible_devices(tf.config.list_physical_devices('GPU')[0], 'GPU')
|
| 26 |
|
|
|
|
| 27 |
def load_transcripts(fasta_files):
|
| 28 |
|
| 29 |
# load all transcripts from fasta files into a DataFrame
|
|
|
|
| 94 |
tf.reshape(one_hot_encode_sequence(target_seq, add_context_padding=False), [len(target_seq), -1]),
|
| 95 |
tf.reshape(one_hot_encode_sequence(guide_seq, add_context_padding=True), [len(guide_seq), -1]),
|
| 96 |
], axis=-1)
|
| 97 |
+
print(model_inputs)
|
| 98 |
return target_seq, guide_seq, model_inputs
|
| 99 |
|
| 100 |
|
|
|
|
| 165 |
off_targets = pd.concat([off_targets, pd.DataFrame(dict_off_targets)])
|
| 166 |
|
| 167 |
# progress update
|
| 168 |
+
if status_bar:
|
| 169 |
+
status_text.text("Scanning for off-targets Percent complete: {:.2f}%".format(int(100 * min(i / len(reference_transcripts), 1))))
|
| 170 |
+
status_bar.progress(int(100 * min(i / len(reference_transcripts), 1)))
|
| 171 |
print('\rPercent complete: {:.2f}%'.format(100 * min(i / len(reference_transcripts), 1)), end='')
|
| 172 |
print('')
|
| 173 |
|
|
|
|
| 188 |
return off_targets.sort_values('Normalized LFC')
|
| 189 |
|
| 190 |
|
| 191 |
+
def tiger_exhibit(transcripts: pd.DataFrame, status_bar=None, status_text=None):
|
| 192 |
|
| 193 |
# load model
|
| 194 |
if os.path.exists('model'):
|
|
|
|
| 206 |
on_target_predictions = pd.concat([on_target_predictions, df.iloc[:NUM_TOP_GUIDES]])
|
| 207 |
|
| 208 |
# progress update
|
| 209 |
+
if status_bar:
|
| 210 |
+
status_text.text("Scanning for on-targets Percent complete: {:.2f}%".format(100 * min((i + 1) / len(transcripts), 1)))
|
| 211 |
+
status_bar.progress(int(100 * min((i + 1) / len(transcripts), 1)))
|
| 212 |
print('\rPercent complete: {:.2f}%'.format(100 * min((i + 1) / len(transcripts), 1)), end='')
|
| 213 |
print('')
|
| 214 |
|