<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Greg Caporaso</title>
	<atom:link href="http://blog.caporaso.us/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.caporaso.us</link>
	<description></description>
	<lastBuildDate>Tue, 26 Jan 2010 19:41:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.caporaso.us' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/c52ae9d4f67d8db31665c3a09e4544ce?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Greg Caporaso</title>
		<link>http://blog.caporaso.us</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.caporaso.us/osd.xml" title="Greg Caporaso" />
	<atom:link rel='hub' href='http://blog.caporaso.us/?pushpress=hub'/>
		<item>
		<title>Integrating news feeds into Sphinx pages</title>
		<link>http://blog.caporaso.us/2010/01/26/integrating-news-feeds-into-sphinx-pages/</link>
		<comments>http://blog.caporaso.us/2010/01/26/integrating-news-feeds-into-sphinx-pages/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 19:40:31 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=292</guid>
		<description><![CDATA[I&#8217;ve worked on a few Sphinx-based websites for software projects lately. (I&#8217;ve found the matplotlib sphinx tutorial useful for getting started.) A couple of examples are the PyCogent and PyNAST sites. One thing I&#8217;ve needed to do was integrate a news feed that is easy for developers on the project to update, without having to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=292&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve worked on a few <a href="http://sphinx.pocoo.org/">Sphinx</a>-based websites for software projects lately. (I&#8217;ve found the <a href="http://matplotlib.sourceforge.net/sampledoc/index.html">matplotlib sphinx tutorial</a> useful for getting started.) A couple of examples are the <a href="http://pycogent.sourceforge.net">PyCogent</a> and <a href="http://pynast.sourceforge.net">PyNAST</a> sites.</p>
<p>One thing I&#8217;ve needed to do was integrate a news feed that is easy for developers on the project to update, without having to mess with uploading new html, sharing the site password, etc. The solution I came up with was creating a wordpress blog (e.g., <a href="http://pycogent.wordpress.com">PyCogent</a>, <a href="http://pynast.wordpress.com">PyNAST</a>); using feed.informer to generate a javascript feed digest; and integrating that javascript into the sidebar via custom layout.html page in Sphinx. See the &#8216;News and Announcements&#8217; sections on the <a href="http://pycogent.sourceforge.net">two</a> <a href="http://pynast.sourceforge.net">sites</a> I mentioned above.</p>
<p>The steps are as follows:</p>
<ol>
<li>Create a blog (I chose wordpress, since that&#8217;s what I&#8217;ve used the most).</li>
<li>Create a <a href="http://feed.informer.com/">free feed.informer</a> account. There are a few different sites out there that will host your javascript-based &#8216;feed digest&#8217;, but I&#8217;ve found this one to be the least obnoxious in terms of including an advertisements (see the &#8216;Powered by Feed Informer&#8217; note on my sites) and fairly customizable.</li>
<li>Run through the steps of adding your feed to a digest at feed.informer &#8212; for my PyNAST wordpress blog, the feed url is: http://pynast.wordpress.com/pynast.
<p>One option you should be sure to use is &#8216;Show Only Live Items&#8217;, which has the effect of refreshing the feed rather than reading it from feed.informer&#8217;s cache. This allows you to, for example, delete posts in your blog and have them no longer show up in your feed digest.</li>
<li>Paste the provided javascript into your layout.html file in your sphinx project if you&#8217;ve created one. If you haven&#8217;t created a custom layout.html file, you can work from the <a href="http://pycogent.svn.sourceforge.net/viewvc/pycogent/trunk/doc/templates/layout.html?content-type=text%2Fplain">PyCogent layout.html</a> or the <a href="http://pynast.svn.sourceforge.net/viewvc/pynast/doc/_templates/layout.html?content-type=text%2Fplain">PyNAST layout.html</a>.
<p>layout.html is the only file you should need to modify to integrate javascript into a Sphinx sidebar. No changes were necessary to conf.py.</li>
<li>Re-build the html pages, and view the result. I usually end up going through a couple of iterations of steps 3-5 to get the feed digest looking exactly as I want it.</li>
<li> Post the html.</li>
</ol>
<p>That should do it. You should now be able to update your blog, and have that automatically update the News and Annonucements section on your website. If other developers on the project need to make updates as well, you can have them create wordpress accounts, and then add them as contributors on the blog. You&#8217;ll then have multiple users able to update this without sharing any passwords.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/292/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=292&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2010/01/26/integrating-news-feeds-into-sphinx-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>
	</item>
		<item>
		<title>Script for performing intermolecular coevolutionary analysis with the PyCogent Bioinformatics Toolkit</title>
		<link>http://blog.caporaso.us/2009/11/24/script-for-performing-intermolecular-coevolutionary-analysis-with-the-pycogent-bioinformatics-toolkit/</link>
		<comments>http://blog.caporaso.us/2009/11/24/script-for-performing-intermolecular-coevolutionary-analysis-with-the-pycogent-bioinformatics-toolkit/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 05:34:56 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Computational Biology]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=284</guid>
		<description><![CDATA[I&#8217;ve posted a script and a basic readme here which allows users of the python bioinformatics toolkit PyCogent to run intermolecular coevolutionary analyses using PyCogent&#8217;s built-in coevolution module. PyCogent&#8217;s coevolution module supports several tree-aware and tree-ignorant methods for identifying pairs of coevolving pairs within and between biological sequences. Additionally it contains support for pre- and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=284&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve posted a script and a basic readme <a href="http://www.caporaso.us//intermolecular_coevolution/ppi_analysis_readme.html">here</a> which allows users of the <a href="http://pycogent.sourceforge.net">python bioinformatics toolkit PyCogent</a> to run intermolecular coevolutionary analyses using PyCogent&#8217;s built-in coevolution module. </p>
<p>PyCogent&#8217;s coevolution module supports several tree-aware and tree-ignorant methods for identifying pairs of coevolving pairs within and between biological sequences. Additionally it contains support for pre- and post-processing coevolution input and results, such as recoding multiple sequence alignments with reduced-state amino acid alphabets. The script included in PyCogent supports intramolecular coevolutionary analysis, while this new script supports intermolecular coevolutionary analysis.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/284/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/284/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/284/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=284&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/11/24/script-for-performing-intermolecular-coevolutionary-analysis-with-the-pycogent-bioinformatics-toolkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>
	</item>
		<item>
		<title>Building a tree of life with PyCogent</title>
		<link>http://blog.caporaso.us/2009/10/03/building-a-tree-of-life-with-pycogent/</link>
		<comments>http://blog.caporaso.us/2009/10/03/building-a-tree-of-life-with-pycogent/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 23:58:39 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Computational Biology]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=232</guid>
		<description><![CDATA[This is a PyCogent use case that I put together for my lecture a few weeks ago in BIOI 7711 at UC Denver. I thought this was a cool example because it quickly shows some powerful aspects of PyCogent, including: parsers for common file formats (MinimalFastaParser); support for common biological data types (alignments, sequences, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=232&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>This is a <a href="http://pycogent.sourceforge.net">PyCogent</a> use case that I put together for my lecture a few weeks ago in BIOI 7711 at UC Denver. I thought this was a cool example because it quickly shows some powerful aspects of PyCogent, including:</p>
<ul>
<li>parsers for common file formats (MinimalFastaParser);
<li>support for common biological data types (alignments, sequences, and trees);
<li>interaction with external applications (MUSCLE and FastTree) via the application controller framework;
<li>and visualization (via the UnrootedDendrogram object).
</ul>
<p>The example illustrates, in about 20 or so lines of code, how to apply PyCogent to evaluate the idea that life on Earth clusters into three related domains, detectable by distances between their small-subunit ribosomal genes (i.e., their 16s rDNA sequences). Using sequences collections derived from the <a href="http://www.arb-silva.de/">Silva database</a> (filtered with <a href="http://bioinformatics.ljcrf.edu/cd-hi/">cd-hit-est</a> so the max pairwise identity between any two sequences is 90%), I randomly select sequences, align the sequences with MUSCLE, build a tree with FastTree, visualize the tree via a PDF. </p>
<p>To run this example, in addition to PyCogent, you&#8217;ll need <a href="http://www.drive5.com/muscle/">MUSCLE</a>, <a href="http://www.microbesonline.org/fasttree/">FastTree</a>, and <a href="http://matplotlib.sourceforge.net/">matplotlib</a> installed. You can read more about the ideas behind this example in <a href="http://www.ncbi.nlm.nih.gov/pubmed/2439888">Woese 1987</a> and <a href="http://www.ncbi.nlm.nih.gov/pubmed/2112744">Woese 1990</a>.</p>
<p>Let&#8217;s get started. I did this with the ipython interpreter, but the standard python interpreter will work fine too.</p>
<p><code><br />
mentat@caporaso tol_example&gt; ipython<br />
</code></p>
<p>First, we&#8217;ll load up the sequences. We&#8217;ll select only sequences that are at least 1000 bases long, and contain no N characters. As I mentioned above, the sequences I am importing here come from the Silva database of 16S sequences, and have been filtered with cd-hit-est at the 90% sequence identity. (Skipping the filtering step would probably result in more sequences being required to see the nice clusters.)</p>
<p><code><br />
&gt; from cogent.parse.fasta import MinimalFastaParser</code></p>
<p><code> </code></p>
<p><code>&gt; arch16s = []<br />
&gt; for seq_id, seq in MinimalFastaParser(open('archaeal_v11.fasta')):<br />
|..&gt;     if len(seq) &gt; 1000 and seq.count('N') &lt; 1:<br />
|..&gt;         arch16s.append((seq_id,seq))<br />
&gt; len(arch16s)<br />
696</p>
<p>&gt; bac16s = []<br />
&gt; for seq_id, seq in MinimalFastaParser(open('bacterial_v11.fasta')):<br />
|..&gt;    if len(seq) &gt; 1000 and seq.count('N') &lt; 1:<br />
|..&gt;         bac16s.append((seq_id,seq))<br />
&gt; len(bac16s)<br />
16826</p>
<p></code></p>
<p><code>&gt; euk16s = []<br />
&gt; for seq_id, seq in MinimalFastaParser(open('eukaryotic_v11.fasta')):<br />
|..&gt;    if len(seq) &gt; 1000 and seq.count('N') &lt; 1:<br />
|..&gt;        euk16s.append((seq_id,seq))<br />
len(euk16s)<br />
3902<br />
</code></p>
<p>Import shuffle from the random module so I can extract a random collection of sequences<br />
<code><br />
&gt; from random import shuffle<br />
&gt; shuffle(arch16s)<br />
&gt; shuffle(bac16s)<br />
&gt; shuffle(euk16s)<br />
</code></p>
<p>Take some random sequences from each domain:<br />
<code><br />
&gt; combined16s = arch16s[:3] + bac16s[:10] + euk16s[:6]<br />
&gt; len(combined16s)</code></p>
<p>Load the combined sequences into a <code>SequenceCollection</code> object. The <code>SequenceCollection</code> object has many useful attributes and methods associated with it. Call <code>dir(seqs)</code> (where <code>seqs</code> is a <code>SequenceCollection</code> object for a listing. <code>getNumSeqs</code> is one method of the <code>SequenceCollection</code> object.  </p>
<p><code>&gt; from cogent import LoadSeqs, DNA<br />
&gt; seqs = LoadSeqs(data=combined16s,moltype=DNA,aligned=False)<br />
&gt; len(seqs)<br />
&gt; seqs.getNumSeqs()</code></p>
<p>Get an aligner function &#8212; here we&#8217;ll align with MUSCLE via the MUSCLE application controller. The result of calling <code>align_unaligned_seqs</code> is an <code>Alignment</code> object.<br />
<code><br />
&gt; from cogent.app.muscle import align_unaligned_seqs<br />
&gt; aln = align_unaligned_seqs(seqs,DNA)<br />
</code></p>
<p>Get a tree-building function &#8212; here we&#8217;ll use FastTree. The result is a <code>PhyloNode</code> object.<br />
<code><br />
&gt; from cogent.app.fasttree import build_tree_from_alignment<br />
&gt; tree = build_tree_from_alignment(aln,DNA)</code></p>
<p>Next I import a drawing function to visualize the tree.<br />
<code><br />
&gt; from cogent.draw.dendrogram import UnrootedDendrogram<br />
&gt; dendrogram = UnrootedDendrogram(tree)</code></p>
<p>I can then generate a PDF of the tree, and save it to file:<br />
<code><br />
&gt; dendrogram.drawToPDF('./tol.pdf')<br />
</code></p>
<p>Here&#8217;s the final figure:</p>
<div id="attachment_240" class="wp-caption alignnone" style="width: 410px"><img class="size-full wp-image-240" title="Tree of Life" src="http://gregcaporaso.files.wordpress.com/2009/09/tol1.png?w=400&#038;h=200" alt="A quick-and-dirty tree of life, built using PyCogent and 16s rDNA sequences from the Silva database." width="400" height="200" /><p class="wp-caption-text">A quick-and-dirty tree of life, built using PyCogent and 16s rDNA sequences from the Silva database.</p></div>
<p>There you have it: about 20 lines of code to reproduce a classic bioinformatics experiment. As we can see the sequences (or tips in the tree), do appear to fall into three distinct clusters. By looking up these sequence identifiers in Silva, we can see that the three clusters match the three domains of life: archaea, bacteria, and eukarya. (We can also see that the number of tips in the clusters match the numbers of sequences we pulled from each of the sequence collections above.)</p>
<p>PyCogent is a very nice toolkit to work with because it lets you ignore the boring and/or frustrating aspects of the study, like parsing files, interacting with the different interfaces associated with different third-party tools, etc., and focus on the fun parts: the experiments. PyCogent is an open-source project with the core development team split between the University of Colorado at Boulder and Australia National University. I&#8217;ve been a developer on the project since about 2003.   </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/232/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=232&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/10/03/building-a-tree-of-life-with-pycogent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>

		<media:content url="http://gregcaporaso.files.wordpress.com/2009/09/tol1.png" medium="image">
			<media:title type="html">Tree of Life</media:title>
		</media:content>
	</item>
		<item>
		<title>PyNAST is live!</title>
		<link>http://blog.caporaso.us/2009/09/22/pynast-is-live/</link>
		<comments>http://blog.caporaso.us/2009/09/22/pynast-is-live/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 04:32:47 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Computational Biology]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=221</guid>
		<description><![CDATA[My latest open source software project went live today on Sourceforge. PyNAST is biological sequence alignment tool which applies the NAST (Nearest Alignment Space Termination) algorithm to align a set of input (or candidate) sequences against a template alignment. The NAST algorithm guarantees that the number of positions in the output alignment will be identical [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=221&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>My latest open source software project went live today on Sourceforge. <a href="http://pynast.sourceforge.net">PyNAST</a> is biological sequence alignment tool which applies the NAST (Nearest Alignment Space Termination) algorithm to align a set of input (or <i>candidate</i>) sequences against a template alignment. The NAST algorithm guarantees that the number of positions in the output alignment will be identical to the number of positions in the template alignment. This is extremely convenient, for example, when you have a multiple sequence alignment that was built manually, and you want to study newly acquired sequences in the context of data (such as phylogenetic trees) which were derived from the manual alignment. </p>
<p>NAST (<a href="http://nar.oxfordjournals.org/cgi/content/full/34/suppl_2/W394">originally published here</a>) has primarily been used for aligning newly acquired 16s rDNA sequences against the Greengenes &#8220;core sets&#8221; via the <a href="http://greengenes.lbl.gov/NAST">Greengenes website</a>. NAST has become a popular tool in microbial community analysis, but wider adoption has been limited by the difficulty of running the original implementation locally. Since users may need to align thousands or even hundreds of thousands of sequences, it is important for them to be able to run the software on their own laptops, servers, or clusters. PyNAST, which was developed in collaboration with some of the original NAST authors, provides a command line interface, an API, and a Mac OS X GUI (which will go live shortly) to provide convenient access in all of these environments. Additionally, because users can provide their own template alignments when running locally, PyNAST is not specific to 16s rDNA alignments. </p>
<p>We currently have an Applications Note which provides more details on PyNAST, in addition to some speed benchmarks, under review at Bioinformatics.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/221/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/221/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/221/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=221&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/09/22/pynast-is-live/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>
	</item>
		<item>
		<title>Script for counting the number of sequences in a fasta file</title>
		<link>http://blog.caporaso.us/2009/09/07/count_seqs/</link>
		<comments>http://blog.caporaso.us/2009/09/07/count_seqs/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 19:16:53 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Computational Biology]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=213</guid>
		<description><![CDATA[I&#8217;ve posted script that I use frequently for quickly finding out how many sequences are in a fasta file. This works for aligned or unaligned protein or xNA sequences. Note that for performance reasons, it does no error checking, so the user is responsible for making sure that the file is a valid fasta file. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=213&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve posted script that I use frequently for quickly finding out how many sequences are in a fasta file. This works for aligned or unaligned protein or xNA sequences.  Note that for performance reasons, it does no error checking, so the user is responsible for making sure that the file is a valid fasta file.</p>
<p>You can download <a href="http://code.google.com/p/highalpinescripts/source/browse/trunk/count_seqs/count_seqs.py">count_seqs.py</a> and <a href="http://code.google.com/p/highalpinescripts/source/browse/trunk/count_seqs/test_count_seqs.py">test_count_seqs.py</a>. </p>
<p>The way I use these is I have a scripts directory where I keep the script, and then have a symbolic link to it from my <code>$HOME/bin</code> directory. To do this, you could do the following:</p>
<p><code><br />
&gt; mkdir $HOME/scripts $HOME/bin<br />
</code></p>
<p>You&#8217;ll need to make sure that <code>$HOME/bin</code> is in your search path, or choose a different directory (e.g., <code>/usr/local/bin</code>) which will be in your search path.</p>
<p>Then save the script from the link above to <code>$HOME/scripts</code>. Make the file executable, and create a symbolic link in <code>$HOME/bin</code> so it&#8217;s in your search path.</p>
<p><code><br />
&gt; chmod 755 $HOME/scripts/count_seqs.py<br />
&gt; ln -s $HOME/scripts/count_seqs.py $HOME/bin/count_seqs<br />
</code></p>
<p>Once you&#8217;ve done that, you should be able to apply the script.</p>
<p>Get usage information:<br />
<code><br />
&gt; count_seqs -h<br />
Usage: count_seqs [options] fasta_filepath1 [fasta_filepath2 [...]]</p>
<p>Options:<br />
  --version             show program's version number and exit<br />
  -h, --help            show this help message and exit<br />
  -s, --suppress_errors<br />
                        Suppress warnings about missing files [default: False]<br />
</code></p>
<p>Count the number of sequences in a set of fasta files in a hypothetical <code>aln_size_tests</code> directory:</p>
<p><code><br />
&gt; count_seqs aln_size_tests/*fasta not_a_real_file1.fasta /data/not_a_file.txt</p>
<p>10  : 10_seq.fasta<br />
160  : 160_seq.fasta<br />
1  : 1_seq.fasta<br />
20  : 20_seq.fasta<br />
2  : 2_seq.fasta<br />
320  : 320_seq.fasta<br />
3  : 3_seq.fasta<br />
40  : 40_seq.fasta<br />
4  : 4_seq.fasta<br />
5  : 5_seq.fasta<br />
80  : 80_seq.fasta<br />
645  : Total</p>
<p>Some files were not accessible. Do they exist? Do you have read permission?<br />
  not_a_real_file1.fasta<br />
  /data/not_a_file.txt</p>
<p></code></p>
<p>If you&#8217;re not interested in a report about files which couldn&#8217;t be found, pass the <code>-s</code> option to suppress error messages.</p>
<p><code></p>
<p>caporaso@mentat aln_size_tests&gt; count_seqs -s *fasta not_a_real_file1.fasta /data/not_a_file.txt</p>
<p>10  : 10_seq.fasta<br />
160  : 160_seq.fasta<br />
1  : 1_seq.fasta<br />
20  : 20_seq.fasta<br />
2  : 2_seq.fasta<br />
320  : 320_seq.fasta<br />
3  : 3_seq.fasta<br />
40  : 40_seq.fasta<br />
4  : 4_seq.fasta<br />
5  : 5_seq.fasta<br />
80  : 80_seq.fasta<br />
645  : Total<br />
</code></p>
<p>Note that the sequence counting functions exactly as using <code>egrep -c</code> to search for lines beginning with <code>&gt;</code>. For example:</p>
<p><code><br />
&gt; egrep -c '^&gt;' aln_size_tests/320_seq.fasta<br />
320<br />
</code></p>
<p>Wrapping it in a python script allows for convenient application to a list of files, and convenient totaling of different sequence files. That&#8217;s useful, for example, if you have a 16S database split on domains of life, and you want to see how many fall into each category and how many there are total. Here&#8217;s an example using a local copy of the Silva 16S data set:</p>
<p><code><br />
&gt; count_seqs silva/*fasta</p>
<p>12635  : silva/archaeal.fasta<br />
296754  : silva/bacterial.fasta<br />
42239  : silva/eukaryotic.fasta<br />
0  : silva/unclassified.fasta<br />
351628  : Total<br />
</code></p>
<p>I hope this is useful!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/213/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=213&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/09/07/count_seqs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>
	</item>
		<item>
		<title>Costa Rica pictures, finally!</title>
		<link>http://blog.caporaso.us/2009/08/31/costa-rica-pictures-finally/</link>
		<comments>http://blog.caporaso.us/2009/08/31/costa-rica-pictures-finally/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 04:13:01 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Trip reports]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=208</guid>
		<description><![CDATA[I&#8217;ve finally put some pictures of our honeymoon in Costa Rica on my Flickr account: here they are. I thought I&#8217;d also put a few of my favorite Costa Rica wildlife photos here. Iguana on the beach. A crocodile, from the bridge above it. Toucan in the forest below Volcano Arenal. White-faced monkeys in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=208&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally put some pictures of our honeymoon in Costa Rica on my Flickr account: <a href="http://www.flickr.com/photos/caporaso/sets/72157622202133034/">here they are.</a></p>
<p>
I thought I&#8217;d also put a few of my favorite Costa Rica wildlife photos here.</p>
<p>
<a href="http://www.flickr.com/photos/caporaso/3876193013/" title="Iguana by caporaso, on Flickr"><img src="http://farm3.static.flickr.com/2460/3876193013_e3ca50745f.jpg" width="500" height="375" alt="Iguana" /></a><br />
Iguana on the beach.
<p><a href="http://www.flickr.com/photos/caporaso/3876984764/" title="Crocodile by caporaso, on Flickr"><img src="http://farm3.static.flickr.com/2463/3876984764_f0607cb93a.jpg" width="500" height="375" alt="Crocodile" /></a><br />
A crocodile, from the bridge above it.
<p><a href="http://www.flickr.com/photos/caporaso/3876986170/" title="Toucan by caporaso, on Flickr"><img src="http://farm4.static.flickr.com/3447/3876986170_2d90bf0132.jpg" width="500" height="397" alt="Toucan" /></a><br />
Toucan in the forest below Volcano Arenal.
<p><a href="http://www.flickr.com/photos/caporaso/3876195775/" title="White-faced monkeys by caporaso, on Flickr"><img src="http://farm3.static.flickr.com/2649/3876195775_62234ddab4.jpg" width="500" height="425" alt="White-faced monkeys" /></a><br />
White-faced monkeys in the forest below Volcano Arenal.<br />
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=208&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/08/31/costa-rica-pictures-finally/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2460/3876193013_e3ca50745f.jpg" medium="image">
			<media:title type="html">Iguana</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2463/3876984764_f0607cb93a.jpg" medium="image">
			<media:title type="html">Crocodile</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3447/3876986170_2d90bf0132.jpg" medium="image">
			<media:title type="html">Toucan</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2649/3876195775_62234ddab4.jpg" medium="image">
			<media:title type="html">White-faced monkeys</media:title>
		</media:content>
	</item>
		<item>
		<title>When will I ever need to use trigonometry? (Or, how to avoid avalanche terrain.)</title>
		<link>http://blog.caporaso.us/2009/08/21/when-will-i-ever-need-to-use-trigonometry-or-how-to-avoid-avalanche-terrain/</link>
		<comments>http://blog.caporaso.us/2009/08/21/when-will-i-ever-need-to-use-trigonometry-or-how-to-avoid-avalanche-terrain/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 04:09:21 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Trip reports]]></category>
		<category><![CDATA[colorado]]></category>
		<category><![CDATA[skiing]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=127</guid>
		<description><![CDATA[I sometimes tutor high school math, and as anyone who has done this knows, a common question is &#8216;But when will I ever need to use blank?&#8217;. This came up last year, where the blank was trigonometry. When will I ever need to use trigonometry? It&#8217;s a legitimate question. As an instructor, you could explain [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=127&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I sometimes tutor high school math, and as anyone who has done this knows, a common question is &#8216;But when will I ever need to use <i>blank</i>?&#8217;. This came up last year, where the <i>blank</i> was trigonometry. </p>
<p><i>When will I ever need to use trigonometry?</i> It&#8217;s a legitimate question. As an instructor, you could explain how it&#8217;s a foundation of mathematics, or how you&#8217;ll need to understand it for any career in science or math, or so on&#8230; (They&#8217;re both true, and are probably close to what I said, but neither are an answer that your student is likely to care much about.) Think about it: what practical problem, in day-to-day life, have you solved by applying trigonometry? (Comment if you have a good one!)</p>
<p>So, when I was backcountry skiing last winter and my friend Erik and I actually applied trigonometry to decide if it was safe to ski a certain slope, we were proud. </p>
<p>It&#8217;s generally accepted that if a slope is 30 degrees or less, it&#8217;s probably not steep enough to avalanche. Slopes around 40-55 degrees are the most dangerous. We were about to cross a slope, but we weren&#8217;t really prepared to be in avalanche terrain: we didn&#8217;t have our beacons, probes, and shovels. In short, we wanted to avoid avalanche terrain by staying off slopes that were 30 degrees or greater. </p>
<p>We didn&#8217;t have a slope meter, but we did know trigonometry. If we could make a right triangle where one of the legs (i.e., sides not opposite the right angle) was double the length of the other leg, the slope of the opposite side (the hypotenuse) would be less than 30 degrees. (We did need a calculator to figure out exactly what that angle would be.) What could we use to make the two legs? Ski poles!  </p>
<div id="attachment_154" class="wp-caption alignnone" style="width: 423px"><img src="http://gregcaporaso.files.wordpress.com/2009/08/26_degree.jpg?w=413&#038;h=480" alt="Figure 1: Identifying a 26 degree slope with two ski poles." title="26_degree" width="413" height="480" class="size-full wp-image-154" /><p class="wp-caption-text">Figure 1: Identifying a 26 degree slope with two ski poles.</p></div>
<p>Here&#8217;s how it works. Plant your first pole vertically, and try to make a 90 degree angle with the second pole beginning halfway down the vertical pole. If the tip of the horizontal pole touches when the poles are at 90 degrees with one another, you&#8217;re on a roughly 26 degree slope (Figure 1). If you can&#8217;t make a 90 degree angle because the horizontal pole hits the slope too high, the slope is steeper than 26 degrees (Figure 2). If you can make an angle smaller than 90 degrees before the tip of the horizontal pole hits the snow, the slope is less than 26 degrees (Figure 3). </p>
<div id="attachment_198" class="wp-caption alignnone" style="width: 430px"><img src="http://gregcaporaso.files.wordpress.com/2009/08/greater_than_26_degree2.jpg?w=420&#038;h=383" alt="Figure 2: Identifying a slope greater than 26 degrees with two ski poles." title="greater_than_26_degree" width="420" height="383" class="size-full wp-image-198" /><p class="wp-caption-text">Figure 2: Identifying a slope greater than 26 degrees with two ski poles.</p></div>
<p><b>The rule-of-thumb is this:</b> If the poles can form a right triangle with the horizontal pole exactly halfway down the vertical pole, and with the slope as the hypotenuse, the slope is less than 30 degrees and you are probably safe. This is the situation depicted in Figures 1 and 3. If you can&#8217;t form the 90 degree angle because the slope is too steep, as in Figure 2, you&#8217;re in possible avalanche terrain so make sure you know what you&#8217;re doing!</p>
<div id="attachment_193" class="wp-caption alignnone" style="width: 430px"><img src="http://gregcaporaso.files.wordpress.com/2009/08/less_than_26_degree1.jpg?w=420&#038;h=316" alt="Figure 3: Identifying a slope less than 26 degrees with two ski poles." title="less_than_26_degree" width="420" height="316" class="size-full wp-image-193" /><p class="wp-caption-text">Figure 3: Identifying a slope less than 26 degrees with two ski poles.</p></div>
<p>Finally, you can also use this trick to identify a 45 degree slope (which is absolutely in avalanche terrain). To do that, this time place the horizontal pole at the top of the vertical pole rather than halfway down. If the tip of the horizontal pole just touches the slope when you have a 90 degree angle between the poles, the slope is just about 45 degrees (Figure 4). If it doesn’t touch, it’s less than 45 degrees. If you can’t make a 90 degree angle because the second pole hits the slope too high, you’re on some steep stuff!</p>
<div id="attachment_197" class="wp-caption alignnone" style="width: 430px"><img src="http://gregcaporaso.files.wordpress.com/2009/08/45_degree3.jpg?w=420&#038;h=415" alt="Figure 4: Identifying a 45 degree slope with two ski poles." title="45_degree" width="420" height="415" class="size-full wp-image-197" /><p class="wp-caption-text">Figure 4: Identifying a 45 degree slope with two ski poles.</p></div>
<p>There you have it: a field application of trigonometry. We&#8217;re not the first ones to figure this out &#8212; I&#8217;ve since heard that the Norwegians have been doing this forever. It&#8217;s a neat trick.</p>
<p>And of course, there is a lot more to avalanche safety than this. This is a basic rule, but by no means definitive. Be scared of avalanches, and don&#8217;t assume that if a slope is less than 30 degrees it can&#8217;t slide. If you&#8217;re planning to travel in avalanche country <a href="http://avtraining.org/">take a class</a>, check the <a href="http://avalanche.state.co.us/index.php">avalanche reports</a>, and if you&#8217;re not scared of avalanches, watch <a href="http://www.youtube.com/watch?v=S1Pi64I2wTU">some</a> <a href="http://www.youtube.com/watch?v=6qVwIuznFW0">videos</a>. </p>
<p><a href="http://www.flickr.com/photos/caporaso/3347715225/" title="Skiing out from Ken's Cabin by caporaso, on Flickr"><img src="http://farm4.static.flickr.com/3551/3347715225_66bf633198.jpg" width="500" height="375" alt="Skiing out from Ken's Cabin" /></a><br />
Skiing out from Ken&#8217;s Cabin</p>
<p>
<a href="http://www.flickr.com/photos/caporaso/sets/72157615127960118/">More photos</a> from this trip.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=127&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/08/21/when-will-i-ever-need-to-use-trigonometry-or-how-to-avoid-avalanche-terrain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>

		<media:content url="http://gregcaporaso.files.wordpress.com/2009/08/26_degree.jpg" medium="image">
			<media:title type="html">26_degree</media:title>
		</media:content>

		<media:content url="http://gregcaporaso.files.wordpress.com/2009/08/greater_than_26_degree2.jpg" medium="image">
			<media:title type="html">greater_than_26_degree</media:title>
		</media:content>

		<media:content url="http://gregcaporaso.files.wordpress.com/2009/08/less_than_26_degree1.jpg" medium="image">
			<media:title type="html">less_than_26_degree</media:title>
		</media:content>

		<media:content url="http://gregcaporaso.files.wordpress.com/2009/08/45_degree3.jpg" medium="image">
			<media:title type="html">45_degree</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3551/3347715225_66bf633198.jpg" medium="image">
			<media:title type="html">Skiing out from Ken's Cabin</media:title>
		</media:content>
	</item>
		<item>
		<title>Python optparse example, part 3</title>
		<link>http://blog.caporaso.us/2009/08/11/python-optparse-example-part-3/</link>
		<comments>http://blog.caporaso.us/2009/08/11/python-optparse-example-part-3/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 02:10:14 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=95</guid>
		<description><![CDATA[In the third part of my python optparse example we&#8217;ll look what my optparse example does, with a focus on how to define and error check the parameters. The example script takes three optional parameters, -v, -s, -i, and one required parameter, output_filepath. (Note that I don&#8217;t need to define the -h or --help option [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=95&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>In the third part of my python optparse example we&#8217;ll look what my <a href="http://www.caporaso.us/code/optparse_example.html">optparse example</a> does,  with a focus on how to define and error check the parameters. </p>
<p>The example script takes three optional parameters, <code>-v</code>, <code>-s</code>, <code>-i</code>, and one required parameter, <code>output_filepath</code>. (Note that I don&#8217;t need to define the <code>-h</code> or <code>--help</code> option &#8212; that functionality is automatically included.) </p>
<p>The <code>-v</code> parameter is a binary verbose flag defined as:</p>
<pre>
<code>
parser.add_option('-v','--verbose',action='store_true',\
        dest='verbose',help='Print information during execution -- '+\
        'useful for debugging [default: %default]')
</code>
</pre>
<p> When the script is called with <code>-v</code> or <code>--verbose</code>, <code>True</code> (because <code>action='store_true'</code>) is stored in the <code>verbose</code> variable (because <code>dest='verbose'</code>). The <code>help</code> parameter defines the help string that will be presented when the user passes <code>-h</code> to the script. When the help string is printed, <code>%default</code> is replaced with the default value of the parameter.</p>
<p>Next I define an option which allows the user to pass a value to the script via <code>-s</code>:</p>
<pre>
<code>
parser.add_option('-s','--string_to_write',action='store',\
          type='string',dest='string_to_write',help='a string to write to '+\
          'file [default: %default]')
</code>
</pre>
<p>This allows for passing a <code>-s</code> or <code>--string_to_write</code> option to the script, the string value of which will be stored (because <code>action='store'</code>) in a variable called <code>string_to_write</code>. Note that we explicitly define the type here (<code>type='string'</code>) &#8212; something that is unusual in python. </p>
<p>The next option is similar, except that an int is stored to <code>int_value</code>:</p>
<pre>
<code>
    parser.add_option('-i','--int_value',action='store',\
          type='int',dest='int_value',help='an integer value to store '+\
          '[default: %default]')
</code>
</pre>
<p>After the options are defined I set defaults for them. The value for all options defaults to <code>None</code>, unless otherwise specified. I define the default for <code>verbose</code> to be <code>False</code> and the default for <code>string_to_write</code> as <code>"Some example input."</code>. I don&#8217;t define a default for <code>int_value</code>.</p>
<p>Finally, I parse the command line arguments into opts and args. I then have the values that the user provided, and am able to perform any necessary error checking. </p>
<p>The script requires that the user provides a single command line argument, <code>output_filepath</code>. So, I check that they have provided exactly one argument, and raise an error if not. Raising the error via <code>parser.error</code> is useful because it provides the user with the usage information in addition to the error message. Try calling the script with no options or arguments for an example. </p>
<p>If no errors are raised, opts and args are returned to the caller &#8212; in this case the main block of the code. The options and arguments can then be accessed as illustrated in the example.</p>
<p>You can see by experimenting with the script that the verbose flag prints some additional information to the terminal at runtime. Try running the script with and without <code>-v</code>, and you&#8217;ll see slightly different results. <code>string_to_write</code> is written to <code>output_filepath</code>. If it&#8217;s not provided by the user, the default value is used. Then <code>int_value</code> is written to <code>output_file</code> if provided.</p>
<p>That just about wraps up my optparse example. I&#8217;ve highlighted some of the optparse functionality in this tutorial, and provided a usage example that you can experiment with on the command line. A good way to learn more would be to start with my optparse example, and experiment with adding new functionality. You can find a lot more information about optparse <a href="http://docs.python.org/library/optparse.html">here</a>.</p>
<p>I previously mentioned that I start all new python scripts with a template file which includes optparse functionality. In my optparse template, which is a simplified version of my <a href="http://www.caporaso.us/code/optparse_example.html">optparse example</a>, I leave in some example options so it&#8217;s easy to add new ones in my script. Rather than having to remember how to instantiate the OptionParser object and define parameters, I can just modify what&#8217;s there and delete what isn&#8217;t necessary. Feel free to use and modify my <a href="http://www.caporaso.us/code/optparse_example.html">optparse example</a> to make it a template for your own python scripts. </p>
<p>Finally, you may have noticed that python has another module for parsing command line parameters: getopt. You should always use optparse over getopt as optparse provides a lot of additional functionality, and will continue to be supported in Python 3 (<s>unlike getopt</s>). (Scratch that about getopt not being supported in Python 3 &#8212; it <a href="http://docs.python.org/3.1/library/getopt.html">looks like it is</a> but the Python docs note that: <a href="http://docs.python.org/3.1/library/getopt.html">&#8220;A more convenient, flexible, and powerful alternative is the optparse module.&#8221;</a>.)</p>
<p>I think you&#8217;ll find that incorporating optparse-based parameter parsing to your python scripts will make them more useful to yourself and your users. I hope that my example will help you get up and running with optparse very quickly. Good luck!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=95&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/08/11/python-optparse-example-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>
	</item>
		<item>
		<title>Twenty 14ers done!</title>
		<link>http://blog.caporaso.us/2009/08/09/twenty-14ers-done/</link>
		<comments>http://blog.caporaso.us/2009/08/09/twenty-14ers-done/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 20:01:22 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Trip reports]]></category>
		<category><![CDATA[14er]]></category>
		<category><![CDATA[colorado]]></category>
		<category><![CDATA[hiking]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=48</guid>
		<description><![CDATA[Yesterday Ingrid and I climbed Mt. Bierstadt and the Sawtooth over to Mt. Evans (Map, credit: 14ers.com). We had both done Bierstadt before (maybe the most popular 14er hike in Colorado?) but the summit of Mt. Evans marked my 20th and Ingrid&#8217;s 6th 14er. This was a long but very fun hike, with four distinct [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=48&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Yesterday Ingrid and I climbed Mt. Bierstadt and the Sawtooth over to Mt. Evans (<a href="http://maps.google.com/maps/ms?hl=en&amp;ie=UTF8&amp;msa=0&amp;t=p&amp;msid=118165177822688159829.00045d9ea35f0c1d665aa&amp;s=AARTsJphsNfC1UId21p_F7w3TmLWvdAPYA&amp;ll=39.587038,-105.662727&amp;spn=0.03175,0.054932&amp;z=14&amp;output=embed">Map</a>, credit: <a>14ers.com</a>). We had both done Bierstadt before (maybe the most popular 14er hike in Colorado?) but the summit of Mt. Evans marked my 20th and Ingrid&#8217;s 6th 14er. </p>
<p>This was a long but very fun hike, with four distinct sections: the Bierstadt ascent, the Sawtooth, the Evans ascent, and the descent. The hike from Guanella Pass to the Mt. Bierstadt summit is a 3.5 mile climb, from the trailhead at 11,669&#8242; to the summit at 14,060&#8242;. Since it was a beautiful Saturday morning, this section was PACKED with people. </p>
<p><a href="http://www.flickr.com/photos/caporaso/3805037366/" title="The Sawtooth and Bierstadt from the Bierstadt Trail by caporaso, on Flickr"><img src="http://farm4.static.flickr.com/3494/3805037366_3aa4ac18f1.jpg" width="500" height="375" alt="The Sawtooth and Bierstadt from the Bierstadt Trail" /></a><br />
The Sawtooth and Bierstadt from the Bierstadt Trail.</p>
<p>From the summit, we scrambled across the Sawtooth. We ran into very few hikers in this 3.5 hour section of the hike (with a lunch and nap break), so it was a nice change from the Bierstadt Trail. This was sketchy in spots but doable. </p>
<p><a href="http://www.flickr.com/photos/caporaso/3804229235/" title="Ingrid on the Sawtooth by caporaso, on Flickr"><img src="http://farm4.static.flickr.com/3010/3804229235_de48b4d0f8.jpg" width="375" height="500" alt="Ingrid on the Sawtooth" /></a><br />
Ingrid on the Sawtooth with the Bierstadt summit in the background.</p>
<p>Once across the Sawtooth, we hiked through a boulder field for about 2 hours up to the Mt. Evans summit at 14,264&#8242;. There is a paved road up to the Evans summit &#8212; the highest paved road in America &#8212; so, of course, the summit of Evans was packed. </p>
<p><a href="http://www.flickr.com/photos/caporaso/3805051062/" title="Mt Evans Observatory from Mt Evans Summit by caporaso, on Flickr"><img src="http://farm4.static.flickr.com/3526/3805051062_87e31e1a10.jpg" width="500" height="375" alt="Mt Evans Observatory from Mt Evans Summit" /></a><br />
Mt. Evans observatory from the Mt. Evans summit.</p>
<p>
We quickly left the summit to make our way back to the Guanella Pass parking lot as we were starting to get tired. Rather than cross the Sawtooth again, we hiked down an alpine meadow, into a gully, and then through the infamous willows. The route finding was straight-forward in this section, and there was a decent trail through the willows (albeit a little soggy). </p>
<p><a href="http://www.flickr.com/photos/caporaso/3804236687/" title="Waterfall by caporaso, on Flickr"><img src="http://farm3.static.flickr.com/2529/3804236687_4b18407e90.jpg" width="375" height="500" alt="Waterfall" /></a><br />
Waterfall just above the willows.</p>
<p>I now understand why everyone warns of how terrible it could be to get lost in the willows. Before there were decent trails through this section the willows could have been a slow, wet end to a long hike. The hike ended up taking us just under 12 hours, from trailhead to trailhead.</p>
<p>Twenty down, thirty-two to go&#8230; A <a href="http://www.14ers.com/php14ers/usrpeaksmap.php?userid=gregcaporaso">map of Colorado 14ers</a> with the ones I&#8217;ve hiked in red.</p>
<p><a href="http://www.flickr.com/photos/caporaso/sets/72157621990632052/">More photos from this hike</a> and photos from <a href="http://www.flickr.com/photos/caporaso/collections/72157600888721707/">my other 14er hikes.</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=48&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/08/09/twenty-14ers-done/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3494/3805037366_3aa4ac18f1.jpg" medium="image">
			<media:title type="html">The Sawtooth and Bierstadt from the Bierstadt Trail</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3010/3804229235_de48b4d0f8.jpg" medium="image">
			<media:title type="html">Ingrid on the Sawtooth</media:title>
		</media:content>

		<media:content url="http://farm4.static.flickr.com/3526/3805051062_87e31e1a10.jpg" medium="image">
			<media:title type="html">Mt Evans Observatory from Mt Evans Summit</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2529/3804236687_4b18407e90.jpg" medium="image">
			<media:title type="html">Waterfall</media:title>
		</media:content>
	</item>
		<item>
		<title>Python optparse example, part 2</title>
		<link>http://blog.caporaso.us/2009/08/04/python-optparse-example-part-2/</link>
		<comments>http://blog.caporaso.us/2009/08/04/python-optparse-example-part-2/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 02:01:34 +0000</pubDate>
		<dc:creator>gregcaporaso</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.caporaso.us/?p=19</guid>
		<description><![CDATA[Alright, so you&#8217;ve downloaded my optparse example and now it&#8217;s time to look at some of the features it provides. Running this script with --help (or just -h) immediately gives the user (you?) useful information about how to interact with the script: $ python optparse_example.py -h Usage: optparse_example.py [options] output_filepath Options: --version show program's version [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=19&subd=gregcaporaso&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Alright, so you&#8217;ve downloaded my <a href="http://www.caporaso.us/code/optparse_example.html">optparse example</a> and now it&#8217;s time to look at some of the features it provides. Running this script with <code>--help</code> (or just <code>-h</code>) immediately gives the user (you?) useful information about how to interact with the script:</p>
<p><code></p>
<pre>
$ python optparse_example.py -h
Usage: optparse_example.py [options] output_filepath

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -v, --verbose         Print information during execution -- useful for
                        debugging [default: False]
  -s STRING_TO_WRITE, --string_to_write=STRING_TO_WRITE
                        a string to write to file [default: Some example
                        input.]
  -i INT_VALUE, --int_value=INT_VALUE
                        an integer value to store [default: none]
</pre>
<p></code> </p>
<p>The first line we get is a usage statement telling us how to call the script. In this case it&#8217;s simple: there is one required argument, <code>input_filepath</code>, and several available options. This line can be really important when there are a few required arguments and you need to know the order of them. Then, we get a list of the available options to the program, the different ways we can call them, brief descriptions of each option, and the default value associated with each. </p>
<p>When you create your own version of <code>parse_command_line_parameters()</code> (or modify mine), you&#8217;ll write the usage statement yourself. To adhere to convention, everything optional should be enclosed in brackets and everything required should not be enclosed in brackets. Reviewing the example above we can see that <code>[options]</code> refers to optional parameters while <code>input_filepath</code> refers to the required parameter. (<code>optparse_example.py</code> is, of course, the name of the program and therefore also required so not enclosed in brackets.) </p>
<p>Let&#8217;s look at a more complex example. Imagine that a program required an integer followed by one or more input filepaths. The way I would write that usage statement would be:</p>
<p><code>optparse_example.py [options] input_int_value input_filepath1 [input_filepath2 [input_filepath3 [...]]]</code></p>
<p>This indicates again that <code>optparse_example.py</code> and <code>input_filepath1</code> are required arguments, in addition to <code>input_int_value</code> (which must be provided before <code>input_filepath1</code>). Additionally however, we see that we can optionally pass an <code>input_filepath2</code>, and so on. The nesting of brackets is meant to indicate that if we want to include the next optional argument, the current one must be provided. </p>
<p>If there is a certain parameter where you always require a value, but where the majority of the time it will be the same, that&#8217;s where defining options with defaults is very useful. Focus on trying to make command line interaction with your script as simple as possible (don&#8217;t require 20 arguments in a specific order!), but harnessing the options with default values to give users full access to what your program can do. </p>
<p>Next we&#8217;ll jump into the code, which is pretty straight-forward, and look at how to define options and arguments, and the benefit of doing error checking in the <code>parse_command_line_parameters()</code> function.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gregcaporaso.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gregcaporaso.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gregcaporaso.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gregcaporaso.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gregcaporaso.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gregcaporaso.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gregcaporaso.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gregcaporaso.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gregcaporaso.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gregcaporaso.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caporaso.us&blog=8873258&post=19&subd=gregcaporaso&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caporaso.us/2009/08/04/python-optparse-example-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/24f019bae9a9c4282123961b01c7f0d5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">gregcaporaso</media:title>
		</media:content>
	</item>
	</channel>
</rss>