Exemple #1
0
def CF_plot(args):
	try:
		import locale
		import matplotlib
		matplotlib.use('Agg')
		import matplotlib.pyplot as plt
		import pylab as P
		from matplotlib.lines import Line2D
		from matplotlib.patches import Rectangle
		_ = locale.setlocale(locale.LC_ALL, '')
	except:
		print "[ERROR] One or more of the required modules for plotting cannot be loaded! Are matplotlib and pylab installed?"
		sys.exit(0)
		
		
	chr, start, stop = cf.parseLocString(args.region)
	
	r = cf.rpkm_reader(args.input)
	
	data = r.getExonValuesByRegion(chr,start,stop)
	_ = data.smooth()
	
	plt.gcf().clear()
	fig = plt.figure(figsize=(10,5))
	ax = fig.add_subplot(111)
	
	
	ax.plot(data.rpkm, linewidth = 0.3, c='k')
	
	
	if args.sample != 'none':
		cnt = 1
		coloriter = iter(['r','b','g','y'])
		for sample in args.sample:
			try:
				color, sampleID = sample.split(":")
			except:
				color =coloriter.next()
				sampleID = sample
			
			ax.plot(data.getSample([sampleID]), linewidth = 1, c=color, label = sampleID)
			
			if cnt == 1:
				cf.plotRawData(ax, r.getExonValuesByRegion(chr,start,stop,sampleList=[sampleID]).getSample([sampleID]),color=color)
			cnt +=1
		plt.legend(prop={'size':10},frameon=False)
		
	cf.plotGenes(ax, data)
	cf.plotGenomicCoords(plt,data)
	plt.xlim(0,data.shape[1])
	plt.ylim(-3,3)
	
	plt.title("%s: %s - %s" % (cf.chrInt2Str(chr),locale.format("%d",start, grouping=True),locale.format("%d",stop, grouping=True)))
	plt.xlabel("Position")
	plt.ylabel("SVD-ZRPKM Values")
	
	plt.savefig(args.output)
	
	sys.exit(0)
Exemple #2
0
def CF_plot(args):
	try:
		import locale
		import matplotlib
		matplotlib.use('Agg')
		import matplotlib.pyplot as plt
		import pylab as P
		from matplotlib.lines import Line2D
		from matplotlib.patches import Rectangle
		_ = locale.setlocale(locale.LC_ALL, '')
	except:
		print "[ERROR] One or more of the required modules for plotting cannot be loaded! Are matplotlib and pylab installed?"
		sys.exit(0)
		
		
	chr, start, stop = cf.parseLocString(args.region)
	
	r = cf.rpkm_reader(args.input)
	
	data = r.getExonValuesByRegion(chr,start,stop)
	_ = data.smooth()
	
	plt.gcf().clear()
	fig = plt.figure(figsize=(10,5))
	ax = fig.add_subplot(111)
	
	
	ax.plot(data.rpkm, linewidth = 0.3, c='k')
	
	
	if args.sample != 'none':
		cnt = 1
		coloriter = iter(['r','b','g','y'])
		for sample in args.sample:
			try:
				color, sampleID = sample.split(":")
			except:
				color =coloriter.next()
				sampleID = sample
			
			ax.plot(data.getSample([sampleID]), linewidth = 1, c=color, label = sampleID)
			
			if cnt == 1:
				cf.plotRawData(ax, r.getExonValuesByRegion(chr,start,stop,sampleList=[sampleID]).getSample([sampleID]),color=color)
			cnt +=1
		plt.legend(prop={'size':10},frameon=False)
		
	cf.plotGenes(ax, data)
	cf.plotGenomicCoords(plt,data)
	plt.xlim(0,data.shape[1])
	plt.ylim(-3,3)
	
	plt.title("%s: %s - %s" % (cf.chrInt2Str(chr),locale.format("%d",start, grouping=True),locale.format("%d",stop, grouping=True)))
	plt.xlabel("Position")
	plt.ylabel("SVD-ZRPKM Values")
	
	plt.savefig(args.output)
	
	sys.exit(0)
