# Spaces: kipfriend /inverted_repeats Stopped

Update app.py
e517d25
 import gradio as gr #------------------------------------------------------------- # first function is taken from lecture notes #------------------------------------------------------------- dna2dna = {'A':'T', 'T':'A', 'C':'G', 'G':'C'} def reverse_comp(dna): """Return a string representing the reverse complement of the single dna strand.""" other = '' # start with an empty string for base in dna: other = other + dna2dna[base] return other[ : :-1] # python trick to reverse a string #------------------------------------------------------------- # second function is your responsibility to implement #------------------------------------------------------------- def mutate(dna, motif): if motif in dna: reverse_motif='' #dna[reverse_comp(motif)] new_dna='' if reverse_motif in dna: #My code #new_dna=dna[:dna.index(motif)]+dna[dna.index(motif)+len(motif):dna.index(reverse_comp(motif))]+dna[dna.index(reverse_comp(motif))+len(reverse_comp(motif)):] #reverse_motif.index(reverse_comp)+len()] new_dna = dna[:dna.index(motif)] + dna[dna.find(reverse_comp(motif), dna.index(motif)) + len(reverse_comp(motif)):] #correct code ^^^ return new_dna else: print('motif not found in sequence: ',end='') return dna #def mutate(dna, motif): #"""Return the result of a mutation based on an inverted repeat of the given motif.""" # your code here! #### (1) Check if the motif exists in dna sequence. If not, return the original sequence. #j = dna.find(motif) #if j == -1: # return dna #### (2) If true, check if the reversed complement of the motif exists in dna sequence, if not, return the orignal sequence. # k = dna.find(reverse_complement(motif), j+len(motif)) # if k == -1: # return dna #### (3) If the motif and its reversed complements exist, remove the region starting from the motif and ending with the inverted repeat, return the new sequence. # """Return the result of a mutation based on an inverted repeat of the given motif.""" #return dna[:j] + dna[k+len(motif): ] #test_data = """ATCCGAATACGGTTCGGGTA CGAA #ATCCGAATACGGTTGGGTA CGAA #ATCCAATACGGTTCGGGTA CGAA #ATCCGAATACGGTTCGGGTTCGA CGAA #AGTCACATGATCAGT C""" #for dna,motif in [line.split() for line in test_data.split('\n')[0:]]: # print('Executing mutate(%s,%s)...' % (dna,motif)) # print(' returned: %s' % (mutate(dna,motif))) input_module1 = gr.inputs.Textbox(label = "Enter your DNA sequence in the box:") input_module2 = gr.inputs.Textbox(label = "Enter your motif of interest in the box:") output_module = gr.outputs.Textbox(label = 'new dna') interface = gr.Interface(fn=mutate, inputs=[input_module1,input_module2], outputs=output_module, title="CSCI1020 Demo 3: Web Application for Finding DNA Inverted Repeats", description= "Click examples below for a quick demo", theme = 'huggingface', layout = 'vertical' ) interface.launch()