Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectAlignmentSummaryMetrics fails on some small inputs due to unsafe Histogram methods #1862

Closed
1 task done
rickymagner opened this issue Feb 23, 2023 · 1 comment · Fixed by #1871
Closed
1 task done
Assignees

Comments

@rickymagner
Copy link
Contributor

rickymagner commented Feb 23, 2023

Bug Report

Affected tool(s)

CollectAlignmentSummaryMetrics, and maybe others which use the Histogram class from htsjdk.

Affected version(s)

  • Latest public release version [3.0.0]

Description

When running this tool on a small bam without good alignments (but properly formatted), the tool throws a NullPointerException. A more useful error message would be appreciated to help users debug what went wrong.

Steps to reproduce

Save the following sam file to null.sam:

@HD	VN:1.6	GO:none	SO:queryname
@RG	ID:test	SM:test_sample	LB:test_lib	PL:ILLUMINA	PU:my_platform	CN:BI	DT:2023-01-01T00:00:00-0500	DS:description
aln1	516	*	0	0	*	*	0	0	AGCTACTG	99999999	RG:Z:test
aln2	516	*	0	0	*	*	0	0	GTCAGTCA	99999999	RG:Z:test
aln3	516	*	0	0	*	*	0	0	CCTTGGAA	99999999	RG:Z:test

Then run

picard CollectAlignmentSummaryMetrics -I null.sam -R <some_ref>.fasta -O test.metrics

to see the error:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.Map$Entry.getValue()" because the return value of "java.util.NavigableMap.firstEntry()" is null
	at htsjdk.samtools.util.Histogram.getMin(Histogram.java:438)
	at picard.analysis.AlignmentSummaryMetricsCollector$IndividualAlignmentSummaryMetricsCollector.finish(AlignmentSummaryMetricsCollector.java:271)
	at picard.analysis.AlignmentSummaryMetricsCollector$GroupAlignmentSummaryMetricsPerUnitMetricCollector.finish(AlignmentSummaryMetricsCollector.java:185)
	at picard.metrics.MultiLevelCollector$AllReadsDistributor.finish(MultiLevelCollector.java:208)
	at picard.metrics.MultiLevelCollector.finish(MultiLevelCollector.java:324)
	at picard.analysis.CollectAlignmentSummaryMetrics.finish(CollectAlignmentSummaryMetrics.java:176)
	at picard.analysis.SinglePassSamProgram.makeItSo(SinglePassSamProgram.java:177)
	at picard.analysis.SinglePassSamProgram.doWork(SinglePassSamProgram.java:94)
	at picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:289)
	at picard.cmdline.PicardCommandLine.instanceMain(PicardCommandLine.java:104)
	at picard.cmdline.PicardCommandLine.main(PicardCommandLine.java:114)

Expected behavior

A more useful error message should be given in this case, or an empty metrics file produced (if appropriate).

Actual behavior

An unhelpful stacktrace is given instead.

More Details

The reason this is happening is related to this issue in htsjdk. One fix is to have this Picard tool be careful about how it calls the htsjdk Histogram methods and essentially ensure it never uses them unless it's safe. Another fix is to have the Histogram methods in htsjdk throw an exception in this sort of case, and make the Picard tools affected have to handle them appropriately, though this feels like a lot of trouble to update every tool depending on it.

@cmnbroad
Copy link
Contributor

cmnbroad commented May 9, 2023

@kockan Waiting for response to review comments.

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 a pull request may close this issue.

3 participants