Example #1
0
def main():
    G = avg.randomEulerianGraph(10)
    C = cactus.Cactus(G)
    NC = normalized.NormalizedCactus(C)
    BC = balancedCactus.BalancedCactus(NC)
    OC = oriented.OrientedCactus(BC)
    H = cycleCover.initialHistory(OC)
    assert areUnitFlows(X.cycle for X in H.parent)
Example #2
0
def main():
    G = avg.randomNearEulerianGraph(10)
    C = cactus.Cactus(G)
    N = normalized.NormalizedCactus(C)
    B = balanced.BalancedCactus(N)
    O = oriented.OrientedCactus(B)
    print C
    print '>>>>>>>>>>>>>>>>>>>>>>'
    print "\n".join(map(str, extractGraphModules(O).values()))
Example #3
0
def main():
    graph = avg.randomNearEulerianGraph(10)
    C = cactus.Cactus(graph)
    NC = normalized.NormalizedCactus(C)
    BC = balanced.BalancedCactus(NC)
    OC = oriented.OrientedCactus(BC)
    H = cycleCover.initialHistory(OC)
    H.validate()
    print H
    c = H.rearrangementCost()
    FH = flattenGraph(H)
    print FH
    print FH.cactus.telomeres
    FH.validate()
Example #4
0
def main():
	options = _parseOptions()

	sampleGraphCycles.TEMPERATURE = options.temp

	if options.dir is not None:
		if not os.path.exists(options.dir):
			os.mkdir(options.dir)
		os.chdir(options.dir)

	if options.index is None:
		## Initial graph construction
		G = _parseGraph(options)
		B = balancedAVG.BalancedAVG(G)
		C = cactus.Cactus(B)
		pickle.dump(C, open('CACTUS', "wb"))
	else:
		H = None

		if options.debug:
			## Picking up from where we started
			OC = pickle.load(open('CACTUS_%i' % options.index))
			random.setstate(pickle.load(open("STATE_%i" % options.index)))
		elif options.cont:
			## Picking up from where we stopped
			OC = pickle.load(open('CACTUS_%i' % options.index))
			## Going through all the histories to the last in file 
			file= open('HISTORIES_%i' % (options.index))
			while True:
				try:
					H = pickle.load(file)
				except:
					break
			file.close()
		else:
			## Just moving from there 
			pickle.dump(random.getstate(), open("STATE_%i" % options.index, "wb"))
			C = pickle.load(open('CACTUS'))

			## Sampling possible cactus
			NC = normalized.NormalizedCactus(C)
			if debug.RATIO_TO_OFFSET:
				BC = balancedCactus.BalancedCactus(NC)
			else:
				BC = NC
			OC = oriented.OrientedCactus(BC)

			## Saving sampled cactus
			pickle.dump(OC, open('CACTUS_%i' % options.index, "wb"))
		

		# Moving into historical space
		if options.integer:
			debug.INTEGER_HISTORY = True
		if H is None:
			H = cycleCover.initialHistory(OC)
		FH = flattened.flattenGraph(H)
		S = FH.simplifyStubsAndTrivials()
		F = S.removeLowRatioEvents(debug.RATIO_CUTOFF)
		O = ordered.OrderedHistory(F)

		# Preparing file for progressive write
		if options.cont:
			stats_file = open("HISTORY_STATS_%li" % options.index, "a")
			pickle_file = open('HISTORIES_%i' % options.index, "ab")
			braney_file = gzip.open("HISTORIES_%i.braney" % options.index, "a")
		else:
			stats_file = open("HISTORY_STATS_%li" % options.index, "w")
			pickle_file = open('HISTORIES_%i' % options.index, "wb")
			braney_file = gzip.open("HISTORIES_%i.braney" % options.index, "w")
		stats_file.write("%s\n" % H.stats())
		#pickle.dump(H, pickle_file)
		braney_file.write("%s\n" % O.braneyText(0, H.rearrangementCost()))
		#tree_file = open("HISTORY_TREES_%li" % options.index, "w")
		#tree_file.write("%s\n" % O.newick())
		tree_file = None

		# Sampling
		for i in range(options.size):
			H2 = copy.copy(H)
			# Shuffle events
			for event in list(H.parent):
				H2.correctSchedulingError(event)
			H = H2
			stats_file.write("%s\n" % H.stats())
			FH = flattened.flattenGraph(H)
			S = FH.simplifyStubsAndTrivials()
			F = S.removeLowRatioEvents(debug.RATIO_CUTOFF)
			O = ordered.OrderedHistory(F)
			braney_file.write("%s\n" % O.braneyText(i+1, H.rearrangementCost()))

		# Cleaning up
		stats_file.close()
		pickle_file.close()
		braney_file.close()
		#tree_file.close()

		## Removing temp file
		if os.path.exists("STATE_%i" % options.index):
			os.remove("STATE_%i" % options.index)