def parameter_sweep(model, sigma, ns): generate_equations(model) logp = [numpy.log10(p.value) for p in model.parameters] ts = numpy.linspace(0, 20 * 3600, 20 * 60) solver = Solver(model, ts) pf.set_fig_params() plt.figure(figsize=(1.8, 1), dpi=300) for i in range(ns): psample = sample_params(logp, 0.05) res = solver.run(param_values=psample) signal = res.observables['p53_active'] plt.plot(signal, color=(0.7, 0.7, 0.7), alpha=0.3) # Highlighted colors = ['g', 'y', 'c'] for c in colors: psample = sample_params(logp, 0.05) res = solver.run(param_values=psample) signal = res.observables['p53_active'] plt.plot(signal, c) # Nominal solver = Solver(model, ts) res = solver.run() signal = res.observables['p53_active'] plt.plot(signal, 'r') plt.xticks([]) plt.xlabel('Time (a.u.)', fontsize=7) plt.ylabel('Active p53', fontsize=7) plt.yticks([]) plt.ylim(ymin=0) pf.format_axis(plt.gca()) plt.savefig(model.name + '_sample.pdf')
def plot_stmt_counts(go_stmt_map, plot_filename, figsize=(3, 3)): # Put together counts for a figure pf.set_fig_params() fig = plt.figure(figsize=(8, 4), dpi=200) ax = fig.gca() counts = [] for go_id in go_stmt_map.keys(): counts.append( (go_stmt_map[go_id]['names'][0], len(go_stmt_map[go_id]['in_go']), len(go_stmt_map[go_id]['not_in_go']))) counts.sort(key=lambda x: x[1] + x[2], reverse=True) indices = np.arange(len(counts)) width = 0.8 in_go = [c[1] for c in counts] labels = [c[0] for c in counts] not_in_go = [c[2] for c in counts] p1 = ax.bar(indices, in_go, width, color='b') p2 = ax.bar(indices, not_in_go, width, color='r', bottom=in_go) ax.set_ylabel('No. of stmts') plt.xlim([-0.2, len(counts)]) plt.xticks(indices + width / 2., labels, rotation='vertical') plt.legend((p1[0], p2[0]), ('In GO', 'Not in GO'), frameon=False, fontsize=7) plt.subplots_adjust(left=0.08, bottom=0.44, top=0.85, right=0.97) pf.format_axis(ax) fig.savefig(plot_filename)
def parameter_sweep(model, sigma, ns): generate_equations(model) logp = [numpy.log10(p.value) for p in model.parameters] ts = numpy.linspace(0, 20*3600, 20*60) solver = Solver(model, ts) pf.set_fig_params() plt.figure(figsize=(1.8, 1), dpi=300) for i in range(ns): psample = sample_params(logp, 0.05) res = solver.run(param_values=psample) signal = res.observables['p53_active'] plt.plot(signal, color=(0.7, 0.7, 0.7), alpha=0.3) # Highlighted colors = ['g', 'y', 'c'] for c in colors: psample = sample_params(logp, 0.05) res = solver.run(param_values=psample) signal = res.observables['p53_active'] plt.plot(signal, c) # Nominal solver = Solver(model, ts) res = solver.run() signal = res.observables['p53_active'] plt.plot(signal, 'r') plt.xticks([]) plt.xlabel('Time (a.u.)', fontsize=7) plt.ylabel('Active p53', fontsize=7) plt.yticks([]) plt.ylim(ymin=0) pf.format_axis(plt.gca()) plt.savefig(model.name + '_sample.pdf')
def plot_stmt_counts(go_stmt_map, plot_filename, figsize=(3, 3)): # Put together counts for a figure pf.set_fig_params() fig = plt.figure(figsize=(8, 4), dpi=200) ax = fig.gca() counts = [] for go_id in go_stmt_map.keys(): counts.append((go_stmt_map[go_id]['names'][0], len(go_stmt_map[go_id]['in_go']), len(go_stmt_map[go_id]['not_in_go']))) counts.sort(key=lambda x: x[1] + x[2], reverse=True) indices = np.arange(len(counts)) width = 0.8 in_go = [c[1] for c in counts] labels = [c[0] for c in counts] not_in_go = [c[2] for c in counts] p1 = ax.bar(indices, in_go, width, color='b') p2 = ax.bar(indices, not_in_go, width, color='r', bottom=in_go) ax.set_ylabel('No. of stmts') plt.xlim([-0.2, len(counts)]) plt.xticks(indices + width/2., labels, rotation='vertical') plt.legend((p1[0], p2[0]), ('In GO', 'Not in GO'), frameon=False, fontsize=7) plt.subplots_adjust(left=0.08, bottom=0.44, top=0.85, right=0.97) pf.format_axis(ax) fig.savefig(plot_filename)
def plot_results(g, stmt_uuids, stmt_nodes, stmt_node_nums, stmt_uuid_nums): norm_node_counts = np.array(stmt_node_nums) / len(g) norm_uuid_counts = np.array(stmt_uuid_nums) / len(g.edges()) pf.set_fig_params() plt.ion() lengths = range(1, len(norm_uuid_counts)+1) plt.figure(figsize=(2, 2), dpi=150) plt.plot(lengths, norm_uuid_counts, color='orange', alpha=0.8, label='Statements') plt.plot(lengths, norm_node_counts, color='blue', alpha=0.8, label='Nodes') plt.legend(loc='upper left', fontsize=pf.fontsize, frameon=False) ax = plt.gca() pf.format_axis(ax)
def plot_result(model, sol): pf.set_fig_params() plt.ion() plt.figure(figsize=(1, 1), dpi=300) species_names = [str(s) for s in model.species] plt.plot(t, sol.y[:, species_names.index("MAPK1(T185='u', Y187='u')")], 'b', label='MAPK1.uu') plt.plot(t, sol.y[:, species_names.index("MAPK1(T185='p', Y187='u')")] + sol.y[:, species_names.index("MAPK1(T185='u', Y187='p')")], 'g', label='MAPK1.p') plt.plot(t, sol.y[:, species_names.index("MAPK1(T185='p', Y187='p')")], 'r', label='MAPK1.pp') plt.xlabel('Time') plt.ylabel('Amount') plt.legend(loc='upper right', fontsize=4) plt.xticks([]) plt.yticks([]) pf.format_axis(plt.gca())
import numpy as np from indra.util import plot_formatting as pf from collections import Counter from indra.statements import * from indra.preassembler import Preassembler from indra.preassembler.hierarchy_manager import hierarchies from copy import deepcopy from indra.databases import uniprot_client import sys from indra.preassembler import grounding_mapper as gm import logging logger = logging.getLogger('reading_results') pf.set_fig_params() def load_file(stmts_file): logger.info("Loading results...") with open(stmts_file, 'rb') as f: results = pickle.load(f) return results def report_stmt_counts(paper_stmts, plot_prefix=None): counts_per_paper = [(pmid, len(stmts)) for pmid, stmts in results.items()] counts = np.array([tup[1] for tup in counts_per_paper]) logger.info("%.2f +/- %.2f statements per paper" % (np.mean(counts), np.std(counts))) logger.info("Median %d statements per paper" % np.median(counts))
from __future__ import absolute_import, print_function, unicode_literals from builtins import dict, str import sys import glob import pickle from os.path import join as pjoin from indra.tools import assemble_corpus as ac from collections import OrderedDict, Counter, namedtuple, defaultdict from indra.preassembler.sitemapper import SiteMapper, default_site_map from indra.util import write_unicode_csv, read_unicode_csv from indra.util import plot_formatting as pf import numpy as np from matplotlib import pyplot as plt pf.set_fig_params() SiteInfo = namedtuple('SiteInfo', [ 'gene', 'res', 'pos', 'valid', 'mapped', 'mapped_res', 'mapped_pos', 'explanation', 'freq', 'source' ]) def map_statements(stmts, source, outfile=None): """Tabulate valid, invalid, and mapped sites from a set of Statements.""" # Look for errors in database statements sm = SiteMapper(default_site_map) valid_stmts, mapped_stmts = sm.map_sites(stmts) # Collect stats from SiteMapper itself sites = [] for site_key, mapping in sm._cache.items():