def domain_end(design: sc.Design, helix, offset): #True if it is a domain end or if nothing exists if len(design.domains_at(helix, offset)) == 2: if design.domains_at(helix, offset)[0].start == offset or \ design.domains_at(helix, offset)[0].end == offset or \ design.domains_at(helix, offset)[1].start == offset or \ design.domains_at(helix, offset)[1].end == offset : return True else: return False elif len(design.domains_at(helix, offset)) == 1: if design.domains_at(helix, offset)[0].start == offset or \ design.domains_at(helix, offset)[0].end == offset : return True else: return False else: return True #since we don't want crossovers where nothing exists
def add_deletions(design: sc.Design): for helix in range(3, maxhelix): if not design.strands_starting_on_helix(helix): pass else: hel1 = helix #first starting helix break for helix in range(hel1, maxhelix, 2): for offset in range(block * cmax): if design.domains_at(helix, offset) and offset % 48 == 0: design.add_deletion(helix, offset)
def valid_deletion_offset(design: sc.Design, helix: int, offset: int) -> bool: domains_at_offset = design.domains_at(helix, offset) if len(domains_at_offset) > 2: raise ValueError(f'Invalid Design; more than two Substrands found at ' f'helix {helix} and offset {offset}: ' f'{domains_at_offset}') elif len(domains_at_offset) != 2: return False for ss in domains_at_offset: if offset in ss.deletions: return False # already a deletion there if offset in (insertion[0] for insertion in ss.insertions): return False # already an insertion there if offset == ss.start: return False # no 5' end if offset == ss.end - 1: return False # no 3' end return True
def add_staple_nicks(design: sc.Design): crossovers = [] for helix in range(3, maxhelix, 2): if not design.strands_starting_on_helix(helix): pass else: hel1 = helix #first starting helix break for helix in range(hel1, maxhelix, 2): scafdom1 = design.strands_starting_on_helix(helix) scafdom2 = design.strands_starting_on_helix(helix + 1) if not (scafdom1 and scafdom2): #check for empty helix at the end of the design break for helix in range(maxhelix): if helix % 2 == 0: for offset in range(block * cmax): if (offset % 32 == 0) and (design.domains_at(helix, offset)): if domain_end(design, helix, offset): #no nick if domain end continue #Prevent very short staples if (design.domains_at(helix, offset-16)) and \ (design.domains_at(helix, offset+16)): design.add_nick(helix=helix, offset=offset, forward=helix % 2 == 1) if 0<=(offset-8)<=block*cmax and \ (design.domains_at(helix, offset-16)) and \ (design.domains_at(helix, offset)) and \ (design.domains_at(helix+1, offset-8)) and \ (design.domains_at(helix+1, offset-9)) and \ not domain_end(design, helix, offset-8): crossovers.append(sc.Crossover(helix=helix, helix2=helix + 1, \ offset=offset-8, forward=helix % 2 == 1)) else: for offset in range(block * cmax): if ((offset + 16) % 32 == 0) and (design.domains_at( helix, offset)): if domain_end(design, helix, offset): continue #Prevent very short staples if (design.domains_at(helix, offset-16)) and \ (design.domains_at(helix, offset+16)): design.add_nick(helix=helix, offset=offset, forward=helix % 2 == 1) if 0<=(offset-8)<=block*cmax and \ (design.domains_at(helix, offset-16)) and \ (design.domains_at(helix, offset)) and \ (design.domains_at(helix+1, offset-8)) and \ (design.domains_at(helix+1, offset-9)) and \ not domain_end(design, helix, offset-8): crossovers.append(sc.Crossover(helix=helix, helix2=helix + 1, \ offset=offset-8, forward=helix % 2 == 1)) design.add_crossovers(crossovers)
def add_staple_nicks(design: sc.Design): crossovers = [] midgap = 3 state = 0 every = -1 #skip every xth crossover for helix in range(3, maxhelix, 2): if not design.strands_starting_on_helix(helix): pass else: hel1 = helix #first starting helix break for helix in range(hel1, maxhelix, 2): scafdom1 = design.strands_starting_on_helix(helix) scafdom2 = design.strands_starting_on_helix(helix + 1) if not (scafdom1 and scafdom2): #check for empty helix at the end of the design break for helix in range(maxhelix): if helix % 2 == 0: for offset in range(block * cmax): if (((offset-3)%32==0) or \ ((offset-3)%32==10) or \ ((offset-3)%32==21)) and \ (design.domains_at(helix, offset+midgap)): state = state + 1 if not every == -1: if state % every == 0: # print(str(helix)+' '+str(offset)) continue if domain_end(design, helix, offset + midgap): #no nick if domain end continue #Prevent very short staples if long_stap_cond(design, helix, offset + midgap) == True: design.add_nick(helix=helix, offset=offset + midgap, forward=helix % 2 == 1) if cross_conds(design, helix, offset): crossovers.append(sc.Crossover(helix=helix, helix2=helix + 1, \ offset=offset, forward=helix % 2 == 1)) elif helix == 2: print("not here " + str(offset)) else: for offset in range(block * cmax): if (((offset-8)%32==0) or \ ((offset-8)%32==11) or \ ((offset-8)%32==21)) and \ (design.domains_at(helix, offset+midgap)): state = state + 1 if not every == -1: if state % every == 0: # print(str(helix)+' '+str(offset)) continue if domain_end(design, helix, offset + midgap): #no nick if domain end continue # #Prevent very short staples # if long_stap_cond(design, helix, offset+midgap)==True: # design.add_nick(helix=helix, offset=offset+midgap, forward=helix % 2 == 1) if cross_conds(design, helix, offset): crossovers.append(sc.Crossover(helix=helix, helix2=helix + 1, \ offset=offset, forward=helix % 2 == 1)) design.add_crossovers(crossovers)