Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Wednesday, November 2, 2011

Beautiful Code from O'Reilly

Beautiful Code: Leading Programmers Explain How They Think (2007) has several chapters that relate to the deeper logic behind scientific programming. While not related to the everyday chores of applied programing and statistics, these look like they would be useful for appreciating what goes on under the hood of well-designed programming languages, packages, and functions.

Chapter 1: "A regular expression matcher" by Brian Kerigham (one of the luminaries of computer science), dissects a simple regular expression editor written in C and extends a discussion on regular expressions started started in his book The Practice of Programming.
Chapter 4: "Finding things," by Tim Bray, also deals with regular expressions.
Chapter 14: "How elegant code evolves with hardware: the case of Gaussian Elimination" discuss some of the mechanics behind computation of systems of linear equations.

Two chapters focus on aspects of how Python works:
Chapter 18: Python's dictionary implementation: being all things to all people
Chapter 19: Multidimensional iterators in Numpy

And two chapters relate specifically to the design of bioinformatics tools.
Chapter 12: Growing beautiful code in BioPerl
Chapter 13: The deign of the Gene Sorter


Also in this series of books is Beautiful Data.

Friday, October 28, 2011

""" Adding comment with "triple quotes" in Python """

The standard symbol for placing comments in both Python and R is the hash mark, #.

You can also add comments to large blocks of texts by putting three sets of quotation marks - """ - at the beginning of the block and the end of the block. Using triple quotes saves you the trouble of putting hash marks at the beginning of every line, which can be a pain.

So, instead of commenting every line like this

#comment a
#comment b
#comment c
#comment d

you can do this

"""comment a
comment b
comment c
comment d"""

Unfortunately, if you try this in R you will get the error
Error: unexpected string constant in """"""

Accessing the Mac Shell through "Terminal"


Terminal is the program that allows you on a Mac to access the shell. Just do a search for "Terminal" and it will come up.

The shell can be used to move, copy, and rename files using typed commands - just as you can with a mouse - and is the entry point for more advanced file manipulation and programming in languages such as Python.

Thursday, October 27, 2011

Graphing in Python with the maplot library

matplot library can be used for making graphs. It has MATLAB-style syntax

Sunday, October 23, 2011

Python resources


A post-doc in our department sent me some links for getting started with Python for data manipulation and statistics.

Enthought Python Distribution:
This packages many of the scientific libraries that might be of interest and will save you a ton of headaches compiling stuff, especially on a Mac. There is a free academic version.

scikit.statsmodel:
Advanced statistical packages

pandas:
Provides a nice set of data structures beyond basic numpy arrays. Statsmodel has pandas as a dependency

rpy:
Access R from python

Software Carpentry --
Basic tutorials on concepts of good software design/programming/computing skills

Learn Python the Hardway:
Basic intro online book to python

Regetron:
Code to learn regex in python. Same author as Learn Python the Hardway, and is meant to be used in his upcoming book on regex. The description can be found here


Python Documentation on Regex:
http://docs.python.org/howto/regex.html
http://docs.python.org/library/re.html

Software Carpentry Reading List

A post-doc in my department just pointed me towards softwarecarpentry.org as a place to learn more about using Python, and for resources for applied programming in general. They have a long, annotated book list which I've whittled down to books that look most applicable to Python and data manipulation.

Data Munging with Perl

Practical Programming: An Introduction to Computer Science Using Python

SQL by Chris Fehily

Python Scripting for Computational Science

A Primer on Scientific Programming with Python

Learning Python: Powerful Object-Oriented Programming