Beispiel #1
0
def plot(cfg, name, fig, canvas, ax, entities, xlabel=' ', ylabel=None, yticks=None):
	quodplot = quod.Plot(fig=fig, canvas=canvas, ax=ax)
	quodplot.width = cfg['width']
	quodplot.height = cfg['height']
	for i, e in enumerate(entities):
		if type(e) is quod.What: 
			e.set_style(i)
			if name in cfg['color']:
				e.set_tms_color(cfg['color'][name][i]['tms'])
				e.set_curve_color(cfg['color'][name][i]['line'])
			if 'linestyle' in cfg and name in cfg['linestyle']:
				if i in cfg['linestyle'][name]: e.set_linestyle(cfg['linestyle'][name][i])
			if 'linewidth' in cfg and name in cfg['linewidth']:
				if i in cfg['linewidth'][name]: e.set_linewidth(cfg['linewidth'][name][i])
		quodplot.add(e)
	quodplot.render()

	ax.set_xlabel(xlabel)
	try: ax.set_title(cfg['titles'][name])
	except KeyError: ax.set_title('')
	if ylabel is not None: ax.set_ylabel(ylabel)
	if yticks is not None: ax.set_yticks(yticks)

	if name in cfg['xticks']:
		xlim = ax.get_xlim()
		ax.set_xticks(np.arange(xlim[0], xlim[1], cfg['xticks'][name]))
Beispiel #2
0
def quod_fragquod(frags,
                  fulls,
                  title,
                  outfile,
                  dpi=300,
                  width=30,
                  height=5.5,
                  kernel=None):

    fig = quod.plt.figure()
    ax = fig.add_subplot(111)
    plot = quod.Plot(fig=fig, ax=ax)
    plot.add(quod.FragmentWhat(frags[0], fulls[0], style=0, kernel=kernel))
    plot.add(quod.FragmentWhat(frags[1], fulls[1], style=1, kernel=kernel))

    correl, cov = plot[0].entdict['hydro'].get_correlation(
        plot[1].entdict['hydro'])

    plot.width = width
    plot.height = height
    plot.render()
    plot.ax.set_title(title)
    plot.fig.savefig(outfile, dpi=dpi)

    return correl, cov
Beispiel #3
0
def entropy_quod(*sequences, **kwargs):
	'''This example plots the entropies of multiple sequences

	sequences: raw sequences
	**kwargs:
		outfile: where to put the resulting figure'''

	outfile = kwargs['outfile'] if 'outfile' in kwargs else kwargs['outfile']

	plot = quod.Plot()
	
	for i, seq in enumerate(sequences):
		plot.add(quod.What(seq, style=i, mode='entropy'))

	plot.render()

	plot.save(outfile)
Beispiel #4
0
def colored_quod(seq1, seq2, linecolor1='red', linecolor2='blue', tmscolor1='orange', tmscolor2='cyan', outfile='test.png'):
	'''This example creates a standard hydropathy plot for two raw sequences, making sure to specify colors manually

	seq1: sequence 1
	seq2: sequence 2
	linecolor1: line color for sequence 1
	linecolor2: line color for sequence 2
	tmscolor1: tms color for sequence 1 
	tmscolor2: tms color for sequence 2
	outfile: what to name the resulting figure'''

	plot = quod.Plot()

	plot.add(quod.What(seq1, tmscolor=tmscolor1, linecolor=linecolor1))
	plot.add(quod.What(seq2, tmscolor=tmscolor2, linecolor=linecolor2))

	plot.render()

	plot.save(outfile)
Beispiel #5
0
def simple_quod(*sequences, **kwargs):
	'''This example creates a standard hydropathy plot from several raw sequences and saves it with a specific filename if given

	*sequences: raw sequences
	**kwargs:
		window: window size for hydropathy averaging (default: 19)
		outfile: what to name the resulting figure'''

	outfile = 'test.png' if ('outfile' not in kwargs) else kwargs['outfile']
	window = 19 if ('window' not in kwargs) else kwargs['window']

	plot = quod.Plot()

	for i, seq in enumerate(sequences):
		plot.add(quod.What(seq, style=i, window=window))
	
	plot.render()

	plot.save(outfile)
