def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        # Get time
        time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time")

        # Get tRNA IDs and counts
        sim_data = cPickle.load(open(simDataFile, "rb"))
        isTRna = sim_data.process.transcription.rnaData["isTRna"]
        rnaIds = sim_data.process.transcription.rnaData["id"][isTRna]
        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))
        moleculeIds = bulkMolecules.readAttribute("objectNames")
        rnaIndexes = np.array(
            [moleculeIds.index(moleculeId) for moleculeId in rnaIds], np.int)
        rnaCountsBulk = bulkMolecules.readColumn("counts")[:, rnaIndexes]
        bulkMolecules.close()

        # Plot
        fig = plt.figure(figsize=(8.5, 11))
        ax = plt.subplot(1, 1, 1)
        ax.plot(time, rnaCountsBulk)
        ax.set_xlim([time[0], time[-1]])
        ax.set_xlabel("Time (s)")
        ax.set_ylabel("Counts of tRNAs")
        ax.spines["right"].set_visible(False)
        ax.spines["top"].set_visible(False)
        ax.tick_params(right="off", top="off", which="both", direction="out")

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

        rnaIds = [
            "EG10367_RNA[c]",
            "EG11036_RNA[c]",
            "EG50002_RNA[c]",
            "EG10671_RNA[c]",
            "EG50003_RNA[c]",
            "EG10669_RNA[c]",
            "EG10873_RNA[c]",
            "EG12179_RNA[c]",
            "EG10321_RNA[c]",
            "EG10544_RNA[c]",
        ]
        names = [
            "gapA - Glyceraldehyde 3-phosphate dehydrogenase",
            "tufA - Elongation factor Tu",
            "rpmA - 50S Ribosomal subunit protein L27",
            "ompF - Outer membrane protein F",
            "acpP - Apo-[acyl carrier protein]",
            "ompA - Outer membrane protein A",
            "rplL - 50S Ribosomal subunit protein L7/L12 dimer",
            "cspE - Transcription antiterminator and regulator of RNA stability",
            "fliC - Flagellin",
            "lpp - Murein lipoprotein",
        ]

        moleculeIds = bulkMolecules.readAttribute("objectNames")
        rnaIndexes = np.array([moleculeIds.index(x) for x in rnaIds], np.int)
        rnaCounts = bulkMolecules.readColumn("counts")[:, rnaIndexes]

        bulkMolecules.close()

        initialTime = TableReader(os.path.join(
            simOutDir, "Main")).readAttribute("initialTime")
        time = TableReader(os.path.join(
            simOutDir, "Main")).readColumn("time") - initialTime

        plt.figure(figsize=(8.5, 11))

        for subplotIdx in xrange(1, 10):

            plt.subplot(3, 3, subplotIdx)

            plt.plot(time / 60., rnaCounts[:, subplotIdx])
            plt.xlabel("Time (min)")
            plt.ylabel("mRNA counts")
            plt.title(names[subplotIdx].split(" - ")[0])

        plt.subplots_adjust(hspace=0.5, top=0.95, bottom=0.05)
        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
Exemplo n.º 3
0
    def do_plot(self, seedOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(seedOutDir):
            raise Exception, "seedOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        fig = plt.figure()
        v = venn3(subsets=dataArea,
                  set_labels=["0 < Freq. < 1", "Freq. = 1", "Freq. = 0"])
        ids = ["100", "010", "001", "110", "101", "011", "111"]

        for i, color in zip(
                ids, ["b", "r", "y", "purple", "green", "orange", "white"]):
            v.get_patch_by_id(i).set_color(color)

        for label, color in zip(v.set_labels, ["b", "r", "y"]):
            label.set_color(color)

        v.get_label_by_id("011").set_text("%s" % data[-2])

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)

        for i in ids:
            v.get_label_by_id(i).set_text("")

        for label in v.set_labels:
            label.set_text("")

        plt.savefig(os.path.join(plotOutDir, plotOutFileName + "__clean.pdf"))
        plt.close()
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

        moleculeIds = bulkMolecules.readAttribute("objectNames")

        waterIndex = np.array(moleculeIds.index('WATER[c]'), np.int)

        waterCount = bulkMolecules.readColumn("counts")[:, waterIndex]
        initialTime = TableReader(os.path.join(
            simOutDir, "Main")).readAttribute("initialTime")
        time = TableReader(os.path.join(
            simOutDir, "Main")).readColumn("time") - initialTime

        bulkMolecules.close()

        plt.figure(figsize=(8.5, 11))

        plt.plot(time / 60., waterCount, linewidth=2)
        plt.xlabel("Time (min)")
        plt.ylabel("WATER[c] counts")
        plt.title("Counts of water")

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
Exemplo n.º 5
0
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        ribosomeData = TableReader(os.path.join(simOutDir, "RibosomeData"))

        initialTime = TableReader(os.path.join(
            simOutDir, "Main")).readAttribute("initialTime")
        time = TableReader(os.path.join(
            simOutDir, "Main")).readColumn("time") - initialTime
        fractionStalled = ribosomeData.readColumn("fractionStalled")

        ribosomeData.close()

        plt.figure(figsize=(8.5, 11))
        plt.plot(time / 60, fractionStalled)

        plt.xlabel("Time (min)")
        plt.ylabel("Fraction of ribosomes stalled")

        plt.subplots_adjust(hspace=0.5, wspace=0.5)

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
    def do_plot(self, seedOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(seedOutDir):
            raise Exception, "seedOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        ap = AnalysisPaths(seedOutDir, multi_gen_plot=True)

        # Get all cells
        allDir = ap.get_cells()

        cellCycleLengths = []
        generations = []
        for idx, simDir in enumerate(allDir):
            simOutDir = os.path.join(simDir, "simOut")
            initialTime = TableReader(os.path.join(
                simOutDir, "Main")).readAttribute("initialTime")
            time = TableReader(os.path.join(simOutDir,
                                            "Main")).readColumn("time")

            cellCycleLengths.append((time[-1] - time[0]) / 60. / 60.)
            generations.append(idx)

        plt.scatter(generations, cellCycleLengths)
        plt.xlabel('Generation')
        plt.ylabel('Time (hr)')
        plt.title('Cell cycle lengths')
        plt.xticks(generations)

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)

        plt.close("all")