Exemple #3
0
def CF_plotcalls(args):
    try:
        import matplotlib
        matplotlib.use('Agg')
        import matplotlib.pyplot as plt
        import pylab as P
        from matplotlib.lines import Line2D
        from matplotlib.patches import Rectangle
    except:
        print "[ERROR] One or more of the required modules for plotting cannot be loaded! Are matplotlib and pylab installed?"
        sys.exit(0)

    import locale
    try:
        _ = locale.setlocale(locale.LC_ALL, 'en_US')
    except:
        _ = locale.setlocale(locale.LC_ALL, '')

    try:
        callfile_fn = str(args.calls)
        callfile_f = open(callfile_fn, mode='r')
    except IOError as e:
        print '[ERROR] Cannot open call file for reading: ', callfile_fn
        sys.exit(0)

    all_calls = []
    header = callfile_f.readline()

    for line in callfile_f:
        sampleID, chr, start, stop, state = line.strip().split()
        chr = cf.chrStr2Int(chr)
        all_calls.append({
            "chromosome": int(chr),
            "start": int(start),
            "stop": int(stop),
            "sampleID": sampleID
        })

    r = cf.rpkm_reader(args.input)

    for call in all_calls:
        chr = call["chromosome"]
        start = call["start"]
        stop = call["stop"]
        sampleID = call["sampleID"]

        exons = r.getExonIDs(chr, int(start), int(stop))

        window_start = max(exons[0] - args.window, 0)
        window_stop = exons[-1] + args.window

        data = r.getExonValuesByExons(chr, window_start, window_stop)
        _ = data.smooth()

        plt.gcf().clear()
        fig = plt.figure(figsize=(10, 5))
        ax = fig.add_subplot(111)

        ax.plot(data.rpkm, linewidth=0.3, c='k')

        ax.plot(data.getSample([sampleID]), linewidth=1, c='r', label=sampleID)
        cf.plotRawData(ax,
                       r.getExonValuesByExons(chr,
                                              window_start,
                                              window_stop,
                                              sampleList=[sampleID]).getSample(
                                                  [sampleID]),
                       color='r')

        plt.legend(prop={'size': 10}, frameon=False)

        cf.plotGenes(ax, data)
        cf.plotGenomicCoords(plt, data)

        exon_start = np.where(data.exons["start"] == start)[0][0]
        exon_stop = np.where(data.exons["stop"] == stop)[0][0]
        _ = ax.add_line(
            matplotlib.lines.Line2D([exon_start, exon_stop], [2, 2],
                                    color='k',
                                    lw=6,
                                    linestyle='-',
                                    alpha=1,
                                    solid_capstyle='butt'))

        _ = plt.xlim(0, data.shape[1])
        _ = plt.ylim(-3, 3)

        plt.title(
            "%s: %s - %s" %
            (cf.chrInt2Str(chr), locale.format("%d", start, grouping=True),
             locale.format("%d", stop, grouping=True)))
        plt.xlabel("Position")
        plt.ylabel("SVD-ZRPKM Values")
        outfile = "%s_%d_%d_%s.png" % (cf.chrInt2Str(chr), start, stop,
                                       sampleID)
        plt.savefig(args.outputdir + "/" + outfile)
Exemple #4
0
def CF_plotcalls(args):
	try:
		import matplotlib
		matplotlib.use('Agg')
		import matplotlib.pyplot as plt
		import pylab as P
		from matplotlib.lines import Line2D
		from matplotlib.patches import Rectangle
	except:
		print "[ERROR] One or more of the required modules for plotting cannot be loaded! Are matplotlib and pylab installed?"
		sys.exit(0)
	
	import locale	
	try:
		_ = locale.setlocale(locale.LC_ALL, 'en_US')
	except:
		_ = locale.setlocale(locale.LC_ALL, '')
	
	try: 
		callfile_fn = str(args.calls)
		callfile_f = open(callfile_fn, mode='r')
	except IOError as e: 
		print '[ERROR] Cannot open call file for reading: ', callfile_fn
		sys.exit(0)
	
	all_calls = []
	header = callfile_f.readline()
	
	for line in callfile_f:
		sampleID, chr, start, stop, state = line.strip().split()
		chr = cf.chrStr2Int(chr)
		all_calls.append({"chromosome":int(chr), "start":int(start), "stop":int(stop), "sampleID":sampleID})
	
	r = cf.rpkm_reader(args.input)
	
	for call in all_calls:
		chr = call["chromosome"]
		start = call["start"]
		stop = call["stop"]
		sampleID = call["sampleID"]
		
		exons = r.getExonIDs(chr,int(start),int(stop))
		
		
		window_start = max(exons[0]-args.window,0)
		window_stop = exons[-1]+args.window
		
		data = r.getExonValuesByExons(chr,window_start, window_stop)
		_ = data.smooth()
		
		plt.gcf().clear()
		fig = plt.figure(figsize=(10,5))
		ax = fig.add_subplot(111)
		
		
		ax.plot(data.rpkm, linewidth = 0.3, c='k')
		
		
		ax.plot(data.getSample([sampleID]), linewidth = 1, c='r', label = sampleID)
		cf.plotRawData(ax, r.getExonValuesByExons(chr,window_start, window_stop,sampleList=[sampleID]).getSample([sampleID]),color='r')
		
		plt.legend(prop={'size':10},frameon=False)
		
		cf.plotGenes(ax, data)
		cf.plotGenomicCoords(plt,data)
		
		exon_start = np.where(data.exons["start"] == start)[0][0]
		exon_stop = np.where(data.exons["stop"] == stop)[0][0]
		_ = ax.add_line(matplotlib.lines.Line2D([exon_start,exon_stop],[2,2],color='k',lw=6,linestyle='-',alpha=1,solid_capstyle='butt'))
		
		_ = plt.xlim(0,data.shape[1])
		_ = plt.ylim(-3,3)
		
		plt.title("%s: %s - %s" % (cf.chrInt2Str(chr),locale.format("%d",start, grouping=True),locale.format("%d",stop, grouping=True)))
		plt.xlabel("Position")
		plt.ylabel("SVD-ZRPKM Values")
		outfile = "%s_%d_%d_%s.png" % (cf.chrInt2Str(chr), start, stop, sampleID)
		plt.savefig(args.outputdir + "/" + outfile)