Beispiel #6
0
def walls_quod(*sequences, **kwargs):
	'''This example plots sequences with walls+wedges defining certain intervals

	*sequences: raw sequences
	**kwargs:
		intervals: a list of Interval objects to generate walls+wedges from (default: [])
		outfile: what to name the resulting figure (default: test.png)'''

	plot = quod.Plot()

	intervals = [] if 'intervals' not in kwargs else kwargs['intervals']
	outfile = 'test.png' if 'outfile' not in kwargs else kwargs['outfile']
	mode = 'wall' if 'mode' not in kwargs else kwargs['mode']

	for i in intervals: plot.add(i.get_auto())

	for n, seq in enumerate(sequences): plot.add(quod.What(seq, style=n))

	plot.render()

	plot.save(outfile)
Beispiel #7
0
    def run(self):
        print('Use [?] to get help on phoboshop shortcuts', file=sys.stderr)
        self.fig = quod.plt.figure()
        self.plot = quod.Plot(fig=self.fig)
        for i, p in enumerate(self.proteins):
            for e in p.render(style=i):
                self.plot.add(e)

        self.update_title()
        self.plot.ax.figure.canvas.mpl_connect('button_press_event',
                                               self.onmousedown)
        self.plot.ax.figure.canvas.mpl_connect('button_release_event',
                                               self.onmouseup)
        self.plot.ax.figure.canvas.mpl_connect('motion_notify_event',
                                               self.onmousemove)
        self.plot.ax.figure.canvas.mpl_connect('key_press_event',
                                               self.onkeydown)
        #self.testline = self.plot.ax.plot([], [])
        self.testline, = self.plot.ax.plot([], [])

        self.plot.render()
        quod.plt.show()
Beispiel #8
0
    plt = quod.plt

    sequences = []
    for i, thing in enumerate(args.infiles):
        if thing.startswith('asis:'):
            sequences.append('>seq{}\n{}'.format(i + 1, thing[5:]))
        else:
            with open(thing) as f:
                s = f.read()
                if not s.startswith('>'):
                    sequences.append('>seq{}\n{}'.format(i + 1, s))
                else:
                    sequences.append(s)

    fig = plt.figure()
    plot = quod.Plot(fig=fig)
    n = 0
    for i in range(0, len(sequences), 2):
        x = quod.FragmentWhat(sequences[i],
                              sequences[i + 1],
                              style=n,
                              kernel=args.kernel)
        plot.add(x)
        whats.append(x)
        n += 1
    plot.render()

    if args.correlate and (len(whats) > 1):
        for i in range(len(whats)):
            hydro1 = whats[i].entdict['hydro'].Y
            for j in range(len(whats)):
