Skip to main content
VierApparatus
On this page
  1. References

Level 07 · Bioinformatics and Computational Biology

Testing and Version Control

Why biological analysis code must be tested against inputs with known outputs, how unit tests are written and run, the use of version control to record every change to the code and its results, the practices of committing small changes with clear messages and the way these practices protect a result from silent errors introduced by later edits.

2 min read · Updated

Listen to this moduleComing soon

Learning objectives

  • Write a unit test for a function that processes sequence records and explain what a failing test tells the analyst.
  • Describe how version control records changes to analysis code and why each change should be small and described.

A unit test runs a function on an input whose correct output is known and checks that the function returns it. A test for a sequence filter might supply three short records, one of which is below the length limit, and check that only the other two are returned. Taschuk and Wilson (2017) described tests of this kind as a basic defence against errors in research software, since a function that passes its tests is known to behave as specified on those inputs, and a later change that breaks it is caught immediately.

Tests are only as good as the cases they cover. They should include the ordinary case, the boundary cases such as an empty file or a record of length exactly equal to the limit, and the malformed cases that the input may contain. A test that passes for typical data but fails on an edge case is valuable, because the edge case is where biological data most often surprise an analysis.

Version control records every change to the code. A version control system stores each version of each file, the author and the date of each change and a message that describes it. Peng (2011) argued that the ability to return to the exact state of an analysis is central to the credibility of computational results, and version control provides that ability.

Good practice is to make small, well-described changes. A commit that changes one function and states why it was changed can be reviewed and, if necessary, reversed. A commit that changes many things at once makes it hard to determine which change caused a new result. Results that are generated by the code should be tagged with the version of the code that produced them.

Sandve et al. (2013) recommended keeping a record of the version of each tool used in an analysis, and version control is the most practical way to keep the record of the code itself.

References

  1. Taschuk, M., & Wilson, G. (2017). Ten simple rules for making research software more robust. PLOS Computational Biology, 13(4), e1005412. https://doi.org/10.1371/journal.pcbi.1005412
  2. Sandve, G. K., Nekrutenko, A., Taylor, J., & Hovig, E. (2013). Ten Simple Rules for Reproducible Computational Research. PLoS Computational Biology, 9(10), e1003285. https://doi.org/10.1371/journal.pcbi.1003285
  3. Peng, R. D. (2011). Reproducible Research in Computational Science. Science, 334(6060), 1226-1227. https://doi.org/10.1126/science.1213847

Callouts marked Commentary or Speculation in the lesson separate interpretation and open questions from established findings.