Open writing projects/Sage and cython a brief introduction: Difference between revisions
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
== Abstract == | == Abstract == | ||
This is a quick introduction to | This is a quick introduction to [http://www.sagemath.org/index.html Sage], a powerful new computational platform that builds on the strengths of Python. This article was directly inspired by Julius B. Lucks' [http://openwetware.org/wiki/Julius_B._Lucks/Projects/Python_All_A_Scientist_Needs "Python: All A Scientist Needs"]; I recommend reading it first as it explains some of the attractions of Python and biopython. | ||
Sage is a free and open-source project for computation of all sorts that uses Python as its primary language and "glue". One of the goals of Sage is to provide a viable free and open-source alternative to Matlab, Maple, and Mathematica. Sage unifies a great deal of open-source mathematical and statistical software; it includes biopython as an optional package and the statistics language R by default. | Sage is a free and open-source project for computation of all sorts that uses Python as its primary language and "glue". One of the goals of Sage is to provide a viable free and open-source alternative to Matlab, Maple, and Mathematica. Sage unifies a great deal of open-source mathematical and statistical software; it includes biopython as an optional package and the statistics language R by default. | ||
Line 15: | Line 15: | ||
A key feature of Sage is its notebook web-browser interface. | A key feature of Sage is its notebook web-browser interface. | ||
Jose Unpingco has made a | Jose Unpingco has made a [http://sage.math.washington.edu/home/wdj/expository/unpingco/ good short introductory video] on the notebook interface that may help get a sense of what its like. | ||
<syntax type="python"> | <syntax type="python"> |
Revision as of 13:19, 1 May 2008
Work in progress
Please check back later for the final version...
Abstract
This is a quick introduction to Sage, a powerful new computational platform that builds on the strengths of Python. This article was directly inspired by Julius B. Lucks' "Python: All A Scientist Needs"; I recommend reading it first as it explains some of the attractions of Python and biopython.
Sage is a free and open-source project for computation of all sorts that uses Python as its primary language and "glue". One of the goals of Sage is to provide a viable free and open-source alternative to Matlab, Maple, and Mathematica. Sage unifies a great deal of open-source mathematical and statistical software; it includes biopython as an optional package and the statistics language R by default.
Sage notebook interface
(TODO: notebook interface screenshots, different computers, good 2-d graphics)
A key feature of Sage is its notebook web-browser interface.
Jose Unpingco has made a good short introductory video on the notebook interface that may help get a sense of what its like.
<syntax type="python"> def PStoRE(PrositePattern):
""" Converts a PROSITE regular expression to a python r.e. """ rePattern = PrositePattern rePattern = rePattern.replace('-',) rePattern = rePattern.replace(' ',) rePattern = rePattern.replace('x','.') rePattern = rePattern.replace('{','[^') rePattern = rePattern.replace('}',']') rePattern = rePattern.replace('(','{') rePattern = rePattern.replace(')','}') return rePattern
from Bio import Fasta import re import urllib2 as U @interact def re_scan(fasta_file_url = 'http://www.d.umn.edu/~mhampton/PlasProtsRef.fa', pat = input_box('G - x - P - [AG] - x(2) - [LIVM] - x - [IV] ', type = str, width = 60)):
re_pat = re.compile(PStoRE(pat)) parser = Fasta.RecordParser() prot_file = U.urlopen(fasta_file_url) fasta_iterator = Fasta.Iterator(prot_file, parser = parser) for record in fasta_iterator: matches = re_pat.findall(record.sequence) if len(matches) != 0: html(record.title) html(matches) print
Cython
Sage initially used an alternative to SWIG (described in Julius's article) called Pyrex to compile Python code to C when performance concerns demanded it. Because they needed to extend Pyrex in various ways, they created a friendly fork of Pyrex called "Cython". I believe it is fair to say that Cython is the easiest way to create C code in Python.
(TODO: example of Cython usage)