<?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/"
	>

<channel>
	<title>Code-itch &#187; python string reversal</title>
	<atom:link href="http://www.code-itch.com/blog/tag/python-string-reversal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.code-itch.com/blog</link>
	<description>A non-coders attempts at writing useful code</description>
	<lastBuildDate>Sun, 19 Dec 2010 11:47:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python command line tricks for reverse primer design</title>
		<link>http://www.code-itch.com/blog/2008/10/quickie-dickie-python-command-line-for-reverse-primer-design/</link>
		<comments>http://www.code-itch.com/blog/2008/10/quickie-dickie-python-command-line-for-reverse-primer-design/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 16:28:45 +0000</pubDate>
		<dc:creator>harijay</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[python string reversal]]></category>
		<category><![CDATA[python-tips]]></category>

		<guid isPermaLink="false">http://www.code-itch.com/blog/?p=50</guid>
		<description><![CDATA[If I were to list one of the most attractive things about python , the interactive command line would rank among the top few. Well today I was forced with a rather simple task. I had to order a primer for a sub-cloning experiment that was the reverse primer corresponding to the last twenty bases of a [...]]]></description>
			<content:encoded><![CDATA[<p>If I were to list one of the most attractive things about python , the interactive command line would rank among the top few.</p>
<p>Well today I was forced with a rather simple task. I had to order a primer for a sub-cloning experiment that was the reverse primer corresponding to the last twenty bases of a given protein coding gene sequence.</p>
<p>Here is how python made the task super easy</p>
<p>1) First I opened the pubmed page with my sequence and copied the forward strand to my interactive python session</p>
<p>2) Then I wrote a couple of  lines to generate the reverse complement at the same time reversing the order of the string</p>
<address><span style="color: #339966;">&gt;&gt;&gt; x=&#8221;GGATGAAGTCCAGATA&#8221;<br />
&gt;&gt;&gt; c={&#8220;A&#8221;:&#8221;T&#8221;,&#8221;T&#8221;:&#8221;A&#8221;,&#8221;G&#8221;:&#8221;C&#8221;,&#8221;C&#8221;:&#8221;G&#8221;}<br />
&gt;&gt;&gt; p=&#8221;"<br />
&gt;&gt;&gt; for i in x :<br />
&#8230;  p = c[i] + p<br />
&#8230;<br />
&gt;&gt;&gt; p<br />
&#8216;TATCTGGACTTCATCC&#8217;</span></address>
<p>So in the above example the</p>
<address><span style="color: #008000;">c = </span><span style="color: #008000;">{&#8220;A&#8221;:&#8221;T&#8221;,&#8221;T&#8221;:&#8221;A&#8221;,&#8221;G&#8221;:&#8221;C&#8221;,&#8221;C&#8221;:&#8221;G&#8221;}</span></address>
<p>Is the reverse complement dictionary. The for loop replaces each nucleotide with its complement and simultaneously reverses the order , because every nucleotide is added to the begining ( i.e prepended) . So the last nucleotide ends up first.</p>
<p>The other way to do the same thing would be to use python string reversal as demonstrated in the code below</p>
<address><span style="color: #008000;">&gt;&gt;&gt; x=&#8221;GGATGAAGTCCAGATA&#8221;<br />
&gt;&gt;&gt; c={&#8220;A&#8221;:&#8221;T&#8221;,&#8221;T&#8221;:&#8221;A&#8221;,&#8221;G&#8221;:&#8221;C&#8221;,&#8221;C&#8221;:&#8221;G&#8221;}<br />
&gt;&gt;&gt; for i in x :<br />
&#8230;  p = p + c[i]<br />
&#8230;<br />
&gt;&gt;&gt; p<br />
&#8216;CCTACTTCAGGTCTAT&#8217;<br />
&gt;&gt;&gt; reverse_5prime_3prime = p[::-1]<br />
&gt;&gt;&gt; reverse_5prime_3prime<br />
&#8216;TATCTGGACTTCATCC&#8217;</span></address>
<p>The cool part here is the funky and admittedly unreadable string-reversal syntax,</p>
<p>[python] reverse_5prime_3prime = p[::-1]<br />
[/python]</p>
<p>So  In python string reversal is powerful. The p[::-1] basically says , give me the string from start to finish in backwards order (-1) . This elegant <a href="http://www.python.org/doc/2.3.5/whatsnew/section-slices.html">string reversal in python</a> is explained well <a href="http://www.answermysearches.com/index.php/super-easy-way-to-reverse-a-string-in-python/188/">in this post </a> and gives us the primer sequence in the correct 5-prime to 3-prime order as required by the oligo-synthesizing order forms.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.code-itch.com/blog/2008/10/quickie-dickie-python-command-line-for-reverse-primer-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