Beispiel #9
0
def quod_set(seqids,
             sequences,
             indir,
             outdir,
             dpi=300,
             force=False,
             bars=[],
             prefix='',
             suffix='',
             silent=False,
             pars=[],
             kernel=None):
    ''' generates QUOD plots for batches of sequences '''
    if not os.path.isdir(outdir): os.mkdir(outdir)

    #wedges = [[[x, 2 * (0.5 - (i % 2))] for i, x in enumerate(span)] for span in bars]

    ove = lambda x: int(2 * (0.5 - (x % 2)))

    wedges = []
    for i, span in enumerate(bars):
        wedges.append([])
        if 1 <= i <= 2: y = -2
        else: y = -2
        wedges[-1].append(quod.Wall(spans=[span], y=y, ylim=[0, 0.5]))

    medges = []
    for i, span in enumerate(pars):
        medges.append([])
        y = 2
        medges[-1].append(quod.Wall(spans=[span], y=y, ylim=[0.5, 1]))

    domains = []
    styledict = {}
    for i, seqid in enumerate(seqids):
        #if i < 2: color = 'red'
        #else: color = 'blue'
        #domains.append(parse_pfam('{}/../pfam/{}.pfam'.format(indir, seqid), color=color))
        entities, styledict = parse_pfam('{}/../pfam/{}.pfam'.format(
            indir, seqid),
                                         styledict=styledict)
        domains.append(entities)

    #Draw A: barred by B
    #quod.what([sequences[seqids[0]]], force_seq=True, title=seqids[0], imgfmt='png', outdir=outdir, outfile=(seqids[0] + '_' + seqids[1] + '.png'), dpi=dpi, hide=1, entities=wedges[0]+domains[0], silent=True, width=15, height=3)

    halfwidth = 7.5
    halfheight = 2
    fig_a = quod.plt.figure()
    ax_a = fig_a.add_subplot(111)
    plot_a = quod.Plot(fig=fig_a, ax=ax_a)
    plot_a.add(quod.What(sequences[seqids[0]], style=0, kernel=kernel))
    for e in wedges[0] + domains[0]:
        plot_a.add(e)
    plot_a.width = halfwidth
    plot_a.height = halfheight
    plot_a.render()
    plot_a.ax.set_title(seqids[0])
    plot_a.fig.savefig('{}/{}_{}.png'.format(outdir, seqids[0], seqids[1]),
                       dpi=dpi)

    #Draw B: barred by C
    #quod.what([sequences[seqids[1]]], force_seq=True, title=seqids[1], imgfmt='png', outdir=outdir, outfile=(seqids[1] + '_' + seqids[2] + '.png'), dpi=dpi, hide=1, entities=wedges[1]+medges[0]+domains[1], silent=True, width=15, height=3)
    fig_b = quod.plt.figure()
    ax_b = fig_b.add_subplot(111)
    plot_b = quod.Plot(fig=fig_b, ax=ax_b)
    plot_b.add(quod.What(sequences[seqids[1]], style=0, kernel=kernel))
    for e in wedges[1] + medges[0] + domains[1]:
        plot_b.add(e)
    plot_b.width = halfwidth
    plot_b.height = halfheight
    plot_b.render()
    plot_b.ax.set_title(seqids[1])
    plot_b.fig.savefig('{}/{}_{}.png'.format(outdir, seqids[1], seqids[2]),
                       dpi=dpi)

    #Draw C: barred by B
    #quod.what([sequences[seqids[2]]], force_seq=True, title=seqids[2], imgfmt='png', outdir=outdir, outfile=(seqids[2] + '_' + seqids[1] + '.png'), dpi=dpi, hide=1, color=1, entities=wedges[2]+medges[1]+domains[2], silent=True, width=15, height=3)
    fig_c = quod.plt.figure()
    ax_c = fig_c.add_subplot(111)
    plot_c = quod.Plot(fig=fig_c, ax=ax_c)
    plot_c.add(quod.What(sequences[seqids[2]], style=1, kernel=kernel))
    for e in wedges[2] + medges[1] + domains[2]:
        plot_c.add(e)
    plot_c.width = halfwidth
    plot_c.height = halfheight
    plot_c.render()
    plot_c.ax.set_title(seqids[2])
    plot_c.fig.savefig('{}/{}_{}.png'.format(outdir, seqids[2], seqids[1]),
                       dpi=dpi)

    #Draw D: barred by C
    #quod.what([sequences[seqids[3]]], force_seq=True, title=seqids[3], imgfmt='png', outdir=outdir, outfile=(seqids[3] + '_' + seqids[2] + '.png'), dpi=dpi, hide=1, color=1, entities=wedges[3]+domains[3], silent=True, width=15, height=3)
    fig_d = quod.plt.figure()
    ax_d = fig_d.add_subplot(111)
    plot_d = quod.Plot(fig=fig_d, ax=ax_d)
    plot_d.add(quod.What(sequences[seqids[3]], style=1, kernel=kernel))
    for e in wedges[3] + domains[3]:
        plot_d.add(e)
    plot_d.width = halfwidth
    plot_d.height = halfheight
    plot_d.render()
    plot_d.ax.set_title(seqids[3])
    plot_d.fig.savefig('{}/{}_{}.png'.format(outdir, seqids[3], seqids[2]),
                       dpi=dpi)
