Author Archives: Thomas Cokelaer

AWK: convert into lower or upper cases

In order to convert a bash variable to lower case with awk, just use this command: a="UPPER CASE" echo "$a" | awk ‘{print tolower($0)}’a="UPPER CASE" echo "$a" | awk ‘{print tolower($0)}’ If you want to convert the content of a … Continue reading

Posted in Linux | Tagged , | Leave a comment

How to sort a dictionary by values in Python

By definition, dictionary are not sorted (to speed up access). Let us consider the following dictionary, which stores the age of several persons as values: d = {"Pierre": 42, "Anne": 33, "Zoe": 24}d = {"Pierre": 42, "Anne": 33, "Zoe": 24} … Continue reading

Posted in Python, Uncategorized | Tagged , | 6 Comments

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