Esempio n. 1
0
def _sampleAVG(avg, size):
	""" Simplified pipeline """
	C = cactus.Cactus(avg)
	NC = normalized.NormalizedCactus(C)
	OC = oriented.OrientedCactus(NC)
	H = cycleCover.initialHistory(OC)
	return sampleGraphCycles.sample(H, size)
Esempio n. 2
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.simulation:
		debug.RATIO_TO_OFFSET = False

	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
		SH = sampleGraphCycles.sample(H, options.size, pickle_file, stats_file, braney_file, tree_file)

		# 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)
Esempio n. 3
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.simulation:
        debug.RATIO_TO_OFFSET = False

    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
        SH = sampleGraphCycles.sample(H, options.size, pickle_file, stats_file,
                                      braney_file, tree_file)

        # 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)