"What programming language should I learn?" is one of the very first questions to tackle if you are a beginner wanting to learn bioinformatics. Choice of language is important since it will be a tool that you utilize often, so the obvious answer is that you should learn the "best" one. What features should this best language have? It should be easy to learn, cover all of your needs as a bioinformatician (like data analysis, text processing, and application development), and be amazingly fast at any task you throw at it... Unfortunately, any greybeard can tell you that this language does not exist.
This language does not exist because it would be impossible for a room full of computer scientists to come to agreement on anything let alone the features of a best language. Instead, we have many computer languages that excel in some aspects while having shortcomings in others. This can probably best be summarized with a hammer analogy. Have you ever wondered why screwdriver attachments for hammers aren't more popular? A hammer is exceptionally good at driving nails, and a screwdriver is exceptionally good at driving screws. Why deal with an over-engineered scrammer when a hammer and a screwdriver work perfectly well independently?
Why R an Python? These languages have all of the features you need to be successful, and it is unlikely that you will run into a bioinformatics problem that can't be solved because of the limitations of these languages. R and Python are consistently ranked as the two most popular programming languages for bioinformatics job positions according to indeed.com's job trends (accessed 08-02-17), so knowing these languages will likely help your job prospects.
|R and Python are consistently the most popular languages for bioinformatics jobs on indeed.com.|
Lets break down three major needs of a bioinformatician (data analysis, text processing, and application development; by no means an exhaustive list) and find out why these two languages are the best for getting started.
Data Analysis (R)
Although bioinformaticians spend a lot of time building software tools, many will spend at least some time working with biological data. For data analysis, R is an excellent choice. It is both a language and an environment for statistical computing and graphics, and it has wide adaptation in the statistics and data science communities. This popularity means that there are thousands of libraries developed by others to take advantage of so you don't have to spend extra time coding. Even better, the Bioconductor project exists solely to provide R libraries for many types of bioinformatic analyses. R is a top choice by academics in bioinformatics and statistics, so a lot of the cutting edge tools based on the newest research are only available in R.
What's the best way to learn R? I am a big proponent of structured classes with homework and project deadlines to help facilitate learning, so I highly recommend the R Programming course at Coursera taught by three big names in the data science world (Peng, Leek, Caffo). This course is part of the Data Science Specialty, which is a great idea if you're going to be spending a lot of time analyzing biological data, and upon completion of the specialization you even receive a certificate that you can list on your resume/CV. If you prefer to be self taught, then I highly recommend R for Data Science: Import, Tidy, Transform, Visualize, and Model Data by Hadley Wickham. If you already know a programming language, then some of the quirks of R might take some getting used to, but it is still an invaluable addition to your toolbox.
Text Processing and Application Development (Python)
Python is an object-oriented scripting language. Python was designed with code readability in mind, so Python code tends to be more readable and can accomplish tasks in fewer lines compared to other object-oriented languages. Python is one of the most popular languages in the world, and IEEE listed Python as the top ranked programming language of 2017 (up from number 3 last year). Python's popularity benefits bioinformaticians using Python because there are extensive libraries for everything from web frameworks to scientific computing. Python can scrape files and websites right out the box thanks to built-in string and HTML/XML processing functions. Have a neat idea for utilizing natural language data? Your idea is only a library install away thanks to the Natural Language Toolkit.
Python is great for both web-based and desktop-based application development. For web-based applications, beginning bioinformaticians can choose between three popular frameworks (flask, django, and Pyramid). For starting out, I recommend flask since you can have a "hello world" page up and running in about six lines of code, and it is very easy to find help if you get stuck. For desktop applications, there are a number of library choices. I recommend starting with the tkinter library, included in most Python installs by default, which provides an interface to the Tk GUI toolkit. The Tk GUI toolkit comes with or is available for most operating systems, meaning that tkinter applications you write are platform independent (can work on multiple operating systems). You can have a tkinter "hello world" pop-up window in as little as three or four lines of code, and it is very easy to find help if you need it.
Unlike R where RStudio is really your only IDE choice, Python has several options. I highly recommend using Sublime Text, a fast text editor with must-have features like regex searches and column highlighting. Sublime can run on Mac, Windows, and even Linux. It can run Python code directly, and with the help of a few easy to install packages, it can be your one stop solution for all Python development. Sublime Text is not free but has an essentially indefinite trial version, and you can get rid of the occasional nag screen by purchasing a lifetime license for $75 USD. If you're looking for something free and open source, then Spyder provides an interface similar to RStudio's. Advanced text editors like vim probably have too steep of a learning curve to be useful to a beginner. However, once you get the hang of programming you might be interested in upping your game.
For learning Python, I suggest An Introduction to Interactive Programming in Python and part two, which will get you well on your way. These courses are part of the Fundamentals of Computing Specialization. If you like the two introductory Python courses, then you should consider taking the rest of the courses in the specialization since the mathematical computing skills you will learn will be helpful on your journey as a bioinformatician (and you get a certificate). For self-teaching, I can't recommend Zed Shaw's Learn Python 3 the Hard Way book enough. This book is a great because it requires you to type all of the exercises, and I'm a big fan of "learning by doing". For biologists looking to learn how to code, I also recommend the well-written, beginner-friendly Python for Biologists.
Python 2 or 3?
Python 3 is the latest version of the official Python release, and I recommend starting with Python 3 since it's arguably better for beginners. I might have told you otherwise a few years ago due to backwards compatibility issues and lack of library support for Python 3, but Python 3 has now been out since 2008 so these issues are mostly history. If you're still concerned or maybe you need to work with some legacy code, then you can read more about Python 2 vs Python 3 to help you figure out what version is most appropriate.
Why not just Python?
If you twisted my arm while insisting that you didn't have time to learn two languages because you were working two jobs, helping shelter puppies find homes on weekends, and learning to play the cello, then I would acquiesce that it was ok to only learn Python. Python can have R-like data analysis functionality with the help of the pandas library, but you will likely run into situations where a library you need is available in R but not Python. In my experience, R is easier to use for data analysis because it was built for data analysis (see above hammer analogy). Keep in mind that not learning R could hurt your job prospects since there are a LOT of positions that want this kind of experience (see above indeed.com graph). If a position that lists R programming experience came down to a candidate who only knew Python and an equally qualified candidate who knew Python but who also had some small R project up on github, then who do you think would get the job?
You'll know when it's time to learn another language. You might come across something unbelievably cool in Erlang that draws you in, or you might start running into performance issues with your code. R and Python are great for a lot of things, but they can be very slow for computationally heavy tasks when compared to a language like C. The good news is that you aren't going to have a hard time picking up new languages since your brain has already been introduced to programming concepts by R and Python.
Biology can be quite complicated and problems are going to come in all shapes and sizes. Taking a complex problem and breaking it down into manageable pieces that can be solved by a computer program is a skill that transcends any language. As a bioinformatician, this is a very important skill to develop in addition to being able to code. With this in mind, I'd like to close with a link to this great article, 'Don't learn to code. Learn to think.'