1 of 19

OLS �Tips and practices for writing good quality code

CC by 4.0

Olaitan I. Awe, Ph.D.

Training Officer, ASBCB

laitanawe@gmail.com

@laitanawe

November 13, 2024

2 of 19

openseeds

mentoring & training program

What is good quality code?

A readable, easy to maintain code that others can extend or build upon is good quality. It is:

  • maintainable,
  • testable,
  • portable,
  • reusable,
  • readable,
  • scalable,
  • robust and adaptable over time,
  • reliable

3 of 19

openseeds

mentoring & training program

Maintainable code

Good quality code is:

  • Maintainable: easy to test, find bugs and fix them for every developer working on the code base.

4 of 19

openseeds

mentoring & training program

Testable code

Good quality code is:

  • Testable: Use different scenarios to test your code thoroughly.

Stages:

dev --> test --> prod

  • Testing ensures that broken code doesn’t find its way into production.

5 of 19

openseeds

mentoring & training program

Portable code

Good quality code is code that is:

  • portable,
  • Functions should not get too big. Otherwise, break it down and create new functions.

6 of 19

openseeds

mentoring & training program

Reusable code

Good quality code is code that is:

  • Reusable
  • DRY: Don’t Repeat Yourself
  • If a part of your code does the same thing in more two or more places, turn it into a function.
  • Combine functions into libraries/subworkflows

7 of 19

openseeds

mentoring & training program

Workflows should be reproducible

  1. Collect data (Biomedical, Omic Sequences etc.)

  • Develop the pipeline/codes

  • Generate Output

  • Interpret the Output (advance our understanding of biology and health)

8 of 19

openseeds

mentoring & training program

Workflow Management Systems enable Reproducible Coding

  1. Nextflow (Interoperability, Component Reuse, Re-entrancy, Parallelisation, Allows use of containers, Reproducibility)

  • Snakemake
  • Cromwell (WDL/CWL)
  • Galaxy

9 of 19

openseeds

mentoring & training program

Write Code and Publish it in a findable Repository (GitHub)

  1. Data
  2. Accessions (SRA, GEO, ENA, RefSeq, Genbank)
  3. Figures
  4. Scripts
  5. Docs
  6. Output
  7. Workflow (Step by Step sequence of tasks)
  8. Notebooks for Demonstration
  9. LICENSE (Open license)
  10. README.md

10 of 19

openseeds

mentoring & training program

Research Standard

Open Science:

  1. Improve the accessibility, quality and efficiency of science
  2. Open Access Articles
  3. Research code, data and pipelines are FAIR:

(Findable, Accessible, Interoperable, Reusable)

Documentation: good comments for your code

11 of 19

openseeds

mentoring & training program

Readable code

Good quality code is:

  • Readable: it can be understood by programming newbies and developers.
  • Use consistent and descriptive naming conventions for objects, functions and file names
  • Good comments

12 of 19

openseeds

mentoring & training program

Scalable code

Good quality code is:

  • Scalable: code should adapt to growing complexity and demands without sacrificing performance.
  • * Write tests (automated tests)
  • * Meaningful variable names
  • * Store configuration data in a single config file
  • * Modular design eases code scalability
  • * Code things you need not things you may need

13 of 19

openseeds

mentoring & training program

Maintaining GitHub repos

  1. To report an issue, use the issues page (URL_REPO/issues)
  2. Contribute to open source projects (fork the repo, make proposed changes, submit a pull request)

14 of 19

openseeds

mentoring & training program

Robust and adaptable code

Good quality code is:

  • robust and adaptable over time

* Get the code reviewed by experienced developers. * Embrace criticism.

* Keep refining the code.

15 of 19

openseeds

mentoring & training program

Reliable code

Good quality code is:

  • Reliable: the code performs as intended without errors or failures.
  • * easy to test and update without easily breaking.

16 of 19

openseeds

mentoring & training program

Automate your Pipelines

Language depends on what you’re comfortable with and your application:

  1. Bash
  2. R
  3. Python
  4. Perl
  5. Java
  6. C/C++
  7. Workflow Lang (Nextflow, Snakemake, CWL, WDL)

17 of 19

openseeds

mentoring & training program

Some Life Science Project Categories

  1. Bulk Transcriptomics, Metagenomics, Human Genomic Variation, Pipeline Development, Biomarker Discovery, Cheminformatics, Clinical Applications, Drug and Vaccine Design, Antimicrobial Resistance, Population Genomics, Genome Wide Association Studies, Polygenic Risk Scores, Mendelian Randomisation, Structural Bioinformatics, Software Development, Epigenomics, Oncology, Plant Genomics, DNA Methylation, Single-cell RNA-seq and Machine Learning.

18 of 19

openseeds

mentoring & training program

Want to start writing good quality code for bioinformatics?

- You can start practicing by using public data (SRA, GEO, ENA, RefSeq, Genbank)

- Check out past codeathon information (asbcb.org/events)

19 of 19

open seeds

mentoring & training program

Thank you!

laitanawe@gmail.com