def buildOneCircuit(parts): ##Instantiate the circuit circuit = gc.GeneticCircuit([]) numberOfParts = len(parts) for pI in range(numberOfParts): ##p is a number if parts[pI] < 0: circuit.addComponent(part.Part(abs(parts[pI]), -1)) else: circuit.addComponent(part.Part(parts[pI], 1)) return [circuit]
def make3GeneTestCircuit(): ##Create the circuit circuit = gc.GeneticCircuit([]) component11 = part.Part(1, -1) component22 = part.Part(14, 1) component33 = part.Part(2, 1) component44 = part.Part(1, -1) component55 = part.Part(5, 1) component66 = part.Part(5, 1) component77 = part.Part(14, -1) circuit.addComponent(component11) circuit.addComponent(site1) circuit.addComponent(component22) circuit.addComponent(site2) circuit.addComponent(component33) circuit.addComponent(site3) circuit.addComponent(component44) circuit.addComponent(site4) circuit.addComponent(component55) circuit.addComponent(site5) circuit.addComponent(component66) circuit.addComponent(site6) circuit.addComponent(component77) return copy.deepcopy(circuit)
def makeFullTestCircuit(): ##Create the circuit circuit = gc.GeneticCircuit([]) component1 = part.Part(14, 1) component2 = part.Part(1, -1) component3 = part.Part(5, 1) component4 = part.Part(5, 1) component5 = part.Part(3, -1) component6 = part.Part(5, 1) component7 = part.Part(5, 1) circuit.addComponent(component1) circuit.addComponent(site1) circuit.addComponent(component2) circuit.addComponent(site2) circuit.addComponent(component3) circuit.addComponent(site3) circuit.addComponent(component4) circuit.addComponent(site4) circuit.addComponent(component5) circuit.addComponent(site5) circuit.addComponent(component6) circuit.addComponent(site6) circuit.addComponent(component7) return copy.deepcopy(circuit)
def makeCircuit3State(): ##Create the circuit circuit = gc.GeneticCircuit([]) ##Overwrite the parts in this circuit part1_1 = part.Part(5, 1) part2_1 = part.Part(5, 1) part3_1 = part.Part(1, 1) part4_1 = part.Part(7, -1) part5_1 = part.Part(5, 1) part6_1 = part.Part(10, -1) part7_1 = part.Part(10, -1) circuit.addComponent(part1_1) circuit.addComponent(site1) circuit.addComponent(part2_1) circuit.addComponent(site2) circuit.addComponent(part3_1) circuit.addComponent(site3) circuit.addComponent(part4_1) circuit.addComponent(site4) circuit.addComponent(part5_1) circuit.addComponent(site5) circuit.addComponent(part6_1) circuit.addComponent(site6) circuit.addComponent(part7_1) return copy.deepcopy(circuit)
def reset(self): if self.head: self.head.delete() self.head = None self.head = Part(self.win, self.game, Point(game.size.x/2, game.size.y/2)) self.head.add_part() self.lastDirection = Point(1, 0) self.lastDistance = 999999 self.dead = False
def AddPart(filename): """This is to add new part to the part table *Note*: This uses data from """ #Doing the insert NewPart = Part.Part() fullparts = ParseInventoryPart(filename) for data in fullparts: NewPart.insertPart(*data)
def __init__(self, win, game): self.win = win self.game = game self.brain = None self.genome = None self.head = Part(win, game, Point(game.size.x/2, game.size.y/2)) self.head.add_part() self.lastDirection = Point(1, 0) self.lastDistance = 999999 self.dead = False
def build5StateCircuit(parts): ##Create the recombination sites site1 = rs.RecognitionSite('D', 1) site2 = rs.RecognitionSite('[', 1) site3 = rs.RecognitionSite('(', 1) site4 = rs.RecognitionSite('[', -1) site5 = rs.RecognitionSite('(', 1) site6 = rs.RecognitionSite('D', -1) sites = [site1, site2, site3, site4, site5, site6] ##Instantiate the circuit circuit = gc.GeneticCircuit([]) numberOfParts = len(parts) for pI in range(numberOfParts): ##p is a number if parts[pI] < 0: circuit.addComponent(part.Part(abs(parts[pI]), -1)) else: circuit.addComponent(part.Part(parts[pI], 1)) ##Add the site as long as its not the last part if (pI + 1 < numberOfParts): circuit.addComponent(sites[pI]) ##Want to return all the induced circuits as well enzyme1 = enz.Enzyme('ATc') enzyme1.addSiteToRecognize('(') enzyme2 = enz.Enzyme('Ara') enzyme2.addSiteToRecognize('[') enzyme2.addSiteToRecognize('D') c1 = circuit c2 = enz.induceCircuit(enzyme1, c1) c3 = enz.induceCircuit(enzyme2, c1) c4 = enz.induceCircuit(enzyme2, c2) c5 = enz.induceCircuit(enzyme1, c3) return [c1, c2, c3, c4, c5]
def convertFromWithCircuits(stateNumber, circuit): if stateNumber == 6: return [ circuit[0], circuit[1], part.Part(circuit[3].getId(), -1 * circuit[3].getOrientation(), circuit[3].getPartLocation()), part.Part(circuit[2].getId(), -1 * circuit[2].getOrientation(), circuit[2].getPartLocation()), circuit[4], circuit[5], circuit[6], circuit[7], circuit[8] ] elif stateNumber == 7: return [ circuit[0], circuit[1], circuit[2], circuit[3], circuit[4], circuit[5], part.Part(circuit[7].getId(), -1 * circuit[7].getOrientation(), circuit[7].getPartLocation()), part.Part(circuit[6].getId(), -1 * circuit[6].getOrientation(), circuit[6].getPartLocation()), circuit[8] ] elif stateNumber == 10: return [ circuit[0], circuit[1], circuit[2], circuit[3], part.Part(circuit[5].getId(), -1 * circuit[5].getOrientation(), circuit[5].getPartLocation()), part.Part(circuit[4].getId(), -1 * circuit[4].getOrientation(), circuit[4].getPartLocation()), circuit[6], circuit[7], circuit[8] ]
def add_part(self): tail = self.parts[-1] x_off = 0 y_off = 0 if tail.direction == LEFT: x_off = BLOCK_SIZE elif tail.direction == RIGHT: x_off = -BLOCK_SIZE elif tail.direction == UP: y_off = BLOCK_SIZE else: y_off = -BLOCK_SIZE # we only have a head if self.get_length() == 1: # create a tail and add it to the snake self.parts.append( Part.Part(self.head.x + x_off, self.head.y + y_off, self.head, SNAKE_IMGS[2])) else: # set tail to body image tail.set_image(SNAKE_IMGS[0]) self.parts.append(Part.Part(tail.x + x_off, tail.y + y_off, tail, SNAKE_IMGS[2]))
def __flipCircuit(oldCircuitComponents, flip1, flip2): tempCircuit = gc.GeneticCircuit([]) subComponents = oldCircuitComponents[flip1:flip2+1][:] newSubsComps = [] for element in subComponents: ##Create new element instance so original circuit does not get modified if isinstance(element, part.Part): newElement = part.Part(element.getId(), element.getOrientation(), element.getPartLocation()) else: newElement = rs.RecognitionSite(element.getSymbol(), element.getOrientation()) newElement.flip() newSubsComps.append(newElement) newSubsComps.reverse() for i in range(len(oldCircuitComponents)): if flip1 <= i and i <= flip2: tempCircuit.addComponent(newSubsComps[i-flip1]) else: tempCircuit.addComponent(oldCircuitComponents[i]) return tempCircuit
def main(): loop_count = 0 score = 0 apple = make_apple() snake = Snake(Part(SNAKE_START_X, SNAKE_START_Y)) eaton = False win = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT)) pygame.display.set_caption('Snake Game') clock = pygame.time.Clock() running = True while running: clock.tick(FRAME_RATE) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False take_input(pygame.key.get_pressed(), snake) if eaton: apple = make_apple() eaton = False # checks if apple is hit if collision(apple, snake): snake.add_part() eaton = True score += SCORE_INCREMENT # exit if you hit a wall or if snake hits self running = wall_collision(snake) # allows the game to take input at the framerate but only draw in the specified interval if loop_count % GAME_CLOCK_SPEED == 0: snake.move() draw(win, score, apple, snake) loop_count += 1 if loop_count > 254: loop_count = 0 blank_scree(win) pygame.quit() quit()
sys = BioSystem() sys.addConstant('k1', 0.01) sys.addConstant('d', 0.1) #constants: k2=k4=k6=d sys.addConstant('k3', 1) sys.addConstant('k5', 0.0005) sys.addConstant('K', 0) dAdt = sys.addCompositor('A', 1) dBdt = sys.addCompositor('B', 1) dCdt = sys.addCompositor('C', 1) dEdt = sys.addCompositor('E', 1) reaction = Part( 'Fist', [dAdt, dBdt, dCdt, dEdt], [Rate('k1/(K+C^6)'), Rate('k3 * A'), Rate('k5 * B'), Rate('0')]) # degradation of A to some E deg_A = Part( 'A -> E', [dAdt, dBdt, dCdt, dEdt], [Rate('-d * A'), Rate('0'), Rate('0'), Rate('d * A')]) # degradation of B to some E deg_B = Part('B -> E', [dAdt, dBdt, dCdt, dEdt], [Rate('0'), Rate('-d * B'), Rate('0'), Rate('d * B')]) # degradation of C to some E
# equivalent of production cycles phases_lst_p1= [pp4, pp2, pp1] phases_lst_p2= [pp6, pp9, pp7, pp5, pp3] phases_lst_p3= [pp8, pp14, pp11, pp10] phases_lst_p4= [pp12, pp15, pp16] phases_lst_p5= [pp13, pp17] # production cycles per product pc1= ProductionCycle(phases_lst_p1) pc2= ProductionCycle(phases_lst_p2) pc3= ProductionCycle(phases_lst_p3) pc4= ProductionCycle(phases_lst_p4) pc5= ProductionCycle(phases_lst_p5) # parts p1= Part("01", pc1, "null", 0, 0) p2= Part("02", pc2, "null", 0, 0) p3= Part("03", pc3, "null", 0, 0) p4= Part("04", pc4, "null", 0, 0) p5= Part("05", pc5, "null", 0, 0) # list of parts parts= [p1, p2, p3, p4, p5] pmim= Pmim(parts) print(pmim)
enzyme1.addSiteToRecognize('[') enzyme1.addSiteToRecognize('D') enzyme2 = enz.Enzyme('ATc') enzyme2.addSiteToRecognize('(') circuit = gc.GeneticCircuit([]) site1 = rs.RecognitionSite('D', 1) site2 = rs.RecognitionSite('[', 1) site3 = rs.RecognitionSite('(', 1) site4 = rs.RecognitionSite('[', -1) site5 = rs.RecognitionSite('(', 1) site6 = rs.RecognitionSite('D', -1) ##Overwrite the parts in this circuit part1_1 = part.Part(1, 1) part2_1 = part.Part(3, 1) part3_1 = part.Part(5, 1) part4_1 = part.Part(7, 1) part5_1 = part.Part(9, 1) part6_1 = part.Part(11, 1) part7_1 = part.Part(13, 1) circuit.addComponent(part1_1) circuit.addComponent(site1) circuit.addComponent(part2_1) circuit.addComponent(site2) circuit.addComponent(part3_1) circuit.addComponent(site3) circuit.addComponent(part4_1) circuit.addComponent(site4)
sys.addConstant('k', 0.05) # Let's define substances: A, B, E # with initial contration values: 10, 0, 1 dAdt = sys.addCompositor('A', 10) dBdt = sys.addCompositor('B', 0) dEdt = sys.addCompositor('E', 1) # Define chemical reaction 'A + E -k> B + E' rates # Set initial substance concentrations. # Substance A decreases by the law '-k * A * E' where A, E are current # concentration of substances. # Substance B increases by the law 'k * A * E' (as much as A decreases). # Substance E is a catalyst, so, its concentration doesn't change. reaction = Part( 'A + E -k> B + E', [dAdt, dBdt, dEdt], [Rate('-k * A * E'), Rate('k * A * E'), Rate('0')]) # Add the reaction to the simulation. sys.addPart(reaction) # Initialise time points and substance concentration values. T = None Y = None # Simulate system with provided reactions for 25 seconds. (T, Y) = sys.run([0, 25]) # T - time points of the simulation. # Y - a matrix, rows shows the substance concentrations at particular time # point, columns - substance concentrations change in time.
def subPartArrayExpressionVectorAnalysis_NonIso(subPartArray, readThrough=False): startStateCombos = [(0, 0), (0, 1), (1, 0), (1, 1)] configurations = [[0, 1, 2, 3, 4], [0, -2, -1, 3, 4], [0, 1, 4], [0, -2, -3, 1, 4]] ##We are going to skip designs that have no genes in them because there is an ##extra layer of complication that we have to consider with these. ##This may not be necessary anymore numberOfGenes = 0 for i in subPartArray: absI = abs(i) if absI in geneCount: numberOfGenes += geneCount[absI] numberOfNonReadThroughStates = 0 geneExpressionByState = {} geneExpressionByStateArray = [{}, {}, {}, {}] outputsByState = [{}, {}, {}, {}] for ci in xrange(len(configurations)): config = configurations[ci] circuit = gc.GeneticCircuit([]) numberOfParts = len(config) for partLocation in config: ##Create parts to add pId = subPartArray[abs(partLocation)] ##For the first part, since its a 0 if partLocation == 0 and pId < 0: circuit.addComponent(part.Part(abs(pId), -1, abs(partLocation))) elif partLocation == 0 and pId > 0: circuit.addComponent(part.Part(abs(pId), 1, abs(partLocation))) elif (partLocation < 0 and pId > 0) or (partLocation > 0 and pId < 0): ##It is flipped circuit.addComponent(part.Part(abs(pId), -1, abs(partLocation))) else: circuit.addComponent(part.Part(abs(pId), 1, abs(partLocation))) partsTopAndBottom = circuit.printAllParts(withLocations=True) ##Read-through check readThroughCircuit = False if len(partsTopAndBottom['TOP']) == 0 or len( partsTopAndBottom['BOTTOM']) == 0: if not readThrough: return 'READTHROUGH' else: readThroughCircuit = True ##In the case when we only want circuits that have read through if not readThroughCircuit and readThrough: numberOfNonReadThroughStates += 1 if numberOfNonReadThroughStates == 4: return 'NONREADTHROUGH' if ci == 0: for ps in partsTopAndBottom['TOP']: ##Get the genes out if ps[0] == 'G': # if ps != 'G.0.1': geneExpressionByState[ps] = [{}, {}, {}, {}] for ps in partsTopAndBottom['BOTTOM']: ##Get the genes out if ps[0] == 'G': # if ps != 'G.4.1': geneExpressionByState[ps] = [{}, {}, {}, {}] for reading in startStateCombos: expressedGenesInThisState = circuit.printOnlyExpressed( returnOnlyExpressedGenes=False, topStart=reading[0], bottomStart=reading[1]) geneExpressionByStateArray[ci][ reading] = expressedGenesInThisState['expressedGenes'] for gene in expressedGenesInThisState['expressedGenes']: geneExpressionByState[gene][ci][reading] = True ##Have to check this outputs stuff again as I am realizing it doesn't make sense. ##For most of the non-isos, it may be state independent actually, so we do not need ##to worry about the input. TRUE but need the reading for cases with dependencies ##like the read through case outputsByState[ci][reading] = { 'topRight': expressedGenesInThisState['topOutputState'], 'bottomLeft': expressedGenesInThisState['bottomOutputState'], ##For cases when we want to check if the out put state is due to the ##input state 'topStateChanged': expressedGenesInThisState['topStateChanged'], 'bottomStateChanged': expressedGenesInThisState['bottomStateChanged'] } # for sn in geneExpressionByStateArray: # print sn return { 'numberOfGenes': numberOfGenes, 'genesToStates': geneExpressionByState, 'statesToGenes': geneExpressionByStateArray, 'outputs': outputsByState }
def subPartArrayExpressionVectorAnalysis_Iso(subPartArray): configurations = [[0, 1, 2, 3, 4], [0, -2, -1, 3, 4], [0, 1, 4], [0, -2, -3, 1, 4]] numberOfGenes = 0 for i in subPartArray: absI = abs(i) if absI in geneCount: numberOfGenes += geneCount[absI] geneExpressionByState = {} geneExpressionByStateArray = [{}, {}, {}, {}] outputsByState = [] ##Read through states passed readThroughCircuitStatesPassed = 0 for ci in xrange(len(configurations)): config = configurations[ci] circuit = gc.GeneticCircuit([]) numberOfParts = len(config) for partLocation in config: ##Create parts to add pId = subPartArray[abs(partLocation)] ##For the first part, since its a 0 if partLocation == 0 and pId < 0: circuit.addComponent(part.Part(abs(pId), -1, abs(partLocation))) elif partLocation == 0 and pId > 0: circuit.addComponent(part.Part(abs(pId), 1, abs(partLocation))) elif (partLocation < 0 and pId > 0) or (partLocation > 0 and pId < 0): ##It is flipped circuit.addComponent(part.Part(abs(pId), -1, abs(partLocation))) else: circuit.addComponent(part.Part(abs(pId), 1, abs(partLocation))) partsTopAndBottom = circuit.printAllParts(withLocations=True) ##Read-through check (should never happen for parts with terms) if len(partsTopAndBottom['TOP']) == 0 or len( partsTopAndBottom['BOTTOM']) == 0: return 'READTHROUGH' else: readThroughCircuitStatesPassed += 1 if ci == 0: for ps in partsTopAndBottom['TOP']: ##Get the genes out if ps[0] == 'G': if ps != 'G.0.1': geneExpressionByState[ps] = [] for ps in partsTopAndBottom['BOTTOM']: ##Get the genes out if ps[0] == 'G': if ps != 'G.4.1': geneExpressionByState[ps] = [] expressedGenesInThisState = circuit.printOnlyExpressed( returnOnlyExpressedGenes=False) for gene in expressedGenesInThisState['expressedGenes']: geneExpressionByState[gene].append(ci) geneExpressionByStateArray[ci][gene] = True outputsByState.append({ 'topRight': expressedGenesInThisState['topOutputState'], 'bottomLeft': expressedGenesInThisState['bottomOutputState'] }) # print geneExpressionByState for gene in geneExpressionByState: if len(geneExpressionByState[gene]) == 0 or len( geneExpressionByState[gene]) == 4: ##This part is either unused or always used and should not be included # print gene return False return { 'genesToStates': geneExpressionByState, 'statesToGenes': geneExpressionByStateArray, 'outputs': outputsByState, 'numberOfGenes': numberOfGenes }
sys.addConstant('k', 0.1) # Let's define substances: A, B, E # with initial contration values: 10, 0, 1 dAdt = sys.addCompositor('A', 10) dBdt = sys.addCompositor('B', 0) dRdt = sys.addCompositor('R', 1) # Define chemical reaction 'A + E -k> B + E' rates # Set initial substance concentrations. # Substance A decreases by the law '-k * A * E' where A, E are current # concentration of substances. # Substance B increases by the law 'k * A * E' (as much as A decreases). # Substance E is a catalyst, so, its concentration doesn't change. reaction = Part( 'A + R -k> B + R', [dAdt, dBdt, dRdt], [Rate('-k * A * R'), Rate('k * A * R'), Rate('0')]) # Add the reaction to the simulation. sys.addPart(reaction) # Initialise time points and substance concentration values. T = None Y = None # Simulate system with provided reactions for 25 seconds. (T, Y) = sys.run([0, 50]) Z = np.concatenate((np.vstack(T), Y), axis=1)
"""Creates a circuit for testing""" import Part as part import RecognitionSite as rs import GeneticCircuit as gc import Enzyme as enz import copy import unittest ##SETUP ##Create the parts part1 = part.Part(1, 1) site1 = rs.RecognitionSite('D', 1) part2 = part.Part(2, 1) site2 = rs.RecognitionSite('[', 1) part3 = part.Part(3, 1) site3 = rs.RecognitionSite('(', 1) part4 = part.Part(4,1) site4 = rs.RecognitionSite('[', -1) part5 = part.Part(5, 1) site5 = rs.RecognitionSite('(', 1) part6 = part.Part(6, 1) site6 = rs.RecognitionSite('D', -1) part7 = part.Part(7,1) ##Create the enzymes enzyme1 = enz.Enzyme('Ara') enzyme1.addSiteToRecognize('[') enzyme1.addSiteToRecognize('D') enzyme2 = enz.Enzyme('ATc')
from Pulse import * import matplotlib.pyplot as plt # Create a BioSystem to simulate. sys = BioSystem() # Add the constant 'k' with a value 0.05. # This will be the speed of the chemical reaction. sys.addConstant('a', 5) sys.addConstant('b', 0.3) sys.addConstant('V', 100) # with initial contration values: 10, 1, 1 dBdt = sys.addCompositor('B', 1) #koncentracija litre reaction = Part('rates', [dBdt], [Rate('B * b * ((V + a * t)^(-1) - t*(V + a * t)^(-2))')]) # Add the reaction to the simulation. sys.addPart(reaction) # Initialise time points and substance concentration values. T = None Y = None # Simulate system with provid # d reactions for 25 seconds. (T, Y) = sys.run([0, 25]) # T - time points of the simulation. # Y - a matrix, rows shows the substance concentrations at particular time # point, columns - substance concentrations change in time.
def generatePromoterOutputs(subPartArray, leftOnly=False, rightOnly=False): ##If we see G.0.1 being transcribed, then we know that the output is 1 on the left #else it's 0 if we see G.4.1 being transcribed, then we know that the output is 1 ##on the right else it is 0 configurations = [[0, 1, 2, 3, 4], [0, -2, -1, 3, 4], [0, 1, 4], [0, -2, -3, 1, 4]] geneExpressionByState = {} geneExpressionByStateArray = [{}, {}, {}, {}] outputsByState = [{}, {}, {}, {}] for ci in xrange(len(configurations)): config = configurations[ci] circuit = gc.GeneticCircuit([]) numberOfParts = len(config) for partLocation in config: ##Create parts to add pId = subPartArray[abs(partLocation)] ##For the first part, since its a 0 if partLocation == 0 and pId < 0: circuit.addComponent(part.Part(abs(pId), -1, abs(partLocation))) elif partLocation == 0 and pId > 0: circuit.addComponent(part.Part(abs(pId), 1, abs(partLocation))) elif (partLocation < 0 and pId > 0) or (partLocation > 0 and pId < 0): ##It is flipped circuit.addComponent(part.Part(abs(pId), -1, abs(partLocation))) else: circuit.addComponent(part.Part(abs(pId), 1, abs(partLocation))) partsTopAndBottom = circuit.printAllParts(withLocations=True) ##Read through check if len(partsTopAndBottom['TOP']) == 0 or len( partsTopAndBottom['BOTTOM']) == 0: return 'READTHROUGH' if ci == 0: if not rightOnly: for ps in partsTopAndBottom['TOP']: ##Get the genes out if ps[0] == 'G': geneExpressionByState[ps] = [] if not leftOnly: for ps in partsTopAndBottom['BOTTOM']: ##Get the genes out if ps[0] == 'G': geneExpressionByState[ps] = [] ##Check if we should be skip the circuit shouldSkip = circuit.printAllParts() if len(shouldSkip['TOP']) == 0 or len(shouldSkip['BOTTOM']) == 0: # print subPartArray # print shouldSkip return 'READTHROUGH' expressedGenesInThisState = circuit.printOnlyExpressed( returnOnlyExpressedGenes=False) outputsByState[ci]['topRight'] = expressedGenesInThisState[ 'topOutputState'] outputsByState[ci]['bottomLeft'] = expressedGenesInThisState[ 'bottomOutputState'] # print expressedGenesInThisState['expressedPromotersFull'] for gene in expressedGenesInThisState['expressedGenes']: if gene in geneExpressionByState: geneExpressionByState[gene].append(ci) geneExpressionByStateArray[ci][gene] = True return { 'genesToStates': geneExpressionByState, 'statesToGenes': geneExpressionByStateArray, 'outputs': outputsByState }
def subCircuitUsedAndUnusedParts(subPartArray, segmentNumber=2): ##The sub array has to be a length 5 # print segmentNumber ##We are going to exluce 4's and 6's from this as well because we want to include these so ##that we know when to replace with one sided genes or promoters toExclude = set([5]) if segmentNumber == 1: if abs(subPartArray[4]) in toExclude: return False elif segmentNumber == 2: if abs(subPartArray[0]) in toExclude or abs( subPartArray[4]) in toExclude: return False elif segmentNumber == 3: if abs(subPartArray[0]) in toExclude: return False ##We only need to check four possible configurations configurations = [[0, 1, 2, 3, 4], [0, -2, -1, 3, 4], [0, 1, 4], [0, -2, -3, 1, 4]] stateNumberToConfig = [ 0, ] toIgnore = { 'G.0.1': [1, 2, 8], 'P.0.1': [-2, -3], 'P.0.2': [6, -3], 'G.4.1': [-1, -2], 'G.4.2': [8], 'P.4.1': [2, 3, 6], 'T.4': [3, -3] } allParts = {} validPartLetters = set(['P', 'G', 'T']) ##For each config, we build a circuit and analyze it and in the end ##We will determine which components have been used for ci in xrange(len(configurations)): config = configurations[ci] ##First have to look at the top circuit = gc.GeneticCircuit([]) numberOfParts = len(config) for partLocation in config: ##Create parts to add pId = subPartArray[abs(partLocation)] # print pId # print partLocation ##For the first part, since its a 0 if partLocation == 0 and pId < 0: circuit.addComponent(part.Part(abs(pId), -1, abs(partLocation))) elif partLocation == 0 and pId > 0: circuit.addComponent(part.Part(abs(pId), 1, abs(partLocation))) elif (partLocation < 0 and pId > 0) or (partLocation > 0 and pId < 0): ##It is flipped circuit.addComponent(part.Part(abs(pId), -1, abs(partLocation))) else: circuit.addComponent(part.Part(abs(pId), 1, abs(partLocation))) ##We can get all the parts for this sub circuit in the first config if ci == 0: partsTopAndBottom = circuit.printAllParts(withLocations=True) for p in partsTopAndBottom['TOP']: if p[0] in validPartLetters: ##Special case for term, where we only add the first two parts of the string ##This is because we are only using bidirectional terms, so we are only ##considering it un unused term if BOTH terms on the bidirectional term ##are unused (do not change the expression of the genes) if p[0] == 'T': ##Split the part splitPart = p.split('.') if abs(subPartArray[int(splitPart[1])]) == 4: newPartName = str(splitPart[0]) + '.' + str( splitPart[1]) allParts[newPartName] = False # elif p[0] == 'P': # ##Split the part # ##If one of the parts with a 6 in it is used, then we want to keep this # ##this circuit # splitPart = p.split('.') # if abs(subPartArray[int(splitPart[1])]) == 6: # newPartName = str(splitPart[0]) + '.' + str(splitPart[1]) # allParts[newPartName] = False else: allParts[p] = False for p in partsTopAndBottom['BOTTOM']: if p[0] in validPartLetters: if p[0] == 'T': ##Split the part splitPart = p.split('.') if abs(subPartArray[int(splitPart[1])]) == 4: newPartName = str(splitPart[0]) + '.' + str( splitPart[1]) allParts[newPartName] = False ##If one of the parts with a 6 in it is used, then we want to keep this ##this circuit # elif p[0] == 'P': # ##Split the part # splitPart = p.split('.') # if abs(subPartArray[int(splitPart[1])]) == 6: # newPartName = str(splitPart[0]) + '.' + str(splitPart[1]) # allParts[newPartName] = False else: allParts[p] = False ##Now look at the expression of this circuit # print circuit.printCircuit() expressionVector = circuit.printOnlyExpressed( returnOnlyExpressedGenes=False) # print expressionVector for k in expressionVector['expressedPromotersFull']: allParts[k] = True for k in expressionVector['expressedGenes']: allParts[k] = True ##Looking at terminators for k in expressionVector['expressedTerminatorsFull']: splitTermPart = k.split('.') newname = str(splitTermPart[0]) + '.' + str(splitTermPart[1]) allParts[newname] = True # print "Segment num: " + str(segmentNumber) + "," + str(subPartArray) # print allParts # print segmentNumber # print allParts for k in allParts: if not allParts[k]: ##We just have to do a quick check that it is not a gene on one of the ends ##which could be used in a dffferent section if k in toIgnore: # print 'Looking to ignore: ' + str(k) splitK = k.split('.') if subPartArray[int(splitK[1])] in toIgnore[k]: continue ##Here is where we can figure out all of the circuits that we can skip ##because they have they will have this sub segment (its all of the) circuit ids ##that have this exact subsegment, so just have to check five values # print 'The one that failed: ' + str(k) # print k return True # print 'Should be false....' return False
def build16StateCircuit(parts, includeAllCircuits=True, includeTheseCircuits={}, compareTo=[], getPromsAndTerms=False): ##Create the recombination sites ##TP901 sites: F,O ##BxbI sites: X, I ##A118 sites: A, B comparingToLength = len(compareTo) site1 = rs.RecognitionSite('X', 1) site2 = rs.RecognitionSite('O', 1) site3 = rs.RecognitionSite('X', -1) site4 = rs.RecognitionSite('O', 1) site5 = rs.RecognitionSite('A', 1) site6 = rs.RecognitionSite('I', 1) site7 = rs.RecognitionSite('A', -1) site8 = rs.RecognitionSite('I', 1) site9 = rs.RecognitionSite('F', 1) site10 = rs.RecognitionSite('B', 1) site11 = rs.RecognitionSite('F', -1) site12 = rs.RecognitionSite('B', 1) sites = [ site1, site2, site3, site4, site5, site6, site7, site8, site9, site10, site11, site12 ] ##Instantiate the circuit circuit = gc.GeneticCircuit([]) numberOfParts = len(parts) partsWithPromotersInThem = {} partsWithTerminatorsInThem = {} allCircuits = [None for i in xrange(16)] for pI in range(numberOfParts): ##p is a number addedComp = None if parts[pI] < 0: posPartId = abs(parts[pI]) addedComp = circuit.addComponent(part.Part(posPartId, -1)) else: addedComp = circuit.addComponent(part.Part(parts[pI], 1)) ##Attempting to remove redundant circuits if addedComp.getId() not in part.PARTSWITHOUTPROMOTERS: partsWithPromotersInThem[addedComp.getPartLocation()] = True ##Using the incomplete array because we are only considering part 4 for ##now as a potential redundant terminator part if addedComp.getId() in part.PARTSWITHTERMINTAORS_INCOMPLETE: #if addedComp.getId() in part.PARTSWITHTERMINTAORS: partsWithTerminatorsInThem[addedComp.getPartLocation()] = True ##Add the site as long as its not the last part if (pI + 1 < numberOfParts): circuit.addComponent(sites[pI]) if includeAllCircuits: ##Want to return all the induced circuits as well enzyme1 = enz.Enzyme('BxbI') enzyme1.addSiteToRecognize('X') enzyme1.addSiteToRecognize('I') enzyme2 = enz.Enzyme('TP901') enzyme2.addSiteToRecognize('F') enzyme2.addSiteToRecognize('O') enzyme3 = enz.Enzyme('A118') enzyme3.addSiteToRecognize('A') enzyme3.addSiteToRecognize('B') c1 = circuit c2 = enz.induceCircuit(enzyme1, c1) c3 = enz.induceCircuit(enzyme2, c1) c4 = enz.induceCircuit(enzyme3, c1) c5 = enz.induceCircuit(enzyme2, c2) c6 = enz.induceCircuit(enzyme3, c2) c7 = enz.induceCircuit(enzyme1, c3) c8 = enz.induceCircuit(enzyme3, c3) c9 = enz.induceCircuit(enzyme1, c4) c10 = enz.induceCircuit(enzyme2, c4) c11 = enz.induceCircuit(enzyme3, c5) c12 = enz.induceCircuit(enzyme2, c6) c13 = enz.induceCircuit(enzyme3, c7) c14 = enz.induceCircuit(enzyme1, c8) c15 = enz.induceCircuit(enzyme2, c9) c16 = enz.induceCircuit(enzyme1, c10) allCircuits = [ c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16 ] if getPromsAndTerms: return { 'allCircuits': allCircuits, 'partsWithPromotersInThem': partsWithPromotersInThem, 'partsWithTerminatorsInThem': partsWithTerminatorsInThem } else: return allCircuits elif len(includeTheseCircuits) > 0: ##Want to return only a subset of the circuits enzyme1 = enz.Enzyme('BxbI') enzyme1.addSiteToRecognize('X') enzyme1.addSiteToRecognize('I') enzyme2 = enz.Enzyme('TP901') enzyme2.addSiteToRecognize('F') enzyme2.addSiteToRecognize('O') enzyme3 = enz.Enzyme('A118') enzyme3.addSiteToRecognize('A') enzyme3.addSiteToRecognize('B') enzymes = [enzyme1, enzyme2, enzyme3] parentCircuit = [None, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9] inducingEnzyme = [None, 0, 1, 2, 1, 2, 0, 2, 0, 1, 2, 1, 2, 0, 1, 0] for i in xrange(len(allCircuits)): if len(includeTheseCircuits) > 0: if (i + 1) not in includeTheseCircuits: continue if i == 0: if comparingToLength > 0: if getNumberOfGenesExpressedForCircuit([circuit ]) != compareTo[i]: return False allCircuits[0] = circuit else: allCircuits[i] = enz.induceCircuit( enzymes[inducingEnzyme[i]], allCircuits[parentCircuit[i]]) if comparingToLength > 0: if getNumberOfGenesExpressedForCircuit([allCircuits[i] ]) != compareTo[i]: return False return allCircuits else: return [circuit]