Exemplo n.º 7
0
    def do_plot(self, inputDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if metadata is not None and SHUFFLE_VARIANT_TAG not in metadata[
                "variant"]:
            print "This plot only runs for variants where parameters are shuffled."
            return

        if not os.path.isdir(inputDir):
            raise Exception, "variantDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        validation_data = cPickle.load(open(validationDataFile, "rb"))
        schmidtCounts = validation_data.protein.schmidt2015Data[
            "glucoseCounts"]

        ap = AnalysisPaths(inputDir, variant_plot=True)

        pool = Pool(processes=parallelization.plotter_cpus())
        args = zip(
            range(ap.n_variant), [ap] * ap.n_variant,
            [validation_data.protein.schmidt2015Data["monomerId"].tolist()] *
            ap.n_variant, [schmidtCounts] * ap.n_variant)
        result = pool.map(getPCC, args)
        # cPickle.dump(result, open("pcc_results.cPickle", "w"), cPickle.HIGHEST_PROTOCOL)
        pool.close()
        pool.join()
        # result = cPickle.load(open("pcc_results.cPickle", "r"))
        controlPcc, controlPvalue = result[0]
        pccs, pvals = zip(*result[1:])
        pccs = np.array(pccs)
        pvals = np.array(pvals)

        fig = plt.figure()
        fig.set_figwidth(5)
        fig.set_figheight(5)
        ax = plt.subplot(1, 1, 1)

        pccs = np.array([x for x in pccs if not np.isnan(x)])
        ax.hist(pccs, np.sqrt(pccs.size))
        ax.axvline(controlPcc, color="k", linestyle="dashed", linewidth=2)

        ax.set_xlabel("Proteome correlation (Pearson r)")
        ax.set_title("Mean: %0.3g     Std: %0.3g     Control: %0.3g" %
                     (pccs.mean(), pccs.std(), controlPcc))

        axes_list = [ax]

        for a in axes_list:
            for tick in a.yaxis.get_major_ticks():
                tick.label.set_fontsize(FONT_SIZE)
            for tick in a.xaxis.get_major_ticks():
                tick.label.set_fontsize(FONT_SIZE)

        whitePadSparklineAxis(ax)

        plt.subplots_adjust(bottom=0.2, wspace=0.3)

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

        rnaIds = [
            "EG10789_RNA[c]",
            "EG11556_RNA[c]",
            "EG12095_RNA[c]",
            "G1_RNA[c]",
            "G360_RNA[c]",
            "EG10944_RNA[c]",
            "EG12419_RNA[c]",
            "EG10372_RNA[c]",
            "EG10104_RNA[c]",
            "EG10539_RNA[c]",
        ]
        names = [
            "ptsI - PTS enzyme I",
            "talB - Transaldolase",
            "secG - SecG",
            "thiS - ThiS protein",
            "flgD - Flagellar biosynthesis",
            "serA - (S)-2-hydroxyglutarate reductase",
            "gatY - GatY",
            "gdhA - Glutamate dehydrogenase",
            "atpG - ATP synthase F1 complex - gamma subunit",
            "livJ - Branched chain amino acid ABC transporter - periplasmic binding protein",
        ]

        moleculeIds = bulkMolecules.readAttribute("objectNames")
        rnaIndexes = np.array([moleculeIds.index(x) for x in rnaIds], np.int)
        rnaCounts = bulkMolecules.readColumn("counts")[:, rnaIndexes]

        bulkMolecules.close()

        initialTime = TableReader(os.path.join(
            simOutDir, "Main")).readAttribute("initialTime")
        time = TableReader(os.path.join(
            simOutDir, "Main")).readColumn("time") - initialTime

        plt.figure(figsize=(8.5, 11))

        for subplotIdx in xrange(1, 10):

            plt.subplot(3, 3, subplotIdx)

            plt.plot(time / 60., rnaCounts[:, subplotIdx])
            plt.xlabel("Time (min)")
            plt.ylabel("mRNA counts")
            plt.title(names[subplotIdx].split(" - ")[0])

        plt.subplots_adjust(hspace=0.5, top=0.95, bottom=0.05)
        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
Exemplo n.º 9
0
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

        rnaIds = [
            "G7355_RNA[c]",
            "EG11783_RNA[c]",
            "G7742_RNA[c]",
            "G6253_RNA[c]",
            "EG10632_RNA[c]",
            "EG11484_RNA[c]",
            "G7889_RNA[c]",
            "EG10997_RNA[c]",
            "EG10780_RNA[c]",
            "EG11060_RNA[c]",
        ]
        names = [
            "ypjD - Predicted inner membrane protein",
            "intA - CP4-57 prophage; integrase",
            "yrfG - Purine nucleotidase",
            "ylaC - Predicted inner membrane protein",
            "nagA - N-acetylglucosamine-6-phosphate deacetylase",
            "yigZ - Predicted elongation factor",
            "lptG - LptG (part of LPS transport system)",
            "mnmE - GTPase, involved in modification of U34 in tRNA",
            "pspE - Thiosulfate sulfurtransferase",
            "ushA - UDP-sugar hydrolase / 5'-ribonucleotidase / 5'-deoxyribonucleotidase",
        ]

        moleculeIds = bulkMolecules.readAttribute("objectNames")
        rnaIndexes = np.array([moleculeIds.index(x) for x in rnaIds], np.int)
        rnaCounts = bulkMolecules.readColumn("counts")[:, rnaIndexes]

        bulkMolecules.close()

        initialTime = TableReader(os.path.join(
            simOutDir, "Main")).readAttribute("initialTime")
        time = TableReader(os.path.join(
            simOutDir, "Main")).readColumn("time") - initialTime

        plt.figure(figsize=(8.5, 11))

        for subplotIdx in xrange(1, 10):

            plt.subplot(3, 3, subplotIdx)

            plt.plot(time / 60., rnaCounts[:, subplotIdx])
            plt.xlabel("Time (min)")
            plt.ylabel("mRNA counts")
            plt.title(names[subplotIdx].split(" - ")[0])

        plt.subplots_adjust(hspace=0.5, top=0.95, bottom=0.05)
        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
Exemplo n.º 10
0
    def do_plot(self, seedOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(seedOutDir):
            raise Exception, 'seedOutDir does not currently exist as a directory'

        filepath.makedirs(plotOutDir)

        with open(simDataFile, 'rb') as f:
            sim_data = cPickle.load(f)
        with open(validationDataFile, 'rb') as f:
            validation_data = cPickle.load(f)

        ap = AnalysisPaths(seedOutDir, multi_gen_plot=True)

        for sim_dir in ap.get_cells():
            simOutDir = os.path.join(sim_dir, 'simOut')

            # Listeners used
            main_reader = TableReader(os.path.join(simOutDir, 'Main'))

            # Load data
            time = main_reader.readColumn('time')

        plt.figure()

        ### Create Plot ###

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close('all')
	def do_plot(self, seedOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(seedOutDir):
			raise Exception, "seedOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		ap = AnalysisPaths(seedOutDir, multi_gen_plot = True)

		# TODO: Declutter Y-axis

		# Get first cell from each generation
		firstCellLineage = []
		for gen_idx in range(ap.n_generation):
			firstCellLineage.append(ap.get_cells(generation = [gen_idx])[0])

		massNames = [
					#"dryMass",
					"proteinMass",
					"tRnaMass",
					"rRnaMass",
					'mRnaMass',
					"dnaMass"
					]

		cleanNames = [
					#"Dry\nmass",
					"Protein\nmass frac.",
					"tRNA\nmass frac.",
					"rRNA\nmass frac.",
					"mRNA\nmass frac.",
					"DNA\nmass frac."
					]

		fig, axesList = plt.subplots(len(massNames), sharex = True)

		for simDir in firstCellLineage:
			simOutDir = os.path.join(simDir, "simOut")
			time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time")
			mass = TableReader(os.path.join(simOutDir, "Mass"))

			massData = np.zeros((len(massNames),time.size))

			for idx, massType in enumerate(massNames):
				massData[idx,:] = mass.readColumn(massNames[idx])

			massData = massData / massData.sum(axis = 0)

			for idx, massType in enumerate(massNames):
				axesList[idx].plot(time / 60, massData[idx,:])
				axesList[idx].set_ylabel(cleanNames[idx])

		for axes in axesList:
			axes.set_yticks(list(axes.get_ylim()))

		axesList[-1].set_xlabel('Time (min)')

		exportFigure(plt, plotOutDir, plotOutFileName,metadata)
		plt.close("all")
    def do_plot(self, variantDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(variantDir):
            raise Exception, "variantDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        # Get all cells in each seed
        ap = AnalysisPaths(variantDir, cohort_plot=True)

        max_cells_in_gen = 0
        for genIdx in range(ap.n_generation):
            n_cells = len(ap.get_cells(generation=[genIdx]))
            if n_cells > max_cells_in_gen:
                max_cells_in_gen = n_cells

        fig, axesList = plt.subplots(ap.n_generation, sharex=True)

        doubling_time = np.zeros((max_cells_in_gen, ap.n_generation))

        for genIdx in range(ap.n_generation):
            gen_cells = ap.get_cells(generation=[genIdx])
            for simDir in gen_cells:
                simOutDir = os.path.join(simDir, "simOut")
                time = TableReader(os.path.join(simOutDir,
                                                "Main")).readColumn("time")
                initialTime = TableReader(os.path.join(
                    simOutDir, "Main")).readAttribute("initialTime")

                doubling_time[np.where(simDir == gen_cells)[0],
                              genIdx] = (time.max() - initialTime) / 60.

        # Plot initial vs final masses
        if ap.n_generation == 1:
            axesList = [axesList]

        for idx, axes in enumerate(axesList):
            if max_cells_in_gen > 1:
                axes.hist(doubling_time[:, idx].flatten(),
                          int(np.ceil(np.sqrt(doubling_time[:, idx].size))))
            else:
                axes.plot(doubling_time[:, idx], 1, 'x')
                axes.set_ylim([0, 2])
            axes.axvline(doubling_time[:, idx].mean(),
                         color='k',
                         linestyle='dashed',
                         linewidth=2)
            axes.text(
                doubling_time[:, idx].mean(), 1, "Mean: %.3f Var: %.3f" %
                (doubling_time[:, idx].mean(), doubling_time[:, idx].var()))

        axesList[-1].set_xlabel("Doubling time (min))")
        axesList[ap.n_generation / 2].set_ylabel("Frequency")

        plt.subplots_adjust(hspace=0.2, wspace=0.5)

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
Exemplo n.º 13
0
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		sim_data = cPickle.load(open(simDataFile, "rb"))
		isMRna = sim_data.process.transcription.rnaData["isMRna"]
		isRRna = sim_data.process.transcription.rnaData["isRRna"]
		isTRna = sim_data.process.transcription.rnaData["isTRna"]

		rnaSynthProbListener = TableReader(os.path.join(simOutDir, "RnaSynthProb"))
		rnaIds = rnaSynthProbListener.readAttribute('rnaIds')
		rnaSynthProb = rnaSynthProbListener.readColumn('rnaSynthProb')
		time = rnaSynthProbListener.readColumn('time')
		rnaSynthProbListener.close()

		mRnaSynthProb = rnaSynthProb[:, isMRna].sum(axis = 1)
		rRnaSynthProb = rnaSynthProb[:, isRRna].sum(axis = 1)
		tRnaSynthProb = rnaSynthProb[:, isTRna].sum(axis = 1)



		# Plot
		rows = 3
		cols = 1
		fig = plt.figure(figsize = (11, 8.5))
		plt.figtext(0.4, 0.96, "RNA synthesis probabilities over time", fontsize = 12)
		nMRnas = np.sum(isMRna)
		nRRnas = np.sum(isRRna)
		nTRnas = np.sum(isTRna)
		subplotOrder = [mRnaSynthProb, rRnaSynthProb, tRnaSynthProb]
		subplotTitles = ["mRNA\n(sum of %s mRNAs)" % nMRnas, "rRNA\n(sum of %s rRNAs)" % nRRnas, "tRNA\n(sum of %s tRNAs)" % nTRnas]

		for index, rnaSynthProb in enumerate(subplotOrder):
			ax = plt.subplot(rows, cols, index + 1)
			ax.plot(time, rnaSynthProb)

			ax.set_title(subplotTitles[index], fontsize = 10)
			ymin = np.min(rnaSynthProb)
			ymax = np.max(rnaSynthProb)
			yaxisBuffer = np.around(1.2*(ymax - ymin), 3)
			ax.set_ylim([ymin, yaxisBuffer])
			ax.set_yticks([ymin, ymax, yaxisBuffer])
			ax.set_yticklabels([ymin, np.around(ymax, 3), yaxisBuffer], fontsize = 10)
			ax.set_xlim([time[0], time[-1]])
			ax.tick_params(axis = "x", labelsize = 10)
			ax.spines["left"].set_visible(False)
			ax.spines["right"].set_visible(False)


		plt.subplots_adjust(hspace = 0.5, )
		exportFigure(plt, plotOutDir, plotOutFileName, metadata)

		plt.close("all")
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		sim_data = cPickle.load(open(simDataFile))

		# Get exchange flux data
		fbaResults = TableReader(os.path.join(simOutDir, "FBAResults"))
		initialTime = units.s * TableReader(os.path.join(simOutDir, "Main")).readAttribute("initialTime")
		time = units.s * TableReader(os.path.join(simOutDir, "Main")).readColumn("time") - initialTime
		externalExchangeFluxes = fbaResults.readColumn("externalExchangeFluxes")
		externalMoleculeIDs = np.array(fbaResults.readAttribute("externalMoleculeIDs"))
		fbaResults.close()

		massExchange = sim_data.getter.getMass(externalMoleculeIDs).asNumber(units.g / units.mmol) * externalExchangeFluxes # g / gDCW-hr

		# Get growth rate data
		growthRateData = TableReader(os.path.join(simOutDir, "Mass"))
		growthRate = ((1 / units.s) * growthRateData.readColumn("instantaniousGrowthRate")).asUnit(1 / units.h) # g / gDCW-hr
		doublingTime = (1 / growthRate) * np.log(2)

		# Plot stuff
		fig = plt.figure()
		fig.set_size_inches(8.5,11)

		ax1 = plt.subplot(3,1,1)
		ax1.plot(time.asNumber(units.min), doublingTime.asNumber(units.min))
		ax1.plot(time.asNumber(units.min), sim_data.doubling_time.asNumber(units.min) * np.ones(time.asNumber().size), linestyle='--')
		medianDoublingTime = np.median(doublingTime.asNumber(units.min)[1:])
		ax1.set_ylim([medianDoublingTime - 2*medianDoublingTime, medianDoublingTime + 2*medianDoublingTime])
		ax1.set_ylabel("Doubling\ntime (min)")

		ax2 = plt.subplot(3,1,2)
		ax2.plot(time.asNumber(units.min), massExchange)
		maxMassExchange = massExchange[100:].max()
		minMassExchange = massExchange[100:].min()
		ax2.set_ylim([minMassExchange, maxMassExchange])
		ax2.set_ylabel("Mass exchange\n(g / gDCW-hr)")

		ax3 = plt.subplot(3,1,3)
		water = massExchange[:, np.where(externalMoleculeIDs == "WATER[p]")[0][0]].copy()
		waterAll = massExchange[:, np.where(externalMoleculeIDs == "WATER[p]")[0][0]].copy()
		water[doublingTime.asNumber() > 0.] = np.nan
		ax3.plot(time.asNumber(units.min), waterAll, 'k.')
		ax3.plot(time.asNumber(units.min), water, 'b.')
		maxMassExchange = massExchange[100:].max()
		minMassExchange = massExchange[100:].min()
		ax3.set_ylim([minMassExchange, maxMassExchange])
		ax3.set_ylabel("Water exchange\nwhen doubling time < 0")

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        # Get the names of rnas from the KB

        sim_data = cPickle.load(open(simDataFile, "rb"))

        rnaIds = sim_data.process.transcription.rnaData["id"][
            sim_data.relation.rnaIndexToMonomerMapping]

        proteinIds = sim_data.process.translation.monomerData["id"]

        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))
        bulkMoleculeCounts = bulkMolecules.readColumn("counts")

        moleculeIds = bulkMolecules.readAttribute("objectNames")

        rnaIndexes = np.array(
            [moleculeIds.index(moleculeId) for moleculeId in rnaIds], np.int)

        rnaCountsBulk = bulkMoleculeCounts[:, rnaIndexes]

        proteinIndexes = np.array(
            [moleculeIds.index(moleculeId) for moleculeId in proteinIds],
            np.int)

        proteinCountsBulk = bulkMoleculeCounts[:, proteinIndexes]

        bulkMolecules.close()

        relativeMRnaCounts = rnaCountsBulk[
            -1, :]  #/ rnaCountsBulk[-1, :].sum()
        relativeProteinCounts = proteinCountsBulk[
            -1, :]  #/ proteinCountsBulk[-1, :].sum()

        plt.figure(figsize=(8.5, 11))

        plt.plot(relativeMRnaCounts,
                 relativeProteinCounts,
                 'o',
                 markeredgecolor='k',
                 markerfacecolor='none')

        plt.xlabel("RNA count (at final time step)")
        plt.ylabel("Protein count (at final time step)")

        # plt.show()

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		sim_data = cPickle.load(open(simDataFile, "r"))
		trpIdx = sim_data.moleculeGroups.aaIDs.index("TRP[c]")

		growthLimits = TableReader(os.path.join(simOutDir, "GrowthLimits"))

		trpRequests = growthLimits.readColumn("aaRequestSize")[BURN_IN:, trpIdx]

		growthLimits.close()

		bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

		moleculeIds = bulkMolecules.readAttribute("objectNames")

		trpSynIdx = moleculeIds.index("TRYPSYN[c]")

		trpSynCounts = bulkMolecules.readColumn("counts")[BURN_IN:, trpSynIdx]

		bulkMolecules.close()

		trpSynKcat = 2**( (37. - 25.) / 10.) * 4.1 # From PMID 6402362 (kcat of 4.1/s measured at 25 C)

		initialTime = TableReader(os.path.join(simOutDir, "Main")).readAttribute("initialTime")
		time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time")[BURN_IN:] - initialTime
		timeStep = TableReader(os.path.join(simOutDir, "Main")).readColumn("timeStepSec")[BURN_IN:]


		trpSynMaxCapacity = trpSynKcat * trpSynCounts * timeStep

		plt.figure(figsize = (8.5, 11))

		plt.subplot(3, 1, 1)

		plt.plot(time / 60., trpSynMaxCapacity, linewidth = 2)
		plt.ylabel("Tryptophan Synthase Max Capacity")

		plt.subplot(3, 1, 2)

		plt.plot(time / 60., trpRequests, linewidth = 2)
		plt.ylabel("TRP requested by translation")

		plt.subplot(3, 1, 3)

		plt.plot(time / 60., trpSynMaxCapacity / trpRequests, linewidth = 2)
		plt.xlabel("Time (min)")
		plt.ylabel("(Max capacity) / (Request)")

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")
	def do_plot(self, seedOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(seedOutDir):
			raise Exception, "seedOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		ap = AnalysisPaths(seedOutDir, multi_gen_plot = True)

		# Get all cells
		allDir = ap.get_cells()

		massNames = [
					"dryMass",
					"proteinMass",
					#"tRnaMass",
					"rRnaMass",
					'mRnaMass',
					"dnaMass"
					]

		cleanNames = [
					"Dry\nmass",
					"Protein\nmass",
					#"tRNA\nmass",
					"rRNA\nmass",
					"mRNA\nmass",
					"DNA\nmass"
					]

		fig, axesList = plt.subplots(len(massNames), sharex = True)

		for simDir in allDir:
			simOutDir = os.path.join(simDir, "simOut")
			time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time")
			mass = TableReader(os.path.join(simOutDir, "Mass"))

			for idx, massType in enumerate(massNames):
				massToPlot = mass.readColumn(massNames[idx])
				axesList[idx].plot(time / 60. / 60., massToPlot, linewidth = 2)

				axesList[idx].set_ylabel(cleanNames[idx] + " (fg)")

		for axes in axesList:
			axes.get_ylim()
			axes.set_yticks(list(axes.get_ylim()))

		axesList[0].set_title("Cell mass fractions")
		axesList[len(massNames) - 1].set_xlabel("Time (hr)")

		plt.subplots_adjust(hspace = 0.2, wspace = 0.5)
		exportFigure(plt, plotOutDir, plotOutFileName,metadata)
		plt.close("all")
	def do_plot(self, variantDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(variantDir):
			raise Exception, "variantDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		# Get all cells in each seed
		ap = AnalysisPaths(variantDir, cohort_plot = True)

		max_cells_in_gen = 0
		for genIdx in range(ap.n_generation):
			n_cells = len(ap.get_cells(generation = [genIdx]))
			if n_cells > max_cells_in_gen:
				max_cells_in_gen = n_cells

		fig, axesList = plt.subplots(ap.n_generation, sharey = True, sharex = True,
			subplot_kw={'aspect': 0.4, 'adjustable': 'box'})

		initial_masses = np.zeros((max_cells_in_gen, ap.n_generation))
		final_masses = np.zeros((max_cells_in_gen, ap.n_generation))

		for genIdx in range(ap.n_generation):
			gen_cells = ap.get_cells(generation = [genIdx])
			for simDir in gen_cells:
				simOutDir = os.path.join(simDir, "simOut")
				mass = TableReader(os.path.join(simOutDir, "Mass"))
				cellMass = mass.readColumn("cellMass")

				initial_masses[np.where(simDir == gen_cells)[0], genIdx] = cellMass[0] / 1000.
				final_masses[np.where(simDir == gen_cells)[0], genIdx] = cellMass[-1] / 1000.

		# Plot initial vs final masses
		if ap.n_generation == 1:
			axesList = [axesList]

		for idx, axes in enumerate(axesList):
			axes.plot(initial_masses[:, idx], final_masses[:, idx], 'o')
			z = np.polyfit(initial_masses[:, idx], final_masses[:, idx], 1)
			p = np.poly1d(z)
			axes.plot(initial_masses[:, idx], p(initial_masses[:, idx]), '--')
			text_x = np.mean(axes.get_xlim())
			text_y = np.mean(axes.get_ylim()) + np.mean(axes.get_ylim())*0.1
			axes.text(text_x, text_y, r"$m_f$=%.3f$\times$$m_i$ + %.3f" % (z[0], z[1]))


		axesList[-1].set_xlabel("Initial mass (pg)")
		axesList[ap.n_generation / 2].set_ylabel("Final mass (pg)")

		plt.subplots_adjust(hspace = 0.2, wspace = 0.5)

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))
		bulkMoleculeCounts = bulkMolecules.readColumn("counts")

		moleculeIds = bulkMolecules.readAttribute("objectNames")
		rnapId = "APORNAP-CPLX[c]"
		rnapIndex = moleculeIds.index(rnapId)
		rnapCountsBulk = bulkMoleculeCounts[:, rnapIndex]

		RNAP_RNA_IDS = ["EG10893_RNA[c]", "EG10894_RNA[c]", "EG10895_RNA[c]", "EG10896_RNA[c]"]
		rnapRnaIndexes = np.array([moleculeIds.index(rnapRnaId) for rnapRnaId in RNAP_RNA_IDS], np.int)
		rnapRnaCounts = bulkMoleculeCounts[:, rnapRnaIndexes]

		bulkMolecules.close()

		uniqueMoleculeCounts = TableReader(os.path.join(simOutDir, "UniqueMoleculeCounts"))

		rnapIndex = uniqueMoleculeCounts.readAttribute("uniqueMoleculeIds").index("activeRnaPoly")
		initialTime = TableReader(os.path.join(simOutDir, "Main")).readAttribute("initialTime")
		time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time") - initialTime
		nActive = uniqueMoleculeCounts.readColumn("uniqueMoleculeCounts")[:, rnapIndex]

		uniqueMoleculeCounts.close()

		plt.figure(figsize = (8.5, 11))

		plt.subplot(5, 1, 1)

		plt.plot(time / 60., nActive + rnapCountsBulk)
		plt.xlabel("Time (min)")
		plt.ylabel("Protein Counts")
		plt.title("RNA Polymerase")

		for subplotIdx in xrange(2, 6):
			rnapRnaCountsIdx = subplotIdx - 2

			plt.subplot(5, 1, subplotIdx)

			plt.plot(time / 60., rnapRnaCounts[:, rnapRnaCountsIdx])
			plt.xlabel("Time (min)")
			plt.ylabel("mRNA counts")
			plt.title(RNAP_RNA_IDS[rnapRnaCountsIdx])

		plt.subplots_adjust(hspace = 0.5, top = 0.95, bottom = 0.05)
		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")
Exemplo n.º 20
0
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		# Exchange flux
		initialTime = TableReader(os.path.join(simOutDir, "Main")).readAttribute("initialTime")
		time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time") - initialTime

		fba_results = TableReader(os.path.join(simOutDir, "FBAResults"))
		exFlux = fba_results.readColumn("externalExchangeFluxes")
		exMolec = fba_results.readAttribute("externalMoleculeIDs")
		moleculeIDs = ["GLC[p]", "OXYGEN-MOLECULE[p]"]

		# Plot
		fig = plt.figure(figsize = (8, 11.5))
		rows = len(moleculeIDs)
		cols = 1

		for index, molecule in enumerate(["GLC[p]", "OXYGEN-MOLECULE[p]"]):
			if molecule not in exMolec:
				continue
			moleculeFlux = -1. * exFlux[:, exMolec.index(molecule)]
			ax = plt.subplot(rows, cols, index + 1)
			ax.plot(time / 60. / 60., moleculeFlux)

			averageFlux = np.average(moleculeFlux)
			yRange = np.min([np.abs(np.max(moleculeFlux) - averageFlux), np.abs(np.min(moleculeFlux) - averageFlux)])
			ymin = np.round(averageFlux - yRange)
			ymax = np.round(averageFlux + yRange)
			ax.set_ylim([ymin, ymax])

			abs_max = np.max(moleculeFlux)
			abs_min = np.min(moleculeFlux)

			plt.figtext(0.7, 1. / float(rows) * 0.7 + (rows - 1 - index) / float(rows),
				"Max: %s\nMin: %s" % (abs_max, abs_min), fontsize = 8)

			ax.set_ylabel("External %s\n(mmol/gDCW/hr)" % molecule, fontsize = 8)
			ax.set_xlabel("Time (hr)", fontsize = 8)
			ax.set_title("%s" % molecule, fontsize = 10, y = 1.1)
			ax.tick_params(labelsize = 8, which = "both", direction = "out")


		plt.subplots_adjust(hspace = 0.5, wspace = 1)

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		# Get the names of rnas from the KB

		sim_data = cPickle.load(open(simDataFile, "rb"))

		isTRna = sim_data.process.transcription.rnaData["isTRna"]

		rnaIds = sim_data.process.transcription.rnaData["id"][isTRna]

		bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

		moleculeIds = bulkMolecules.readAttribute("objectNames")

		rnaIndexes = np.array([moleculeIds.index(moleculeId) for moleculeId in rnaIds], np.int)

		rnaCountsBulk = bulkMolecules.readColumn("counts")[:, rnaIndexes]

		bulkMolecules.close()

		# avgCounts = rnaCountsBulk.mean(0)

		# relativeCounts = avgCounts / avgCounts.sum()

		# relativeCounts = rnaCountsBulk[-1, :] / rnaCountsBulk[-1, :].sum()

		plt.figure(figsize = (8.5, 11))

		counts = rnaCountsBulk[-1, :]

		expectedCountsArbitrary = sim_data.process.transcription.rnaExpression[sim_data.condition][isTRna]

		expectedCounts = expectedCountsArbitrary/expectedCountsArbitrary.sum() * counts.sum()

		maxLine = 1.1 * max(expectedCounts.max(), counts.max())
		plt.plot([0, maxLine], [0, maxLine], '--r')
		plt.plot(expectedCounts, counts, 'o', markeredgecolor = 'k', markerfacecolor = 'none')

		plt.xlabel("Expected tRNA count (scaled to total)")
		plt.ylabel("Actual tRNA count (at final time step)")

		# plt.show()

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")
    def do_plot(self, seedOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(seedOutDir):
            raise Exception, "seedOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        if DISABLED:
            print "Currently disabled because it requires too much memory."
            return

        ap = AnalysisPaths(seedOutDir, multi_gen_plot=True)

        # Get all cells
        allDir = ap.get_cells()

        for simDir in allDir:
            simOutDir = os.path.join(simDir, "simOut")

            time = TableReader(os.path.join(simOutDir,
                                            "Main")).readColumn("time")
            counts = TableReader(os.path.join(
                simOutDir, "BulkMolecules")).readColumn("counts")
            countsToMolar = TableReader(
                os.path.join(simOutDir,
                             "EnzymeKinetics")).readColumn("countsToMolar")
            allNames = TableReader(os.path.join(
                simOutDir, "BulkMolecules")).readAttribute('objectNames')

            compoundNames = []
            nonZeroCounts = counts.T[np.any(counts.T, axis=1)]
            for idx, counts in enumerate(nonZeroCounts):
                if (counts[BURN_IN_SECONDS:] > 0).sum() > 100:
                    compartment = allNames[idx][-3:]
                    compoundNames.append(allNames[idx][:20])
                    concentrations = (counts * countsToMolar)
                    if time[0] < 1:
                        concentrations[:BURN_IN_SECONDS] = np.mean(
                            concentrations[BURN_IN_SECONDS:])
                    plt.plot(time / 60.,
                             concentrations / np.mean(concentrations))

            # plt.legend(compoundNames, fontsize=5)
            plt.title("Protein Concentrations")
            plt.xlabel("Time (min)")
            plt.ylabel("Mean-normalized concentration")

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
    def do_plot(self, seedOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(seedOutDir):
            raise Exception, "seedOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        ap = AnalysisPaths(seedOutDir, multi_gen_plot=True)

        # TODO: Declutter Y-axis

        # Get all cells
        allDir = ap.get_cells().tolist()

        massNames = [
            "dryMass",
        ]

        cleanNames = [
            "Dry\nmass",
        ]

        for simDir in allDir:
            simOutDir = os.path.join(simDir, "simOut")
            initialTime = TableReader(os.path.join(
                simOutDir, "Main")).readAttribute("initialTime")
            time = TableReader(os.path.join(
                simOutDir, "Main")).readColumn("time") - initialTime
            mass = TableReader(os.path.join(simOutDir, "Mass"))

            for idx, massType in enumerate(massNames):
                massToPlot = mass.readColumn(massNames[idx])

                f = plt.figure(figsize=(1.25, 0.8), frameon=False)

                ax = f.add_axes([0, 0, 1, 1])
                ax.axis("off")

                ax.plot(time, massToPlot, linewidth=2)
                ax.set_ylim([massToPlot.min(), massToPlot.max()])
                ax.set_xlim([time.min(), time.max()])

                exportFigure(
                    plt, plotOutDir,
                    "r01_{}_gen{}".format(massType, allDir.index(simDir)))
                plt.close("all")
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))
		processNames = bulkMolecules.readAttribute("processNames")

		atpAllocatedInitial = bulkMolecules.readColumn("atpAllocatedInitial")
		atpRequested = bulkMolecules.readColumn("atpRequested")

		initialTime = TableReader(os.path.join(simOutDir, "Main")).readAttribute("initialTime")
		time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time") - initialTime

		bulkMolecules.close()


		# Plot
		plt.figure(figsize = (8.5, 11))
		rows = 7
		cols = 2

		for processIndex in np.arange(len(processNames)):
			ax = plt.subplot(rows, cols, processIndex + 1)
			ax.plot(time / 60., atpAllocatedInitial[:, processIndex])
			ax.plot(time / 60., atpRequested[:, processIndex])
			ax.set_title(str(processNames[processIndex]), fontsize = 8, y = 0.85)

			ymin = np.amin([atpAllocatedInitial[:, processIndex], atpRequested[:, processIndex]])
			ymax = np.amax([atpAllocatedInitial[:, processIndex], atpRequested[:, processIndex]])
			ax.set_ylim([ymin, ymax])
			ax.set_yticks([ymin, ymax])
			ax.set_yticklabels(["%0.2e" % ymin, "%0.2e" % ymax])
			ax.spines['top'].set_visible(False)
			ax.spines['bottom'].set_visible(False)
			ax.xaxis.set_ticks_position('bottom')
			ax.tick_params(which = 'both', direction = 'out', labelsize = 6)
			# ax.set_xticks([])

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")

		plt.subplots_adjust(hspace = 2.0, wspace = 2.0)
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		initialTime = TableReader(os.path.join(simOutDir, "Main")).readAttribute("initialTime")
		time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time") - initialTime
		timeStepSec = TableReader(os.path.join(simOutDir, "Main")).readColumn("timeStepSec")

		fba_results = TableReader(os.path.join(simOutDir, "FBAResults"))
		exFlux = fba_results.readColumn("externalExchangeFluxes")
		exMolec = fba_results.readAttribute("externalMoleculeIDs")
		fba_results.close()

		mass = TableReader(os.path.join(simOutDir, "Mass"))
		processMassDifferences = mass.readColumn("processMassDifferences")
		cellMass = mass.readColumn("dryMass")
		mass.close()

		exchangeMasses = {} # some duplicates in exMolec like CO2 and water so create dict to avoid double counting
		raw_data = KnowledgeBaseEcoli()
		for metabolite in raw_data.metabolites:
			for molecID in exMolec:
				if molecID.split("[")[0] == "WATER":
					exchangeMasses[molecID] = 18.015 * exFlux[:,exMolec.index(molecID)] * 10**-3 * cellMass * timeStepSec / 60 / 60
				if molecID.split("[")[0] == metabolite["id"]:
					exchangeMasses[molecID] = metabolite["mw7.2"] * exFlux[:,exMolec.index(molecID)] * 10**-3 * cellMass * timeStepSec / 60 / 60

		massInflux = 0
		for molecID in exchangeMasses.keys():
			massInflux += exchangeMasses[molecID]

		massProduced = processMassDifferences[:,0]	# in metabolism
		massDiff = massInflux + massProduced

		plt.plot(time / 60. / 60., -massDiff)
		plt.tick_params(axis='both', which='major', labelsize=10)
		plt.ylabel("Mass Accumulation per time step (fg)")
		plt.title("Mass imported - mass created in metabolism process")

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")
Exemplo n.º 26
0
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		sim_data = cPickle.load(open(simDataFile, "rb"))

		fbaResults = TableReader(os.path.join(simOutDir, "FBAResults"))
		externalExchangeFluxes = fbaResults.readColumn("externalExchangeFluxes")
		initialTime = TableReader(os.path.join(simOutDir, "Main")).readAttribute("initialTime")
		time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time") - initialTime
		timeStepSec = TableReader(os.path.join(simOutDir, "Main")).readColumn("timeStepSec")
		externalMoleculeIDs = np.array(fbaResults.readAttribute("externalMoleculeIDs"))
		fbaResults.close()

		if GLUCOSE_ID not in externalMoleculeIDs:
			print "This plot only runs when glucose is the carbon source."
			return

		glucoseIdx = np.where(externalMoleculeIDs == GLUCOSE_ID)[0][0]
		glucoseFlux = FLUX_UNITS * externalExchangeFluxes[:, glucoseIdx]

		mass = TableReader(os.path.join(simOutDir, "Mass"))
		cellMass = MASS_UNITS * mass.readColumn("cellMass")
		cellDryMass = MASS_UNITS * mass.readColumn("dryMass")
		growth = GROWTH_UNITS * mass.readColumn("growth") / timeStepSec
		mass.close()

		glucoseMW = sim_data.getter.getMass([GLUCOSE_ID])[0]

		glucoseMassFlux = glucoseFlux * glucoseMW * cellDryMass

		glucoseMassYield = growth / -glucoseMassFlux

		fig = plt.figure(figsize = (8.5, 11))
		plt.plot(time, glucoseMassYield)
		plt.xlabel("Time (s)")
		plt.ylabel("g cell / g glucose")

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")
Exemplo n.º 27
0
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

        moleculeIds = bulkMolecules.readAttribute("objectNames")
        rnapId = "APORNAP-CPLX[c]"
        rnapIndex = moleculeIds.index(rnapId)
        rnapCountsBulk = bulkMolecules.readColumn("counts")[:, rnapIndex]

        bulkMolecules.close()

        uniqueMoleculeCounts = TableReader(
            os.path.join(simOutDir, "UniqueMoleculeCounts"))

        rnapIndex = uniqueMoleculeCounts.readAttribute(
            "uniqueMoleculeIds").index("activeRnaPoly")
        initialTime = TableReader(os.path.join(
            simOutDir, "Main")).readAttribute("initialTime")
        time = TableReader(os.path.join(
            simOutDir, "Main")).readColumn("time") - initialTime
        nActive = uniqueMoleculeCounts.readColumn(
            "uniqueMoleculeCounts")[:, rnapIndex]

        uniqueMoleculeCounts.close()

        plt.figure(figsize=(8.5, 11))

        plt.plot(time / 60., nActive * 100. / (nActive + rnapCountsBulk))
        #plt.axis([0,60,0,25])
        plt.xlabel("Time (min)")
        plt.ylabel("Percent of RNA Polymerase Molecules that are Active")
        plt.title("Active RNA Polymerase Percentage")

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
Exemplo n.º 28
0
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

        moleculeIds = bulkMolecules.readAttribute("objectNames")

        sim_data = cPickle.load(open(simDataFile))

        aaIDs = sim_data.moleculeGroups.aaIDs
        aaIndexes = np.array([moleculeIds.index(aaId) for aaId in aaIDs],
                             np.int)
        aaCounts = bulkMolecules.readColumn("counts")[:, aaIndexes]

        initialTime = TableReader(os.path.join(
            simOutDir, "Main")).readAttribute("initialTime")
        time = TableReader(os.path.join(
            simOutDir, "Main")).readColumn("time") - initialTime

        bulkMolecules.close()

        plt.figure(figsize=(8.5, 11))

        for idx in xrange(21):

            plt.subplot(6, 4, idx + 1)

            plt.plot(time / 60., aaCounts[:, idx], linewidth=2)
            plt.xlabel("Time (min)")
            plt.ylabel("Counts")
            plt.title(aaIDs[idx])

        plt.subplots_adjust(hspace=0.5, wspace=0.5)

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
Exemplo n.º 29
0
    def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if not os.path.isdir(simOutDir):
            raise Exception, "simOutDir does not currently exist as a directory"

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

        moleculeIds = bulkMolecules.readAttribute("objectNames")

        NTP_IDS = ['ATP[c]', 'CTP[c]', 'GTP[c]', 'UTP[c]']
        ntpIndexes = np.array([moleculeIds.index(ntpId) for ntpId in NTP_IDS],
                              np.int)

        ntpCounts = bulkMolecules.readColumn("counts")[:, ntpIndexes]
        initialTime = TableReader(os.path.join(
            simOutDir, "Main")).readAttribute("initialTime")
        time = TableReader(os.path.join(
            simOutDir, "Main")).readColumn("time") - initialTime

        bulkMolecules.close()

        plt.figure(figsize=(8.5, 11))

        for idx in xrange(4):

            plt.subplot(2, 2, idx + 1)

            plt.plot(time / 60., ntpCounts[:, idx], linewidth=2)
            plt.xlabel("Time (min)")
            plt.ylabel("Counts")
            plt.title(NTP_IDS[idx])

        print "NTPs required for cell division (nt/cell-cycle) = %d" % sum(
            ntpCounts[0, :])
        plt.subplots_adjust(hspace=0.5)

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")
Exemplo n.º 30
0
	def do_plot(self, simOutDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata):
		if not os.path.isdir(simOutDir):
			raise Exception, "simOutDir does not currently exist as a directory"

		if not os.path.exists(plotOutDir):
			os.mkdir(plotOutDir)

		bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules"))

		moleculeIds = bulkMolecules.readAttribute("objectNames")

		RIBOSOME_RNA_IDS = ["RRLA-RRNA[c]", "RRSA-RRNA[c]", "RRFA-RRNA[c]"]
		ribosomeRnaIndexes = np.array([moleculeIds.index(rRnaId) for rRnaId in RIBOSOME_RNA_IDS], np.int)
		ribosomeRnaCountsBulk = bulkMolecules.readColumn("counts")[:, ribosomeRnaIndexes]

		bulkMolecules.close()

		uniqueMoleculeCounts = TableReader(os.path.join(simOutDir, "UniqueMoleculeCounts"))

		ribosomeIndex = uniqueMoleculeCounts.readAttribute("uniqueMoleculeIds").index("activeRibosome")
		initialTime = TableReader(os.path.join(simOutDir, "Main")).readAttribute("initialTime")
		time = TableReader(os.path.join(simOutDir, "Main")).readColumn("time") - initialTime
		nActive = uniqueMoleculeCounts.readColumn("uniqueMoleculeCounts")[:, ribosomeIndex]

		uniqueMoleculeCounts.close()

		plt.figure(figsize = (8.5, 11))

		plt.plot(time / 60, nActive)
		plt.plot([time[0] / 60., time[-1] / 60.], [2 * nActive[0], 2 * nActive[0]], "r--")
		plt.xlabel("Time (min)")
		plt.ylabel("Counts")
		plt.title("Active Ribosomes Final:Initial = %0.2f" % (nActive[-1] / float(nActive[0])))

		exportFigure(plt, plotOutDir, plotOutFileName, metadata)
		plt.close("all")