Skip to content

Instantly share code, notes, and snippets.

@vmesel
Created November 22, 2017 02:26
Show Gist options
  • Save vmesel/664ef212a3ebba3f282da0a283308988 to your computer and use it in GitHub Desktop.
Save vmesel/664ef212a3ebba3f282da0a283308988 to your computer and use it in GitHub Desktop.
import unittest
def frame_calc(sequence):
modulo = len(sequence) % 3
if modulo == 0:
return 0
elif modulo == 1:
return 1
elif modulo == 2:
return 2
def replacer(x, rep0, rep1, rep2):
if x == 0:
return rep0
elif x == 1:
return rep1
elif x == 2:
return rep2
def motif_replacer(seq, rep0, rep1, rep2, restriction_site):
mult_mx = {
"ecor5": 6,
"pst1": 6,
"nco1": 6,
"5a": 5,
"5t": 5
}
multiplier = mult_mx[restriction_site]
seq_dup = list(seq)
to_replace = []
def_to_replace = []
for i, a in enumerate(seq):
if seq[i:i+multiplier] == "x"*multiplier:
to_replace.append((i, i+multiplier))
for i, j in enumerate(to_replace):
print(i,j)
if i == 0:
def_to_replace.append(j)
else:
ind = def_to_replace[i-1]
print(j[0]+1, "\n", ind)
if j[0]+1 not in range(ind[0], ind[1]):
def_to_replace.append(j)
# print(i, j)
print(def_to_replace)
for item in def_to_replace:
frag = replacer(frame_calc(seq[:item[0]]), rep0, rep1, rep2)
for k, v in enumerate(seq_dup[item[0]:item[1]]):
seq_dup[int(item[0]) + int(k)] = list(frag)[k]
return "".join(seq_dup)
class TestStringMethods(unittest.TestCase):
def setUp(self):
self.rep0 = "ccttgg"
self.rep1 = "ctatgg"
self.rep2 = "ccacgg"
self.restriction_site = "nco1"
# def test_sub_um_ncoi(self):
# seq = "TCGGGAACGACCCCGACCGGCCTGCGCGXXXXXXCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCGTAACCGTCCT"
# seq_mod = "TCGGGAACGACCCCGACCGGCCTGCGCGCTATGGCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCGTAACCGTCCT"
# seq_output = motif_replacer(seq.lower(), self.rep0, self.rep1, self.rep2, self.restriction_site)
# self.assertTrue(seq_mod.lower() == seq_output.lower())
#
#
# def test_sub_dois_ncoi(self):
# seq = "TCGGGAACGACCCCGACCGGCCTGCGCGXXXXXXCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACXXXXXXCGTCCT"
# seq_mod = "TCGGGAACGACCCCGACCGGCCTGCGCGCTATGGCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCCTTGGCGTCCT"
# seq_output = motif_replacer(seq.lower(), self.rep0, self.rep1, self.rep2, self.restriction_site)
# self.assertTrue(seq_mod.lower() == seq_output.lower())
#
# def test_duas_extremidades(self):
# seq = "XXXXXXTCGGGAACGACCCCGACCGGCCTGCGCGCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCGTCCTXXXXXX"
# seq_mod = "CCTTGGTCGGGAACGACCCCGACCGGCCTGCGCGCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCGTCCTCCTTGG"
# seq_output = motif_replacer(seq.lower(), self.rep0, self.rep1, self.rep2, self.restriction_site)
# self.assertTrue(seq_mod.lower() == seq_output.lower())
#
# def test_uma_extremidade(self):
# seq = "XXXXXXTCGGGAACGACCCCGACCGGCCTGCGCGCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCGTCCT"
# seq_mod = "CCTTGGTCGGGAACGACCCCGACCGGCCTGCGCGCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCGTCCT"
# seq_output = motif_replacer(seq.lower(), self.rep0, self.rep1, self.rep2, self.restriction_site)
# self.assertTrue(seq_mod.lower() == seq_output.lower())
#
def test_repeats_juntas(self):
seq = "XXXXXXXXXXXXTCGGGAACGACCCCGACCGGCCTGCGCGCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCGTCCT"
seq_mod = "CCTTGGCCTTGGTCGGGAACGACCCCGACCGGCCTGCGCGCCACCCCAAATTTCGGATCGGCTGCCATTACGATTCCGGGTGCAGGAATTCCGATGACCCCAGAACAGTTACAAGTGTATGCCTGGCAAAAAGAGATTGACGACCGTCCT"
import ipdb; ipdb.set_trace()
seq_output = motif_replacer(seq.lower(), self.rep0, self.rep1, self.rep2, self.restriction_site)
print(seq_output)
# self.assertTrue(seq_mod.lower() == seq_output.lower())
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment