Skip to content

Commit

Permalink
Fix IMO error on motif input
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumitti committed Jan 7, 2025
1 parent d72a5ce commit 4e9451d
Showing 2 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion clock.time
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Last updated at 16:15 10/09/2024
Last updated at 10:20 07/01/2025 (dd/mm/aaaa)
58 changes: 33 additions & 25 deletions navigation/IMF.py
Original file line number Diff line number Diff line change
@@ -248,13 +248,16 @@ def analyse(dna_sequence=None):
st.success(f"{TF_species} transcription factor {TF_name}")
with REcol2:
st.image(weblogo)
isUIPAC = True
button = False
error_input_im = True
else:
isUIPAC = False
button = True
error_input_im = False
st.error('Wrong JASPAR_ID')
else:
isUIPAC = False
button = True
error_input_im = False
st.warning('Please enter a JASPAR_ID')
@@ -265,7 +268,6 @@ def analyse(dna_sequence=None):
matrix_type = st.radio('🔹 :blue[**Step 2.2bis**] Matrix:', ('With FASTA sequences', 'With PWM'),
label_visibility='collapsed')
if matrix_type == 'With PWM':
isUIPAC = True
with REcol2:
st.markdown("🔹 :blue[**Step 2.3**] Matrix:")
matrix_str = st.text_area("🔹 :blue[**Step 2.3**] Matrix:",
@@ -303,12 +305,14 @@ def analyse(dna_sequence=None):
weblogo.fig.savefig(logo, format='png')
logo.seek(0)
st.session_state['weblogo'] = logo

isUIPAC = True
error_input_im = True
except Exception as e:
isUIPAC = False
error_input_im = False
REcol2.error(e)
else:
isUIPAC = False
error_input_im = False
REcol2.warning("Please input your PWM :)")
else:
@@ -322,7 +326,6 @@ def analyse(dna_sequence=None):
label_visibility='collapsed')
st.session_state['individual_motif_save'] = individual_motif
individual_motif = individual_motif.upper()
isUIPAC = True

try:
matrix, weblogo = IMO.individual_motif_pwm(individual_motif)
@@ -339,8 +342,10 @@ def analyse(dna_sequence=None):
weblogo.fig.savefig(logo, format='png')
logo.seek(0)
st.session_state['weblogo'] = logo
isUIPAC = True
error_input_im = True
except Exception as e:
isUIPAC = False
error_input_im = False
REcol1.error(e)

@@ -357,33 +362,36 @@ def analyse(dna_sequence=None):

IUPAC_code = ['A', 'T', 'G', 'C', 'R', 'Y', 'M', 'K', 'W', 'S', 'B', 'D', 'H', 'V', 'N', '-', '.']

if all(char in IUPAC_code for char in IUPAC):
isUIPAC = True
try:
matrix = IMO.generate_iupac_variants(IUPAC)
_, weblogo = IMO.individual_motif_pwm(matrix, "UIPAC")
if len(IUPAC) > 0:
if all(char in IUPAC_code for char in IUPAC):
isUIPAC = True
try:
matrix = IMO.generate_iupac_variants(IUPAC)
_, weblogo = IMO.individual_motif_pwm(matrix, "UIPAC")

matrix_str = ""
for base, values in matrix.items():
values_str = " ".join([f"{val:.4f}" for val in values])
matrix_str += f"{base} [ {values_str} ]\n"
matrix_str = ""
for base, values in matrix.items():
values_str = " ".join([f"{val:.4f}" for val in values])
matrix_str += f"{base} [ {values_str} ]\n"

with REcol2:
matrix_text = st.text_area('PWM', value=matrix_str, height=125,
help='Copy to use later. Not editable.',
disabled=True)
with REcol2:
matrix_text = st.text_area('PWM', value=matrix_str, height=125,
help='Copy to use later. Not editable.',
disabled=True)

st.pyplot(weblogo.fig)
logo = io.BytesIO()
weblogo.fig.savefig(logo, format='png')
logo.seek(0)
st.session_state['weblogo'] = logo
st.pyplot(weblogo.fig)
logo = io.BytesIO()
weblogo.fig.savefig(logo, format='png')
logo.seek(0)
st.session_state['weblogo'] = logo

error_input_im = True
error_input_im = True

except Exception as e:
error_input_im = False
REcol1.error(e)
except Exception as e:
error_input_im = False
REcol1.error(e)
else:
isUIPAC = False
else:
isUIPAC = False

0 comments on commit 4e9451d

Please sign in to comment.