Example #1
1
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)
Example #2
1
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
Example #3
0
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)
Example #4
0
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)
Example #5
0
def __cutCircuit(oldCircuitComponents, cut1, cut2):
	tempCircuit = gc.GeneticCircuit([])
	for i in range(len(oldCircuitComponents)):
		if cut1 <= i and i < cut2:
			next
		else:
			tempCircuit.addComponent(oldCircuitComponents[i])
	return tempCircuit
def makeSimpleCicuit():
        circuit = gc.GeneticCircuit([])
        circuit.addComponent(part1)
        circuit.addComponent(site1)
        circuit.addComponent(part2)
        circuit.addComponent(site6)
        circuit.addComponent(part3)

        return copy.deepcopy(circuit)
Example #7
0
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 makeCircuit3State():
    ##Create the circuit
    circuit = gc.GeneticCircuit([])
    circuit.addComponent(part1)
    circuit.addComponent(site1)
    circuit.addComponent(part2)
    circuit.addComponent(site2)
    circuit.addComponent(part3)
    circuit.addComponent(site3)
    circuit.addComponent(part4)
    circuit.addComponent(site4)
    circuit.addComponent(part5)
    circuit.addComponent(site5)
    circuit.addComponent(part6)
    circuit.addComponent(site6)
    circuit.addComponent(part7)

    return copy.deepcopy(circuit)
Example #9
0
def induceCircuit(enzyme, geneticcircuit):	
	##Now iterate through each site that this enzyme recognizes and id the
	##genetic circuit contains those sites, then we have to either flip or cut
	components = geneticcircuit.getComponents()
	newCircuit = gc.GeneticCircuit(components)
	for site in enzyme.sitesRecognized:
		##Get the cut site locations, which can be different from what they were
		##in the original circuit if it's been cut
		siteLocations = __getCutSiteLocations(enzyme, newCircuit)
		if site in siteLocations:
			##There are cut sites. Check if there are two. Won't worry about other
			##Cases for now but should be implemented later on
			##
			##TODO: handle cases when there are more than 2 cut sites
			if len(siteLocations[site]) == 2:
				[cut1, cut2] = siteLocations[site]
				tempCircuit = __induceWithSingleSite(newCircuit, cut1, cut2)
				newCircuit = tempCircuit
	return newCircuit
Example #10
0
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
Example #11
0
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]
import Part as part
import RecognitionSite as rs
import GeneticCircuit as gc
import Enzyme as enz

##Create the enzymes
enzyme1 = enz.Enzyme('Ara')
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)
Example #13
0
def convertFromAsGeneticCircuits(stateNumber, gcElement):
    components = gcElement.getComponents()[:]
    ##Flip components order and return newCircuit
    newComponents = convertFrom(stateNumber, components)
    return gc.GeneticCircuit(newComponents)
Example #14
0
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
    }
Example #15
0
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
    }
Example #16
0
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]
Example #17
0
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
    }