예제 #1
0
파일: GenePair.py 프로젝트: polyactis/annot
	def _plot(self, x_list, y_list, x_range, y_range):
		self.no_of_curves += 1
		if self.no_of_curves==1:
			r.plot(x_list, y_list, type='o',pch='*',xlab='dataset no.',xlim=x_range,ylim=y_range, \
			ylab='expression value', col=self.no_of_curves)
		else:
			r.lines(x_list, y_list, type='o',pch='*',col=self.no_of_curves)
예제 #2
0
파일: run.py 프로젝트: rkdarst/dragunov
 def rplot(data, par={}, title={}, xlab="", ylab=""):
     r.plot_new()
     xmax = -1e6
     xmin = 1e6
     ymax = -1e6
     ymin = 1e6
     for x in data:
         #print x[0]
         #print x[1]
         xmax = max(xmax, max(x[0]))
         xmin = min(xmin, min(x[0]))
         ymax = max(ymax, max(x[1]))
         ymin = min(ymin, min(x[1]))
         #print xmin, xmax, ymin, ymax
     r.plot_window(xlim=(xmin, xmax), ylim=(ymin, ymax))
     r.title(
         main=title.get("main", ""),
         xlab=title.get("xlab", ""),
         ylab=title.get("ylab", ""))
     r.box(col="black") ; r.axis(1) ; r.axis(2)
     for i, x in enumerate(data):
         r.lines(x[0], x[1], col=i+1, **par)
예제 #3
0
	def _plot(self, row):
		self.no_of_curves += 1
		#position 3 in row is the varying value
		self.varying_list.append(row[3])
		x_list = []
		y_list = []
		self.curs.execute("select tp, tp_m, tp1, tp1_m, tn, fp, fp_m, fn from stat_plot_data where\
			%s=%s and %s=%s and %s=%s and %s=%s and tag='%s' order by p_value_cut_off"%\
			(self.option_num_dict[0].label, row[0], self.option_num_dict[1].label, row[1], self.option_num_dict[2].label,\
			row[2], self.option_num_dict[3].label, row[3], row[4]))
		plot_data = self.curs.fetchall()
		for entry in plot_data:
			tn = entry[4]
			fn = entry[7]
			if self.based_on_clusters:
				#using the tp_m, tp1_m and fp_m
				tp = entry[1]
				tp1 = entry[3]
				fp = entry[6]
			else:
				#using the tp, tp1, fp
				tp = entry[0]
				tp1 = entry[2]
				fp = entry[5]
			if self.l1:
				#tp1 is counted as true positive
				tp += tp1
			else:
				#tp1 is counted as false positive
				fp += tp1
			x_list.append(tp)
			y_list.append(float(tp)/(tp+fp))

		if self.no_of_curves==1:
			r.plot(x_list, y_list, type='o',pch='*',xlab='consistent predictions',xlim=self.x_range,ylim=self.y_range, \
			ylab='percentage', main='%s'%(self.option_num_dict[3].label), col=self.no_of_curves)
		else:
			r.lines(x_list, y_list, type='o',pch='*',col=self.no_of_curves)
    def plotBundle(self, bundleD, full_filename, colorsD=None, bundlePointsD=None, legendL=None, title=None, y_max=None):

        if y_max is None:
            y_max = 0.4
            
        if legendL is None:
            legendL = bundleD.keys()
            legendL.sort()
            
        if title is None:
            title = 'data'            

        bundleIdL = bundleD.keys()
        bundleIdL.sort()

        if colorsD is None:            
            colorsL = r.rainbow(len(bundleIdL))
            colorsD = dict(zip(bundleIdL, colorsL))
        
        colorsL = [colorsD[x] for x in bundleIdL]
        
        time_min = min([len(bundleD[x]) for x in bundleD.keys()])
        timeVec = [0.5 * x for x in range(time_min)]

        try:
            r.png(full_filename, width=800, height=600)
            oldPar = r.par(xpd = True, mar = [x + y for (x,y) in zip(r.par()['mar'], [0,0,0,6])])
        
            print 'plot %s' % full_filename
            r.plot(timeVec, timeVec,
                   type='n',
                   main=title, ylim=(0, y_max),
                   xlab="time in hours after transfection", ylab="Relative Cell Counts",
                   pch=20, lwd=1, lty = 1, 
                   cex=1.0, cex_lab=1.2, cex_main=1.5)
        
        
            for bundleId in bundleIdL:
                
                if not bundlePointsD is None:
                    r.points(timeVec, bundlePointsD[bundleId],
                             col=colorsD[bundleId], pch=20,
                             lwd=1)
                    r.lines(timeVec, bundlePointsD[bundleId],
                            col=colorsD[bundleId],
                            lwd=1, lty = 1)

                r.lines(timeVec, bundleD[bundleId],
                        col=colorsD[bundleId],
                        lwd=3, lty = 1)

            r.legend(max(timeVec) * 1.1, y_max, legend=legendL, fill=colorsL, cex=1.0, bg= 'whitesmoke')
            r.par(oldPar)
            r.grid(col="darkgrey")
        
            r.dev_off() 
        except:
            r.dev_off()
            print full_filename + ' has not been printed.'
            

        return
