biopython, doctest and makefiles – slides uploaded

The ‘clandestine’ barcelona python developers meetup of last Thursday has been a success!!

Almost 35 people attended, which is a nice result considering the time late and the fact that it was a very technical seminar.

I have uploaded the slides on slideshare:


View SlideShare presentation

You can find all the slides from this series of meetups on this group on slideshare:

- http://www.slideshare.net/group/barcelona-python-developers

I would like to thank all the people who came to the seminar and/or encouraged me while I was preparing it :) .
We are going to have another meeting like this in January, and most probably, I will try to prepare some other technical seminars on python and bioinformatics to present here in the prbb.

  • Share/Save/Bookmark

clandestine python seminar on the 11th in the PRBB

I must be very easy to convince. Or maybe, I like to give seminars. I don’t know what is worst!! :) .

Anyway, I am going to present a small talk on python in the PRBB (the research institute where I am now) on the 11th of December.

It will be a 30-minutes seminar, in which I will try to illustrate three things:

  • what is biopython
  • how the doctest module could be used to improve its documentation/the documentation of any bioinformatics script
  • automated build tools that can be used to create pipelines (in bioinformatics, of course)

The talk is organized in the framework of the Barcelona Python Developers Meetups. This is a community built around a website (meetup.com), of people who program in python and want to meet to discuss about it from time to time.

It is usual for all the new people that enter the group to give a talk to present themselves and explain their areas of interest; so, this will be my introductory talk.

If you are around Barcelona for the 11th, and you are interested in these arguments, you will be very wellcome to come. In any case, I will post the slides on slideshare (and on this blog) after the talk.

  • Share/Save/Bookmark

Women in bioinformatics

It seems that on scivee.tv, somebody is organizing a series of talks about women in bioinformatics:

women in bioinformatics - video on scivee.tv

women in bioinformatics - video on scivee.tv

I confess I was a bit surprised at first :) .
Honestly I don’t think there is so much discrimination in bioinfo, because almost half of the bioinformaticians that I know are women, and Margaret Dayhoff herself was a woman :) .

But if this initiative can attract more people into this field or into science in general, well done.

Anyway.. Women rules, and we don’t have any other choice if not to surrender :)

  • Share/Save/Bookmark

What is the real bottleneck in scientific computing

What is the real bottleneck in scientific computer‘ is the title of one of my favorite articles, published on American Scientist some years ago.

It describes the problems that tipically affect bioinformatics and bioinformaticians, and that could be summarized as:

  • lack of training on programming. The passage from biology to bioinformatics is usually too quick, and many scientists have to spend a considerable amount of energy and time because of the lack of good courses and tutorials.
  • people in bioinformatics don’t use revision control software (subversion, cvs, git, which are great tools). This means most of the experiments published are not reproducible.
  • people in bioinformatics don’t test their programs, and usually the reviewers during the publication process don’t mind about asking for it. I frequently wonder if the whole bioinformatics field will implode on itself some day :-/
  • people in bioinformatics never work in groups. Many don’t even use standard libraries such as BioPython, BioPerl, and they prefer to write their programs by their own. In many laboratories, nobody knows that there are cool techniques like agile or pair programming, and usually nobody do software engineering :( .

If you are new to the bioinformatics field, I suggest you to start reading many blogs and resources on Internet, and use public and standard libraries as much as you can.

A good way is to start using open source software and understand what is the meaning of it. When you will become accostumed to send bug reports every time you encounter an error in a program, and read different mailing lists, you will have learnt enought to be considered indipendent.

There are many blogs and articles that you can read to start, and in the future I will probably list them in a dedicated section of this blog.

A most recent but very interesting blog is called ‘programming4scientists’:
- programming4scientists.com

Moreover, I am particulary grateful to the author of this one:
- bioinformaticszen.com

Until some time ago, there it was nodalpoint, but now it seems to have been abandoned :( .

About the AmericanScientist article, I suggest you to read the Tutorial from the same author, hosted on scipy.org:
- software carpentry – Tutorial from the same author

There is also this article published on Plos, which seems interesting:
- http://www.ploscompbiol.org/article/info:doi/10.1371/journal.pcbi.0020087

  • Share/Save/Bookmark

A tip for grep

grep is a very useful command line tool, that can be used to find strings and patterns in multiple text files.

It is widely popular among most of the bioinformaticians I know. It can be used to quickly check if your files contain the right results, or to extract lines from huge sequence files, and so on.

Here it is a nice trick for it, that will allow you to enable color highlight in its output.
Open your ~/.bashrc file and put these two lines at its bottom:

alias grep="grep --color=auto"
export GREP_COLOR='0;30;43'

now you should type ’source ~/.bashrc’ on the command line, otherwise the change won’t be applied until you open another terminal application.

Et voilà, thanks to these two instruction, from this moment the output from grep will be colored, making it a lot easier to understand its results:

grep - before and after applying the --color option

grep - before and after applying the "--color" option

Yes, I know, I called my computer Sadako, like the little girl from The Ring :) .

old post in italian, for reference: here.

  • Share/Save/Bookmark

Genome diagrams included in biopython 1.50!

The 1.49 release of BioPython has been released ufficially a few days ago, and it is full of interesting changes: one of them is the introduction of doctest documentation for some modules, which I have proposed some time ago :) .