Beispiel #10
0
def plot(cfg, name, fig, ax, entities, xlabel=' ', ylabel=None, yticks=None):
    quodplot = quod.Plot(fig=fig, ax=ax)
    quodplot.width = cfg['width']
    quodplot.height = cfg['height']

    if name in cfg['xlim']: quodplot.xlim = cfg['xlim'][name]
    if name in cfg['ylim']: quodplot.ylim = cfg['ylim'][name]

    for i, e in enumerate(entities):
        if quod.is_what(e):
            e.set_style(i)
            if (name in cfg['color']) and (i in cfg['color'][name]):
                e.set_tms_color(cfg['color'][name][i]['tms'])
                e.set_curve_color(cfg['color'][name][i]['line'])
            if 'linestyle' in cfg and name in cfg['linestyle']:
                if i in cfg['linestyle'][name]:
                    e.set_linestyle(cfg['linestyle'][name][i])
            if 'linewidth' in cfg and name in cfg['linewidth']:
                if i in cfg['linewidth'][name]:
                    e.set_linewidth(cfg['linewidth'][name][i])
        else:
            if avehas3 is not None:
                if type(e) is avehas3.Avehas:
                    e.set_style(i)
                    if (name in cfg['color']) and (i in cfg['color'][name]):
                        e.entities[0].style = cfg['color'][name][i]['line']
                        e.entities[1].style = cfg['color'][name][i]['tms']
                    #if 'linestyle' in cfg and name in cfg['linestyle']:
                    #	if i in cfg['linestyle'][name]: e.entities[0].linestyle = cfg['linestyle'][name][i]
                    #if 'linewidth' in cfg and name in cfg['linewidth']:
                    #	if i in cfg['linewidth'][name]: e.entities[0].linewidth = cfg['linewidth'][name][i]
                    #	if i in cfg['linewidth'][name]: e.entities[1].linewidth = cfg['linewidth'][name][i]
                    for prop in cfg:
                        #UNSTABLE!!!
                        if prop.startswith('linewidth') and name in cfg[prop]:
                            if '.' not in prop:
                                if i in cfg['linewidth'][name]:
                                    e.entdict['hydro'].linewidth = cfg[
                                        'linewidth'][name][i]
                                if i in cfg['linewidth'][name]:
                                    e.entdict['amphi'].linewidth = cfg[
                                        'linewidth'][name][i]
                                if i in cfg['linewidth'][name]:
                                    e.entdict['simil'].linewidth = cfg[
                                        'linewidth'][name][i]
                            else:
                                sp = prop.split('.')
                                rootprop = sp[0]
                                if sp[1] == 'simil':
                                    e.linewidthsimil = cfg[prop][name][i]
                                elif sp[1] == 'amphi':
                                    e.linewidthamphi = cfg[prop][name][i]

                        if prop.startswith('linestyle') and name in cfg[prop]:
                            if '.' not in prop:
                                if i in cfg['linestyle'][name]:
                                    e.entities[0].linestyle = cfg['linestyle'][
                                        name][i]
                            else:
                                sp = prop.split('.')
                                rootprop = sp[0]
                                if sp[1] == 'simil':
                                    e.linestylesimil = cfg[prop][name][i]
                                elif sp[1] == 'amphi':
                                    e.linestyleamphi = cfg[prop][name][i]
        quodplot.add(e)
    quodplot.render()

    ax.set_xlabel(xlabel)
    #ax.set_title(cfg['title'].get(name, ''), fontsize=get_titlefont(cfg, name))
    ax.set_title('')
    if ylabel is not None: ax.set_ylabel(ylabel)
    if yticks is not None: ax.set_yticks(yticks)

    if name in cfg['xticks']:
        xlim = ax.get_xlim()
        ax.set_xticks(np.arange(xlim[0], xlim[1], cfg['xticks'][name]))