from rpy import r

# first plot
x = range(1,11)
y = [i**2 for i in x]

r.plot(x, y, xlab='x', ylab='y', main='My first plot',
      pch=21, col='blue', bg='lightblue', type='o') 


# second plot
x = range(1,11)
y = [i**2 for i in x]
z = [i**3 for i in x]
r.plot(x, y, main='My second plot', xlab='x', ylab='y', type='l', col='blue')
r.lines(x, z, col='red') 

# cosine function, save to file
import math
r.png('cosine.png')
x = r.seq(0,50, by=0.1)
y = [math.cos(i) for i in x]
r.plot(x, y, main='COS(X)', xlab='x', ylab='cos(x)', type='l', col='blue')
r.dev_off() 

# histogram
x = range(10) + range(3,6) + range(5,10)
r.hist(x, main='A histogram', xlab='x', col='lightblue') 

# adust plotting area
from rpy import r
예제 #6
0
def myhist(lnw, color="black", makenewplot=True, main=None, bins=None, support=None, xlab=None, ylab="", sub=None, xmin=None, xmax=None, bin_numbers=True):
    nbins = len(lnw)

    if bins!=None:
        assert(nbins==len(bins)-1)

    xss = [[]]
    yss = [[]]
    xlim = None
    connect_to_prev = False
    
    if bins==None:
        for bin in range(nbins):
            if (lnw[bin] > -inf or lnw[bin] < inf) and (support==None or support[bin]) and (xmin==None or xmin<=bin) and (xmax==None or (bin+1)<=xmax):
                xss[-1] += [bin, bin+1]
                yss[-1] += [lnw[bin], lnw[bin]]

            elif xss[-1]!=[]:
                xss.append([])
                yss.append([])

        if xmin==None and xmax==None:
            xlim = (0, nbins+1)
        else:
            xs = reduce(operator.add, xss, [])
            xlim = (min(xs), max(xs))
    else:
        for bin in range(nbins):
            if (lnw[bin] > -inf or lnw[bin] < inf) and (support==None or support[bin]) and (xmin==None or xmin<=bins[bin]) and (xmax==None or bins[bin+1]<=xmax):
                xss[-1] += [bins[bin], bins[bin+1]]
                yss[-1] += [lnw[bin], lnw[bin]]

            elif xss[-1]!=[]:
                xss.append([])
                yss.append([])

        if xmin==None and xmax==None:
            xlim = (bins[0], bins[-1])
        else:
            xs = reduce(operator.add, xss, [])
            xlim = (min(xs), max(xs))

    # Do the plotting
    if makenewplot:
        r.plot_new()

        ys = reduce(operator.add, yss, [])
        ymin = min(ys)
        ymax = max(ys)
        
        r.plot_window(xlim=xlim, ylim=(ymin, ymax))

        if bins!=None and bin_numbers:
            labels = array(r.pretty(range(nbins), 8), dtype=int)
            labels = labels[(0<=labels) & (labels<nbins)]
            ats = bins[labels]

            r.axis(1)
            r.axis(1, tick=False, labels=labels, at=ats, mgp=(3,2,0))
            r.axis(2)

            this_xlab = "E, bin"
        else:
            r.axis(1)
            r.axis(2)

            this_xlab = "E"
        
        r.axis(1)
        r.axis(2)
        r.box()
        r.title(ylab=ylab)

        if xlab==None:
            r.title(xlab=this_xlab)
        else:
            r.title(xlab=xlab)
        
        if main!=None:
            r.title(main=main)

        if sub!=None:
            r.title(sub=sub)

    for (xs, ys) in zip(xss, yss):
        r.lines(xs, ys, col=color, lwd=0.5)

    return (xss, yss)
