background preloader

Python Quick Hacks and Codes

Facebook Twitter

The Binomial Distribution, Python and Bisulphite Sequencing. This is Part 2 in a series on Bisulphite Sequencing.

The Binomial Distribution, Python and Bisulphite Sequencing

You can return to Part 1 (Post Processing Bismark Bisulphite Sequencing Data) or skip to Part 3 (Simple Visualisation of Bisulphite Sequencing Data). Today I'm going to describe how the binomial distribution can be applied to bisulphite sequencing data in order to accurately determine the number of CpG sites which exhibit methylation in a sample. The binomial distribution is actually pretty straightforward. If you have a coin that has a probability to come up heads then the binomial distribution can tell us the probability that if you throw coins then what is the probability that you will get heads. We call this the probability mass function. Let's do the simplest example first. A Newbie Guide to pygame — Pygame v1.9.2 documentation. Or Things I learned by trial and error so you don’t have to, or How I learned to stop worrying and love the blit.

A Newbie Guide to pygame — Pygame v1.9.2 documentation

Pygame is a python wrapper for SDL, written by Pete Shinners. What this means is that, using pygame, you can write games or other multimedia applications in Python that will run unaltered on any of SDL’s supported platforms (Windows, Unix, Mac, beOS and others). Pygame may be easy to learn, but the world of graphics programming can be pretty confusing to the newcomer. I wrote this to try to distill the practical knowledge I’ve gained over the past year or so of working with pygame, and it’s predecessor, pySDL. Using PyInstaller to make EXEs from Python scripts (and a 48-hour game design compo) Here’s how you use PyInstaller and PyGame to create a single-file executable from a project that has a data directory that contains resources like images, fonts, and music.

Using PyInstaller to make EXEs from Python scripts (and a 48-hour game design compo)

Get PyInstaller.On Windows, you might also need pywin32 (and possibly MinGW if you don’t have Visual Studio).On Mac OS X, you will need XCode’s command line tools. To install the Command Line tools, first install XCode from the App Store, then go to Preferences – Downloads and there is an option to download them there.Modify your code so that whenever you refer to your data directory, you wrap it using the following function: def resource_path(relative): if hasattr(sys, "_MEIPASS"): return os.path.join(sys. Phew! Programming For Biologists. Intelligently handle dropbox link · Issue #141 · ipython/nbviewer. 1.4. Matplotlib: plotting — Scipy lecture notes. 1.4.2.

1.4. Matplotlib: plotting — Scipy lecture notes

Simple plot Tip In this section, we want to draw the cosine and sine functions on the same plot. Starting from the default settings, we’ll enrich the figure step by step to make it nicer. First step is to get the data for the sine and cosine functions: import numpy as np X = np.linspace(-np.pi, np.pi, 256, endpoint=True)C, S = np.cos(X), np.sin(X) X is now a numpy array with 256 values ranging from -π to +π (included). To run the example, you can type them in an IPython interactive session: This brings us to the IPython prompt: Adjust settings for matplotlib using rc and matplotlibrc « scienceoss.com. Py2Exe and MatPlotLib: Plot won't Appear. How to create Windows executable (.exe) from Python script. Python is a simple and powerful language for scripting and even application development.

How to create Windows executable (.exe) from Python script

Various GUI packages available for Python makes it suitable for developing full fledged applications in python. Ok that is fine, but ever thought of creating an executable file from the python script you wrote? This seems to be a nice idea, there are many reasons why! Importing Python Modules. January 07, 1999 | Updated February 02, 2001 | Fredrik Lundh Introduction The import and from-import statements are a constant cause of serious confusion for newcomers to Python.

Importing Python Modules

Luckily, once you’ve figured out what they really do, you’ll never have problems with them again. This note tries to sort out some of the more common issues related to import and from-import and everything. There are Many Ways to Import a Module. Python - Functions. A function is a block of organized, reusable code that is used to perform a single, related action.

Python - Functions

Functions provide better modularity for your application and a high degree of code reusing. 2.7. Mathematical optimization: finding minima of functions — Scipy lecture notes. Mathematical optimization deals with the problem of finding numerically minimums (or maximums or zeros) of a function. In this context, the function is called cost function, or objective function, or energy.

Here, we are interested in using scipy.optimize for black-box optimization: we do not rely on the mathematical expression of the function that we are optimizing. Note that this expression can often be used for more efficient, non black-box, optimization. Prerequisites Numpy, ScipyIPythonmatplotlib References Mathematical optimization is very ... mathematical. Convex Optimization by Boyd and Vandenberghe (pdf available free online).Numerical Optimization, by Nocedal and Wright. Python - Specifying constraints for fmin_cobyla in scipy.

Numpy

Math with Python. Graphing. Data Munging. Python Tools. Python for Scientific Computing. Python.