However, I think that even better enhancements will come with the 1.50. One of my favorites is the inclusion of a module called ‘GenomeDiagrams‘, which will finally make possible to generate good-quality genome diagrams with biopython.

Here it is a sample picture generated with this library:

Circular diagram of Erwinia carotovora ssp. atroseptica comparison against 229 bacterial genomes, constructed using GenomeDiagram

I think biopython was really missing some integration with a graphic library like this, since other similar Bio::* projects already had it.

For example, it is very easy to draw a sequence features diagram with bioperl:

A plot of sequence features with bioperl

A plot of sequence features with bioperl

You will be able to plot similar diagrams with biopython, I think an equivalent linear image could be:

A linear genome diagram created with the new biopython module

A linear genome diagram created with the new GenomeDiagram module

I still need to look at this module closely, so I don’t know well how much it can be customized and how.

The GenomeDiagram module has been written by Leighton Pritchard, and described in this publication:

He should be really thanked for making this contribution. Here you can find the home page of the module, and here the proposal on bioython’s bug tracker.

Articolo in Italiano: http://www.molecularlab.it/insidebioinfo/?p=64

  • Share/Save/Bookmark

Going English!

Hi people :)
I am sorry for those of my readers who preferred to read my blog in Italian, but I have decided to start writing my articles here in English.

I feel I really have to make this choice. I have been writing on this blog in my mother language for more than one year, and it has been really fun, a very nice way to learn and discuss about bioinformatics; but now, I need to make it available to everyone, like my new colleagues, many friends, and other bioinformaticians.

I will continue writing in Italian on the molecularlab’s blog, Inside Bioinfo.

This is a very dark period for research in Italy.
The government is going to cut a third of the fundings to the universities, which will be probably mean the bankrupt for many historical Institutions like the University of Firenze, and will drastically reduce the number of opportunities to young researchers in Italy.

I have just started a phd here in Spain, and I am very happy with it, I am working in a very fascinating environment and I am meeting many interesting people.
However, when I look back at Italy, I have a real bad feeling – I really hope that nothing bad will happen to my family and my friends, because I feel like it won’t be easy for me to return back if I’d have the need.

Ciao a tutti!!

Come forse avrete gia’ notato, ho deciso di iniziare a scrivere su questo blog in Inglese.

Mi dispiace veramente per coloro che preferivano leggere in Italiano, perche’ mi rendo conto che per certe persone (immagino soprattutto studenti alle prime armi) possa essere piu’ difficile.

Pero’, credo di avere veramente bisogno di fare questo passaggio. Sara’ piu’ complicato scrivere, ma penso sia una cosa buona che i contenuti siano a disposizione di tutti, anche a quelli che non capiscono la nostra lingua.
Adesso lavoro a contatto con molte persone che parlano solo inglese o spagnolo, e ho bisogno che quello che posto qui sia accessibile anche a loro.

In ogni caso, continuero’ a scrivere in italiano sul blog di molecularlab, Inside Bioinfo.
Sono a piena disposizione per qualsiasi iniziativa vogliate propormi: altri blog, forum, magazine, meeting, battaglie di divulgazione scientica. Io personalmente credo che non sia stupido discutere di argomenti scientifici o tecnici nella propria lingua madre, perche’ in questo modo si e’ capaci di raggiungere un numero diverso di persone, la qual cosa e’ un vantaggio.