예제 #7
0
파일: report.py 프로젝트: herry13/fdt
def plot(outfile, data, out_format='png'):
    w = int(round(len(data)/4.0))

    if out_format == 'png':
        r.png(outfile, width=w*100, height=1000, res=72)
    elif out_format == 'pdf':
        r.pdf(outfile, width=w, height=10)
    else:
        raise Exception('Unrecognised format: ' + str(out_format))

    print("total: " + str(len(data)))

    series = []
    points = {'translate': [], 'preprocessing': []}

    for dat in data:
        points['translate'].append(float(dat['translate']))
        points['preprocessing'].append(float(dat['preprocessing']))

    xlabels = []
    for k, v in data[0].iteritems():
        if k not in ["problem", 'translate', 'preprocessing']:
            series.append(k)
            points[k] = []

    index = 0
    for dat in data:
        for k in series:
            if dat[k] != 'no-plan':
                points[k].append(float(dat[k]) + \
                                 points['translate'][index] + \
                                 points['preprocessing'][index])
            else:
                points[k].append(-1000)
        xlabels.append(dat['problem'])
        index += 1

    max_value = max(iter([max(iter(points[k]))  for k in series]))
    yrange = (0, max_value)
    legend_labels = []

    x = [i for i in range(1,len(points['translate'])+1)]
    y = [-1000 for i in x]
    r.par(mar=(7,5,4,2))
    r.plot(x, y, main='', xlab="", ylab='',
           xaxt='n', yaxt='n', pch=0, ylim=yrange,
           mgp=(5,1,0))
    r.mtext("Problem", side=1, line=5)
    r.mtext("CPU Time (s)", side=2, line=3)

    pch_start = 1
    pch_index = pch_start
    # plotting "translate"
    #r.plot(x, points['translate'], main='',
    #       xlab='', ylab='Time (s)',
    #       xaxt='n', yaxt='n',
    #       pch=0, ylim=yrange)
    #legend_labels.append('translate')
    r.lines(x, points['translate'], lty=1)
    
    # preprocessing -- Removed since it's insignificant
    #r.points(x, points['preprocessing'], pch=pch_index)
    #pch_index =+ 1

    # planner output
    for k in series:
        if k != 'translate' and k != 'preporcessing':
            r.points(x, points[k], pch=pch_index)
            pch_index += 1
            legend_labels.append("FD+" + k.upper())

    # put x-axis labels
    for i in range(0, len(xlabels)):
        r.axis(side=1, at=i+1, labels=xlabels[i], las=2)

    # put y-axis labels
    base, step = get_y_step(max_value)
    print("base: " + str(base) + " -- step: " + str(step))
    y = base
    for i in range(0, step):
        r.axis(side=2, at=y, labels=str(y), las=2)
        y += base

    # legend
    r.legend(1, max_value, legend_labels, pch=[i for i in range(pch_start, pch_index)])

    r.dev_off()
예제 #8
0
파일: report.py 프로젝트: herry13/fdt
def plot(outfile, data, out_format='png'):
    w = int(round(len(data) / 4.0))

    if out_format == 'png':
        r.png(outfile, width=w * 100, height=1000, res=72)
    elif out_format == 'pdf':
        r.pdf(outfile, width=w, height=10)
    else:
        raise Exception('Unrecognised format: ' + str(out_format))

    print("total: " + str(len(data)))

    series = []
    points = {'translate': [], 'preprocessing': []}

    for dat in data:
        points['translate'].append(float(dat['translate']))
        points['preprocessing'].append(float(dat['preprocessing']))

    xlabels = []
    for k, v in data[0].iteritems():
        if k not in ["problem", 'translate', 'preprocessing']:
            series.append(k)
            points[k] = []

    index = 0
    for dat in data:
        for k in series:
            if dat[k] != 'no-plan':
                points[k].append(float(dat[k]) + \
                                 points['translate'][index] + \
                                 points['preprocessing'][index])
            else:
                points[k].append(-1000)
        xlabels.append(dat['problem'])
        index += 1

    max_value = max(iter([max(iter(points[k])) for k in series]))
    yrange = (0, max_value)
    legend_labels = []

    x = [i for i in range(1, len(points['translate']) + 1)]
    y = [-1000 for i in x]
    r.par(mar=(7, 5, 4, 2))
    r.plot(x,
           y,
           main='',
           xlab="",
           ylab='',
           xaxt='n',
           yaxt='n',
           pch=0,
           ylim=yrange,
           mgp=(5, 1, 0))
    r.mtext("Problem", side=1, line=5)
    r.mtext("CPU Time (s)", side=2, line=3)

    pch_start = 1
    pch_index = pch_start
    # plotting "translate"
    #r.plot(x, points['translate'], main='',
    #       xlab='', ylab='Time (s)',
    #       xaxt='n', yaxt='n',
    #       pch=0, ylim=yrange)
    #legend_labels.append('translate')
    r.lines(x, points['translate'], lty=1)

    # preprocessing -- Removed since it's insignificant
    #r.points(x, points['preprocessing'], pch=pch_index)
    #pch_index =+ 1

    # planner output
    for k in series:
        if k != 'translate' and k != 'preporcessing':
            r.points(x, points[k], pch=pch_index)
            pch_index += 1
            legend_labels.append("FD+" + k.upper())

    # put x-axis labels
    for i in range(0, len(xlabels)):
        r.axis(side=1, at=i + 1, labels=xlabels[i], las=2)

    # put y-axis labels
    base, step = get_y_step(max_value)
    print("base: " + str(base) + " -- step: " + str(step))
    y = base
    for i in range(0, step):
        r.axis(side=2, at=y, labels=str(y), las=2)
        y += base

    # legend
    r.legend(1,
             max_value,
             legend_labels,
             pch=[i for i in range(pch_start, pch_index)])

    r.dev_off()