Monday, April 13, 2015

How to create a new mime-type for IPython notebook files in Ubuntu

Installing IPython adds a very useful format for scientific calculations called the IPython notebook. These are text files with JSON (JavaScript Object Notation) code with the .ipynb file ending. It makes sense to open these with the IPython notebook, but under Ubuntu, they are opened by the default text editor (Gedit).

I would like to be able to open them by double clicking in the file manager and also having a nice icon for the files.

To achieve this I needed to create a new mime-type for .ipynb files

Creating a new mime type 

There are many ways to create mime-types in Ubuntu, but this is what I did. I used this blog post by termueske as a guide.

I created a text file called ipynb.xml on my desktop with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/x-ipynb+json">
<comment>IPython Notebook</comment>
<glob pattern="*.ipynb"/>
</mime-type>

</mime-info>

I then opened a terminal in desktop and typed the following command:

bjorn@bjorn-UL30A:~/Desktop$ xdg-mime install ipynb.xml --novendor

If there is no response, everything is ok. Then I updated the mime database:

bjorn@bjorn-UL30A:~/Desktop$ update-mime-database /home/bjorn/.local/share/mime/

My username is bjorn and my home folder is /home/bjorn/ so the path above has to be changed for other user names.

That should be it. Check properties of a .ipynb file to see the new mime type.

Obtaining a nice icon

I downloaded "ipython-3.1.0.zip" from https://pypi.python.org/pypi/ipython/3.1.0

inside the zip file (/ipython-3.1.0/docs/resources/) there is a nice svg icon called "ipynb_icon_512x512.svg"


Adding an icon the the new mime type

I renamed the icon file above to:

application-x-ipynb+json.svg

This is the mime-type in the ipynb.xml file above, but with the slash substituted by a minus sign (dash).

Now put this file where you file manager can find it. I tried with:

/home/bjorn/.local/share/icons/hicolor/scalable/mimetypes



I had to create the sub folders /scalable/mimetypes/ 

Then I simply turned off my file manager in the terminal:

bjorn@bjorn-UL30A:~/Desktop$ nemo -qq

I use Nemo, but if you use Nautilus, type instead 
nautilus -qq

Then restart Nemo using the "Files" icon in the unity launcher.

This worked well for me, this is a notebook on my desktop:



Right clicking on this file gives:


Why?

Why did I choose /home/bjorn/.local/share/icons/hicolor/scalable/mimetypes
as the location for the icon?

Trial and error!

They say here that the "hicolor" icon theme is a fallback theme for icons. I looked in  /home/bjorn/.local/share/icons/ and I had only a folder there called hicolor. I wanted to put the icon in my home folder (see below).

Icon themes have an index.theme file that determines where they look for the actual icon files. This file is located in /usr/share/icons/hicolor 



There is an entry in this file called "Directory=" which contains all icon lookup directories. This is a very long comma separated list on my computer.

As my icon is a scalable (svg) I looked for and found the entry "scalable/mimetypes", so it would make sense to use this location. 

I didnt want to put the icon in /usr/share/icons/hicolor/scalable/mimetypes since I would loose the icon when I upgrade or reinstall Ubuntu.

Apparently /home/bjorn/.local/share/icons/hicolor/scalable/mimetypes works just as well.

Hope this can help !

Other useful resources:










Monday, January 12, 2015

Inserting plain text references in Paperpile

I used to use zotero for reference management, but now I use paperpile since it is a bit more stable. One peculiarity of paperpile is that it only provides plug-in for google docs (an advantage in my opinion) since it is easier to collaborate over google docs.

I often encounter having to insert references from a formatted paper in some document format like ms word where the original dynamic references inserted by a reference manager was lost. Doing this manually is very tedious.

There is a work around for this that worked very well when I used it:

and paste the reference list in the window of the crossref site, which returns nicely formatted references.

on the output and uploaded the resulting bibtex file to Paperpile.

Very easy!

Sunday, December 15, 2013

PCR simulation with WebPCR

It is handy to have a bioinformatics tool to simulate various aspects of the Polymerase Chain Reaction (PCR). Errors are easily introduced in the primer design step so it is useful to have a simulation tools that can predict the sequence of the PCR product so that it can be verified.

I have put a PCR simulation script online called WebPCR . It is written in Python and runs using Flask on PythonAnywhere

The PCR simulation script used is from the pydna package.


The WebPCR window accepts a list of sequences in FASTA or Genbank format (or a mixture of both formats).

The last of the sequences in this list is assumed to be the template sequence while all preceding ones are assumed to be PCR primers.

The simulator will return a text based report describing the PCR product from each primer pair that is able to form one:



Two PCR programs are suggested for each PCR product, one for Taq polymerase and one for polymerases containing a DNA binding domain such as the Phusion DNA polymerase.

WebPCR has some capabilities not found in any or most other simulators:
  • Tailed primers are handled correctly
  • Inverse PCR of circular templates
The WebPCR  script has to be told that the template is circular. This can be done in two ways, depending on the format of the template sequence:

For FASTA format template sequence, simply add the keyword "circular" in the FASTA header:


For Genbank format template sequence, the DNA topology is set to either "linear" or "circular" in the LOCUS line: