└── bacteria.py /bacteria.py: -------------------------------------------------------------------------------- 1 | class Bacteria: 2 | def __init__(self): 3 | self.strand1 = None 4 | self.strand2 = None 5 | self.strand1_sliced = None 6 | self.strand2_sliced = None 7 | self.site_location = None 8 | self.counter_plasmids = { 9 | 'A': 'T', 10 | 'T': 'A', 11 | 'C': 'G', 12 | 'G': 'C', 13 | ' ': ' ' 14 | } 15 | 16 | def complementary_strand(self, seq): 17 | complementary_seq = [self.counter_plasmids[char] for char in seq] 18 | complementary_seq_str = ''.join(complementary_seq) 19 | return complementary_seq_str 20 | 21 | def find_restriction_site(self, strand, site, side='left'): 22 | if side == 'right': 23 | self.site_location = strand.rfind(site) 24 | else: 25 | self.site_location = strand.find(site) 26 | return self.site_location 27 | 28 | def main(self): 29 | with open(input(), 'r') as file: 30 | data = file.read().split('\n') 31 | self.strand1 = data[0] 32 | site1 = data[1] 33 | gfp_strand = data[2] 34 | gfp_site1, gfp_site2 = data[3].split() 35 | cut_index1 = self.find_restriction_site(self.strand1, site1) + 1 36 | gfp_cut_index1 = self.find_restriction_site(gfp_strand, gfp_site1) + 1 37 | gfp_cut_index2 = self.find_restriction_site(gfp_strand, gfp_site2, 'right') + 1 38 | strand1_str = self.strand1[:cut_index1] + gfp_strand[gfp_cut_index1:gfp_cut_index2] + self.strand1[cut_index1:] 39 | print(strand1_str) 40 | 41 | print(self.complementary_strand(strand1_str)) 42 | 43 | # self.strand2 = self.complementary_strand(self.strand1) 44 | # site1 = self.complementary_strand(site1) 45 | # gfp_strand = self.complementary_strand(gfp_strand) 46 | # gfp_site1 = self.complementary_strand(gfp_site1) 47 | # gfp_site2 = self.complementary_strand(gfp_site2) 48 | # cut_index1 = self.find_restriction_site(self.strand2, site1) + len(site1) - 1 49 | # gfp_cut_index1 = self.find_restriction_site(gfp_strand, gfp_site1) + len(gfp_site1) - 1 50 | # gfp_cut_index2 = self.find_restriction_site(gfp_strand, gfp_site2, 'right') + len(gfp_site2) - 1 51 | # print(f'{self.strand2[:cut_index1]}{gfp_strand[gfp_cut_index1:gfp_cut_index2]}{self.strand2[cut_index1:]}') 52 | 53 | 54 | if __name__ == "__main__": 55 | Bacteria().main() 56 | 57 | 58 | 59 | --------------------------------------------------------------------------------