Find the Bug: Six Broken Analyses

The worst bugs in bioinformatics never crash. They quietly hand you a wrong number. Here are six real-world examples to diagnose and fix, from a GC count to a DESeq2 result that points the wrong way.

🟡 Beginner to intermediate ⏱️ ~45 min 🐍 Python · R · DESeq2 🌐 Runs in your browser

Before you start

  • Each bug comes from a different part of the roadmap. You will get the most from one after you have done its lesson, but you can try any of them now.
  • The Python and R boxes run in your browser. Read the code, predict what is wrong, then fix it and press Run.

Learning objectives

By the end you will be able to: spot six of the most common silent errors in bioinformatics analyses; explain why each one gives a wrong answer without any error message; and use simple checks (looking at the data, a known result, or a count) to catch them in your own work.

Why practise on broken code?

The most dangerous bugs in bioinformatics do not crash. The code runs, prints a number, and the number is wrong. Real analysis work is largely checking, and checking is a skill you can train. Each exercise below is a short analysis with a hidden mistake taken from everyday practice. For each one:

  1. Read the scenario and the code.
  2. Look at the output. Does it make sense?
  3. Decide what is wrong before you open the answer.
  4. Where there is a Run box, fix the code and run it again.
Bug 1 · Python foundations

The GC content that is too low

You copy a region from a genome browser and compute its GC content. Genome browsers often show repeats in lowercase (called "soft-masking"). The result says 36.4%, but the sequence looks GC-rich to you. Run it, then find and fix the bug.

Show the bug and the fix

The bug: count("G") only counts capital G. The six lowercase g and c letters are ignored, but they still count towards the length, so GC content is underestimated.

The fix: make the case consistent first, with s = s.upper() as the first line of the function. The answer becomes 63.6%.

The habit: before counting letters in a sequence, check which letters are actually in it, for example set(seq). Lowercase letters, N for unknown bases, and line breaks all change your counts.

Bug 2 · Files and the command line

Too many reads

Every FASTQ record starts with a header line beginning with @, so counting lines that start with @ seems like a quick way to count reads. This file has 3 reads. What does the code say, and why?

Show the bug and the fix

The bug: @ is also a quality character. In the usual Phred+33 encoding it means a base quality of 31, so a quality line can start with @. The code counts read2's quality line as an extra read and prints 4.

The fix: a FASTQ record is always exactly 4 lines, so count lines and divide by 4: len(lines) // 4 in Python, or echo $(( $(wc -l < reads.fastq) / 4 )) on the command line. The same trap catches grep -c "^@" reads.fastq.

The habit: when a shortcut relies on a character, ask whether that character can appear anywhere else in the file.

Bug 3 · Genomic coordinates

The variant that moved by one base

A VCF file says there is an A-to-G variant at position 1000 of chr1. You turn it into a BED interval so you can intersect it with gene regions. The code below produces chr1 1000 1001. Is that the right base?

Show the bug and the fix

The bug: VCF positions are 1-based (the first base is 1), but BED is 0-based, half-open (the first base is 0, and the end is one past the last base). chr1 1000 1001 in BED is the 1001st base, one base to the right of the variant.

The fix: bed_start = pos - 1 and bed_end = pos - 1 + len(ref), giving chr1 999 1000. A one-base shift can move a variant out of an exon, or onto the wrong codon.

The habit: every time you move between file formats, ask "0-based or 1-based?". The genomic coordinates lesson has the full table.

Bug 4 · RNA-seq

The steroid that switched genes off

You analyse the airway data (dexamethasone-treated versus untreated cells) with DESeq2. Dexamethasone is known to switch on genes such as DUSP1, FKBP5 and KLF15. Here is the code and part of the result:

# samples$dex holds "untrt" or "trt"
samples$dex <- factor(samples$dex)
dds <- DESeqDataSetFromMatrix(counts, samples, design = ~ cell + dex)
dds <- DESeq(dds)
res <- results(dds)
resultsNames(dds)
[5] "dex_untrt_vs_trt"

         log2FoldChange
DUSP1             -2.94
FKBP5             -4.04
KLF15             -4.46

The well-known steroid-response genes come out strongly negative. Did dexamethasone really switch them off?

Show the bug and the fix

The bug: factor() orders levels alphabetically, so "trt" comes before "untrt" and becomes the baseline. DESeq2 then reports untreated versus treated (look at dex_untrt_vs_trt), which flips every sign. The biology is fine; the direction is reversed.

