<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Beginning Python for Bioinformatics</title>
	
	<link>http://python.genedrift.org</link>
	<description>a step-by-step guide to create Python applications in bioinformatics</description>
	<lastBuildDate>Wed, 10 Mar 2010 13:03:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/BeginningPythonForBioinformatics" /><feedburner:info uri="beginningpythonforbioinformatics" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-nd/3.0/</creativeCommons:license><feedburner:emailServiceId>BeginningPythonForBioinformatics</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Python Testing Beginner’s Guide, review</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/L7IYhlz8nY8/</link>
		<comments>http://python.genedrift.org/2010/03/03/python-testing-beginner%e2%80%99s-guide-review/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 03:46:35 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=351</guid>
		<description>I posted about a week ago that Packt Publishing had invited me to review Python Testing Beginner&amp;#8217;s Guide by Daniel Arbuckle. Having finished reading the book (I must admit that I haven&amp;#8217;t tried all the code in it), I can say that I have an excellent initial impression of the book.
PTBG is not a long [...]</description>
			<content:encoded><![CDATA[<p>I posted about a week ago that Packt Publishing had invited me to review <strong><a href="http://www.packtpub.com/python-testing-beginners-guide/book/mid/240210aaphjg?utm_source=python.genedrift.org&#038;utm_medium=bookrev&#038;utm_content=blog&#038;utm_campaign=mdb_002570">Python Testing Beginner&#8217;s Guide</a></strong> by Daniel Arbuckle. Having finished reading the book (I must admit that I haven&#8217;t tried all the code in it), I can say that I have an excellent initial impression of the book.</p>
<p>PTBG is not a long book and the topic is divided in 10 chapters and one appendix. One of the first things that I liked about the book is that there&#8217;s no <em>introduction</em> (or something similar) to Python. It just goes straight to the point assuming that you have some good understanding of the language and everything that surrounds it. In the past I was frustrated with some &#8220;Introduction to X with Python&#8221; that wasted precious space talking over and over about a topic, learning Python, better covered in many other books. PTBG does not waste time and space introducing its main topic which is testing, and in my opinion that&#8217;s the best approach, even though it might look a little bit abrupt by some.</p>
<p>The language and text in the book is clear and very pleasant. PTBG is a very well written book and I really enjoyed its style. The first chapters of the book cover Python testing using doctests. For someone like me that didn&#8217;t write so many tests in the normal software development workflow (I know I should write more tests), this section seems like a really nice introduction to the topic, with well thought real-life like examples and a good flow on the explanation of the different features. One small complain that I have is that for a beginner sometimes the code listed in the examples might seem a little bit confusing, and maybe the addition of line numbers might have helped a bit here. But at the same I understand that this is normal style of some Packt books.</p>
<p>After the doctests section, PTBG gets into more advanced techniques, covering a little bit mock objects with <a href="http://labix.org/mocker">Mocker</a>, then moving into unittest and <a href="http://code.google.com/p/python-nose/">nose</a>. The latter is a Python tool that allows for managing, running and automating tests. Also covered is <a href=" http://pypi.python.org/pypi/ twill/">Twill</a>, another third-party library that allows for testing of web applications.</p>
<p>One full chapter is devoted to test-driven development, with a complete walkthrough of this approach. This gives a wrap-up of most of the techniques and modules covered in the book, but there&#8217;s still space for another chapter that shows how beautifully doctests, unittest and nose can be fully integrated and help the development of applications using the test-driven approach.</p>
<p>Overall, I really enjoyed PTBG. As I mentioned, test driven development was never a high priority in the application I usually developed with Python. But certainly this book can be a good starting point for some Python test beginners to incorporate these techniques in their usual development workflow. Scientific software is also a perfect  niche for this type of approach and we should do what is possible in order to avoid the <a href="http://boscoh.com/protein/a-sign-a-flipped-structure-and-a-scientific-flameout-of-epic-proportions">nightmares of the past</a>. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=L7IYhlz8nY8:aJYMofLHK_A:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=L7IYhlz8nY8:aJYMofLHK_A:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=L7IYhlz8nY8:aJYMofLHK_A:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=L7IYhlz8nY8:aJYMofLHK_A:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=L7IYhlz8nY8:aJYMofLHK_A:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/L7IYhlz8nY8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2010/03/03/python-testing-beginner%e2%80%99s-guide-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2010/03/03/python-testing-beginner%e2%80%99s-guide-review/</feedburner:origLink></item>
		<item>
		<title>Preview of Python Testing Beginner’s Guide</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/dJv49-da6QI/</link>
		<comments>http://python.genedrift.org/2010/02/22/preview-of-python-testing-beginners-guide/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 16:00:53 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[preview]]></category>
		<category><![CDATA[python testing]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=347</guid>
		<description>I was invited by Packt Publishing to review Python Testing Beginner&amp;#8217;s Guide by Daniel Arbuckle. This is a book on one of the most important aspects of scientific programming (even though the majority of scientific software don&amp;#8217;t have any testing routines): code testing, checking if your code actually does what is intended to do. I [...]</description>
			<content:encoded><![CDATA[<p>I was invited by Packt Publishing to review <strong><a href="http://www.packtpub.com/python-testing-beginners-guide/book/mid/240210aaphjg">Python Testing Beginner&#8217;s Guide</a></strong> by Daniel Arbuckle. This is a book on one of the most important aspects of scientific programming (even though the majority of scientific software don&#8217;t have any testing routines): code testing, checking if your code actually does what is intended to do. I can say I&#8217;m not really an expert on testing so I guess I&#8217;m the right audience for it:</p>
<blockquote><p>You&#8217;ll learn about several of Python&#8217;s automated testing tools, and you&#8217;ll learn about the philosophies and methodologies that they were designed to support, like unit testing and test-driven development. When you&#8217;re done, you&#8217;ll be able to produce thoroughly tested code faster and more easily than ever before, and you&#8217;ll be able to do it in a way that doesn&#8217;t distract you from your &#8220;real&#8221; programming.</p></blockquote>
<p>Packt also supplied a preview/sample chapter that you can download <a href='http://python.genedrift.org/wordpress/wp-content/uploads/2010/02/8846-python-testing-beginners-guide-sample-chapter-5-when-doctest-isnt-enough-unittest-to-the-rescue.pdf'>here</a>.</p>
<p>I hope to get a review ready by the end of the week. before the Ontario Institute of Cancer Research retreat, otherwise I will try to post a full review next week.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=dJv49-da6QI:OGuZNG8p4eg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=dJv49-da6QI:OGuZNG8p4eg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=dJv49-da6QI:OGuZNG8p4eg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=dJv49-da6QI:OGuZNG8p4eg:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=dJv49-da6QI:OGuZNG8p4eg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/dJv49-da6QI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2010/02/22/preview-of-python-testing-beginners-guide/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2010/02/22/preview-of-python-testing-beginners-guide/</feedburner:origLink></item>
		<item>
		<title>Preliminary review of Python for Bioinformatics by Sebastian Bassi</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/t56Lj4uzY_M/</link>
		<comments>http://python.genedrift.org/2010/01/03/preliminary-review-of-python-for-bioinformatics-by-sebastian-bassi/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 19:25:00 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[biopython]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=339</guid>
		<description>Let me start by saying that Python for Bioinformatics (Chapman &amp;#38; Hall/Crc Mathematical &amp;#38; Computational Biology) is a massive book, massive in a way that it contains a lot of material. I still didn&amp;#8217;t have enough time to check everything, but I&amp;#8217;m well into the first section of the book that gives an initial view [...]</description>
			<content:encoded><![CDATA[<p>Let me start by saying that <a href="http://www.amazon.com/gp/product/1584889292?ie=UTF8&amp;tag=genedrift-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1584889292">Python for Bioinformatics (Chapman &amp; Hall/Crc Mathematical &amp; Computational Biology)</a><img src="http://www.assoc-amazon.com/e/ir?t=genedrift-20&amp;l=as2&amp;o=1&amp;a=1584889292" alt="" style="border: medium none  ! important; margin: 0px ! important;" border="0" height="1" width="1"> is a massive book, massive in a way that it contains a lot of material. I still didn&#8217;t have enough time to check everything, but I&#8217;m well into the first section of the book that gives an initial view of Python and how to program it. </p>
<p>The initial section of the book is well written (I&#8217;m not going criticize the book in terms of good/poor English, as I&#8217;m not well qualified to do that), and gives a clear perspective on how to program Python for scientists, who are the main target demographic of the book. Of course, it always help to have some basic knowledge of command line shells, but the book also includes some explanations of IDLE and other Python-capable IDEs. I cannot say that I read this section with the enough care and attention, but what I can say is that you won&#8217;t miss a beat with PfB, as it has more material than I expected. I still have to start with the more advanced topics, like <a class="zem_slink freebase/en/biopython" href="http://biopython.org/" title="Biopython" rel="homepage">BioPython</a> and so forth, what I plan to do in the coming month, and as I don&#8217;t have a lot of experience with BioPython, I&#8217;m looking forward to it. </p>
<p>On the other hand I have a small-ish complaint, that maybe is more about style than substance. I don&#8217;t like the design of the book, the way the code interleaves with the text and the way the code explanations are presented. Most of the code blocks are followed by a careful explanation, but this explanation works as a figure label for the code block. That is quite annoying because there are too many stops in the text fluidity as one tends to lose attention to it (my case, not exactly everyone&#8217;s).  </p>
<p>Another minor detail is the use of &#8220;he&#8221; every time scientists are referred (one example is on page 3 on the second phrase of the introduction). The (politically) correct would be to use &#8220;he or she&#8221; or &#8220;she or he&#8221; (but that&#8217;s OK with me).</p>
<p>I will try to post more complete reviews of the sections that I don&#8217;t master. I would also like to thank Sebastian for sending me a copy of the book.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/99930d7a-5cef-4e74-b46c-71e031c4d627/" title="Reblog this post [with Zemanta]"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=99930d7a-5cef-4e74-b46c-71e031c4d627" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related more-info pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=t56Lj4uzY_M:w1bJYoHJ0oc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=t56Lj4uzY_M:w1bJYoHJ0oc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=t56Lj4uzY_M:w1bJYoHJ0oc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=t56Lj4uzY_M:w1bJYoHJ0oc:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=t56Lj4uzY_M:w1bJYoHJ0oc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/t56Lj4uzY_M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2010/01/03/preliminary-review-of-python-for-bioinformatics-by-sebastian-bassi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2010/01/03/preliminary-review-of-python-for-bioinformatics-by-sebastian-bassi/</feedburner:origLink></item>
		<item>
		<title>This is (more or less) the end</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/2eupHMmDQCY/</link>
		<comments>http://python.genedrift.org/2009/05/22/this-is-more-or-less-the-end/#comments</comments>
		<pubDate>Sat, 23 May 2009 02:19:01 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[The End]]></category>
		<category><![CDATA[end]]></category>
		<category><![CDATA[fim]]></category>
		<category><![CDATA[fin]]></category>
		<category><![CDATA[final]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=334</guid>
		<description>So, I&amp;#8217;m closing the blog, maybe for good, maybe not. I haven&amp;#8217;t been updating it and some other responsibilities are consuming my spare time. 
I would like to thank everyone that contributed, commented and read it. You have my deepest appreciation. My work is fulfilled if I helped at least one person  along the [...]</description>
			<content:encoded><![CDATA[<p>So, I&#8217;m closing the blog, maybe for good, maybe not. I haven&#8217;t been updating it and some other responsibilities are consuming my spare time. </p>
<p>I would like to thank everyone that contributed, commented and read it. You have my deepest appreciation. My work is fulfilled if I helped at least one person  along the way.</p>
<p>Cheers<br />
Paulo</p>
<p>PS: there&#8217;s the wiki, so register and help me improve it.<br />
PS II: sorry that I couldn&#8217;t finish the last project. Maybe some other time.</p>
<p><!--adsense--></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=2eupHMmDQCY:u2til5fnAmM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=2eupHMmDQCY:u2til5fnAmM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=2eupHMmDQCY:u2til5fnAmM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=2eupHMmDQCY:u2til5fnAmM:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=2eupHMmDQCY:u2til5fnAmM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/2eupHMmDQCY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/05/22/this-is-more-or-less-the-end/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/05/22/this-is-more-or-less-the-end/</feedburner:origLink></item>
		<item>
		<title>Wiki</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/jO9Nn9Oh6VE/</link>
		<comments>http://python.genedrift.org/2009/05/11/wiki/#comments</comments>
		<pubDate>Mon, 11 May 2009 22:43:31 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=294</guid>
		<description>Image via Wikipedia



I&amp;#8217;m slowly moving the posts from the blog to a wiki. It makes easier to display post series and allows people to modify/enhance/discuss.
The wiki address is http://wiki.genedrift.org.</description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl style="width: 310px;" class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:History_comparison_example.png"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/3/3d/History_comparison_example.png/300px-History_comparison_example.png" alt="History comparison reports highlight the chang..." title="History comparison reports highlight the chang..." width="300" height="263"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:History_comparison_example.png">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>I&#8217;m slowly moving the posts from the blog to a wiki. It makes easier to display post series and allows people to modify/enhance/discuss.</p>
<p>The wiki address is <a href="http://wiki.genedrift.org">http://wiki.genedrift.org</a>.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/ddf23630-4b1e-4cb1-8363-47b964768c18/" title="Reblog this post [with Zemanta]"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_a.png?x-id=ddf23630-4b1e-4cb1-8363-47b964768c18" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=jO9Nn9Oh6VE:tgx39xLZA9M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=jO9Nn9Oh6VE:tgx39xLZA9M:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=jO9Nn9Oh6VE:tgx39xLZA9M:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=jO9Nn9Oh6VE:tgx39xLZA9M:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=jO9Nn9Oh6VE:tgx39xLZA9M:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/jO9Nn9Oh6VE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/05/11/wiki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/05/11/wiki/</feedburner:origLink></item>
		<item>
		<title>Managing a simple database with Python, SQLite and wxPython, 8</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/8mqTN_35zw0/</link>
		<comments>http://python.genedrift.org/2009/04/22/managing-a-simple-database-with-python-sqlite-and-wxpython-8/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 15:04:17 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[wxPython]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=282</guid>
		<description>Image via Wikipedia



Thanks to the comments and suggestions to the last post, it&amp;#8217;s possible to make now a more pythonic and clearly generic database update class. Let&amp;#8217;s check how the &amp;#8220;generic&amp;#8221; update/edit entry function is currently:

def update_data(self, values_list):
    &amp;#039;&amp;#039;&amp;#039;edits and updates fields&amp;#039;&amp;#039;&amp;#039;

    if sys.platform == &amp;#039;darwin&amp;#039;:
    [...]</description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl style="width: 210px;" class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:Gene.png"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/0/07/Gene.png/200px-Gene.png" alt="Diagram of the location of introns and exons w..." title="Diagram of the location of introns and exons w..." height="160" width="200"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:Gene.png">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>Thanks to the comments and suggestions to the last post, it&#8217;s possible to make now a more pythonic and clearly generic database update class. Let&#8217;s check how the &#8220;generic&#8221; update/edit entry function is currently:</p>
<pre name="code" class="python">
def update_data(self, values_list):
    &#039;&#039;&#039;edits and updates fields&#039;&#039;&#039;

    if sys.platform == &#039;darwin&#039;:
        (cursor, database) = link_db(self.db_path)
    else:
        (cursor, database) = link_db()

    cursor.execute(&quot;UPDATE bac SET  projects = ?, comments = ?, temperature = ?, cell = ?, box = ?, tubes = ?, chromosome = ?, sdate = ?, clone = ?, source
	= ?, location1 = ?, startpos = ?, endpos = ?,
	gene = ?, genelink = ?, dnaex = ?, validation = ?, pcr = ?, refs = ?, antibiotic = ? WHERE idbac = ?&quot;,
    values_list[&#039;projects&#039;], values_list[&#039;comments&#039;], values_list[&#039;temperature&#039;], values_list[&#039;cell&#039;], values_list[&#039;box&#039;], values_list[&#039;tubes&#039;],
    values_list[&#039;chromo&#039;], values_list[&#039;date&#039;], values_list[&#039;clone&#039;], values_list[&#039;source&#039;], values_list[&#039;location&#039;], values_list[&#039;start&#039;]
    values_list[&#039;end&#039;], values_list[&#039;gene&#039;], values_list[&#039;genelink&#039;], values_list[&#039;dna&#039;], values_list[&#039;validation&#039;], values_list[&#039;pcr&#039;],
    values_list[&#039;refs&#039;], values_list[&#039;antibiotic&#039;], values_list[&#039;idbac&#039;]))

    database.commit()
    database.close()
</pre>
<p>which is really ugly and, although it works, is not really useful outside this small project. Based on the comments the best option was to use placeholders and a dictionary, similar to the approach used on the insert data function. Pre-formatting a string to have both the field name to be updated and a placeholder (for instance <code>:idbac</code>) that will receive the values</p>
<pre name="code" class="python">
update = &#039;,&#039;.join([&#039;%s=:%s&#039; % (y, y) for y in values_list])
</pre>
<p>where update is the string we want and values_list is the dictionary with all the key-value pairs. I tried this approach, using this structure in the generic function, but then I decided that the best alternative was to put this <code>join</code> in the derived class function and pre-populate the string with the values and then send this string directly to the update function. In the end I opted to use this </p>
<pre name="code" class="python">
update = &#039;,&#039;.join([&#039;%s=\&quot;%s\&quot;&#039; % (y, values_list[y]) for y in values_list])
</pre>
<p>The latter is slightly different to what was suggested. The original one would create a tuple with the keys from the dictionary, making for instance <code>sdate:sdate</code>. With all these place holders just pass the dictionary and you have all the values inserted. This would be handy if the insert string was being created on the &#8220;generic&#8221; function. If we move this to the derived class, we can use the the alternative, keeping in mind that the values parsed should be surrounded by quotes, otherwise the SQL UPDATE statement will have problems with spaces and other foreign characters that should not be there. So instead of placeholders we will have <code>gene:"<a class="zem_slink" href="http://en.wikipedia.org/wiki/PTEN_%28gene%29" title="PTEN (gene)" rel="wikipedia">PTEN</a>"</code> and we can attache this joined string to the actual commands. We then can move all the machinery from the &#8220;generic&#8221; function that can be written as</p>
<pre name="code" class="python">
def update_data(self, update_string):
    &#039;&#039;&#039;edits and updates fields&#039;&#039;&#039;

    if sys.platform == &#039;darwin&#039;:
        (cursor, database) = link_db(self.db_path)
    else:
        (cursor, database) = link_db()
    cursor.execute(update_string)

    database.commit()
    database.close()
</pre>
<p>That&#8217;s it, very elegant (we will see the derived class in the next post). And finishing our generic class, we would need a delete function, so the user can eliminate entries that he/she doesn&#8217;t want anymore. It&#8217;s also a very simple function</p>
<pre name="code" class="python">
def delete_data(self, delete_string):
    &#039;&#039;&#039;deletes one field&#039;&#039;&#039;

    if sys.platform == &#039;darwin&#039;:
        (cursor, database) = link_db(self.db_path)
    else:
        (cursor, database) = link_db()
    cursor.execute(delete_string)

    database.commit()
    database.close()
</pre>
<p>We will check the delete string next time. Again, I would like to thank for all the comments, it has been really helpful for me.</p>
<p>Previously in the series:<br />
<a href="http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/">Part 1</a><br />
<a href="http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/">Part 2</a><br />
<a href="http://python.genedrift.org/2009/02/18/managing-a-simple-database-with-python-sqlite-and-wxpython-3/">Part 3</a><br />
<a href="http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-4/">Part 4</a><br />
<a href="http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-5/">Part 5</a><br />
<a href="http://python.genedrift.org/2009/03/31/managing-a-simple-database-with-python-sqlite-and-wxpython-6/">Part 6</a><br />
<a href="http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/">Part 7</a></p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/e8dc77f5-e3de-4d4f-8ec1-8c0006225743/" title="Reblog this post [with Zemanta]"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_a.png?x-id=e8dc77f5-e3de-4d4f-8ec1-8c0006225743" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=8mqTN_35zw0:Q_DgUIbt6A4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=8mqTN_35zw0:Q_DgUIbt6A4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=8mqTN_35zw0:Q_DgUIbt6A4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=8mqTN_35zw0:Q_DgUIbt6A4:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=8mqTN_35zw0:Q_DgUIbt6A4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/8mqTN_35zw0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/04/22/managing-a-simple-database-with-python-sqlite-and-wxpython-8/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/04/22/managing-a-simple-database-with-python-sqlite-and-wxpython-8/</feedburner:origLink></item>
		<item>
		<title>Managing a simple database with Python, SQLite and wxPython, 7 (includes a question)</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/nPwfjuPGLhc/</link>
		<comments>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 17:21:59 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[wxPython]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/</guid>
		<description>And we&amp;#8217;re back. After a couple of weeks of inactivity we will get back to our small soap-opera pf Python, wxPython and SQLite. Continuing in our database management code let&amp;#8217;s check two other functions that changed since our first inception of the code. The first one is the insert_data function that looks like this now

def [...]</description>
			<content:encoded><![CDATA[<p>And we&#8217;re back. After a couple of weeks of inactivity we will get back to our small soap-opera pf Python, wxPython and SQLite. Continuing in our database management code let&#8217;s check two other functions that changed since our first inception of the code. The first one is the <code>insert_data</code> function that looks like this now</p>
<pre name="code" class="python">
def insert_data(self, values_list, insert_string):
    &#039;&#039;&#039;inserts data in the database&#039;&#039;&#039;

    if sys.platform == &#039;darwin&#039;:
        (cursor, database) = link_db(self.db_path)
    else:
        (cursor, database) = link_db()

    cursor.execute(insert_string % self.table_name, values_list)

    database.commit()
    database.close()
</pre>
<p>Basically no changes, apart from the obvious check for the current running operating system, which was explained in the last post. The other function to check is the <code>update_data</code>. This function is new and it wasn&#8217;t in the first version, but as it can be seen it has a problem being a &#8220;generic&#8221; function, because it contains information pertained to the table and database being used in the interface. This function basically received information that needs to be updated in the table&#8217;s fields and by using the SQL <code>UPDATE ... SET</code> edits and updates data in the changed fields. I have tried several different syntaxes to make the execute generic, mainly trying to pre-format the string without success. IF anyone reading this can help, I&#8217;d appreciate.</p>
<pre name="code" class="python">
def update_data(self, values_list):
    &#039;&#039;&#039;edits and updates fields&#039;&#039;&#039;

    if sys.platform == &#039;darwin&#039;:
        (cursor, database) = link_db(self.db_path)
    else:
        (cursor, database) = link_db()

    cursor.execute(&quot;UPDATE bac SET  projects = ?, comments = ?, temperature = ?, cell = ?, box = ?, tubes = ?, chromosome = ?, sdate = ?, clone = ?, source = ?, location1 = ?, startpos = ?, endpos = ?,
	gene = ?, genelink = ?, dnaex = ?, validation = ?, pcr = ?, refs = ?, antibiotic = ? WHERE idbac = ?&quot;,
    values_list[&#039;projects&#039;], values_list[&#039;comments&#039;], values_list[&#039;temperature&#039;], values_list[&#039;cell&#039;], values_list[&#039;box&#039;], values_list[&#039;tubes&#039;],
    values_list[&#039;chromo&#039;], values_list[&#039;date&#039;], values_list[&#039;clone&#039;], values_list[&#039;source&#039;], values_list[&#039;location&#039;], values_list[&#039;start&#039;],  values_list[&#039;end&#039;],
    values_list[&#039;gene&#039;], values_list[&#039;genelink&#039;], values_list[&#039;dna&#039;], values_list[&#039;validation&#039;], values_list[&#039;pcr&#039;],
    values_list[&#039;refs&#039;], values_list[&#039;antibiotic&#039;], values_list[&#039;idbac&#039;]))

    database.commit()
    database.close()
</pre>
<p>Anyway, I will explain the logic of the command (OK for a stop gap, but not as a definite solution). <code>values_list</code> is a dictionary that is passed to the function and contains the field names as keys and the new/changed information as values. The execute method simply parses the values from each key in the update string which is then sent to the database and table to be changed. Everything is committed and the database is closed.</p>
<p>As this is a &#8220;generic&#8221; function from a &#8220;generic&#8221; class the ideal scenario would be to the function to receive a pre-formatted string with all the information, as in the insert data function, and update the information in the database. </p>
<p>I would like to thank in advance anyone that can comment on this. Next time we will continue checking the generic class and finalize this part in order to start with the interface build process.</p>
<p>Previously in the series:<br />
<a href="http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/">Part 1</a><br />
<a href="http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/">Part 2</a><br />
<a href="http://python.genedrift.org/2009/02/18/managing-a-simple-database-with-python-sqlite-and-wxpython-3/">Part 3</a><br />
<a href="http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-4/">Part 4</a><br />
<a href="http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-5/">Part 5</a><br />
<a href="http://python.genedrift.org/2009/03/31/managing-a-simple-database-with-python-sqlite-and-wxpython-6/">Part 6</a></p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/d0bb5d11-6f9d-8521-9a2f-6cd30868e375/" title="Reblog this post [with Zemanta]"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_a.png?x-id=d0bb5d11-6f9d-8521-9a2f-6cd30868e375" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=nPwfjuPGLhc:XvwrmMLHOCE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=nPwfjuPGLhc:XvwrmMLHOCE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=nPwfjuPGLhc:XvwrmMLHOCE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=nPwfjuPGLhc:XvwrmMLHOCE:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=nPwfjuPGLhc:XvwrmMLHOCE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/nPwfjuPGLhc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/</feedburner:origLink></item>
		<item>
		<title>Managing a simple database with Python, SQLite and wxPython, 6</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/SteRPKO_Rec/</link>
		<comments>http://python.genedrift.org/2009/03/31/managing-a-simple-database-with-python-sqlite-and-wxpython-6/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 17:06:08 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[wxPython]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=276</guid>
		<description>Image via Wikipedia



Let&amp;#8217;s get back to our SQLite and wxPython project. We haven&amp;#8217;t seen anything on wxPython yet, and we will check the interface only on the next post. For now, let&amp;#8217;s see some extra code added to the SQLite access class. Remember that we have a generic class and one class derived from it [...]</description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl style="width: 212px;" class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:SQLite_Logo_4.png"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/SQLite_Logo_4.png/202px-SQLite_Logo_4.png" alt="The :en:SQLite logo as of 2007-12-15" title="The :en:SQLite logo as of 2007-12-15" height="60" width="202"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:SQLite_Logo_4.png">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>Let&#8217;s get back to our SQLite and wxPython project. We haven&#8217;t seen anything on wxPython yet, and we will check the interface only on the next post. For now, let&#8217;s see some extra code added to the SQLite access class. Remember that we have a generic class and one class derived from it that would work on accessing specific tables in our database file.</p>
<p>When we last covered the db access routines, there was no search for an entry (the function returned everything in the table no matter what), there was no update function in case someone would want to modify an entry and there was no delete method if you wanted to delete something. In the meantime, I added all of this functionality (and some other) to the generic class and extended it to the class derived from it. Let&#8217;s check how the generic class is now (you will notice that there is an issue in one of the methods, if someone can help me I&#8217;d appreciate. More details later.)</p>
<pre name="code" class="python">
class DB_Generic():
    &#039;&#039;&#039;generic class to add DB functionality&#039;&#039;&#039;
    def __init__(self, table_name, db_path = &#039;&#039;):
        #par= name of the table to be used
        self.table_name = table_name
        if len(db_path) &amp;gt; 0:
            self.db_path = db_path
            print db_path

    def get_data_generic(self, range = 1, bac_to_get = 0):
        &#039;&#039;&#039;gets the data from the database&#039;&#039;&#039;       

        if sys.platform == &#039;darwin&#039;:
            (cursor, database) = link_db(self.db_path)
        else:
            (cursor, database) = link_db()

        if range == 1:
            cursor.execute(&quot;&quot;&quot;SELECT * FROM %s&quot;&quot;&quot; % self.table_name)
        elif range == 2:
            cursor.execute(&quot;&quot;&quot;SELECT * FROM %s where idbac = %d&quot;&quot;&quot; % (self.table_name, bac_to_get))

        table_data = cursor.fetchall()
        raw_data = []
        for i in table_data:
            raw_data.append(list(i))

        self.table_data = raw_data
        database.close()

    def insert_data(self, values_list, insert_string):
        &#039;&#039;&#039;inserts data in the database&#039;&#039;&#039;

        if sys.platform == &#039;darwin&#039;:
            (cursor, database) = link_db(self.db_path)
        else:
            (cursor, database) = link_db()

        cursor.execute(insert_string % self.table_name, values_list)

        database.commit()
        database.close()

    def update_data(self, values_list):
        &#039;&#039;&#039;edits and updates fields&#039;&#039;&#039;

        if sys.platform == &#039;darwin&#039;:
            (cursor, database) = link_db(self.db_path)
        else:
            (cursor, database) = link_db()

        #change this to generic!!!!!!!!!!!!
        cursor.execute(&quot;UPDATE bac SET  projects = ?, comments = ?, temperature = ?, cell = ?, box = ?, tubes = ?, chromosome = ?, sdate = ?, clone = ?, source = ?, location1 = ?, startpos = ?, endpos = ?,
		gene = ?, genelink = ?, dnaex = ?, validation = ?, pcr = ?, refs = ?, antibiotic = ? WHERE idbac = ?&quot;,
        (values_list[&#039;projects&#039;], values_list[&#039;comments&#039;], values_list[&#039;temperature&#039;], values_list[&#039;cell&#039;], values_list[&#039;box&#039;], values_list[&#039;tubes&#039;],
         values_list[&#039;chromo&#039;], values_list[&#039;date&#039;], values_list[&#039;clone&#039;], values_list[&#039;source&#039;], values_list[&#039;location&#039;], values_list[&#039;start&#039;], values_list[&#039;end&#039;],
         values_list[&#039;gene&#039;], values_list[&#039;genelink&#039;], values_list[&#039;dna&#039;], values_list[&#039;validation&#039;], values_list[&#039;pcr&#039;],
         values_list[&#039;refs&#039;], values_list[&#039;antibiotic&#039;], values_list[&#039;idbac&#039;]))

        database.commit()
        database.close()

    def delete_data(self, delete_string):
        &#039;&#039;&#039;deletes one field&#039;&#039;&#039;

        if sys.platform == &#039;darwin&#039;:
            (cursor, database) = link_db(self.db_path)
        else:
            (cursor, database) = link_db()
        cursor.execute(delete_string)

        database.commit()
        database.close()
</pre>
<p>In the next couple of posts we&#8217;ll dissect each function and see what&#8217;s going on. The class definition wasn&#8217;t changed, so we start with <code>get_data_generic</code></p>
<pre name="code" class="python">
def get_data_generic(self, range = 1, bac_to_get = 0):
	&#039;&#039;&#039;gets the data from the database&#039;&#039;&#039;       

	if sys.platform == &#039;darwin&#039;:
		(cursor, database) = link_db(self.db_path)
	else:
		(cursor, database) = link_db()

	if range == 1:
		cursor.execute(&quot;&quot;&quot;SELECT * FROM %s&quot;&quot;&quot; % self.table_name)
	elif range == 2:
		cursor.execute(&quot;&quot;&quot;SELECT * FROM %s where idbac = %d&quot;&quot;&quot; % (self.table_name, bac_to_get))

	table_data = cursor.fetchall()
	raw_data = []
	for i in table_data:
		raw_data.append(list(i))

	self.table_data = raw_data
	database.close()
</pre>
<p>The first difference we notice here is the <code>sys.platform</code> usage. This is required if we intend to package our application as an OS X app, using py2app. When a Python/wxPython application is packaged in OS X, the actual application executable is inside the a directory named after the application (or whatever you set up). In our case here we don&#8217;t provide a way for the Python script to receive the path and name for the database on a command line, as we expect it to be in the executable&#8217;s current directory. Because of that we need to provide a &#8220;config&#8221; file (in our case here a one-line text file with the database path) inside the application wrapper, something we will see in the end of the series.</p>
<p>Another modification here is the <code>range</code> parameter and the addition of the <code>bac_to_get</code> parameter. Notice that both parameters have a value assigned to it. This means that they are optional, the function&#8217;s call can pass them or not. If it doesn&#8217;t pass, their value will be the one assigned on the function declaration. So, here if we are interested in getting all bacs, <code>range</code> will have the value of 1 and we don&#8217;t need to worry about it. If we want an specific bac we will pass <code>range</code> as 2 and then pass the <code>bac_to_get</code> ID to be returned. </p>
<p>A final change/addition is that we added a new select statement for the cases when <code>range</code> equals 2. This time we are adding the bac ID to be returned.</p>
<p>Previously in the series:<br />
<a href="http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/">Part 1</a><br />
<a href="http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/">Part 2</a><br />
<a href="http://python.genedrift.org/2009/02/18/managing-a-simple-database-with-python-sqlite-and-wxpython-3/">Part 3</a><br />
<a href="http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-4/">Part 4</a><br />
<a href="http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-5/">Part 5</a></p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/ea53b728-33c6-47db-aabf-0c695dcfabd8/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_a.png?x-id=ea53b728-33c6-47db-aabf-0c695dcfabd8" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=SteRPKO_Rec:_-yakNEoXxo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=SteRPKO_Rec:_-yakNEoXxo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=SteRPKO_Rec:_-yakNEoXxo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=SteRPKO_Rec:_-yakNEoXxo:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=SteRPKO_Rec:_-yakNEoXxo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/SteRPKO_Rec" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/03/31/managing-a-simple-database-with-python-sqlite-and-wxpython-6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/03/31/managing-a-simple-database-with-python-sqlite-and-wxpython-6/</feedburner:origLink></item>
		<item>
		<title>RoR commits</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/tdYtipc1aDs/</link>
		<comments>http://python.genedrift.org/2009/03/15/ror-commits/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 16:59:18 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=272</guid>
		<description>Just illustrating my point (or lack of), an animation about the commits of RoR to its repository. Notice the jump after it was migrated to Github
Ruby on Rails from Ilya Grigorik on Vimeo.
Sorry for the non-Python post.</description>
			<content:encoded><![CDATA[<p>Just illustrating my point (or lack of), an animation about the commits of RoR to its repository. Notice the jump after it was migrated to Github</p>
<p><object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=2979844&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=2979844&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object><br /><a href="http://vimeo.com/2979844">Ruby on Rails</a> from <a href="http://vimeo.com/user1211508">Ilya Grigorik</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Sorry for the non-Python post.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=tdYtipc1aDs:42WUaZl19W8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=tdYtipc1aDs:42WUaZl19W8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=tdYtipc1aDs:42WUaZl19W8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=tdYtipc1aDs:42WUaZl19W8:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=tdYtipc1aDs:42WUaZl19W8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/tdYtipc1aDs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/03/15/ror-commits/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/03/15/ror-commits/</feedburner:origLink></item>
		<item>
		<title>BioPython and CVS</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/YorBykGxURk/</link>
		<comments>http://python.genedrift.org/2009/03/13/biopython-and-cvs/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 19:25:38 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[off topic]]></category>
		<category><![CDATA[biopython]]></category>
		<category><![CDATA[CVS]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=266</guid>
		<description>Image via Wikipedia



I start this post with an apology. I usually don&amp;#8217;t rant or vent here, which are feelings that I usually reserve to my personal blog.
I don&amp;#8217;t use BioPython, never used it. I have it installed in my systems, but I never wrote a piece of code importing BioPython routines. But I subscribe to [...]</description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl style="width: 135px;" class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://en.wikipedia.org/wiki/Image:Bazaar_logo_%28software_product%29.svg"><img src="http://upload.wikimedia.org/wikipedia/en/thumb/c/c1/Bazaar_logo_%28software_product%29.svg/125px-Bazaar_logo_%28software_product%29.svg.png" alt="Bazaar" title="Bazaar" height="128" width="125"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://en.wikipedia.org/wiki/Image:Bazaar_logo_%28software_product%29.svg">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>I start this post with an apology. I usually don&#8217;t rant or vent here, which are feelings that I usually reserve to my personal blog.</p>
<p>I don&#8217;t use BioPython, never used it. I have it installed in my systems, but I never wrote a piece of code importing BioPython routines. But I subscribe to their mailing lists, both user and developer. I maybe have written once to the list, and I just follow the discussions there. </p>
<p>Since last year one of the main topics has been the possibility of moving BioPython from CVS to another version control system. Yes, you read it right. It&#8217;s 2009 and BioPython uses CVS and their version control system. Soon, CVS will be like typewriters and LPs to young developers. Last stable release of CVS was sometime in 2005, what in interwebs time is equivalent to something like 1972. Since 2005, Subversion has taken the world of version control by storm, and Git is getting also very strong, not to mention Bazaar, Darcs, Mercurial and some others that I might not be aware of.</p>
<p>This is a discussion that have been dragging for sometime in the list. And it&#8217;s a shame, a clear lack of leadership from whoever is (not) leading the project. BioRuby is Git, BioPerl SVN and BioPython is CVS, because they &#8220;need to care for the legacy developers&#8221;. It&#8217;s like MSFT keeping two copies of the Notepad executable because they needed to cater to legacy applications, but with a different scale of course. With the current Python steam in the non-bioinformatics and bioinformatics community is very sad to see BioPython not evolving (before you ask me, no, I&#8217;m not interested in helping, not the way things are now). Perl which is language forever-in-waiting for its holy grail (Perl 6) has a strong community behind it, and more important an excellent leadership, that&#8217;s not scare of making decisions.</p>
<p>So, if you&#8217;re still using CVS, it&#8217;s 2009!</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/06117f0a-6d25-497d-b686-1a96e8a7d81c/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=06117f0a-6d25-497d-b686-1a96e8a7d81c" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=YorBykGxURk:cTUAps0n5jo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=YorBykGxURk:cTUAps0n5jo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=YorBykGxURk:cTUAps0n5jo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=YorBykGxURk:cTUAps0n5jo:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=YorBykGxURk:cTUAps0n5jo:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/YorBykGxURk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/03/13/biopython-and-cvs/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/03/13/biopython-and-cvs/</feedburner:origLink></item>
		<item>
		<title>Managing a simple database with Python, SQLite and wxPython, 5</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/Wkmik3NTYGg/</link>
		<comments>http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-5/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 00:23:42 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[wxPython]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=253</guid>
		<description>We have seen how to connect, get and insert data (at least theoretically) in the database. Now, a little not about the SQL engine of choice here: SQLite. SQLite databases have the main characteristic that they are self-contained files. Also it does not require an installation, works without a server and works pretty well in [...]</description>
			<content:encoded><![CDATA[<p>We have seen how to connect, get and insert data (at least theoretically) in the database. Now, a little not about the SQL engine of choice here: SQLite. SQLite databases have the main characteristic that they are self-contained files. Also it does not require an installation, works without a server and works pretty well in most operating systems. </p>
<p>Basically for the type of application we&#8217;re developing here, SQLite seems ideal. It eliminates a lot of infrastructure that would be needed if we were working with MySQL or postgresql. We don&#8217;t need a server or know how to configure users or manage the databases and tables. All we need is contained in a single file that can be transported from system to system and can be accesed from the computers used in the lab, mainly XP and OS X. Also some web frameworks (Rails and <a class="zem_slink" href="http://www.djangoproject.com" title="Django (web framework)" rel="homepage">Django</a>, for instance) can use SQLite, so in the end we can have a desktop application and a web application accessing the same file without extra configuration.</p>
<p>Now the database created for this application has 8 tables and almost no relationships among them. SQLite allows the creation of relationships but in our case only a couple of cases were required. For the table we are using at the moment (bac) there is no need for relationships, although there are some fileds that can benefit from a more relational structure. Also SQLite don&#8217;t have the same data types that are found on the bigger SQL engines. All values can be stored as text, integer, real (floating point numbers), null and blob (verbose type, what you store is what you get). As actual types, you can set columns as Boolean and Data for instance and SQLite will understand them. If you have no experience in creating databases, let&#8217;s check again the table we are using in this small project. First, I would recommend the use of some SQLite database editor. You can find pretty good ones for any computer system and there is even a Firefox extension that allows you to edit some files. Editors make it easier to generate the SQL table creation scripts and make easier to visualize what we are doing.</p>
<p>So, the table bac looks like </p>
<pre name="code" class="sql">
CREATE TABLE bac
(idbac INTEGER PRIMARY KEY,
clone Text,
sdate Date,
source Text,
gene Text,
chromosome Text,
startpos Integer,
endpos Integer,
antibiotic Text,
location1 Text,
temperature Integer,
tubes Integer,
box Integer,
cell Integer,
dnaex Boolean,
validation Boolean,
pcr Boolean,
projects Text,
comments Text,
genelink Text,
refs Text);
</pre>
<p>If you go back to our last post, you will see that in the insert statement there is no mention of the <code>idbac</code> field. We don&#8217;t actually insert ay value there, the values that populate this field are created automatically. And <code>idbac</code> is our primary key, meaning it&#8217;s the unique identifier of each bac we insert in this table. And in SQLite a integer primary key is automatically incremented whenever values are inserted in the table. So our first insertion will create <code>idbac</code> 1, the second will create <code>idbac</code> 2 and so on. </p>
<p>I&#8217;m not going to enter in details about database development and administration, but it&#8217;s usual and safe to create tables with an auto-incremental integer primary keys. These fields, apart from make it easier t identify records, make access to such records faster and are great when relationships among tables are set. Let&#8217;s say that we had a column user in our bac table. And let&#8217;s say we had an user table with two columns: user_id and name, user_id being a auto-increment primary key. The user column in back could be linked with the user_id column in the user table, in what we call a one-to-many relationship (one user can insert as many bacs as he wants). One day we want to know who is actually working in the lab and we want to check how many bacs were catalogued by each user. We can easily search the user table and extract information from bacs at the same time thanks to the relationship between the tables. And the result should be returned quite quickly, as we are only searching integers.</p>
<p>All the other fields/columns in our table are straightforward to understand. They are basically related to the type of data they need to store. <code>validation</code> is a boolean because the bac might have been validated or not, just as <code>danex</code> (DNA extraction). At the same time, the number of tubes stored in the freezer will always be an integer. So, why does temperature is an integer? Because we can only store bacs in two type of freezers: -80 (ultra freezers) or -20 (regular freezer that we can have at home), and we don&#8217;t need to worry about fractional numbers. </p>
<p>Well, this is a very short and limited explanation of tables and SQLite. The web is full of resources about it, so next time we will get back to Python.</p>
<p>Previously in the series:<br />
<a href="http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/">Part 1</a><br />
<a href="http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/">Part 2</a><br />
<a href="http://python.genedrift.org/2009/02/18/managing-a-simple-database-with-python-sqlite-and-wxpython-3/">Part 3</a><br />
<a href="http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-4/">Part 4</a></p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/4be1389f-5603-4b76-961b-b79d985066cc/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=4be1389f-5603-4b76-961b-b79d985066cc" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=Wkmik3NTYGg:6tCWERJRlfI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=Wkmik3NTYGg:6tCWERJRlfI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=Wkmik3NTYGg:6tCWERJRlfI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=Wkmik3NTYGg:6tCWERJRlfI:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=Wkmik3NTYGg:6tCWERJRlfI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/Wkmik3NTYGg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-5/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-5/</feedburner:origLink></item>
		<item>
		<title>Managing a simple database with Python, SQLite and wxPython, 4</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/BN38F0oFV2o/</link>
		<comments>http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-4/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 16:58:09 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[wxPython]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=250</guid>
		<description>Image via Wikipedia



Let&amp;#8217;s continue building our small db app. As mentioned in the previous post we need now to instantiate a specific class from our generic SQLite access class. In order to do this we just have to declare a new class and its type will be DB_Generic.  

class Bac(DB_Generic)

This new class is called [...]</description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl style="width: 212px;" class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:SQLite_Logo_4.png"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/SQLite_Logo_4.png/202px-SQLite_Logo_4.png" alt="The :en:SQLite logo as of 2007-12-15" title="The :en:SQLite logo as of 2007-12-15" height="60" width="202"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:SQLite_Logo_4.png">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>Let&#8217;s continue building our small db app. As mentioned in the previous post we need now to instantiate a specific class from our generic <a class="zem_slink" href="http://sqlite.org/" title="SQLite" rel="homepage">SQLite</a> access class. In order to do this we just have to declare a new class and its type will be <code>DB_Generic</code>.  </p>
<pre name="code" class="python">
class Bac(DB_Generic)
</pre>
<p>This new class is called Bac because it&#8217;s linked to the bac table in our database file. A side note, bacs are Bacterial Artificial Chromosomes and are used in different molecular biology techniques. Mainly in our case bacs have incorporated human DNA segments and are used as probes for deletion, duplication, etc studies.</p>
<p>Now, back to our Python code, as soon as we instantiate our generic class, the object (class) we create has access to all methods and functions from the parent class (by using <code>self</code>), but we still need to create functionality and expose other methods that can be accessed from a class object derived from <code>Bac</code>.</p>
<p>Our instantiated class will be </p>
<pre name="code" class="python">
class Bac(DB_Generic):
    def __init_(self):
        self.bac_data = []
        DB_Generic.__init__(self, &#039;bac&#039;)

    def get_data(self):
        return self.get_data_generic()

    def load_data(self):
        pass

    def add_data(self, values_list):
        insert_string = &quot;&quot;&quot;INSERT INTO %s (projects, comments, temperature, cell, box, tubes, chromosome, sdate, clone, source,
        location1, startpos, endpos, gene, genelink, dnaex, validation, pcr, refs, antibiotic)
        VALUES (:projects, :comments, :temperature, :cell, :box, :tubes, :chromo, :date, :clone, :source, :location, :start,
        :end, :gene, :genelink, :dna, :validation, :pcr, :refs, :antibiotic)&quot;&quot;&quot;
        self.insert_data(values_list, insert_string)
</pre>
<p>Pretty simple so far, as we don&#8217;t have a lot of declared methods. Let&#8217;s check one by one</p>
<pre name="code" class="python">
def __init_(self):
    DB_Generic.__init__(self, &#039;bac&#039;)
</pre>
<p>The only line is the initialization required by the parent class, and we&#8217;re passing the value that is the table to be accessed. 	</p>
<pre name="code" class="python">
def get_data(self):
	self.get_data_generic()
	return self.table_data
</pre>
<p>The <code>get_data</code> function returns the all elements in our table (So far, we still don&#8217;t have an elegant range option) and has one too many lines in it. We will get rid of some useless code here in the future, but it&#8217;s OK the way it is. Basically this code access the <code>get_data_generic</code> from the parent class and gets all the values stored in the table. </p>
<p>There is a function not yet complete that will load data, and will be used in the future. And the last one is the function that actually adds the data to the table with a SQL insert statement</p>
<pre name="code" class="python">
def add_data(self, values_list):
	insert_string = &quot;&quot;&quot;INSERT INTO %s (projects, comments, temperature, cell, box, tubes, chromosome, sdate, clone, source,
	location1, startpos, endpos, gene, genelink, dnaex, validation, pcr, refs, antibiotic)
	VALUES (:projects, :comments, :temperature, :cell, :box, :tubes, :chromo, :date, :clone, :source, :location, :start,
	:end, :gene, :genelink, :dna, :validation, :pcr, :refs, :antibiotic)&quot;&quot;&quot;
	self.insert_data(values_list, insert_string)
</pre>
<p>In this function, we have a large string with all the SQL insert options. A SQL insert statement is divided into two parts, one where you point where to insert the values and another where you input the values. Usually simple insert statements will have this structure</p>
<pre name="code" class="sql">
INSERT INTO my_table_name (table_column1, table_column2) VALUES (value1, value2);
</pre>
<p>So, we have the table we want to insert values into, its columns and the values we set for each column. After executed this will put value1 into table_column1 and value2 into table_column2. The actual syntax can vary a bit for different SQL engines but the structure is identical in most cases. Pretty simple.</p>
<p>For our insert string above, there are some aspects to call for attention. Again note the triple quote around the statement. This make sure that it&#8217;s not changed and parsed correctly. We also have a <code>%s</code> for the table name, which will be parsed by the parent class function that insert values, then a list of all the tables in the database and then a list of values to insert. And why the values to be inserted have this <code>:value</code> syntax? Because we are previously storing the values in a dictionary, and the &#8220;:&#8221; indicates that we need to get the dictionary value for the correspondent key.</p>
<p>The insert string, and the list of values (actually a dictionary, not the best variable/object name I must admit) is then sent to the parent class to be inserted. Storing the values to be inserted in a dictionary is OK for a one time insert case, where the values are obtained from a form. If you are parsing a large CSV or TSV file, ideally it&#8217;s better to put it in a list, and dump them at the same time.</p>
<p>We&#8217;re progressing. Next we will take a look on some simple SQL table structure and then move to create the form to insert the values and check the table.</p>
<p>Previously in the series:<br />
<a href="http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/">Part 1</a><br />
<a href="http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/">Part 2</a><br />
<a href="http://python.genedrift.org/2009/02/18/managing-a-simple-database-with-python-sqlite-and-wxpython-3/">Part 3</a></p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/4c2737a4-f1de-46bf-ae53-c5de040daf97/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=4c2737a4-f1de-46bf-ae53-c5de040daf97" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<p>evi</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=BN38F0oFV2o:ZnT5OJel2iw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=BN38F0oFV2o:ZnT5OJel2iw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?i=BN38F0oFV2o:ZnT5OJel2iw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=BN38F0oFV2o:ZnT5OJel2iw:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?a=BN38F0oFV2o:ZnT5OJel2iw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/BeginningPythonForBioinformatics?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/BN38F0oFV2o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/03/02/managing-a-simple-database-with-python-sqlite-and-wxpython-4/</feedburner:origLink></item>
		<item>
		<title>Why do I blog. Or: Science Blogging, is it worth?</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/uCZ0gw6zGUg/</link>
		<comments>http://python.genedrift.org/2009/02/21/why-do-i-blog-or-science-blogging-is-it-worth/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 23:18:24 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=248</guid>
		<description>Image via Wikipedia



Mirroring the post that appeared on Blind.Scientist
Some time ago there was a meme about science blogging and one of the questions were &amp;#8220;why do you blog&amp;#8221;. Well, I do it because of the &amp;#8220;Nada Surf effect&amp;#8221;. You don&amp;#8217;t know the &amp;#8220;Nada Surf effect&amp;#8221;? Pity you weren&amp;#8217;t in Washington, DC 2001. 
In March or [...]</description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl style="width: 212px;" class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://en.wikipedia.org/wiki/Image:Nshl.jpg"><img src="http://upload.wikimedia.org/wikipedia/en/thumb/6/61/Nshl.jpg/202px-Nshl.jpg" alt="High/Low album cover" title="High/Low album cover" height="201" width="202"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://en.wikipedia.org/wiki/Image:Nshl.jpg">Wikipedia</a></dd>
</dl>
</div>
</div>
<p><i>Mirroring the post that appeared on Blind.Scientist</i></p>
<p>Some time ago there was a meme about science blogging and one of the questions were &#8220;why do you blog&#8221;. Well, I do it because of the &#8220;<a class="zem_slink" href="http://www.nadasurf.com/" title="Nada Surf" rel="homepage">Nada Surf</a> effect&#8221;. You don&#8217;t know the &#8220;Nada Surf effect&#8221;? Pity you weren&#8217;t in Washington, DC 2001. </p>
<p>In March or April of 2001, Nada Surf played a concert there. It was a small bar on 14th Street W, close to the more famous Black Cat. It was a spring night, I was with a couple of Dutch friends that had told me about the concert, if I&#8217;m not wrong, a couple of days before. It was also mid-week, so you wouldn&#8217;t expect big crowds in most concerts. We left ISH around 7 pm, with spare time for the 9 pm concert. We didn&#8217;t know the venue, we got there and it was empty, just a couple of souls at the bar. We sat and for about an hour we were pondering if we were in the right place, until a guy came and asked if we were staying for the concert. We said yes, paid th US$ 7.50 of the admittance and sipped our beers waiting for the opening act. Soon after we paid, a van parked outside and some guys started bringing music equipment inside. At that time there must have been around 20 people there. The van guys set the instruments, wasted 5 minutes soundchecking, and started. IT was Ashtray Babyhead. </p>
<p>They played for 40 minutes and as fast as they arrived they left. Another van parked outside and this time Nada Surf members started unloading and setting up the stage. Now roadies. OK, maybe one guy helped, but I&#8217;m getting old and the memory sometimes falters. At that point in time, almost 9 pm, the number of brave souls was at 50. They played as they were playing for 50.000 people in Wembley. Nice set, great songs, unforgettable night. After the show, they sold CDs at the usual after-show gathering, we talked about New York, Brazil and feijoada. </p>
<p>And why do I call it the &#8220;Nada Surf effect&#8221;? A band that used to play for thousands of people in festivals and stadiums, had a number one video on MTV (Popular), played in a midweek night in a small bar in Washington, DC as it was the band farewell. Every fan that night felt that they were the most important one, maybe even the only one.</p>
<p>And this type of example is the one that brings me to write this, and to write Beginning Python for Bioinformatics. Especially the latter (as I spend too much time here, writing about non-important stuff). If I can make one person have an idea, one person there to use Python, or least to learn something extra in their lives, I&#8217;m happy. I don&#8217;t care if I have a huge audience or if I&#8217;m famous. I care for the undergrad that is starting today, the high school kid that is hacking at night, or the Java coder that is looking for some better language (Ok, not really, but I couldn&#8217;t resist). And this is one of the things that I learned in Science, always give back and don&#8217;t expect anything in return. Just add to the pile of knowledge.</p>
<p>So, my advice for the three people that read this site is: let Nada Surf in!</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/2db17c83-bb95-4371-911a-0b58b781409b/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=2db17c83-bb95-4371-911a-0b58b781409b" alt="Reblog this post [with Zemanta]"></a></div>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=90407633-45c2-41dc-912f-4b3d57e7eb2b" /></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=XMZT1mUM"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=pBiib3Q6"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?i=pBiib3Q6" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=Pz2BuNPG"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=50" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=s49nrCeI"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=52" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/uCZ0gw6zGUg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/02/21/why-do-i-blog-or-science-blogging-is-it-worth/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/02/21/why-do-i-blog-or-science-blogging-is-it-worth/</feedburner:origLink></item>
		<item>
		<title>Managing a simple database with Python, SQLite and wxPython, 3</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/9xptBVtfhlg/</link>
		<comments>http://python.genedrift.org/2009/02/18/managing-a-simple-database-with-python-sqlite-and-wxpython-3/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 16:06:58 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=244</guid>
		<description>In the last post we saw how to connect to a SQLite database file and generate a cursor that would allow us to actually interact with such database. Now we need some functionality that will interact with the data, add, read, delete and search. As was mentioned before the idea is to have a generic [...]</description>
			<content:encoded><![CDATA[<p>In the last post we saw how to connect to a <a class="zem_slink" href="http://sqlite.org/" title="SQLite" rel="homepage">SQLite</a> database file and generate a cursor that would allow us to actually interact with such database. Now we need some functionality that will interact with the data, add, read, delete and search. As was mentioned before the idea is to have a generic database interaction class and have unique instantiated class objects for each database of the project. In the <code>db_obj.py</code> file we have an initial structure set, so let&#8217;s check the <code>DB_Generic</code> class. </p>
<pre name="code" class="python">
class DB_Generic():
    &#039;&#039;&#039;generic class to add DB functionality&#039;&#039;&#039;
    def __init__(self, table_name):
        #par= name of the table to be used
        self.table_name = table_name

    def delete_entry(self):
        pass

    def get_data_generic(self):
        &#039;&#039;&#039;gets the data from the database
        generic so far, needs to be updated to include range&#039;&#039;&#039;        

        range = 1
        (cursor, database) = link_db()

        if range == 1:
            cursor.execute(&quot;&quot;&quot;SELECT * from %s&quot;&quot;&quot; % self.table_name)

        table_data = cursor.fetchall()
        raw_data = []
        for i in table_data:
            raw_data.append(list(i))

        self.table_data = raw_data

        database.close()

    def insert_data(self, values_list, insert_string):
        &#039;&#039;&#039;inserts data in the database&#039;&#039;&#039;

        (cursor, database) = link_db()
        cursor.execute(insert_string % self.table_name, values_list)

        database.commit()
        database.close()
</pre>
<p>There are different functions in this class, we will take a look at each one individually. We can see that the class is far from being complete, something that we&#8217;ll do in the next posts. We start with the class initialization:</p>
<pre name="code" class="python">
def __init__(self, table_name):
        #par= name of the table to be used
        self.table_name = table_name
</pre>
<p>Very simple and direct, it receives the table name that is being used by the interface (in this case). The table name is then stored in a  object that can be accessed by other functions in the class. The function to delete entries is not finished as we only have a <code>pass</code> in it. We&#8217;ll will do it soon. Next we have a function that gets the data from the table. </p>
<pre name="code" class="python">
    def get_data_generic(self):
        &#039;&#039;&#039;gets the data from the database
        generic so far, needs to be updated to include range&#039;&#039;&#039;        

        range = 1
        (cursor, database) = link_db()

        if range == 1:
            cursor.execute(&quot;&quot;&quot;SELECT * from %s&quot;&quot;&quot; % self.table_name)

        table_data = cursor.fetchall()
        raw_data = []
        for i in table_data:
            raw_data.append(list(i))

        self.table_data = raw_data

        database.close()
</pre>
<p>So far it grabs everything, there is no range selection based on any of the table fields, so it&#8217;s a generic SQL <code>SELECT</code>. Let&#8217;s dissect it. The <code>range</code> object is a dummy variable that at the moment is there only to remind us that we need to include a range select. The next line is the most important in this function: it will call the <code>link_db</code> function and start the connection. Remember that <code>link_db</code> returns a tuple with the cursor and database connection. Basically we will work with cursor methods to get the data, and the first action is to execute a SQL <code>SELECT</code> stetement where we select everything in the table</p>
<pre name="code" class="python">
cursor.execute(&quot;&quot;&quot;SELECT * from %s&quot;&quot;&quot; % self.table_name)
</pre>
<p>Notice that the statement is a regular string and we use string formating <code>%</code> in ordert o add the table that we are searching, which was defined when we initialized the class object in the first place. Also, notice the triple quotes around the select statement: this will avoid any problems in parsing it when sending to the database, making it a <a class="zem_slink" href="http://en.wikipedia.org/wiki/String_literal" title="String literal" rel="wikipedia">string literal</a>.</p>
<p>So this line executes the statement we pass to the method, but it does not actually get the data <i>per se</i>. We need to use another method and fetch everything returned by the select. This is done by </p>
<pre name="code" class="python">
table_data = cursor.fetchall()
</pre>
<p>A couple of things here. The data fetched will be always (or in most cases) in unicode, when it&#8217;s a string field. And the data returned will be in a list of tuples, with the actual number of fields from the table. We know that it&#8217;s easier to work with lists than tuples, so we code something to convert types</p>
<pre name="code" class="python">
table_data = cursor.fetchall()
raw_data = []
for i in table_data:
    raw_data.append(list(i))

self.table_data = raw_data
</pre>
<p>There are extra lines here that are not needed, and we will get rid of them in a code refactoring soon. This short function is able to connect to database, execute a SQL statement on a specified table and grab the data selected, returning a list of lists with every field and value available. We need to add a better selection statement later, and we will do as soon as we have a good structure set.</p>
<p>The last function in this generic class is the one that inserts data into the table.</p>
<pre name="code" class="python">
def insert_data(self, values_list, insert_string):
    &#039;&#039;&#039;inserts data in the database&#039;&#039;&#039;

    cursor, database) = link_db()

    cursor.execute(insert_string % self.table_name, values_list)

    database.commit()
    database.close()
</pre>
<p>Identical procedure: connect, get a cursor, execute a statement. But in this case the extra step is not to get the data, but to commit the data to the table, which is done by the commit method. We will explain later how the execute method works here and what are the <code>insert_string</code> and <code>values_list</code>. Notice at the end that we need to close the connection to the database, so we know that the data has been inserted properly.</p>
<p>Next, we will instantiate a class from this generic one and see how easy is to manipulate the data. Stay tuned.</p>
<p>Previously in the series:<br />
<a href="http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/">Part 1</a><br />
<a href="http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/">Part 2</a></p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/1663854e-5aba-4ff1-9a75-dffb8e6b7945/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=1663854e-5aba-4ff1-9a75-dffb8e6b7945" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=SsJ6WTPi"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=WUkn06NY"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?i=WUkn06NY" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=dnMkwx7n"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=50" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=yNPicM3q"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=52" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/9xptBVtfhlg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/02/18/managing-a-simple-database-with-python-sqlite-and-wxpython-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/02/18/managing-a-simple-database-with-python-sqlite-and-wxpython-3/</feedburner:origLink></item>
		<item>
		<title>Managing a simple database with Python, SQLite and wxPython, 2</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/Cd7lPFdF7H8/</link>
		<comments>http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 16:04:18 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[bioinformatics]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=242</guid>
		<description>Let&amp;#8217;s continue coding our small Python + SQLite application. The initial idea was to have a file for the interface and another file for the DB access. We will start with the later. If you have access to the repository you will see two Python files, bac_form.py and db_obj.py. At the moment they are not [...]</description>
			<content:encoded><![CDATA[<p>Let&#8217;s continue coding our small Python + SQLite application. The initial idea was to have a file for the interface and another file for the DB access. We will start with the later. If you have access to the repository you will see two Python files, <code>bac_form.py</code> and <code>db_obj.py</code>. At the moment they are not well commented and have some junk lines at the bottom, legacy from older versions. Take a look on <code>db_obj.py</code>.</p>
<p>It has two class declarations, one called <code>DB_Generic</code> and another one called <code>Bac</code>. Remember in the last post where I mentioned that the idea was to have different simple tables in the same SQLite database and each table would have a simple input/output interface (If I didn&#8217;t mention that, I just did!). So, we can create a generic DB access class and we can subtype from it for every table that we will be using. In the <code>db_obj.py</code> file we have at the moment the generic database management class, a class derived from the generic to access the Bac database and an initialization function, that opens the access to the SQLite file. Let&#8217;s take a look at it:</p>
<pre name="code" class="python">
def link_db():
    &#039;&#039;&#039;initializes the database file&#039;&#039;&#039;
    try:
        db = sqlite3.connect(&quot;samples.db&quot;)
    except sqlite3.Error, errmsg:
        print &#039;DB not available &#039; + str(errmsg)
        sys.exit()

    db_cursor = db.cursor()
    return db_cursor, db
</pre>
<p>In order to access a SQLite database file we need initially the name of the file. After importing sqlite3 (we&#8217;re using the latest version of SQLite here) Python has everything it needs to access, change and manipulate data in a SQLite database. Just to be sure the database file is there and we don&#8217;t get an error, we have the initialization code inside an exception. We have seen exceptions before and in this case we use it to be sure the database file has been accessed with no problems. The exception structure looks like</p>
<pre name="code" class="python">
try:
	#here we try to do something
	#the code placed here would be executed
	#if no error reported it will go until the end and exit
	#if not, some error (exception) raised
except:
	#the code under except will be executed
</pre>
<p>So, the first step is to connect to the database file</p>
<pre name="code" class="python">
db = sqlite3.connect(&quot;samples.db&quot;)
</pre>
<p>In our case it&#8217;s a fixed file, but the connect method receives any kind of string. It could have been some parameter obtained from the command line or a string from a configuration file. If the connect is successful, no error will be raised and we are safe to continue. We connected to database, now what? We need a cursor, an object that will actually access the data and allow us to execute <a class="zem_slink" href="http://en.wikipedia.org/wiki/SQL" title="SQL" rel="wikipedia">SQL</a> commands on it.</p>
<pre name="code" class="python">
db_cursor = db.cursor()
</pre>
<p><code>cursor</code> method works on the database connection object that we created previously. We&#8217;re set. This function returns the cursor and database connection objects that we created, in a tuple and this function can be called from the classes we are going to work. The classes will then have connection to the database and a cursor that would manage, select, delete and add data to it.</p>
<p>Next time we&#8217;ll see how our generic table class works.</p>
<p>Previously in the series:<br />
<a href="http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/">Part 1</a></p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/cbbab23e-338a-4756-8f4c-25cc0a5239dc/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=cbbab23e-338a-4756-8f4c-25cc0a5239dc" alt="Reblog this post [with Zemanta]"></a><span class="zem-script more-related"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=Lbxinz3K"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=OiLSWBYU"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?i=OiLSWBYU" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=AZOD19fp"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=50" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=rjELnaU3"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=52" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/Cd7lPFdF7H8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/02/17/managing-a-simple-database-with-python-sqlite-and-wxpython-2/</feedburner:origLink></item>
		<item>
		<title>Managing a simple database with Python, SQLite and wxPython, 1</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/pezmeguuCx4/</link>
		<comments>http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 20:11:57 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>
		<category><![CDATA[Graphical user interface]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=238</guid>
		<description>Image via Wikipedia



A little break from reviewing the book, let&amp;#8217;s check some database topics in Python. I was asked to create a simple database to organize wet-lab stuff. No relationships needs, no relational tables required. Just a simple table with determined columns, and a nice GUI to go with it so people can edit, search [...]</description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl style="width: 212px;" class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://commons.wikipedia.org/wiki/Image:WxPython-logo.png"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/c/c0/WxPython-logo.png/202px-WxPython-logo.png" alt="The official wxPython logo" title="The official wxPython logo" height="126" width="202"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://commons.wikipedia.org/wiki/Image:WxPython-logo.png">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>A little break from reviewing the book, let&#8217;s check some database topics in Python. I was asked to create a simple database to organize wet-lab stuff. No relationships needs, no relational tables required. Just a simple table with determined columns, and a nice GUI to go with it so people can edit, search and use.</p>
<p>My first idea was to use SQLite database, and I stuck with it. After the initial phase of &#8220;interviews&#8221; to check database requirements, I ended up with a list of tables and decided to start working on the table that organizes the BACs used in the lab. BAC is a DNA vector into which large DNA fragments can be inserted and cloned in a bacterial host, and are used mainly in cytogenetics around here. In the end the table had this structure</p>
<pre name="code" class="sql">
CREATE TABLE bac
(idbac INTEGER PRIMARY KEY,
clone Text,
sdate Date,
source Text,
gene TEXT,
chromosome Text,
startpos Integer,
endpos Integer,
antibiotic Text,
location1 Text,
temperature Integer,
tubes Integer,
box Integer,
cell Integer,
dnaex Boolean,
validation Boolean,
pcr Boolean,
projects Text,
comments Text,
genelink Text,
refs Text);
</pre>
<p>I won&#8217;t explain in detail each of the fields, but we can see that there is a mix of different types. SQLite doesn&#8217;t allow many different field types, so we stick to the basics. </p>
<p>And why SQLite? The module to access it comes with Python 2.5, the whole database is stored in one file that can be moved around and it allows a full SQL query language, which is perfect for these simple cases. So we will going to use Python, SQLite and wxPython to create a simple application to manage our simple database.</p>
<p>I already created a GitHub <a href="http://github.com/nuin/python_sqlite_wxpython/tree/master">repository</a> for the upcoming code.</p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/1a2359cd-d9c7-4cee-a26b-c41b281ec3d2/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=1a2359cd-d9c7-4cee-a26b-c41b281ec3d2" alt="Reblog this post [with Zemanta]"></a></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=owClNcFp"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=Q5Fj7alZ"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?i=Q5Fj7alZ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=mEP18A4L"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=50" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=fmBHn9GQ"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=52" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/pezmeguuCx4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/02/09/managing-a-simple-database-with-python-sqlite-and-wxpython-1/</feedburner:origLink></item>
		<item>
		<title>Expert Python Programming by Tarek Ziadé – a review of Chapter 3</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/YPd4AeGcGoQ/</link>
		<comments>http://python.genedrift.org/2009/02/09/expert-python-programming-by-tarek-ziade-a-review-of-chapter-3/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 18:29:24 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[off topic]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/2009/02/09/expert-python-programming-by-tarek-ziade-a-review-of-chapter-3/</guid>
		<description>The chapter 3 review that I promised for &amp;#8220;tomorrow&amp;#8221; (last Saturday) was lazily postponed until today. So, let&amp;#8217;s get to it. Tarek in this chapter continues with syntax best practices, but at this time at class level. As expected the chapter requires that you have a minimal knowledge of Python classes, so I can say [...]</description>
			<content:encoded><![CDATA[<p>The chapter 3 review that I promised for &#8220;tomorrow&#8221; (last Saturday) was lazily postponed until today. So, let&#8217;s get to it. Tarek in this chapter continues with syntax best practices, but at this time at class level. As expected the chapter requires that you have a minimal knowledge of Python classes, so I can say it&#8217;s geared to somewhat experienced programmers, and not to newcomers. There is a short explanation on sub-classing that warms up things for the next sections. </p>
<p>Next is the built-in method (type?) <code>super</code>, which was new to me. Basically <code>super</code> gives you access a method or attribute of a class by calling its parent directly. This is a segue into understanding the Method Resolution Order in Python, which is understanding which class has precedence over the others. For me, I haven&#8217;t dealt with such structures before it was a good and straight explanation, especially when he explains about possible pitfalls of using <code>super</code>. A short list of best practices helps:</p>
<ul>
<li></li>
<li>Multiple inheritance should be avoided: </li>
<li>super usage has to be consistent: Mixing super and classic calls is a confusing practice. </li>
<li>Don&#8217;t mix old-style and new-style classes</li>
<li>Class hierarchy has to be looked over when a parent class is called</li>
</ul>
<p>After dealing with MRO, comes what I think is one of the best sections of the book so far, where Tarek explains about object descriptors and gives a little bit of the Python&#8217;s approach to introspection. This short section is basically all code, but it&#8217;s good to have a good best practices reference, including here properties and slots. </p>
<p>The last part of the chapter covers meta programming, and as Chris pointed in the comments, that&#8217;s a difficult area of Python (maybe for the ones like me that don&#8217;t have a CS formation). I would have to try the examples by hand and maybe define areas in my code where I can use it, so to take fully advantage and fully understand it.</p>
<p>Overall, the chapter gives a good series of topics about Python classes and I enjoyed learning a little bit more things that I couldn&#8217;t understand previously. Next we will see a review of chapter 4, that deals with PEP 8 and naming best practices.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=L2Kfx3P1"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=fKIpARfU"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?i=fKIpARfU" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=Bp72buY9"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=50" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=PpKwyFTz"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=52" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/YPd4AeGcGoQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/02/09/expert-python-programming-by-tarek-ziade-a-review-of-chapter-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/02/09/expert-python-programming-by-tarek-ziade-a-review-of-chapter-3/</feedburner:origLink></item>
		<item>
		<title>Expert Python Programming by Tarek Ziadé – a review of Chapter 2</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/MskQSrJarI8/</link>
		<comments>http://python.genedrift.org/2009/02/06/expert-python-programming-by-tarek-ziade-a-review-of-chapter-2/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 16:08:03 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[off topic]]></category>
		<category><![CDATA[expert]]></category>
		<category><![CDATA[expert python programming]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=235</guid>
		<description>Cover via Amazon



So we&amp;#8217;re up to the second chapter of Tarek&amp;#8217;s book. A short disclaimer before diving into it. I started this blog, basically one year after I had started programming with Python. The initial idea was to &amp;#8220;convert&amp;#8221; the Beginning Perl for Bioinformatics book to Python and see what were the advantages and disadvantages [...]</description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl style="width: 159px;" class="wp-caption alignright">
<dt class="wp-caption-dt"><a href="http://www.amazon.com/Beginning-Perl-Bioinformatics-James-Tisdall/dp/0596000804%3FSubscriptionId%3D0G81C5DAZ03ZR9WH9X82%26tag%3Dzemanta-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0596000804"><img src="http://ecx.images-amazon.com/images/I/41GpHIPgOlL._SL200_.jpg" alt="Cover of &quot;Beginning Perl for Bioinformati..." title="Cover of &quot;Beginning Perl for Bioinformati..." height="200" width="149"></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;"><a href="http://www.amazon.com/Beginning-Perl-Bioinformatics-James-Tisdall/dp/0596000804%3FSubscriptionId%3D0G81C5DAZ03ZR9WH9X82%26tag%3Dzemanta-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0596000804">Cover via Amazon</a></dd>
</dl>
</div>
</div>
<p>So we&#8217;re up to the second chapter of Tarek&#8217;s book. A short disclaimer before diving into it. I started this blog, basically one year after I had started programming with Python. The initial idea was to &#8220;convert&#8221; the Beginning Perl for Bioinformatics book to Python and see what were the advantages and disadvantages of both languages. I was far from being a advanced Python programmer, and the inception of the blog helped me getting close to that, even though I consider myself far from being an expert programmer in Python. I learned a lot working on converting the Perl and learned a lot from the comments and interaction with other programmers and visitors of the blog. As anything in life one&#8217;s path is long and tortuous and there&#8217;s nothing better than daily learning and exercise.</p>
<p>So, as I mentioned in the previous post, this book was tailored for someone like me. I needed a boost on advanced Python techniques and the second chapter just gave me that. Tarek writes in this chapter about good syntax practices below the class level, functions and methods that are common in daily usage. He starts with list comprehensions, that we have seen in this site. It&#8217;s a short and concise section and gives you exactly what you need about this functionality.</p>
<p>Next, iterators and generators. I had a little bit of background on iterators, and have used them here and there, but not a lot on generators. I learned a bit from this section, what you expect from a book like this, things like the <code>close</code> and <code>throw</code>. Although this was good first step on generators, I wished the section could be longer, but that maybe not the focus of the book.</p>
<p>Coroutines was a completely new subject for me. Maybe I haven&#8217;t been diving into Python as much as I needed to, but time is short these days and programming Python is not the first objective of my work. The example is complete and easy to understand, but again I wish it was a tad bit longer. Tarek then explains a bit of generator expressions (list comprehension for generators) and enters the itertools module. So far so good, it&#8217;s a nice summary (at least for me) of simple techniques that can be incorporated into daily coding. And then &#8230; Decorators. </p>
<p>I blame on my poor CS skills or maybe my whole background on programming, but I still cannot get decorators. In my short-sighted view of the programming world I cannot see a place, at least on the things I&#8217;m doing, where I can use a decorator. And here comes the first criticism of the book: I still cannot get after reading the section. One thing that would help a bit would be to have colours on the examples and maybe go over them explaining some code lines. But at the same time, I admit that this might be a personal problem, where the concept of decorators don&#8217;t fit into my brain, and maybe the focus of the book is to show this advanced technique to someone that has a better grasp of the concept.</p>
<p>Overall, it&#8217;s a very good chapter and a good pointer to some expert/advanced techniques in Python. Tomorrow, chapter 3, and we&#8217;re a going to see classes. </p>
<div style="margin-top: 10px; height: 15px;" class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/2b86d192-b0ab-48fa-88ac-28aacbdf82e5/" title="Zemified by Zemanta"><img style="border: medium none ; float: right;" class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=2b86d192-b0ab-48fa-88ac-28aacbdf82e5" alt="Reblog this post [with Zemanta]"></a></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=p7jMgTzQ"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=hObJ7SAb"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?i=hObJ7SAb" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=A6DbKknQ"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=50" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=U4lcmXhB"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=52" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/MskQSrJarI8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/02/06/expert-python-programming-by-tarek-ziade-a-review-of-chapter-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/02/06/expert-python-programming-by-tarek-ziade-a-review-of-chapter-2/</feedburner:origLink></item>
		<item>
		<title>Expert Python Programming by Tarek Ziadé – a review of Chapter 1</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/kH34f-snfyU/</link>
		<comments>http://python.genedrift.org/2009/02/05/expert-python-programming-by-tarek-ziade-a-review-of-chapter-1/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 23:20:23 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[off topic]]></category>
		<category><![CDATA[expert python programming]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/2009/02/05/expert-python-programming-by-tarek-ziade-a-review-of-chapter-1/</guid>
		<description>I&amp;#8217;ve bought (no, Packt Publishing didn&amp;#8217;t send me a copy for review) Tarek&amp;#8217;s book quite sometime ago, but job changes, and extra-Python issues kept me away from reading it with the attention if fully deserve. When I saw the announcement, I thought that this was the book I wanted in Python. First, a little bit [...]</description>
			<content:encoded><![CDATA[<p>I&#8217;ve bought (no, Packt Publishing didn&#8217;t send me a copy for review) Tarek&#8217;s book quite sometime ago, but job changes, and extra-Python issues kept me away from reading it with the attention if fully deserve. When I saw the announcement, I thought that this was the book I wanted in Python. First, a little bit of perspective.</p>
<p>I&#8217;m a a biologist, self-taught programmer/coder/you-name-it. I only had a brief course on programming logic with Pascal in 1993 (I think). I first learned Basic on Apple ][, then on PC, then moved to Visual Basic, Pascal, C and C++, most of them with the help of books. About three and a half years ago, I got tired of compiling things and decided to learn a different language that would be more agile to code with. Not liking Perl, made me check Python. And I got hooked. Of course as a lay programmer, I won&#8217;t discuss why it&#8217;s better or worse than any other language using technical terms, but I can say that Python fits my needs in fast and efficient programming and I&#8217;m quite happy with the choice I&#8217;ve made. So, this review will not be technical, but will try to expose the book&#8217;s strengths and the weak parts. </p>
<p>Chapter one gives a good introduction on how to install Python and some nice pointers on how to program Python, such as IDEs and initial settings you can add to it. Also there is a short overview of the modern Python implementations. Is it a necessary chapter? Yes and no. No, because the schooled Python user won&#8217;t need it, his or her programming environment will already be installed, configured, set and ready to go. Yes, because this chapter works as a disclaimer for the not-so-experienced Python programmer, and shows everyone of what is expected of this book and what standards will be used. In my opinion, it&#8217;s a necessary starting point, so the author knows that everyone is at the same level. This chapter is also a good short summary of good practices of installing and setting up Python.</p>
<p>Tomorrow, chapter 2.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=LTWjycRc"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=2j625zbl"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?i=2j625zbl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=AhjpEpAL"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=50" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=CclMfdbK"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=52" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/kH34f-snfyU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/02/05/expert-python-programming-by-tarek-ziade-a-review-of-chapter-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/02/05/expert-python-programming-by-tarek-ziade-a-review-of-chapter-1/</feedburner:origLink></item>
		<item>
		<title>BPforB is now PEP 8 compliant!</title>
		<link>http://feedproxy.google.com/~r/BeginningPythonForBioinformatics/~3/QRXfGixp_lY/</link>
		<comments>http://python.genedrift.org/2009/01/31/bpforb-is-now-pep-8-compliant/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 17:51:10 +0000</pubDate>
		<dc:creator>Paulo Nuin</dc:creator>
				<category><![CDATA[Phase 2]]></category>

		<guid isPermaLink="false">http://python.genedrift.org/?p=222</guid>
		<description>As mentioned in the previous post, Robin Stocker kindly provided a git patch with the required changes to all scripts stored on the repository to be compliant with the PEP 8.
The changes were mainly regarding variable/object names, but they were important as make the code available here more Pythonic following the rules of the Benevolent [...]</description>
			<content:encoded><![CDATA[<p>As mentioned in the previous post, Robin Stocker kindly provided a git patch with the required changes to all scripts stored on the repository to be compliant with the PEP 8.</p>
<p>The changes were mainly regarding variable/object names, but they were important as make the code available here more Pythonic following the rules of the Benevolent Dictator for Life.</p>
<p>I would like to thank Robin for spending his time doing this. Much appreciated.</p>
<p>Now, just a quick git tutorial on how to apply patches:</p>
<p>git apply __patch_file__<br />
git commit -a -m &#8220;patch applied&#8221;<br />
git push</p>
<p>That&#8217;s it. Apply, commit, push and you&#8217;re done. The repository is already updated.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=yDAkpmDV"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=41" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=7Yblr5tT"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?i=7Yblr5tT" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=ZAyzD1t5"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=50" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?a=Tjla3Z0y"><img src="http://feeds.feedburner.com/~f/BeginningPythonForBioinformatics?d=52" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/BeginningPythonForBioinformatics/~4/QRXfGixp_lY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://python.genedrift.org/2009/01/31/bpforb-is-now-pep-8-compliant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://python.genedrift.org/2009/01/31/bpforb-is-now-pep-8-compliant/</feedburner:origLink></item>
	</channel>
</rss>
