File size: 3,169 Bytes
731bd10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e517d25
de37bdf
 
731bd10
de37bdf
 
d54db96
731bd10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d295ad0
731bd10
4833747
731bd10
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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()