Author Archives: Thomas Cokelaer

Python: how to copy a list

To explain how to create a copy of a list, let us first create a list. We will use a simple list of 4 items: list1 = [1, 2, "a", "b"]list1 = [1, 2, "a", "b"] Why do we want … Continue reading

Posted in Python | Tagged , | 2 Comments

Python: ternary operator

In C language (and many other languages), there is a compact ternary conditional operator that is a compact if-else conditional construct. For instance, in C, a traditional if-else construct looks like: if (a > b) { result = x; } … Continue reading

Posted in Python | Leave a comment

Difference between __repr__ and __str__ in Python

When implementing a class in Python, you usually implement the __repr__ and __str__ methods. __str__ should print a readable message __repr__ should print a message that is unambigous (e.g. name of an identifier, class name, etc). You can see __str__ … Continue reading

Posted in Python | Tagged , | 3 Comments

python: how to merge two dictionaries

Let us suppose two dictionaries storing ages of different individuals: list1 = {"Pierre": 28, "Jeanne": 27} list2 = {"Marc": 32, "Helene": 34}list1 = {"Pierre": 28, "Jeanne": 27} list2 = {"Marc": 32, "Helene": 34} If you do mind losing the contents … Continue reading

Posted in Python | Tagged | Leave a comment

Search for a pattern in a set of files using find and grep commands

A common task for developers is to search for a pattern amongst a bunch of files that are in different directories. For instance, you are looking for the pattern “import sys” within a set of Python files. Those files are … Continue reading

Posted in Linux | Tagged , | Leave a comment

okular: export annotations in the PDF file

One open source software to add annotations under Linux is okular (https://okular.kde.org/). One can add annotations easily (go to Tools, tick review, or just type F6). Then, it is time to save your document or to send it to a … Continue reading

Posted in Linux | Tagged | 3 Comments

No more space left on /tmp under Fedora

Under Fedora, one of my software requires more than 4Gb of temporary space and I realised that the /tmp directory is limited to 4Gb. In order to increase the /tmp directory, just edit the /etc/fstab file and add this line … Continue reading

Posted in Linux | Leave a comment

blasr (pacbio) installation on fedora box

I wanted to use blasr tool for Pacbio mapping and had difficulties in using or installing the tool. I first use a local installation of the tool on the provided cluster and it look like the installation was quite old. … Continue reading

Posted in biology | Tagged , | Leave a comment

swapping two columns with awk keeping tabulation

Assuming you have a data file with N columns and you want to swap the first and second one, just type: awk -F $’\t’ ‘ { t = $1; $1 = $2; $2 = t; print; } ‘ OFS=$’\t’ input_fileawk … Continue reading

Posted in Linux | Tagged | Leave a comment

set a default version to an environment module

Context: “The environment modules package provides for an easy dynamic modification of a user’s environment via modulefiles. which typically instruct the module command to alter or set shell environment variables such as PATH, MANPATH, etc. as well as define aliases … Continue reading

Posted in Linux | Tagged | Leave a comment