情节未显示

时间:2015-02-26 14:27:54

标签: python plot

目的是创建一个情节。我有以下脚本:

#!/usr/bin/python

import sys
from matplotlib import pyplot as plt
from matplotlib.collections import BrokenBarHCollection

file = sys.argv[1]

color_lookup = {
  'INS': (1., 1., 1.),
  'DEL': (.6, .6, .6),
  'DUP': (.4, .4, .4),
  'INV': (.2, .2, .2),
  'TRA': (0., 0., 0.),
}

height = 0.9
spacing = 0.9

def ideograms(fn):
    last_chrom = None
    fin = open(fn)
    fin.readline()
    xranges, colors = [], []
    ymin = 0
    print "Reading input..."
    for line in fin:
        chrom, start, stop, label = line.strip().split('\t')
        start = int(start)
        stop = int(stop)
        width = stop - start
        if chrom == last_chrom or (last_chrom is None):
            xranges.append((start, width))
            colors.append(color_lookup[label])
            last_chrom = chrom
            continue

        ymin += height + spacing
        yrange = (ymin, height)
        yield xranges, yrange, colors, last_chrom
        xranges, colors = [], []
        xranges.append((start, width))
        colors.append(color_lookup[label])
        last_chrom = chrom

    # last one
    ymin += height + spacing
    yrange = (ymin, height)
    yield xranges, yrange, colors, last_chrom

fig = plt.figure()
ax = fig.add_subplot(111)
d = {}
yticks = []
yticklabels = []

# ideogram.txt downloaded from UCSC's table browser
for xranges, yrange, colors, label in ideograms(file):
    coll = BrokenBarHCollection(xranges, yrange, facecolors=colors)
    ax.add_collection(coll)
    center = yrange[0] + yrange[1]/2.
    yticks.append(center)
    yticklabels.append(label)
    d[label] = xranges

ax.axis('tight')
ax.set_yticks(yticks)
ax.set_yticklabels(yticklabels)
ax.set_xticks([])
fig.show()

采用以下文本文件:

15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   1020262 1021297 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   3997094 3997771 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   7554794 7555726 INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   12102772        12127279        INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   12222645        12256683        INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   12641052        12642314        INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   12852136        12854980        INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   13049643        13113925        INV
15_dna:chromosome_chromosome:Sscrofa10.2:15:1:157681621:1_REF   13199758        13206459        INV

但脚本不输出任何绘图,也没有给出错误。你对发生的事情有任何想法吗?

编辑:我刚刚在center = yrange[0] + yrange[1]/2.之后删除了该点,现在它抛出了以下错误/home/software/002-Interpreters/lib/python2.7/site-packages/matplotlib/figure.py:387: UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure "matplotlib is currently using a non-GUI backend, "

0 个答案:

没有答案