Vi saluto.. nel post in inglese mi sono lamentato un poco della situazione della ricerca italiana, anche se vivendo all’estero mi riesce difficile capire come stanno le cose esattamente.

  • Share/Save/Bookmark

biopython e doctest

In questi giorni sto cercando di proporre l’utilizzo del modulo doctest all’interno del progetto biopython, perché penso ne potrebbe migliorare la documentazione.

doctest é un modulo incluso nella distribuzione standard di python, che permette di introdurre i test per i propri script direttamente nella loro documentazione.

Facciamo un piccolo esempio. Mettiamo di voler scrivere un modulo in grado di parsare un nuovo formato di sequenze, che chiameremo ‘MinusMinus’. Senza dettagliare il codice, la sua documentazione con doctest sarebbe qualcosa del genere:

def MinusMinusFormatParser(filehandle, options):
    """
    Parse the 'MinusMinus' file format for sequences.
    Returns a 'SequenceSet' object.

    # Here it is a sample 'MinusMinus' file:
    >>> from StringIO import StringIO
    >>> testfile = StringIO('''
    ... --seq1
    ... ACGTCGATCGATCGTCAGTCGATC
    ... ACGTACGTATCGTACGTACGTAGC
    ... --seq2
    ... AGATCGTACGTAGCTAGCTAGTCG
    ... ''')
    >>> sequences = MinusMinusFormatParser(testfile, options=None)
    File parsed. ok!

    # MinuxMinusFormatParser returns a SequenceSet object:
    >>> print sequences
    SequenceSet object with 2 sequences

    # use the .format method to print these sequences in the fasta format:
    >>> print sequences.format('fasta')
    >seq1
    ACGTCGATCGATCGTCAGTCGATC
    ACGTACGTATCGTACGTACGTAGC
    >seq2
    AGATCGTACGTAGCTAGCTAGTCG

    """
    pass

if __name__ == '__main__':
    import doctest
    doctest.testmod()

Questa é la documentantazione di un ipotetico parser per il formato MinusMinus.
Vedete che nella stessa docstring del modulo ho messo degli esempi di come questo dovrebbe essere utilizzato, imitando la tipica shell di python.
Le prime due istruzioni:

    >>> from StringIO import StringIO
    >>> testfile = StringIO('''
    ... --seq1
    ... ACGTCGATCGATCGTCAGTCGATC
    ... ACGTACGTATCGTACGTACGTAGC
    ... --seq2
    ... AGATCGTACGTAGCTAGCTAGTCG
    ... ''')

illustrano un esempio di formato ‘MinusMinus’. Così, quando digitate help(MinusMinusFormatParser), potete capire subito se state utilizzando il parser corretto, oppure se vi siete confusi con un altro.

La terza istruzione, invece, vi mostra qual é la sintassi tipica di una chiamata alla funzione.
Se lanciate MinusMinusFormatParser sopra un file simile a quello precedente, dovreste ricevere il messaggio ‘File parsed. ok!’:

    >>> sequences = MinusMinusFormatParser(testfile, options=None)
    File parsed. ok!

E così via, per le altre istruzioni mostrate nel doctest il funzionamento é molto simile.
Scrivo gli esempi di comandi come se mi trovassi su una shell python, prefissandoli con ‘>>> ‘; e il loro output immediatamente sotto.

Notate anche che eseguendo il programma come uno script in python, viene eseguita la funzione doctest.testmod():

if __name__ == '__main__':
    import doctest
    doctest.testmod()

Questa é la chiamata al modulo doctest che esegue la vera magia. Quando chiamo ‘testmod()’, gli esempi che ho posto nella documentazione vengono eseguiti, come se fossero codice vero e proprio: il risultato della loro esecuzione viene confrontato con quello previsto nell’esempio, e nel caso di differenze, mi viene segnalato un errore.
Se per esempio, la chiamata a MinusMinusFormatParser non mi avesse restituito ‘File parsed. ok!’, avrei ricevuto una notificazione, aiutandomi a risolvere un possibile bug.

La mia idea era di proporre questo tipo di documentazione al progetto biopython. Sono già riuscito a far accettare alcune doctest in biopython 1.49 :) , ma spero di riuscire a contribuire maggiormente nei prossimi giorni, affinchè ve ne siano altre.

