User:Jarle Pahr/Python
Scientific computing using Python
PeptideBuilder: A simple Python library to generate model peptides: https://peerj.com/articles/80/
PDB file parser and structure class implemented in Python: http://bioinformatics.oxfordjournals.org/content/19/17/2308
http://bioinformatics.oxfordjournals.org/content/25/11/1422
Python for scientific computing: Where to start: http://sjbyrnes.com/?page_id=67
Official documentation
Python standard library (Python 3.3): http://docs.python.org/3.3/library/
Python 2. 7 Documentation: http://docs.python.org/2.7/
Python 3.3 tutorial: http://docs.python.org/3.3/tutorial/
Python 3.3 glossary: http://docs.python.org/3.3/glossary.html#glossary
Python on Windows FAQ: http://docs.python.org/3.3/faq/windows.html
Python 3.3 Built-in functions: http://docs.python.org/3.3/library/functions.html#execfile
Learning Python
Beginning Python for bioinformatics Wiki: http://wiki.genedrift.org
http://www.codecademy.com/tracks/python
Bioinformatics Programming Using Python Practical Programming for Biological Data: http://shop.oreilly.com/product/9780596154516.do?
http://www.python-course.eu/matrix_arithmetic.php
http://www.daniweb.com/software-development/python/114
http://en.wikibooks.org/wiki/Python_Programming
http://bioinformaticsonline.com/news/view/140/python-education-material
http://interactivepython.org/courselib/static/thinkcspy/index.html
Python for developers: http://ricardoduarte.github.io/python-for-developers/
A crash course in Python for scientists: http://nbviewer.ipython.org/5920182
Misc
PyRegex: http://pyregex.com/
http://www.python.org/dev/peps/
http://stackoverflow.com/questions/4583367/how-to-run-multiple-python-version-on-windows
Article: Programming biological models in Python using PySB /doku.php?id=beginning_python_for_bioinformatics
http://ubuntuforums.org/showthread.php?t=127426
http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch20s05.html
http://www.syntagmatic.net/matrix-multiplication-in-python/
Stackoverflow - Python questions: http://stackoverflow.com/questions/tagged/python
Python books: http://wiki.python.org/moin/IntroductoryBooks
Python basic syntax: http://www.tutorialspoint.com/python/python_basic_syntax.htm
http://en.wikipedia.org/wiki/Python_syntax_and_semantics
Simple Python programs: http://wiki.python.org/moin/SimplePrograms
http://www.bin-co.com/blog/2008/03/python-hello-script/
About Python shells: http://python.about.com/od/programmingglossary/g/defshell.htm
Popular Python recipes: http://code.activestate.com/recipes/langs/python/
O'reilly Python devcenter: http://www.onlamp.com/python/
Differences between Python 2 and Python 3
- Print is changed from a statement (print "something") to a function (print("something"))
- raw_input() is replaced by input()
- Integer/float division.
http://wiki.python.org/moin/Python2orPython3
http://docs.python.org/3/whatsnew/3.0.html
http://www.cs.ucsb.edu/~pconrad/cs8/textbooks/MillerRanum/python2.x.issues/
Q&A /How-tos
http://stackoverflow.com/questions/3786881/what-is-a-method-in-python
http://stackoverflow.com/questions/522563/accessing-the-index-in-python-for-loops
http://love-python.blogspot.no/2008/09/remove-duplicate-items-from-list-using.html
http://stackoverflow.com/questions/5711452/how-do-i-slice-a-string-every-3-indices
http://stackoverflow.com/questions/1303347/getting-a-map-to-return-a-list-in-python-3-1
http://stackoverflow.com/questions/674764/examples-for-string-find-in-python
http://stackoverflow.com/questions/8113684/python-itertools-permutations
http://www.petercollingridge.co.uk/python-tricks/list-comprehensions
http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python
http://code.activestate.com/recipes/499304-hamming-distance/
http://python.about.com/od/simplerscripts/qt/Getlinebynumber.htm
http://stackoverflow.com/questions/3939361/remove-specific-characters-from-a-string-in-python
http://stackoverflow.com/questions/9831097/is-open-read-safe
http://stackoverflow.com/questions/3173915/modification-of-the-list-items-in-the-loop-python
http://stackoverflow.com/questions/4081217/how-to-modify-list-entries-during-for-loop
http://stackoverflow.com/questions/6513967/running-python-script-from-idle-on-windows-7-64-bit
http://stackoverflow.com/questions/1027714/how-to-execute-a-file-within-the-python-interpreter
http://stackoverflow.com/questions/2545397/converting-a-string-into-a-list-in-python
http://stackoverflow.com/questions/12336105/python-reverse-list
http://stackoverflow.com/questions/4481724/python-convert-list-of-char-into-string
Printing commands:
http://stackoverflow.com/questions/11266068/python-avoid-new-line-with-print-command
http://docs.python.org/2/tutorial/inputoutput.html
http://www.tutorialspoint.com/python/python_files_io.htm
Data strutures
Dictionaries
Lists
Tuples:
Applications
Hidden Markov MOdels. http://www.black-glass.com/?p=299
Monte Carlo simulations: http://www.black-glass.com/?p=404
Modules and libraries
TkInter GUI: http://wiki.python.org/moin/TkInter
Automating Microsoft Office with Python: http://nbviewer.ipython.org/urls/raw.github.com/sanand0/ipython-notebooks/master/Office.ipynb
HTseq: http://seqanswers.com/forums/showthread.php?t=4805
http://www.tutorialspoint.com/python/python_modules.htm
Installation:
http://docs.python.org/3.3/install/index.html
http://wiki.python.org/moin/Distutils/Tutorial
http://stackoverflow.com/questions/1471994/what-is-setup-py
Importing modules and libraries:
http://effbot.org/zone/import-confusion.htm
http://docs.python.org/dev/reference/import.html
http://pythonconquerstheuniverse.wordpress.com/2011/03/28/why-import-star-is-a-bad-idea/
Creating modules:
http://docs.python.org/2/tutorial/modules.html
http://mikegrouchy.com/blog/2012/05/be-pythonic-__init__py.html
http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH
http://greeennotebook.com/2010/06/how-to-change-pythonpath-in-windows-and-ubuntu/
http://www.bdnyc.org/2012/09/17/editing-pythonpath-to-import-modules/
http://greeennotebook.com/2010/06/using-__name__-in-python/
NumPy & SciPy
SciPy is a packafe for scientific computing which depends on the NumPy package.
http://www.scipy.org/Topical_Software
SciPy: www.scipy.org/SciPy
Documentation: http://docs.scipy.org/doc/
http://www.scipy.org/more_about_SciPy
Projects using NumPy and/or SciPy: http://www.scipy.org/Projects
http://www.scipy.org/NumPy_for_Matlab_Users
NumPy & SciPy FAQ: http://www.scipy.org/FAQ
http://www.youtube.com/watch?v=oYTs9HwFGbY
Biology & Bioinformatics
Biopython:http://biopython.org/wiki/Main_Page
Cock PJ, Antao T, Chang JT, Chapman BA, Cox CJ, et al. (2009) Biopython: freely available Python tools for computational molecular biology and bioinformatics. Bioinformatics 25: 1422–1423.
Biopython tutorial: http://biopython.org/DIST/docs/tutorial/Tutorial.html
www.biocodershub.net/community/hitchhikers-guide-to-biopython-seqrecords/
http://telliott99.blogspot.no/
Other
PyPI - Python package index: https://pypi.python.org/pypi
Python.org - useful modules: http://wiki.python.org/moin/UsefulModules
http://code.google.com/p/pythonxy/
PyDoc: http://docs.python.org/2/library/pydoc
PyLab is part of matplotlib: http://stackoverflow.com/questions/12987624/confusion-between-numpy-scipy-matplotlib-and-pylab
iPython Notebook viewer: http://nbviewer.ipython.org/
Development environments
http://code.google.com/p/spyderlib/
http://ipython.org/ (See iPython)
Distributions
EPD free edition: http://www.enthought.com/products/epd_free.php
Includes Python, iPython, IDLE, matplotlib, numpy and SciPy.
WinPython: https://code.google.com/p/winpython/
Includes NumPy, SciPy, matplotlib and Spyder.
Functions/methods
Function definition:
http://docs.python.org/3/tutorial/controlflow.html#defining-functions
Docstrings:
http://www.python.org/dev/peps/pep-0257/
String methods:
string.split("delimiter"): Splits a string into a list of strings. Ex: sequenc = ATGCA seq = sequence.split("G") --> seq = ['AT', 'CA']
string.find() :
string.strip([chars]): "Return a copy of the string with the leading and trailing characters removed." Character to be removed are specified by [chars]. If no argument given, the chars argument defaults to removing whitespace.
Array/list methods:
Enumerate: http://docs.python.org/2/library/functions.html#enumerate
list.append(x): Append object x to the end of list.
list.reverse(): Reverse order of elements in a list.
range / xrange(start, stop[,step]): returns a list of plain integers [start, start + step, start + 2 * step, ...]
"".join(list): Join list elements into a string.
Slice: slice(stop) slice(start, stop[, step])
"Returns a slice object representing the set of indices specified by range(start, stop, step)"
dictionary.item() Returns an array of tuples with each tuple consisting of a key/value pair from the dictionary:
map(function,iterable): Apply function to every item in iterable and return the result.
Anonymous functions/lambda functions:
http://www.secnetix.de/olli/Python/lambda_functions.hawk
filter(function, iterable): Constructs a list from those elements of iterable for which the condition in function evaluates to true.
sum(): From official Python documentation: "Sums start and the items of an iterable from left to right and returns the total. Start defaults to 0"
Input/Output (I/O):
From http://www.python.org/dev/peps/pep-0234/ :
" Because the file iterator uses an internal buffer, mixing this
with other file operations (e.g. file.readline()) doesn't work right:
Fore more on iteration over files, see:
http://www.bogotobogo.com/python/python_iterators.php
Class-related functions:
isinstance.
Keywords and statements
in :
with ... as
Indentation
http://stackoverflow.com/questions/119562/tabs-versus-spaces-in-python-programming
http://www.secnetix.de/olli/Python/block_indentation.hawk
http://stackoverflow.com/questions/5685406/inconsistent-use-of-tabs-and-spaces-in-indentation
http://stackoverflow.com/questions/1024435/howto-fix-python-indentation
Classes
http://www.tutorialspoint.com/python/python_classes_objects.htm
http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html
http://www.w3resource.com/python/python-object-classes.php
http://en.wikibooks.org/wiki/Python_Programming/Classes
A simple class inheritance example: http://www.daniweb.com/software-development/python/code/216596/a-simple-class-inheritance-example-python
An introduction to classes and inheritance in Python: http://www.jesshamrick.com/2011/05/18/an-introduction-to-classes-and-inheritance-in-python/
http://en.wikibooks.org/wiki/Think_Python/Inheritance
Inheritance in Python: http://www.packtpub.com/article/inheritance-python
Creating instances:
http://stackoverflow.com/questions/2136760/creating-an-instance-of-a-class-with-a-variable-in-python
Class scope:
http://www.codecademy.com/courses/python-intermediate-en-WL8e4/1/2#
Super:
Things to know about Python Super: http://www.artima.com/weblogs/viewpost.jsp?thread=236275
Method Resolution Order:
http://www.cafepy.com/article/python_attributes_and_methods/ch02.html
http://python-history.blogspot.no/2010/06/method-resolution-order.html
http://luisartola.com/software/2010/method-resolution-order-blues/
Misc.:
http://www.python.org/doc/essays/ppt/acm-ws/sld051.htm
Input/Output
Executing shell commands:
import os os.system("script.py argument")
Opening files:
os.startfile(filepath)
Command line input
http://www.daniweb.com/software-development/python/threads/12326/how-to-do-input-in-python
http://stackoverflow.com/questions/70797/python-and-user-input
Interfacing
http://www.pythonforbeginners.com/python-on-the-web/how-to-access-various-web-services-in-python/
Tips & Tricks
Execute python scripts online: http://www.compileonline.com/execute_python_online.php
Get current working directory:
import os os.getcwd()
Set current working directory:
os.chdir(aPath)
To stay in the Python interpreter environment after running a script, add - i before the script name: python -i script.py
A list can be reversed by the reverse function, or by list slicing with a negative stride:
backwards = my_list[::-1]
Calling file from interpreter command line:
command = "find /tmp -name '*.jpg'" subprocess.call(command.split())
29 common errors: http://pythonforbiologists.com/index.php/29-common-beginner-python-errors-on-one-page/
Common newbie mistakes part 1: http://blog.amir.rachum.com/post/54770419679/python-common-newbie-mistakes-part-1
Developing your own scientific Python code: http://www.linuxjournal.com/content/developing-your-own-scientific-python-code?utm_content=buffer1d018&utm_source=buffer&utm_medium=twitter&utm_campaign=Buffer
About iterations: http://nedbatchelder.com/text/iter/iter.html#13
Python on Android
http://google-opensource.blogspot.no/2009/06/introducing-android-scripting.html
http://code.google.com/p/android-scripting/
https://ep2013.europython.eu/conference/talks/developing-android-apps-completely-in-python
Packaging
http://guide.python-distribute.org/introduction.html
https://python-packaging-user-guide.readthedocs.org/en/latest/index.html
http://answers.yahoo.com/question/index?qid=20110705223937AA8vFXz
Installing Python modules: http://docs.python.org/3/install/index.html
Distributing Python modules: http://docs.python.org/3/distutils/index.html
PIP
http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows
http://en.wikipedia.org/wiki/Pip_%28Python%29
http://stackoverflow.com/questions/3849762/python-3-easy-install-pip-and-pypi
easy_install
- module bundled with setup_tools
http://peak.telecommunity.com/DevCenter/EasyInstall
http://en.wikipedia.org/wiki/EasyInstall
Distribute
Setuptools
- Replaced by Distribute
Python Package index (PyPi)
Error handling
http://wiki.python.org/moin/HandlingExceptions
http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch17s03.html
http://stackoverflow.com/questions/2052390/how-do-i-manually-throw-raise-an-exception-in-python
http://docs.python.org/3.3/tutorial/errors.html http://stackoverflow.com/questions/1313812/raise-exception-vs-return-none-in-python-functions
http://stackoverflow.com/questions/730764/try-catch-in-python-how-to-properly-ignore-exceptions
Examples
Get index of list element:
for i,v in enumerate(line_segments): print i, v
Use of zip:
x = [1,2,3] y = [2,3,4] f = zip(x,y)
String formatting
http://stackoverflow.com/questions/7351270/control-a-print-format-when-printing-a-list-in-python
http://stackoverflow.com/questions/15575359/print-list-elements-with-comprehension-python
http://stackoverflow.com/questions/7568627/using-python-string-formatting-with-lists
http://www.velocityreviews.com/forums/t677371-type-float-problem.html
http://stackoverflow.com/questions/9535954/python-printing-lists-as-tabular-data
http://stackoverflow.com/questions/3018295/how-do-i-print-a-table-in-python
http://stackoverflow.com/questions/2762058/format-all-elements-of-a-list
http://docs.python.org/2/tutorial/inputoutput.html
http://www.shocksolution.com/2011/11/python-string-format-examples/
Division operations
http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch05s06.html
Plotting & animation
Several ways to create an animation:
Using easyviz:
import scitools.easyviz as ev counter = 0 for i in range(10): counter +=1 y = 0.1*i*x ev.plot(x,y,'go', axis=[0,100,0,100],savefig ='jpa%04d.png' % counter) ev.show() time.sleep(0.5)
ev.movie('jpa*.png')
Using matplotlib.animation:
http://matplotlib.org/api/animation_api.html
http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/
http://stackoverflow.com/questions/16732379/stop-start-pause-in-python-matplotlib-animation
http://scipyscriptrepo.com/wp/?p=9