Thursday, May 1, 2014

Checking md5 sums for lots of files from Windows

I run a lot of local BLAST searches on Windows machines. When you download a blast database from NCBI, you should also download the md5 file so you can check that the downloaded file is exactly the same as the one on the server (sometimes there can be fidelity issues when transferring data). Linux has a handy tool for comparing md5 sums, called md5sum. Example.

Saturday, April 12, 2014

Finding a minimal set of English vocabulary with WordNet, Perl, and GLPK integer programming

Preface:
This was my semester project for the class "Principles of Optimization" which was one of my absolute favorite classes that I took in college. It uses WordNet, which is a fantastic database for looking at relationships between English words, (it seems to be the basis of many online tools such as the Visual Thesuarus that is constantly advertised on dictionary.com, it was fun to see how the graphs I made for this project exactly matched the content of Visual Thesuarus, a website that seems to be just begging for an open-source ripoff...). To access WordNet, I used the Perl library WordNet::QueryData which seemed to work quite well. For the Integer Programming, I had a much harder time, I used the library Math::GLPK which has bugs that confused me for quite a while (I wish I remembered what they were, but I don't, all I remember is a general feeling of frustration with the library), if I were to redo this project, I'd take a different approach, maybe writing lp text files and solving with the glpk command line interface, or maybe using Python to interface with an IP solver. I used Cytoscape to generate the network graphs.

For those just here for example code for WordNet::QueryData, or Math::GLPK,
you can find it in a the perl file that you can download here. All others, Read On!


Monday, March 31, 2014

Python Numpy Munkres Hungarian matching algorithm

I didn't make this, but there is a numpy implementation of this algorithm available through scikit-learn in sklearn/utils/linear_assignment_.py . I'm glad I found it, as it seems to be about 4 times faster than the munkres package from PyPI (on which it is based, and which is the python implementation that comes up the most on google).

Reference:
http://stackoverflow.com/questions/1398822/the-assignment-problem-a-numpy-function

Tuesday, March 25, 2014

building a django app that uses ZeroMQ: an annotated webliography


Introduction:
I wanted to build a website that allows people to search their data against a database (in the not too distant future, when the website is live I'll link it and the source code and give more of an explanation. Edit: and here it is, the code, the ZeroMQ stuff is mostly at "/nmr/management/commands", and the website ). Each search takes a few seconds, so in order to be able to serve multiple clients at a time, and allow scaling, I wanted to build a system where the main wsgi process does not block, but passes the search request off to another process that puts it in a queue and executes requests in the queue one by one. I ended up following a simple approach using ZeroMQ. There is a scheduler that runs as a thread in the main wsgi process. When the search input view receives a search request, it writes the search parameters into the database and opens a connection to the scheduler thread and passes it the unique ID of the database record storing the search parameters. There are one or more worker processes each running as a subprocess. The workers are permanently attached via a socket to the scheduler. When a worker completes a job, the scheduler sends it the ID of the next job in the queue, the worker executes the job, writes the results in a database table, and tells the scheduler it is ready for another job. There can be many workers attached to the scheduler, so that multiple searches can be run concurrently.

Here then is a list of (some of) the websites I used for reference while writing this program.

Tuesday, March 18, 2014

ChemDraw ChemAxon synergy

In my previous post, I was complaining that there wasn't any free software with a nice command line interface to reliably convert molfiles to InChI strings, and back again. I also mentioned that there was an issue with the way ChemDraw converts structures to InChI strings that made it unacceptable for my purposes. The technical issue with ChemDraw is that it doesn't preserve the isoform of tautomers. Some of the molecules I'm interested in contain amides that are typically found in the amide form, rather than the imidic acid form. When I copy these molecules as InChI from ChemDraw, and then paste them back in, the amide is changed to the imidic acid form, which I don't want. It turns out that this is due to a feature of the InChI format (a format that is still mostly opaque to me) called "Mobile H Perception", where it simplifies a molecule encoding by not specifying the which tautomer it is (thereby saving 1 bit of information I guess). Many programs have the option to export InChI with Mobile H perception off, which is what I want, but I can't find that option in Chemdraw.

Automating Chemdraw: win32 com scripting with python pywin32

Once again I find myself adventuring in the land of Windows COM scripts. Last time I tried, with mixed success. This time, I'm using it to control ChemDraw to help me convert molecule formats. Anytime I use COM scripts, it feels pretty clumsy, like it would be a lot slicker just to have a command line utility, but in this case I couldn't find anything that seemed like it would work well enough (update: I later found out about ChemAxon Molconverter which is quite nice), so COM scripts it is. Python is currently the language I do general purpose programming in, and pywin32 works quite well for COM scripting.

The problem: I want to take molfiles from multiple sources and normalize them so that they can be rendered with the same style settings by chemdoodle web components. While I'm at it, I'd like to generate SMILES strings, InChI strings, and InChI key strings (I'd also like to generate IUPAC names, but I gave up on that part) for the molecules in these molfiles.

Thursday, January 30, 2014

Only listening to music in the right ear while working

I used to have a lot of trouble listening to music and doing homework or programming at the same time. It was distracting and I had trouble thinking while the music was going. Sometimes I'd have it on for tedious parts of a task and then when I got to a part that took a lot of careful thinking, I'd turn it down until I got to another boring part. I probably wasted a lot of time just flipping the music on and off. I also noticed that music with words was much more distracting than music without words, so sometimes I'd just listen to light orchestral music instead of the rock and folk I usually listen to.

In any case, what I noticed eventually is that if I listen to music through a headphone on my right ear only, I find it easier to tune out, and less distracting than when I use both ears, or just my left ear. In fact, I find having music in only the left ear to be rather obnoxious.

Why the right ear? It's hard to know, and with a sample size of one, and an investigation that is hardly double blind (or even single blind), it's not at all likely that I'll ever figure it out for sure. But it strikes me as an interesting phenomenon and there's no harm in speculating so here are some ideas:

It could be that the particular ear is not relevant, and the reason I favor one ear over the other is random. I don't remember quite when this habit started (sometime in the last 3 years I think), or why I originally chose to use only my right ear and not the left. It's possible that it was random, that I thought the music was too loud or distracting so I took one headphone off and it seemed better, so the next time I took the same one off even though it wouldn't have made a difference. However, I vaguely remember that even at the beginning the reason I chose the right ear is that the music was only unpleasant in my left ear, hence there was negative feedback encouraging me to remove the headphone from my left ear, but not from the right.

It may be that my right ear just happens to be slightly less sensitive than my right ear. This isn't at all obvious in everyday life, but perhaps there is some 5% or 20% difference in sensitivity peculiar to me.

My favorite, hypothesis, however is that it has something to do with the division of labor in the brain (and hopefully I don't fall victim to too many pop-neuroscience misconceptions here). I'm right handed, so when I type, use the mouse, or write or draw, as I would while working, my left hemisphere has to work harder than my right hemisphere. The left hemisphere contains the center for language, and it was the words in songs that I found most distracting, so maybe the one level of indirection is enough to prevent the music from unduly interfering with my internal dialog. Stretching a bit more, a lot of what I do is highly analytical (like computer programming, or math and science homework), so if the left brain is the center of logic then I may be relying on it more than on the right brain (when doing so called right-brain centric activities, especially drawing, but also writing poetry, I often listen to music from speakers or with both headphones, so there may be some connection there too).

Google turns up a few other reports of things like this on this, but it's all anecdotal (although I haven't yet tried to search the scientific literature, maybe there is something there, not sure how much of it I'd understand though).

What about you, oh vast teeming readership, do you think this is a real phenomenon? Or is it just stochastic noise (pun intended!) and confirmation bias?