Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    • Archives

    • Recent comments

    Archive for the 'Python' Category

    Graphs in Python

    13th July 2013

    directed graphSooner or later, everyone has to deal with graphs. Some people have to do programming with graphs, and a subset of those – do that in Python.

    NetworkX is a pure Python implementation, where anything can be nodes. Both nodes and edges have attributes. NetworkX supports directed graphs and multigraphs (where there are multiple edges between nodes). It might be slower than other implementations, but you may even not notice that – especially when working with smaller graphs, or not applying computationally-intensive algorithms to your graphs.

    graph-tool uses the Boost graph library (C++), so it should be really fast. It could be the only multi-threaded graph library for Python. It supports pickling the graphs, allows interactive graph drawing, and has well-illustrated documentation. If performance and efficiency are of utmost importance – could be the best choice.

    igraph is also really fast – just like graph-tool when using 1 CPU; graph-tool only wins conclusively when it is run on multiple CPUs/cores. igraph has an R package bindings to C.

    Pure python is also an option for really smaller cases.

    Finally, there’s a discussion around Python Graph API to simplify the inter-changeability and inter-operability of various existing Python graph modules. It also has a list of some less-known Python graph libraries, so check it out.

    Share

    Posted in Programming, Python | No Comments »

    Beanstalkd and related tools for easy parallelizing and backgrounding

    18th February 2012

    beanstalkd: a simple, fast work queue.
    Jack and the Beanstalkd: a web-app for basic work queue administration.
    beanstalkc: a simple beanstalkd client library for Python.
    queueit: a CLI interface tool which helps to integrate beanstalkd into shell scripts.

    Share

    Posted in Links, Programming, Python, Software | No Comments »

    Python performance: set vs list

    15th August 2011

    Sometimes there is a need to be sure that no identifier is processed twice – for example, when parsing a file into a database, with file potentially containing duplicate records. An obvious solution is to properly wrap the DB insertion code into try…except block, and process duplicate primary ID exceptions. Another, sometimes more desired solution is to maintain a set/list of processed IDs internally, and check against that list prior to attempting the insertion of anything. So is it a set or a list?

    There are already quite a few internet resources discussing “python set vs list”, but probably the simplest while elegant way to test that is below.
    Read the rest of this entry »

    Share

    Posted in Notepad, Programming, Python | 1 Comment »

    Using Python in a Java project

    17th May 2011

    If you are a Python zealot, and Java doesn’t feel right, but the project you are working on is a Java project – try

    • Jython – Python for the Java platform, compile your python scripts into Java bytecode
    • Groovy – not Python, but still a scripting language which compiles to jars
    Share

    Posted in Links, Movies, Programming, Python | No Comments »

    Introduction to Python for bioinformatics

    25th February 2011

    This overview presentation is two years old, but still a highly valuable resource: modules and tools mentioned are alive and useful.
    I think this is the second presentation by Giovanni I’m embedding (first one being about GNU/make for bioinformatics).

    Share

    Posted in Bioinformatics, Links, Python, Software | No Comments »

    How to easily install any PyPi/easy_install python module on Debian

    16th February 2011

    Imagine you need to install pycassa (which uses easy_install). Here are the 2 (at maximum) very simple steps to have it properly debianized and installed on your Debian/Ubuntu:

    • if you don’t have the python-stdeb package: sudo aptitude install python-stdeb
    • pypi-install pycassa

    That’s it.

    Refer to stdeb readme for more information. You will need that if there are dependencies – which might not be resolved automatically by stdeb.

    Before stdeb, it wasn’t exactly trivial to make a .deb from python module.

    Share

    Posted in *nix, how-to, Notepad, Python, Software | 1 Comment »

    DreamPie: the ultimate Python shell

    11th August 2010

    DreamPie: the Python shell you’ve always dreamt about!

    • Type your code in the lower pane of the window. To execute, press Ctrl+Enter. One-liners can be executed by simply pressing Enter; If you don’t want them executed, press Space and then Enter.

    • Use Ctrl+Up and Ctrl+Down to navigate between code segments you’ve already executed. You can write a few letters before pressing Ctrl+Up, and DreamPie will only search through code segments starting with those letters.

    • Press Tab or Ctrl+Space to show a list of completions to the current expression. It will also complete file names!

    • Your results are stored in variables named _0, _1, and so on.

    • Type a function name and press the space key and DreamPie will automatically add parentheses for you!

    Share

    Posted in Links, Programming, Python | No Comments »