Skip to content

fix: fail with a GTF-specific error when no genes can be extracted - #132

Closed
BenjaminDEMAILLE wants to merge 1 commit into
seqeralabs:mainfrom
BenjaminDEMAILLE:fix/empty-gtf-diagnosis
Closed

BenjaminDEMAILLE wants to merge 1 commit into
seqeralabs:mainfrom
BenjaminDEMAILLE:fix/empty-gtf-diagnosis

Conversation

@BenjaminDEMAILLE

Copy link
Copy Markdown
Contributor

Fixes #126.

Problem

When a GTF yields zero genes, parse_gtf only logged a WARN and returned an empty map. The run then died much later in count_reads with the chromosome-mismatch diagnosis, which cannot apply — there is nothing on the GTF side to mismatch against:

    Parsing GTF annotation...
[WARN  rustqc::gtf] No genes extracted from GTF file './truncated.gtf'. ...

  ✗ error: Failed to process sample.bam: Chromosome name mismatch: no reads could be assigned to any gene.

Alignment chromosomes (first 5): chr1, chr10, chr11, chr12, chr13
GTF chromosomes (first 5):

...
chromosome_mapping:

The suggested fix (chromosome_mapping) is empty and cannot help, and the actual cause is a WARN line that is easy to miss.

Fix

parse_gtf now records why nothing was extracted while scanning, and returns a fatal error naming the most likely cause:

Situation Message
No non-comment lines the file contains no annotation lines (it is empty, or every line is a comment)
Every line has < 9 columns all N annotation lines have fewer than the 9 mandatory tab-separated GTF columns (truncated file, or space- instead of tab-separated)
No exon features no 'exon' features were found; feature types present: gene, mRNA. GFF3 files ... are not supported — convert to GTF
Exons but no gene_id N feature lines were found but none carried a 'gene_id' attribute

count_reads keeps a guard for library callers: an empty annotation index now produces an empty-annotation error rather than the chromosome-mismatch text.

Behaviour change

An empty annotation is now a hard error at parse time instead of a warning. This is the same outcome as before (the run always failed a few seconds later), just reported at the point where the cause is known.

Verification

Reproducing the issue's steps with cut -f1-5 tests/data/test.gtf:

    Parsing GTF annotation...
Error: No genes could be extracted from GTF file '.../trunc.gtf': all 22 annotation lines have
fewer than the 9 mandatory tab-separated GTF columns (truncated file, or space- instead of
tab-separated).

Every RustQC analysis needs a usable gene annotation, so processing cannot continue.
Check that the file is uncorrupted, tab-separated GTF (not GFF3) with 'exon' features carrying
'gene_id' attributes.

Four new unit tests cover the truncated, GFF3, missing-gene_id and empty-file cases.

  • cargo test — 204 lib + 18 integration tests pass
  • cargo fmt --check, cargo clippy -- -D warnings clean

🤖 Generated with Claude Code

A malformed or truncated GTF that yields zero genes used to log a WARN and
carry on, so the run died later in count_reads with a "Chromosome name
mismatch" error, an empty "GTF chromosomes (first 5):" list and a
chromosome_mapping suggestion with nothing in it. The real cause (bad
annotation file) was buried in an easy-to-miss warning above.

parse_gtf now tracks why nothing was extracted and returns a fatal,
actionable error naming the most likely cause: no annotation lines, lines
with fewer than the 9 mandatory columns, no exon features (listing the
feature types actually present, which flags GFF3 input), or exon features
without gene_id attributes.

count_reads keeps a guard for library callers: an empty annotation index now
reports an empty-annotation error instead of the chromosome-mismatch
diagnosis, which cannot apply when there is nothing to match against.

Closes seqeralabs#126

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ewels

ewels commented Dec 3, 2026

Copy link
Copy Markdown
Member

Closing in favour of #217, which rebases this onto main after the noodles migration (#118), together with #176, since both change the same 'no reads assigned to any gene' error. Your commit is there with the same content; only the surrounding code in gtf.rs and counting.rs changed during the rebase. Thanks!

@ewels ewels closed this Dec 3, 2026
ewels added a commit that referenced this pull request Dec 4, 2026
fix: clearer errors when no reads are assigned to genes (rebased #132 + #176)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Malformed GTF (0 genes extracted) is misdiagnosed as a chromosome name mismatch

2 participants