Managing a simple database with Python, SQLite and wxPython, 1
Phase 2 February 9th, 2009
- Image via Wikipedia
A little break from reviewing the book, let’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.
My first idea was to use SQLite database, and I stuck with it. After the initial phase of “interviews” 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
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);
I won’t explain in detail each of the fields, but we can see that there is a mix of different types. SQLite doesn’t allow many different field types, so we stick to the basics.
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.
I already created a GitHub repository for the upcoming code.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=1a2359cd-d9c7-4cee-a26b-c41b281ec3d2)
February 9th, 2009 at 3:55 pm
Did you consider Dabo for this? This is almost trivially simple to do in Dabo, and yes, it’s Python, SQLite and wxPython.
February 9th, 2009 at 5:04 pm
Hi Ed
I haven’t learned Dabo yet. I tried once and I’m willing to get back to it. It’s a “large” project so I guess I can use it in the future.
February 13th, 2009 at 5:52 pm
[...] Managing a simple database with Python, SQLite and wxPython [...]
February 16th, 2009 at 2:09 am
Hmmm looks interesting! both dabo and what you are doing.. I was just thinking of an LIMS using the same tools myself..
February 17th, 2009 at 8:24 pm
Hi Paulo,
Avid follower of blog. Newbie, first time posting. Thanks for everything.
I had a question.
In the SQL query, why is gene field with TEXT instead of Text as others. Does it make a difference?
Thanks
February 17th, 2009 at 9:41 pm
No difference at all, Rama. I created the database with one program and ended up editing and adding some other fields/columns with another that puts everything in big caps. I think I checked every field but this one might have slipped through. Thanks for your comment and please keep posting if yoy have any other question.
Paulo
March 3rd, 2009 at 11:05 am
Hi Paulo,
Got the part 5 link from reddit.
Just a suggestion, even though these posts are almost sequential, I think a simple update on each of the posts with the permalink to the rest of the seris would be useful.
Either that or I didn;t see ‘em tags.
Kinda late here, all sleepy already
Great series btw.
March 3rd, 2009 at 2:20 pm
Will do that. It’s a good idea, and I should have implemented it a long time ago.
March 7th, 2009 at 8:01 am
[...] in the series: Part 1 Part 2 Part 3 Part [...]
March 7th, 2009 at 8:02 am
[...] in the series: Part 1 Part 2 Part [...]
March 7th, 2009 at 8:03 am
[...] in the series: Part 1 Part [...]
March 15th, 2009 at 12:00 pm
I like elixir and sqlalchemy a lot. Have a look at them:
- http://bioinfoblog.it/2009/01/python-and-databases/
- http://elixir.ematia.de/
Also, the pygr project seem to provide some good tools that may be useful if I understood correctly what you want to accomplish.
March 27th, 2009 at 2:46 pm
[...] whole process. I was able to recreate the bookstore (not until the end, I admit) and even convert a desktop Python application to [...]
March 31st, 2009 at 12:06 pm
[...] in the series: Part 1 Part 2 Part 3 Part 4 Part [...]
April 22nd, 2009 at 5:03 pm
[...] in the series: Part 1 Part 2 Part 3 Part 4 Part 5 Part [...]
April 22nd, 2009 at 5:05 pm
[...] in the series: Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 Part [...]
May 22nd, 2009 at 10:32 am
[...] Previously in the series: Part 1 [...]