Knitting tables with kable

The kable function from the knitr package allows to display nicely formatted tables using R Markdown, as explained here. I recently encountered unexpected behaviour of kable when calling it from lapply or a function, which led to this post on StackOverflow. The answers were very detailed and enlightening, and I invite you to read them. They could be summarized in two points: be aware of side-effects, and prefer cat (with new lines) to print.


Batch tsv to csv conversion

I recently had to convert tables from tsv to csv format and found several ways to do it in this thread from StackOverflow, including the Python script below:

import sys
import csv

tabin = csv.reader(sys.stdin, dialect=csv.excel_tab)
commaout = csv.writer(sys.stdout, dialect=csv.excel)
for row in tabin:

Here is a simple wrapper Bash script to run the conversion in batch:

for file in *.tsv
    python < $file > ${file%.*}.csv

Running ApE on Ubuntu 14.4

ApE is a free plasmid editor, convenient to plan a cloning experiment. The Linux version is not maintained anymore, but still runs on Ubuntu 14.4 (Mac and Windows versions are both maintained).
To run on Ubuntu, download the latest Linux version, unzip and run, using:

cd ApE Linux
tclsh8.5 AppMain.tcl

If this does not work, you may have to install tk8.5 and tcl8.5:

sudo apt-get install tk8.5 tcl8.5

Automate GeneTrail with iMacros

GeneTrail is a comprehensive web-based application to perform Gene Ontology and pathway analysis, with a user-friendly graphical interface. It is not possible, however, to access it programmatically, which can be cumbersome when processing more than a few datasets. It is nevertheless possible to automate interactions with the graphical interface using iMacros, which works as an add-on to web browsers such as Firefox.

iMacros is very simple to use:

  1. Once installed, open iMacros in Firefox.
  2. Click on “Record” and perform all the tasks you normally do on GeneTrail, including upload and download. Stop recording when done.
  3. The macro is now saved and you should see it in the iMacros panel. Right click on it and edit as follows:
    • Locate the name of the file to be uploaded and replace it by a new file name.
    • Add “WAIT SECONDS=120″ before the line starting with “ONDOWNLOAD”. If necessary, replace 120 with a number of seconds greater than the time GeneTrail takes to process results, so iMacros waits long enough before to try downloading.
    • Edit the line starting with “ONDOWNLOAD” to indicate the folder and file names (e.g. “ONDOWNLOAD FOLDER=/home/sebastien/imacrosresults WAIT=YES”). Delete other lines starting with “ONDOWNLOAD”, if any.
  4. Click on play. To replay with different upload and download file names, edit the script as indicated above.

iMacros can also be called from the command line, and it is possible to automate further, both on Linux and Windows.