def mp_worker(sim_dir): sim_out_dir = os.path.join(sim_dir, 'simOut') rnap_count_avg_cell = None try: bulk_molecule_reader = TableReader( os.path.join(sim_out_dir, 'BulkMolecules')) index_rnap = bulk_molecule_reader.readAttribute('objectNames').index( rnap_id) rnap_count = bulk_molecule_reader.readColumn('counts', np.array([index_rnap])) unique_molecule_reader = TableReader( os.path.join(sim_out_dir, 'UniqueMoleculeCounts')) unique_molecule_ids = unique_molecule_reader.readAttribute( 'uniqueMoleculeIds') unique_molecule_counts = unique_molecule_reader.readColumn( 'uniqueMoleculeCounts') unique_molecule_reader.close() index_rnap = unique_molecule_ids.index('activeRnaPoly') rnap_active_count = unique_molecule_counts[:, index_rnap] index_average_cell = int(len(rnap_active_count) * CELL_CYCLE_FRACTION) rnap_count_avg_cell = rnap_count[ index_average_cell] + rnap_active_count[index_average_cell] except Exception as e: print('Excluded from analysis due to broken files: {}'.format( sim_out_dir)) return rnap_count_avg_cell
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")
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")
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")
def mp_worker(sim_dir): sim_out_dir = os.path.join(sim_dir, 'simOut') ribosome_count_avg_cell = None try: (ribosome_30s_count, ribosome_50s_count) = read_bulk_molecule_counts( sim_out_dir, ( [ribosome_30s_id], [ribosome_50s_id])) unique_molecule_reader = TableReader(os.path.join(sim_out_dir, 'UniqueMoleculeCounts')) unique_molecule_ids = unique_molecule_reader.readAttribute('uniqueMoleculeIds') unique_molecule_counts = unique_molecule_reader.readColumn('uniqueMoleculeCounts') unique_molecule_reader.close() index_ribosome = unique_molecule_ids.index('activeRibosome') ribosome_active_count = unique_molecule_counts[:, index_ribosome] index_average_cell = int(len(ribosome_active_count) * CELL_CYCLE_FRACTION) ribosome_count_avg_cell = ribosome_active_count[index_average_cell] + min( ribosome_30s_count[index_average_cell], ribosome_50s_count[index_average_cell]) except Exception as e: print('Excluded from analysis due to broken files: {}'.format(sim_out_dir)) return ribosome_count_avg_cell
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")
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")
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 read_bulk_molecule_counts(sim_out_dir, mol_names): ''' Reads a subset of molecule counts from BulkMolecules using the indexing method of readColumn. Should only be called once per simulation being analyzed with all molecules of interest. Args: sim_out_dir (str): path to the directory with simulation output data mol_names (list-like or tuple of list-like): lists of strings containing names of molecules to read the counts for. A single array will be converted to a tuple for processing. Returns: generator of ndarray: int counts with all time points on the first dimension and each molecule of interest on the second dimension. The number of generated arrays will be separated based on the input dimensions of mol_names (ie if mol_names is a tuple of two arrays, two arrays will be generated). Example use cases: names1 = ['ATP[c]', 'AMP[c]'] names2 = ['WATER[c]'] # Read one set of molecules (counts1,) = read_bulk_molecule_counts(sim_out_dir, names1) # Read two or more sets of molecules (counts1, counts2) = read_bulk_molecule_counts(sim_out_dir, (names1, names2)) TODO: generalize to any TableReader, not just BulkMolecules, if readColumn method is used for those tables. ''' # Convert an array to tuple to ensure correct dimensions if not isinstance(mol_names, tuple): mol_names = (mol_names, ) # Check for string instead of array since it will cause mol_indices lookup to fail for names in mol_names: if isinstance(names, basestring): raise Exception( 'mol_names must be a tuple of arrays not strings like {}'. format(names)) bulk_reader = TableReader(os.path.join(sim_out_dir, 'BulkMolecules')) bulk_molecule_names = bulk_reader.readAttribute("objectNames") mol_indices = {mol: i for i, mol in enumerate(bulk_molecule_names)} lengths = [len(names) for names in mol_names] indices = np.hstack([[mol_indices[mol] for mol in names] for names in mol_names]) bulk_counts = bulk_reader.readColumn('counts', indices) start_slice = 0 for length in lengths: counts = bulk_counts[:, start_slice:start_slice + length].squeeze() start_slice += length yield counts
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, 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")
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 test_performance(sim_out_dir): ''' Performs tests on multiple index conditions to compare times of various methods. Inputs: sim_out_dir (str): directory of simulation output to read from ''' # Bulk molecule information bulk_molecules = TableReader(os.path.join(sim_out_dir, 'BulkMolecules')) bulk_ids = bulk_molecules.readAttribute('objectNames') n_mols = len(bulk_ids) # Sets of functions to test three_functions = [test_old, test_new_block, test_new_multiple] two_functions = [test_old, test_new_block] # Test reads ## Single index indices = np.array([0]) test_functions(three_functions, 'One index', bulk_molecules, indices) ## First and last index indices = np.array([0, n_mols - 1]) test_functions(three_functions, 'First and last indices', bulk_molecules, indices) ## Large block indices = np.array(range(BLOCK_SIZE)) test_functions(three_functions, 'Block indices', bulk_molecules, indices) ## 2 Large blocks indices = np.array(range(BLOCK_SIZE) + range(n_mols)[-BLOCK_SIZE:]) test_functions(three_functions, 'Two blocks of indices', bulk_molecules, indices) ## Dispersed reads - multiple reads method is slow so only test two methods indices = np.linspace(0, n_mols - 1, BLOCK_SIZE, dtype=np.int64) test_functions(two_functions, 'Dispersed indices', bulk_molecules, indices) ## Random reads - multiple reads method is slow so only test two methods indices = np.array(range(n_mols)) np.random.shuffle(indices) indices = indices[:BLOCK_SIZE] test_functions(two_functions, 'Random indices', bulk_molecules, indices) ## All indices indices = np.array(range(n_mols)) test_functions(three_functions, 'All indices', bulk_molecules, indices)
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")
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")
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")
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")
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")
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) # Load data from KB sim_data = cPickle.load(open(simDataFile, "rb")) endoRnaseIds = sim_data.process.rna_decay.endoRnaseIds exoRnaseIds = sim_data.moleculeGroups.exoRnaseIds RnaseIds = np.concatenate((endoRnaseIds, exoRnaseIds)) # Load count data for s30 proteins, rRNA, and final 30S complex bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules")) moleculeIds = bulkMolecules.readAttribute("objectNames") bulkMoleculeCounts = bulkMolecules.readColumn("counts") # Get indexes proteinIndexes = np.array( [moleculeIds.index(protein) for protein in RnaseIds], np.int) exoproteinIndexes = np.array( [moleculeIds.index(protein) for protein in exoRnaseIds], np.int) endoproteinIndexes = np.array( [moleculeIds.index(protein) for protein in endoRnaseIds], np.int) # Load data initialTime = TableReader(os.path.join( simOutDir, "Main")).readAttribute("initialTime") time = TableReader(os.path.join( simOutDir, "Main")).readColumn("time") - initialTime RnaseCounts = bulkMoleculeCounts[:, proteinIndexes] exoRnaseCounts = bulkMoleculeCounts[:, exoproteinIndexes] endoRnaseCounts = bulkMoleculeCounts[:, endoproteinIndexes] bulkMolecules.close() rnaDegradationListenerFile = TableReader( os.path.join(simOutDir, "RnaDegradationListener")) countRnaDegraded = rnaDegradationListenerFile.readColumn( 'countRnaDegraded') nucleotidesFromDegradation = rnaDegradationListenerFile.readColumn( 'nucleotidesFromDegradation') FractionActiveEndoRNases = rnaDegradationListenerFile.readColumn( 'FractionActiveEndoRNases') DiffRelativeFirstOrderDecay = rnaDegradationListenerFile.readColumn( 'DiffRelativeFirstOrderDecay') FractEndoRRnaCounts = rnaDegradationListenerFile.readColumn( 'FractEndoRRnaCounts') fragmentBasesDigested = rnaDegradationListenerFile.readColumn( 'fragmentBasesDigested') rnaDegradationListenerFile.close() TranscriptElongationListenerFile = TableReader( os.path.join(simOutDir, "TranscriptElongationListener")) countNTPsUSed = TranscriptElongationListenerFile.readColumn( 'countNTPsUSed') countRnaSynthesized = TranscriptElongationListenerFile.readColumn( 'countRnaSynthesized') TranscriptElongationListenerFile.close() totalRnaseCounts = RnaseCounts.sum(axis=1) requiredRnaseTurnover = nucleotidesFromDegradation / RnaseCounts.sum( axis=1) totalexoRnaseCounts = exoRnaseCounts.sum(axis=1) totalendoRnaseCounts = endoRnaseCounts.sum(axis=1) # Load data growthLimitsDataFile = TableReader( os.path.join(simOutDir, "GrowthLimits")) # Translation gtpUsed = growthLimitsDataFile.readColumn("gtpAllocated") growthLimitsDataFile.close() # Load metabolism production fbaResults = TableReader(os.path.join(simOutDir, "FBAResults")) initialTime = TableReader(os.path.join( simOutDir, "Main")).readAttribute("initialTime") time = TableReader(os.path.join( simOutDir, "Main")).readColumn("time") - initialTime deltaMetabolites = fbaResults.readColumn("deltaMetabolites") outputMoleculeIDs = np.array( fbaResults.readAttribute("metaboliteNames")) fbaResults.close() # Load ntps required for cell doubling 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 = bulkMoleculeCounts[:, ntpIndexes] bulkMolecules.close() # Plotting plt.figure(figsize=(8.5, 11)) plt.rc('font', **FONT) max_yticks = 5 ax = plt.subplot(7, 2, 1) plt.plot(time / 60., countRnaSynthesized.sum(axis=1)) plt.ylabel("RNAs synthesized", fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 2) plt.plot(time / 60., gtpUsed / 1e6) plt.ylabel("Translation ($10^{%d}$nt)" % 6, fontsize=9) plt.title("GTPs needed (x$10^{%d}$) = %.2f" % (6, (gtpUsed.sum() / 1e6)), fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 3) plt.plot(time / 60., countRnaDegraded.sum(axis=1)) plt.ylabel("RNAs degraded", fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 5) plt.plot(time / 60., totalendoRnaseCounts) plt.ylabel("EndoRNase counts", fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 4) plt.plot(time / 60., countNTPsUSed / 1e6) plt.ylabel("Transcription ($10^{%d}$nt)" % 6, fontsize=9) plt.title("NTPs needed(x$10^{%d}$) = %.2f" % (6, (countNTPsUSed.sum() / 1e6)), fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 7) plt.plot(time / 60., totalexoRnaseCounts) plt.ylabel("ExoRNase counts", fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) IdxAtp = (np.where("ATP[c]" == outputMoleculeIDs))[0][0] ATP = np.sum(deltaMetabolites[:, IdxAtp]) IdxGtp = (np.where("GTP[c]" == outputMoleculeIDs))[0][0] GTP = np.sum(deltaMetabolites[:, IdxGtp]) IdxCtp = (np.where("CTP[c]" == outputMoleculeIDs))[0][0] CTP = np.sum(deltaMetabolites[:, IdxCtp]) IdxUtp = (np.where("UTP[c]" == outputMoleculeIDs))[0][0] UTP = np.sum(deltaMetabolites[:, IdxUtp]) NtpsProduced = ATP + GTP + CTP + UTP ax = plt.subplot(7, 2, 6) plt.plot(time / 60., (deltaMetabolites[:, IdxAtp] + deltaMetabolites[:, IdxGtp] + deltaMetabolites[:, IdxCtp] + deltaMetabolites[:, IdxUtp]) / 1e6) plt.ylabel("Metabolism ($10^{%d}$nt)" % 6, fontsize=9) plt.title( "NTPs produced (x$10^{%d}$) = %.2f" % (6, (sum(deltaMetabolites[:, IdxAtp] + deltaMetabolites[:, IdxGtp] + deltaMetabolites[:, IdxCtp] + deltaMetabolites[:, IdxUtp]) / 1e6)), fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 9) plt.plot(time / 60., FractionActiveEndoRNases * 100) plt.ylabel("EndoRN capacity (%)", fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 8) plt.plot(time / 60., fragmentBasesDigested / 1e6) plt.ylabel("Exo-digestion ($10^{%d}$nt)" % 6, fontsize=9) plt.title("NTPs recycled (x$10^{%d}$) = %.2f" % (6, (fragmentBasesDigested.sum() / 1e6)), fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 11) plt.plot(time / 60., DiffRelativeFirstOrderDecay) plt.ylabel("sum(Residuals)", fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) ax = plt.subplot(7, 2, 10) plt.plot(time / 60., (ntpCounts[:, 0] + ntpCounts[:, 1] + ntpCounts[:, 2] + ntpCounts[:, 3]) / 1e6) plt.ylabel("Net production ($10^{%d}$nt)" % 6, fontsize=9) plt.title("NTPs required for cell division (x$10^{%d}$) = %.2f" % (6, ((ntpCounts[0, 0] + ntpCounts[0, 1] + ntpCounts[0, 2] + ntpCounts[0, 3]) / 1e6)), fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) # compute active ExoRNase capacity (%) ActiveExoRNcapacity = fragmentBasesDigested.astype(float) / ( totalexoRnaseCounts * sim_data.constants.KcatExoRNase.asNumber()) * 100 ax = plt.subplot(7, 2, 13) plt.plot(time / 60., ActiveExoRNcapacity) plt.xlabel("Time (min)") plt.ylabel("ExoRN capacity (%)", fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) # compute instantaneous balance of nTPs InstantaneousNTPs = -gtpUsed - countNTPsUSed + ( deltaMetabolites[:, IdxAtp] + deltaMetabolites[:, IdxGtp] + deltaMetabolites[:, IdxCtp] + deltaMetabolites[:, IdxUtp]) + fragmentBasesDigested ax = plt.subplot(7, 2, 12) plt.plot(time / 60., InstantaneousNTPs / 1e6) plt.xlabel("Time (min)") plt.ylabel("Balance ($10^{%d}$nt)" % 6, fontsize=9) plt.title("Average instantaneous balance (x$10^{%d}$) = %.4f" % (6, (np.mean(InstantaneousNTPs) / 1e6)), fontsize=9) yloc = plt.MaxNLocator(max_yticks) ax.yaxis.set_major_locator(yloc) plt.subplots_adjust(hspace=0.6, wspace=0.35) 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) validation_data = cPickle.load(open(validationDataFile, "rb")) sim_data = cPickle.load(open(simDataFile, "rb")) cellDensity = sim_data.constants.cellDensity initialTime = TableReader(os.path.join( simOutDir, "Main")).readAttribute("initialTime") time = TableReader(os.path.join( simOutDir, "Main")).readColumn("time") - initialTime massListener = TableReader(os.path.join(simOutDir, "Mass")) cellMass = massListener.readColumn("cellMass") * units.fg dryMass = massListener.readColumn("dryMass") * units.fg massListener.close() fbaResults = TableReader(os.path.join(simOutDir, "FBAResults")) reactionIDs = np.array(fbaResults.readAttribute("reactionIDs")) reactionFluxes = (COUNTS_UNITS / VOLUME_UNITS / TIME_UNITS) * np.array( fbaResults.readColumn("reactionFluxes")) fbaResults.close() dryMassFracAverage = np.mean(dryMass / cellMass) toya_reactions = validation_data.reactionFlux.toya2010fluxes[ "reactionID"] toya_fluxes = FLUX_UNITS * np.array( [(dryMassFracAverage * cellDensity * x).asNumber(FLUX_UNITS) for x in validation_data.reactionFlux.toya2010fluxes["reactionFlux"]]) netFluxes = [] for toyaReactionID in toya_reactions: fluxTimeCourse = net_flux( toyaReactionID, reactionIDs, reactionFluxes).asNumber(FLUX_UNITS).squeeze() netFluxes.append(fluxTimeCourse) trimmedReactions = FLUX_UNITS * np.array(netFluxes) corrCoefTimecourse = [] for fluxes in trimmedReactions.asNumber(FLUX_UNITS).T: correlationCoefficient = np.corrcoef( fluxes, toya_fluxes.asNumber(FLUX_UNITS))[0, 1] corrCoefTimecourse.append(correlationCoefficient) meanCorr = np.mean( np.array(corrCoefTimecourse)[~np.isnan(corrCoefTimecourse)]) plt.figure() plt.plot(time / 60., corrCoefTimecourse) plt.axhline(y=meanCorr, color='r') plt.title("Measured vs. Simulated Central Carbon Fluxes") plt.text(.5 * np.max(time / 60.), .95 * meanCorr, "Mean = {:.2}".format(meanCorr), horizontalalignment="center") plt.xlabel("Time (min)") plt.ylabel("Pearson R") exportFigure(plt, plotOutDir, plotOutFileName, metadata) plt.close("all")
def do_plot(self, inputDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata): if metadata.get('variant', '') != 'flux_sensitivity': print 'This plot only runs for the flux_sensitivity variant.' return if not os.path.isdir(inputDir): raise Exception, 'inputDir does not currently exist as a directory' filepath.makedirs(plotOutDir) ap = AnalysisPaths(inputDir, variant_plot=True) variants = ap.get_variants() succ_fluxes = [] iso_fluxes = [] for variant in variants: for sim_dir in ap.get_cells(variant=[variant]): simOutDir = os.path.join(sim_dir, "simOut") # Listeners used fba_reader = TableReader(os.path.join(simOutDir, 'FBAResults')) # Load data reactions = np.array( fba_reader.readAttribute('sensitivity_reactions')) succ_fluxes += [ fba_reader.readColumn('succinate_flux_sensitivity')[1:, :] ] iso_fluxes += [ fba_reader.readColumn('isocitrate_flux_sensitivity')[1:, :] ] succ_fluxes = np.vstack(succ_fluxes) iso_fluxes = np.vstack(iso_fluxes) succ_z = calc_z(succ_fluxes) iso_z = calc_z(iso_fluxes) threshold = -0.1 # Plot data plt.figure() gs = gridspec.GridSpec(2, 2) ## Succinate dehydrogenase all fluxes ax = plt.subplot(gs[0, 0]) plot_lows(ax, succ_z, threshold, 'succinate dehydrogenase') ## Succinate dehydrogenase fluxes over threshold ax = plt.subplot(gs[0, 1]) plot_threshold(ax, succ_z, threshold, reactions) ## Isocitrate dehydrogenase all fluxes ax = plt.subplot(gs[1, 0]) plot_lows(ax, iso_z, threshold, 'isocitrate dehydrogenase') ## Isocitrate dehydrogenase fluxes over threshold ax = plt.subplot(gs[1, 1]) plot_threshold(ax, iso_z, threshold, reactions) plt.tight_layout() 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)) constraintIsKcatOnly = sim_data.process.metabolism.constraintIsKcatOnly mainListener = TableReader(os.path.join(simOutDir, "Main")) initialTime = mainListener.readAttribute("initialTime") time = mainListener.readColumn("time") - initialTime mainListener.close() massListener = TableReader(os.path.join(simOutDir, "Mass")) cellMass = massListener.readColumn("cellMass") dryMass = massListener.readColumn("dryMass") massListener.close() coefficient = dryMass / cellMass * sim_data.constants.cellDensity.asNumber(MASS_UNITS / VOLUME_UNITS) # read constraint data enzymeKineticsReader = TableReader(os.path.join(simOutDir, "EnzymeKinetics")) targetFluxes = (COUNTS_UNITS / MASS_UNITS / TIME_UNITS) * (enzymeKineticsReader.readColumn("targetFluxes").T / coefficient).T actualFluxes = (COUNTS_UNITS / MASS_UNITS / TIME_UNITS) * (enzymeKineticsReader.readColumn("actualFluxes").T / coefficient).T reactionConstraint = enzymeKineticsReader.readColumn("reactionConstraint") constrainedReactions = np.array(enzymeKineticsReader.readAttribute("constrainedReactions")) enzymeKineticsReader.close() targetFluxes = targetFluxes.asNumber(units.mmol / units.g / units.h) actualFluxes = actualFluxes.asNumber(units.mmol / units.g / units.h) targetAve = np.mean(targetFluxes[BURN_IN_STEPS:, :], axis = 0) actualAve = np.mean(actualFluxes[BURN_IN_STEPS:, :], axis = 0) kcatOnlyReactions = np.all(constraintIsKcatOnly[reactionConstraint[BURN_IN_STEPS:,:]], axis = 0) kmAndKcatReactions = ~np.any(constraintIsKcatOnly[reactionConstraint[BURN_IN_STEPS:,:]], axis = 0) mixedReactions = ~(kcatOnlyReactions ^ kmAndKcatReactions) thresholds = [2, 10] categorization = np.zeros(reactionConstraint.shape[1]) categorization[actualAve == 0] = -2 categorization[actualAve == targetAve] = -1 for i, threshold in enumerate(thresholds): # categorization[targetAve / actualAve > threshold] = i + 1 categorization[actualAve / targetAve > threshold] = i + 1 # url for ecocyc to highlight fluxes that are 0 on metabolic network diagram siteStr = "https://ecocyc.org/overviewsWeb/celOv.shtml?zoomlevel=1&orgid=ECOLI" excluded = ['RXN0-2201', 'RXN-16000', 'RXN-12583', 'RXN-11496', 'DIMESULFREDUCT-RXN', '3.6.1.41-R[4/63051]5-NUCLEOTID-RXN'] # reactions not recognized by ecocyc rxns = [] for i, reaction in enumerate(constrainedReactions): if actualAve[i] == 0: rxn = re.findall(".+RXN", reaction) if len(rxn) == 0: rxn = re.findall("RXN[^-]*-[0-9]+", reaction) if rxn[0] not in excluded: siteStr += "&rnids=%s" % rxn[0] rxns.append(rxn[0]) # print siteStr csvFile = open(os.path.join(plotOutDir, plotOutFileName + ".tsv"), "wb") output = csv.writer(csvFile, delimiter = "\t") output.writerow(["ecocyc link:", siteStr]) output.writerow(["Km and kcat", "Target", "Actual", "Category"]) for reaction, target, flux, category in zip(constrainedReactions[kmAndKcatReactions], targetAve[kmAndKcatReactions], actualAve[kmAndKcatReactions], categorization[kmAndKcatReactions]): output.writerow([reaction, target, flux, category]) output.writerow(["kcat only"]) for reaction, target, flux, category in zip(constrainedReactions[kcatOnlyReactions], targetAve[kcatOnlyReactions], actualAve[kcatOnlyReactions], categorization[kcatOnlyReactions]): output.writerow([reaction, target, flux, category]) if np.sum(mixedReactions): output.writerow(["mixed constraints"]) for reaction, target, flux, category in zip(constrainedReactions[mixedReactions], targetAve[mixedReactions], actualAve[mixedReactions], categorization[mixedReactions]): output.writerow([reaction, target, flux, category]) csvFile.close() targetAve += 1e-6 actualAve += 1e-6 axes_limits = [1e-7, 1e4] plt.figure(figsize = (8, 8)) ax = plt.axes() plt.loglog(axes_limits, axes_limits, 'k') plt.loglog(targetAve, actualAve, "ob", markeredgewidth = 0.25, alpha = 0.25) plt.xlabel("Target Flux (mmol/g/hr)") plt.ylabel("Actual Flux (mmol/g/hr)") plt.minorticks_off() whitePadSparklineAxis(ax) ax.set_ylim(axes_limits) ax.set_xlim(axes_limits) ax.set_yticks(axes_limits) ax.set_xticks(axes_limits) exportFigure(plt, plotOutDir, plotOutFileName) plt.close("all") source = ColumnDataSource( data = dict( x = targetAve, y = actualAve, reactionName = constrainedReactions) ) hover = HoverTool( tooltips = [ ("Reaction", "@reactionName"), ] ) TOOLS = [hover, BoxZoomTool(), LassoSelectTool(), PanTool(), WheelZoomTool(), ResizeTool(), UndoTool(), RedoTool(), "reset", ] p1 = figure(x_axis_label = "Target", x_axis_type = "log", x_range = [min(targetAve[targetAve > 0]), max(targetAve)], y_axis_label = "Actual", y_axis_type = "log", y_range = [min(actualAve[actualAve > 0]), max(actualAve)], width = 800, height = 800, tools = TOOLS, ) p1.scatter(targetAve, actualAve, source = source, size = 8) p1.line([1e-15, 10], [1e-15, 10], line_color = "red", line_dash = "dashed") ## bar plot of error # sortedReactions = [constrainedReactions[x] for x in np.argsort(aveError)[::-1]] # aveError[np.log10(aveError) == -np.inf] = 0 # source = ColumnDataSource( # data = dict( # x = sorted(relError, reverse = True), # reactionName = sortedReactions # ) # ) # p2 = Bar(data, values = "x") # hover2 = p2.select(dict(type=HoverTool)) # hover2.tooltips = [("Reaction", "@reactionName")] ## flux for each reaction hover2 = HoverTool( tooltips = [ ("Reaction", "@reactionName"), ] ) TOOLS2 = [hover2, BoxZoomTool(), LassoSelectTool(), PanTool(), WheelZoomTool(), ResizeTool(), UndoTool(), RedoTool(), "reset", ] p2 = figure(x_axis_label = "Time(s)", y_axis_label = "Flux", y_axis_type = "log", y_range = [1e-8, 1], width = 800, height = 800, tools = TOOLS2, ) colors = COLORS_LARGE nTimesteps = len(time[BURN_IN_STEPS:]) x = time[BURN_IN_STEPS:] y = actualFluxes[BURN_IN_STEPS:, 0] reactionName = np.repeat(constrainedReactions[0], nTimesteps) source = ColumnDataSource( data = dict( x = x, y = y, reactionName = reactionName) ) p2.line(x, y, line_color = colors[0], source = source) # Plot remaining metabolites onto initialized figure for m in np.arange(1, actualFluxes.shape[1]): y = actualFluxes[BURN_IN_STEPS:, m] reactionName = np.repeat(constrainedReactions[m], nTimesteps) source = ColumnDataSource( data = dict( x = x, y = y, reactionName = reactionName) ) p2.line(x, y, line_color = colors[m % len(colors)], source = source) if not os.path.exists(os.path.join(plotOutDir, "html_plots")): os.makedirs(os.path.join(plotOutDir, "html_plots")) p = bokeh.io.vplot(p1, p2) bokeh.io.output_file(os.path.join(plotOutDir, "html_plots", plotOutFileName + ".html"), title=plotOutFileName, autosave=False) bokeh.io.save(p) bokeh.io.curstate().reset()
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) # Load data from KB sim_data = cPickle.load(open(simDataFile, "rb")) nAvogadro = sim_data.constants.nAvogadro cellDensity = sim_data.constants.cellDensity # Load time initialTime = TableReader(os.path.join( simOutDir, "Main")).readAttribute("initialTime") time = TableReader(os.path.join( simOutDir, "Main")).readColumn("time") - initialTime # Load mass data # Total cell mass is needed to compute concentrations (since we have cell density) # Protein mass is needed to compute the mass fraction of the proteome that is tyrA massReader = TableReader(os.path.join(simOutDir, "Mass")) cellMass = units.fg * massReader.readColumn("cellMass") proteinMass = units.fg * massReader.readColumn("proteinMass") massReader.close() # Load data from bulk molecules bulkMoleculesReader = TableReader( os.path.join(simOutDir, "BulkMolecules")) bulkMoleculeIds = bulkMoleculesReader.readAttribute("objectNames") # Get the concentration of intracellular phe pheId = ["PHE[c]"] pheIndex = np.array([bulkMoleculeIds.index(x) for x in pheId]) pheCounts = bulkMoleculesReader.readColumn( "counts")[:, pheIndex].reshape(-1) pheMols = 1. / nAvogadro * pheCounts volume = cellMass / cellDensity pheConcentration = pheMols * 1. / volume # Get the amount of active tyrR (that isn't promoter bound) tyrRActiveId = ["MONOMER0-162[c]"] tyrRActiveIndex = np.array( [bulkMoleculeIds.index(x) for x in tyrRActiveId]) tyrRActiveCounts = bulkMoleculesReader.readColumn( "counts")[:, tyrRActiveIndex].reshape(-1) # Get the amount of inactive tyrR tyrRInactiveId = ["PD00413[c]"] tyrRInactiveIndex = np.array( [bulkMoleculeIds.index(x) for x in tyrRInactiveId]) tyrRInactiveCounts = bulkMoleculesReader.readColumn( "counts")[:, tyrRInactiveIndex].reshape(-1) # Get the promoter-bound status of the tyrA gene tyrATfBoundId = ["EG11039_RNA__MONOMER0-162"] tyrATfBoundIndex = np.array( [bulkMoleculeIds.index(x) for x in tyrATfBoundId]) tyrATfBoundCounts = bulkMoleculesReader.readColumn( "counts")[:, tyrATfBoundIndex].reshape(-1) # Get the amount of monomeric tyrA tyrAProteinId = ["CHORISMUTPREPHENDEHYDROG-MONOMER[c]"] tyrAProteinIndex = np.array( [bulkMoleculeIds.index(x) for x in tyrAProteinId]) tyrAProteinCounts = bulkMoleculesReader.readColumn( "counts")[:, tyrAProteinIndex].reshape(-1) tyrAComplexId = ["CHORISMUTPREPHENDEHYDROG-CPLX[c]"] tyrAComplexIndex = np.array( [bulkMoleculeIds.index(x) for x in tyrAComplexId]) tyrAComplexCounts = bulkMoleculesReader.readColumn( "counts")[:, tyrAComplexIndex].reshape(-1) bulkMoleculesReader.close() tyrAProteinTotalCounts = tyrAProteinCounts + 2 * tyrAComplexCounts # Compute the tyrA mass in the cell tyrAMw = sim_data.getter.getMass(tyrAProteinId) tyrAMass = 1. / nAvogadro * tyrAProteinTotalCounts * tyrAMw # Compute the proteome mass fraction proteomeMassFraction = tyrAMass.asNumber( units.fg) / proteinMass.asNumber(units.fg) # Get the tyrA synthesis probability rnaSynthProbReader = TableReader( os.path.join(simOutDir, "RnaSynthProb")) rnaIds = rnaSynthProbReader.readAttribute("rnaIds") tyrASynthProbId = ["EG11039_RNA[c]"] tyrASynthProbIndex = np.array( [rnaIds.index(x) for x in tyrASynthProbId]) tyrASynthProb = rnaSynthProbReader.readColumn( "rnaSynthProb")[:, tyrASynthProbIndex].reshape(-1) recruitmentColNames = sim_data.process.transcription_regulation.recruitmentColNames tfs = sorted( set([ x.split("__")[-1] for x in recruitmentColNames if x.split("__")[-1] != "alpha" ])) tyrRIndex = [i for i, tf in enumerate(tfs) if tf == "MONOMER0-162"][0] tyrRBound = rnaSynthProbReader.readColumn("nActualBound")[:, tyrRIndex] rnaSynthProbReader.close() # Calculate total tyrR - active, inactive and bound tyrRTotalCounts = tyrRActiveCounts + tyrRInactiveCounts + tyrRBound # Compute moving averages width = 100 tyrATfBoundCountsMA = np.convolve(tyrATfBoundCounts, np.ones(width) / width, mode="same") tyrASynthProbMA = np.convolve(tyrASynthProb, np.ones(width) / width, mode="same") plt.figure(figsize=(8.5, 11)) ############################################################## ax = plt.subplot(6, 1, 1) ax.plot(time, pheConcentration.asNumber(units.umol / units.L)) plt.ylabel("Internal phe Conc. [uM]", fontsize=6) ymin = np.amin(pheConcentration.asNumber(units.umol / units.L) * 0.9) ymax = np.amax(pheConcentration.asNumber(units.umol / units.L) * 1.1) if ymin != ymax: ax.set_ylim([ymin, ymax]) ax.set_yticks([ymin, ymax]) ax.set_yticklabels(["%0.0f" % ymin, "%0.0f" % ymax]) ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.xaxis.set_ticks_position('none') ax.tick_params(which='both', direction='out', labelsize=6) ax.set_xticks([]) ############################################################## ############################################################## ax = plt.subplot(6, 1, 2) ax.plot(time, tyrRActiveCounts) ax.plot(time, tyrRInactiveCounts) ax.plot(time, tyrRTotalCounts) plt.ylabel("TyrR Counts", fontsize=6) plt.legend(["Active", "Inactive", "Total"], fontsize=6) ymin = min(np.amin(tyrRActiveCounts * 0.9), np.amin(tyrRInactiveCounts * 0.9)) ymax = np.amax(tyrRTotalCounts * 1.1) if ymin != ymax: ax.set_ylim([ymin, ymax]) ax.set_yticks([ymin, ymax]) ax.set_yticklabels(["%0.0f" % ymin, "%0.0f" % ymax]) ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.xaxis.set_ticks_position('none') ax.tick_params(which='both', direction='out', labelsize=6) ax.set_xticks([]) ############################################################## ############################################################## ax = plt.subplot(6, 1, 3) ax.plot(time, tyrATfBoundCounts) ax.plot(time, tyrATfBoundCountsMA, color="g") plt.ylabel("TyrR Bound To tyrA Promoter", fontsize=6) ymin = np.amin(tyrATfBoundCounts * 1.) ymax = np.amax(tyrATfBoundCounts * 1.) if ymin != ymax: ax.set_ylim([ymin, ymax]) ax.set_yticks([ymin, ymax]) ax.set_yticklabels(["%0.0f" % ymin, "%0.0f" % ymax]) ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.xaxis.set_ticks_position('none') ax.tick_params(which='both', direction='out', labelsize=6) ax.set_xticks([]) ############################################################## ############################################################## ax = plt.subplot(6, 1, 4) ax.plot(time, tyrASynthProb) ax.plot(time, tyrASynthProbMA, color="g") plt.ylabel("tyrA Synthesis Prob.", fontsize=6) ymin = np.amin(tyrASynthProb[1:] * 0.9) ymax = np.amax(tyrASynthProb[1:] * 1.1) if ymin != ymax: 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('none') ax.tick_params(which='both', direction='out', labelsize=6) ax.set_xticks([]) ############################################################## ############################################################## ax = plt.subplot(6, 1, 5) ax.plot(time, tyrAProteinTotalCounts) plt.ylabel("TyrA Counts", fontsize=6) ymin = np.amin(tyrAProteinTotalCounts * 0.9) ymax = np.amax(tyrAProteinTotalCounts * 1.1) if ymin != ymax: ax.set_ylim([ymin, ymax]) ax.set_yticks([ymin, ymax]) ax.set_yticklabels(["%0.0f" % ymin, "%0.0f" % ymax]) ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.xaxis.set_ticks_position('none') ax.tick_params(which='both', direction='out', labelsize=6) ax.set_xticks([]) ############################################################## ############################################################## ax = plt.subplot(6, 1, 6) ax.plot(time, proteomeMassFraction) plt.ylabel("TyrA Mass Fraction of Proteome", fontsize=6) ymin = np.amin(proteomeMassFraction * 0.9) ymax = np.amax(proteomeMassFraction * 1.1) if ymin != ymax: 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('none') ax.tick_params(which='both', direction='out', labelsize=6) ax.set_xticks([]) ############################################################## exportFigure(plt, plotOutDir, plotOutFileName, metadata) plt.close("all")
def do_plot(self, inputDir, plotOutDir, plotOutFileName, simDataFile, validationDataFile, metadata): if not os.path.isdir(inputDir): raise Exception, 'inputDir does not currently exist as a directory' filepath.makedirs(plotOutDir) with open(os.path.join(inputDir, 'kb', constants.SERIALIZED_FIT1_FILENAME), 'rb') as f: sim_data = cPickle.load(f) with open(validationDataFile, 'rb') as f: validation_data = cPickle.load(f) ap = AnalysisPaths(inputDir, variant_plot=True) variants = ap.get_variants() expected_n_variants = 2 n_variants = len(variants) if n_variants < expected_n_variants: print('This plot only runs for {} variants.'.format(expected_n_variants)) return # IDs for appropriate proteins ids_complexation = sim_data.process.complexation.moleculeNames ids_complexation_complexes = sim_data.process.complexation.ids_complexes ids_equilibrium = sim_data.process.equilibrium.moleculeNames ids_equilibrium_complexes = sim_data.process.equilibrium.ids_complexes ids_translation = sim_data.process.translation.monomerData['id'].tolist() ids_protein = sorted(set(ids_complexation + ids_equilibrium + ids_translation)) # Stoichiometry matrices equil_stoich = sim_data.process.equilibrium.stoichMatrixMonomers() complex_stoich = sim_data.process.complexation.stoichMatrixMonomers() # Protein container views protein_container = BulkObjectsContainer(ids_protein, dtype=np.float64) view_complexation = protein_container.countsView(ids_complexation) view_complexation_complexes = protein_container.countsView(ids_complexation_complexes) view_equilibrium = protein_container.countsView(ids_equilibrium) view_equilibrium_complexes = protein_container.countsView(ids_equilibrium_complexes) # Load model data model_counts = np.zeros((len(PROTEINS_WITH_HALF_LIFE), expected_n_variants)) model_std = np.zeros((len(PROTEINS_WITH_HALF_LIFE), expected_n_variants)) for i, variant in enumerate(variants): if i >= expected_n_variants: print('Skipping variant {} - only runs for {} variants.'.format(variant, expected_n_variants)) continue variant_counts = [] for sim_dir in ap.get_cells(variant=[variant]): simOutDir = os.path.join(sim_dir, 'simOut') # Listeners used unique_counts_reader = TableReader(os.path.join(simOutDir, 'UniqueMoleculeCounts')) # Account for bulk molecules (bulk_counts,) = read_bulk_molecule_counts(simOutDir, ids_protein) protein_container.countsIs(bulk_counts.mean(axis=0)) # Account for unique molecules ribosome_index = unique_counts_reader.readAttribute('uniqueMoleculeIds').index('activeRibosome') rnap_index = unique_counts_reader.readAttribute('uniqueMoleculeIds').index('activeRnaPoly') n_ribosomes = unique_counts_reader.readColumn('uniqueMoleculeCounts')[:, ribosome_index] n_rnap = unique_counts_reader.readColumn('uniqueMoleculeCounts')[:, rnap_index] protein_container.countsInc(n_ribosomes.mean(), [sim_data.moleculeIds.s30_fullComplex, sim_data.moleculeIds.s50_fullComplex]) protein_container.countsInc(n_rnap.mean(), [sim_data.moleculeIds.rnapFull]) # Account for small-molecule bound complexes view_equilibrium.countsDec(equil_stoich.dot(view_equilibrium_complexes.counts())) # Account for monomers in complexed form view_complexation.countsDec(complex_stoich.dot(view_complexation_complexes.counts())) variant_counts.append(protein_container.countsView(PROTEINS_WITH_HALF_LIFE).counts()) model_counts[:, i] = np.mean(variant_counts, axis=0) model_std[:, i] = np.std(variant_counts, axis=0) # Validation data schmidt_ids = {m: i for i, m in enumerate(validation_data.protein.schmidt2015Data['monomerId'])} schmidt_counts = validation_data.protein.schmidt2015Data['glucoseCounts'] validation_counts = np.array([schmidt_counts[schmidt_ids[p]] for p in PROTEINS_WITH_HALF_LIFE]) # Process data model_log_counts = np.log10(model_counts) model_log_lower_std = model_log_counts - np.log10(model_counts - model_std) model_log_upper_std = np.log10(model_counts + model_std) - model_log_counts validation_log_counts = np.log10(validation_counts) r_before = stats.pearsonr(validation_log_counts, model_log_counts[:, 0]) r_after = stats.pearsonr(validation_log_counts, model_log_counts[:, 1]) # Scatter plot of model vs validation counts max_counts = np.ceil(max(validation_log_counts.max(), model_log_upper_std.max())) limits = [0, max_counts] plt.figure() colors = plt.rcParams['axes.prop_cycle'].by_key()['color'] ## Plot data for i in range(expected_n_variants): plt.errorbar(validation_log_counts, model_log_counts[:, i], yerr=np.vstack((model_log_lower_std[:, i], model_log_upper_std[:, i])), fmt='o', color=colors[i], ecolor='k', capsize=3, alpha=0.5) plt.plot(limits, limits, 'k--', linewidth=0.5, label='_nolegend_') ## Format axes plt.xlabel('Validation Counts\n(log10(counts))') plt.ylabel('Average Simulation Counts\n(log10(counts))') ax = plt.gca() ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['left'].set_position(('outward', 10)) ax.spines['bottom'].set_position(('outward', 10)) ax.xaxis.set_major_locator(MaxNLocator(integer=True)) ax.yaxis.set_major_locator(MaxNLocator(integer=True)) ## Add legend legend_text = [ 'Before: r={:.2f}, p={:.3f}'.format(r_before[0], r_before[1]), 'After: r={:.2f}, p={:.3f}'.format(r_after[0], r_after[1]), ] plt.legend(legend_text, frameon=False) plt.tight_layout() 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) # Get all cells ap = AnalysisPaths(seedOutDir, multi_gen_plot=True) allDir = ap.get_cells() enzymeMonomerId = "GLUTCYSLIG-MONOMER[c]" enzymeRnaId = "EG10418_RNA[c]" reactionId = "GLUTCYSLIG-RXN" transcriptionFreq = 1.0 metaboliteId = "GLUTATHIONE[c]" # Get all cells ap = AnalysisPaths(seedOutDir, multi_gen_plot=True) allDir = ap.get_cells() sim_data = cPickle.load(open(simDataFile, "rb")) rnaIds = sim_data.process.transcription.rnaData["id"] isMRna = sim_data.process.transcription.rnaData["isMRna"] mRnaIndexes = np.where(isMRna)[0] mRnaIds = np.array([rnaIds[x] for x in mRnaIndexes]) simOutDir = os.path.join(allDir[0], "simOut") bulkMolecules = TableReader(os.path.join(simOutDir, "BulkMolecules")) moleculeIds = bulkMolecules.readAttribute("objectNames") enzymeMonomerIndex = moleculeIds.index(enzymeMonomerId) enzymeRnaIndex = moleculeIds.index(enzymeRnaId) metaboliteIndex = moleculeIds.index(metaboliteId) bulkMolecules.close() time = [] enzymeFluxes = [] enzymeMonomerCounts = [] enzymeRnaCounts = [] enzymeRnaInitEvent = [] metaboliteCounts = [] for gen, simDir in enumerate(allDir): simOutDir = os.path.join(simDir, "simOut") time += TableReader(os.path.join( simOutDir, "Main")).readColumn("time").tolist() bulkMolecules = TableReader( os.path.join(simOutDir, "BulkMolecules")) moleculeCounts = bulkMolecules.readColumn("counts") enzymeMonomerCounts += moleculeCounts[:, enzymeMonomerIndex].tolist() enzymeRnaCounts += moleculeCounts[:, enzymeRnaIndex].tolist() metaboliteCounts += moleculeCounts[:, metaboliteIndex].tolist() bulkMolecules.close() fbaResults = TableReader(os.path.join(simOutDir, "FBAResults")) reactionIDs = np.array(fbaResults.readAttribute("reactionIDs")) reactionFluxes = np.array(fbaResults.readColumn("reactionFluxes")) enzymeFluxes += reactionFluxes[:, np.where(reactionIDs == reactionId )[0][0]].tolist() fbaResults.close() rnapDataReader = TableReader(os.path.join(simOutDir, "RnapData")) enzymeRnaInitEvent += rnapDataReader.readColumn( "rnaInitEvent")[:, np.where( mRnaIds == enzymeRnaId)[0][0]].tolist() rnapDataReader.close() time = np.array(time) # Plot fig = plt.figure(figsize=(10, 10)) rnaInitAxis = plt.subplot(5, 1, 1) rnaAxis = plt.subplot(5, 1, 2, sharex=rnaInitAxis) monomerAxis = plt.subplot(5, 1, 3, sharex=rnaInitAxis) fluxAxis = plt.subplot(5, 1, 4, sharex=rnaInitAxis) metAxis = plt.subplot(5, 1, 5, sharex=rnaInitAxis) rnaInitAxis.plot(time / 3600., enzymeRnaInitEvent) rnaInitAxis.set_title("%s transcription initiation events" % enzymeRnaId, fontsize=10) rnaInitAxis.set_ylim([0, rnaInitAxis.get_ylim()[1] * 1.1]) rnaInitAxis.set_xlim([0, time[-1] / 3600.]) rnaAxis.plot(time / 3600., enzymeRnaCounts) rnaAxis.set_title("%s counts" % enzymeRnaId, fontsize=10) monomerAxis.plot(time / 3600., enzymeMonomerCounts) monomerAxis.set_title("%s counts" % enzymeMonomerId, fontsize=10) fluxAxis.plot(time / 3600., enzymeFluxes) fluxAxis.set_title( "%s flux (%s / %s / %s)" % (reactionId, COUNTS_UNITS, VOLUME_UNITS, TIME_UNITS), fontsize=10) metAxis.plot(time / 3600., metaboliteCounts) metAxis.set_title("%s counts" % metaboliteId, fontsize=10) metAxis.set_xlabel( "Time (hour)\n(%s frequency of at least 1 transcription per generation)" % transcriptionFreq, fontsize=10) plt.subplots_adjust( wspace=0.4, hspace=0.4 ) #, right = 0.83, bottom = 0.05, left = 0.07, top = 0.95) exportFigure(plt, plotOutDir, plotOutFileName, metadata) plt.close("all")