The fix: set the baseline explicitly: samples$dex <- factor(samples$dex, levels = c("untrt", "trt")). Re-run, and DUSP1 becomes +2.94, FKBP5 +4.04 and KLF15 +4.46.

The habit: always print resultsNames(dds) and check one gene whose direction you already know (a positive control). This bug is invisible in a volcano plot; it just mirrors it.

Bug 5 · R and missing values

The count that came back as NA

DESeq2 sets some adjusted p-values to NA on purpose, for example for genes with very low counts. In the airway analysis, 626 genes have NA. You try to count the significant genes, and R answers NA. Run it, then fix it.

Show the bug and the fix

The bug: any comparison with NA gives NA ("unknown"), and a sum that includes an unknown is unknown. Worse, the second line quietly keeps the NAs in your "significant" list.

The fix: sum(padj < 0.05, na.rm = TRUE) gives 3, and padj[which(padj < 0.05)] keeps only real values. In the full airway analysis the corrected count is 4,077 genes.

The habit: before summarising a column, run sum(is.na(x)) so you know how many values are missing and why.

Bug 6 · Statistics

The longer list that looked better

A colleague's report says: "5,488 genes were significantly changed by dexamethasone (p < 0.05)." Their code:

sig <- subset(res, pvalue < 0.05)
nrow(sig)          # 5488

The same analysis with adjusted p-values gives 4,077. Which number belongs in the report, and why?

Show the bug and the fix

The bug: the code uses the raw pvalue column. With about 16,000 genes tested, a 5% cutoff on raw p-values lets through hundreds of genes by chance alone, and nobody can tell which ones.

The fix: filter on the adjusted column, subset(res, padj < 0.05), which controls the false discovery rate: on average, at most about 5% of the reported genes are expected to be false positives. Report 4,077, and say that it is an FDR threshold.

The habit: whenever you test many things at once, ask "which p-value is this?". See the multiple-testing lesson.

What the six bugs have in common

None of them produced an error message. Each one was caught the same way: by comparing the output with something you already know. That can be a sequence you can see is GC-rich, a file you know has 3 reads, a gene whose direction is famous, or the fact that a count cannot be "unknown". Building that reflex is what the Thinking Like a Researcher mini-course calls a positive control.

Check your understanding

Why are the bugs on this page more dangerous than code that crashes?
A crash stops you and tells you something is wrong. A silent bug hands you a plausible answer, so only your own checks can catch it.
A DESeq2 result shows a famous treatment-induced gene with a strongly negative log2 fold change. What should you check first?
A reversed baseline flips every sign while keeping every p-value. One known gene in the wrong direction is the fastest way to catch it.
A VCF variant is at POS 500. Which BED line describes the same single base?
VCF is 1-based; BED is 0-based and half-open. Base 500 in VCF starts at 499 in BED and ends (exclusive) at 500.
In R, sum(x > 1) returns NA. What is the most likely reason?
If nothing were above 1, the sum would be 0, not NA. NA means at least one comparison was unknown; use na.rm = TRUE and check sum(is.na(x)).
What single habit would have caught all six bugs on this page?
Running the same buggy code twice gives the same wrong answer. A known fact (a positive control) is what exposes the problem.

Sources & further reading

  1. Cock PJ, Fields CJ, Goto N, Heuer ML, Rice PM. The Sanger FASTQ file format for sequences with quality scores, and the Solexa/Illumina FASTQ variants. Nucleic Acids Res 38: 1767-1771, 2010. doi:10.1093/nar/gkp1137
  2. Quinlan AR, Hall IM. BEDTools: a flexible suite of utilities for comparing genomic features. Bioinformatics 26: 841-842, 2010. doi:10.1093/bioinformatics/btq033
  3. SAMtools/hts-specs. The Variant Call Format specification (VCFv4.3; positions are 1-based). samtools.github.io
  4. Love MI, Huber W, Anders S. Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2. Genome Biol 15: 550, 2014. doi:10.1186/s13059-014-0550-8
  5. Benjamini Y, Hochberg Y. Controlling the false discovery rate: a practical and powerful approach to multiple testing. J R Stat Soc B 57: 289-300, 1995. doi:10.1111/j.2517-6161.1995.tb02031.x
  6. Sandve GK, Nekrutenko A, Taylor J, Hovig E. Ten simple rules for reproducible computational research. PLoS Comput Biol 9: e1003285, 2013. doi:10.1371/journal.pcbi.1003285

Last reviewed: October 2026.

Build the checking habit

Mini-course: Thinking Like a Researcher →