def plot_coverages(lengths, main=""): x = numpy.arange(0,0.5e6+1,1e4) y = coverages(lengths, x) r.plot(x/1e3, y, type="l", xlim=[0,575], lwd=2, cex=1.5, xlab="Read length (kb)", ylab="Coverage by reads > length", main=main) highlight_x = [0, 50e3, 100e3, 250e3, 500e3] highlight_y = coverages(lengths, highlight_x) r.points(numpy.array(highlight_x)/1e3, highlight_y, pch=20) r.text(numpy.array(highlight_x)/1e3, highlight_y, ["{:.2f} ({:.1%})".format(i, i/highlight_y[0]) for i in highlight_y], pos=4) r.mtext(f"{lengths.sum()/1e6:,.1f}mb total")
self.factor = self.scotts_factor() # Cache covariance and inverse covariance of the data if not hasattr(self, '_data_inv_cov'): self._data_covariance = atleast_2d( np.cov(self.dataset, rowvar=1, bias=False)) self._data_inv_cov = linalg.inv(self._data_covariance) self.covariance = self._data_covariance * self.factor**2 self.inv_cov = self._data_inv_cov / self.factor**2 self._norm_factor = sqrt(linalg.det(2 * pi * self.covariance)) * self.n if __name__ == '__main__': from biorpy import r from scipy import stats values = np.concatenate( [np.random.normal(size=20), np.random.normal(loc=6, size=30)]) kde = stats.gaussian_kde(values) x = np.linspace(-5, 10, 50) y = kde(x) print y r.plot(x, y, type="l", col="red") kde2 = gaussian_kde(values) y2 = kde2(x) r.lines(x, y2, col="blue", lty=2) raw_input("")
if not hasattr(self, '_data_inv_cov'): self._data_covariance = atleast_2d(np.cov(self.dataset, rowvar=1, bias=False)) self._data_inv_cov = linalg.inv(self._data_covariance) self.covariance = self._data_covariance * self.factor**2 self.inv_cov = self._data_inv_cov / self.factor**2 self._norm_factor = sqrt(linalg.det(2*pi*self.covariance)) * self.n if __name__ == '__main__': from biorpy import r from scipy import stats values = np.concatenate([np.random.normal(size=20), np.random.normal(loc=6, size=30)]) kde = stats.gaussian_kde(values) x = np.linspace(-5,10, 50) y = kde(x) print y r.plot(x, y, type="l", col="red") kde2 = gaussian_kde(values) y2 = kde2(x) r.lines(x, y2, col="blue", lty=2) raw_input("")
# -*- coding: utf-8 -*- # <nbformat>3.0</nbformat> # <codecell> from biorpy import r, iimage # <codecell> iimage.start() r.plot(range(5)) iimage.finish() # <codecell>
# Using the biorpy wrapper # <codecell> import collections import numpy import pandas from biorpy import r, plotting # <codecell> # converts numpy arrays transparently x = numpy.arange(10) y = x + numpy.random.normal(scale=0.5, size=10) r.plot(x, y) # <codecell> result = r["wilcox.test"](range(5), range(5, 10)) # <codecell> result # <codecell> result.names # <codecell>