A voi che ve ne pare, come idea? Questo é il bug report che ho inviato: 2640.
Vi sembrano più chiare le doctest? Pensate che un loro utilizzo massiccio potrebbe aiutare a rendere biopython più facile da utilizzare, più diffuso?
Una ultima cosa: come vedete, in questo caso ho scritto la documentazione e i test prima di iniziare a scrivere il codice. Se dovessi veramente scrivere un parser per il formato MinusMinus, adesso mi sarebbe molto più facile, perché già saprei come questo si dovrebbe comportare. La lezione é: scrivete sempre i test e la documentazione per le vostre funzioni prima del codice :) .

links:

- la mia proposta su biopython: http://bugzilla.open-bio.org/show_bug.cgi?id=2640
- documentazione ufficiale sulle doctest http://www.python.org/doc/2.5.2/lib/module-doctest.htm

  • Share/Save/Bookmark

In arrivo nuove slides!

Sto preparando un piccolo seminario da presentare ai miei nuovi colleghi qui al prbb, sulle buone pratiche da seguire in bioinformatica.

Il laboratorio in cui mi trovo adesso é piuttosto grande, con diverse collaborazioni e un buon numero di ricercatori; una buona parte di essi utilizza il computer per fare calcoli (soprattutto test di genetica di popolazioni e operazioni su grossi files), e molti sanno programmare in perl, python o R.

E’ il tipico laboratorio in fase ‘pro-bioinformatica’: un gruppo che ha lavorato parecchio sui banconi tradizionali, guadagnandosi una buona reputazione, e che adesso ha bisogno di imparare ad usare correttamente gli strumenti messi a disposizione dalla bioinfo.

Per questo motivo, mi é venuto in mente di proporre un seminario per presentare quelli che sono considerati attualmente gli ‘argomenti caldi’ di questo campo: quelli su cui si discute di più sui forum e blog dedicati.

In particolare, vorrei discutere di:

  • sistemi di controlli di revisioni, come cvs, svn, git, etc…
  • testing di programmi di bioinformatica. Ogni volta che scrivete un programma, per calculare una statistica, scaricare delle sequenze da internet, cambiare formato ad un file, scrivete dei test per dimostrare che il vostro programma funziona correttamente? Avete qualche abitudine  particolare per controllare i vostri scripts?
  • automated builds e workflow. Il sistema più tradizionale per coordinare vari scripts, per ricordarsi quali opzioni avete usato per ottenere dei risultati e per poterli ricalcolare correttamente ogni volta che i vostri dati cambiano, é gnu/make. Il quale però non é sempre il massimo, e ci sono delle alternative. Voi cosa usate?
  • database e flat file. si potrebbe parlare un poco di moduli ORM, dei vantaggi/svantaggi di un database per salvare i propri dati.
  • agile programming: vediamo se riesco a convincere a qualcuno, che lavorare in gruppo é molto meglio!!

Insomma, io credo che nel mio laboratorio in cui mi trovo adesso, questo sia il momento giusto per proporre un talk del genere. Se va bene (mi sembrano molto interessati), forse faremo addirittura delle piccole riunoni, tipo ‘journal club’, ma sulla bioinfo.

Che ve ne pare? Purtroppo, penso che fra poco dovrò iniziare a parlare inglese, anche su questo blog… :(

  • Share/Save/Bookmark

Corsi di Perl e C per bioinformatici al Cineca (Bologna)

Vi segnalo due corsi gratuiti di tre giorni, di introduzione al perl e al C per bioinformatici, organizzati dal centro di calcolo Cineca di Bologna:

La sede delle lezioni sarà Casalecchio di Reno, una cittadina raggiungibile con autobus urbani da Bologna.

Si tratta di corsi molto introduttivi, di soli due/tre giorni, destinati a biologi che non abbiano mai visto molto di programmazione. Spero che però riescano almeno a fare in tempo a spiegare make, e volendo anche le basi dei sistemi di controllo delle revisioni.

Devo ammettere che l’annuncio mi ha preso un poco di sorpresa, in quanto non pensavo che si organizzassero corsi di questo tipo in Italia (ci sono così tanti bioinformatici al Cineca?).

Bene, adesso se vi ci volete iscrivere, affrettatevi!! :)

  • Share/Save/Bookmark