broadinstitute / picard

A set of command line tools (in Java) for manipulating high-throughput sequencing (HTS) data and formats such as SAM/BAM/CRAM and VCF.
https://broadinstitute.github.io/picard/
MIT License
980 stars 369 forks source link

java.lang.IllegalArgumentException: Alignments added out of order in SAMFileWriterImpl.addAlignment #1429

Open ranijames opened 4 years ago

ranijames commented 4 years ago

Dear All,

I am using Picard FilterSamReads for filtering a list of sorted reads from a read_name/_id sorted BAM file. I am wanna sort the list of reads which are of certain mapping quality.

Here is what I tried,

java -jar -Xmx4G /path/picard-2.18.4-0/picard.jar FilterSamReads I=simulate_50X_pat_sorted_read.bam O=simulate_50X_pat_sorted_quality_pat.bam READ_LIST_FILE=pat_quality2 FILTER=includeReadList

And the above line is throwing the following error,

INFO    2019-11-19 16:51:40 FilterSamReads  Filtering [presorted=true] simulate_50X_pat_sorted_read.bam -> OUTPUT=simulate_50X_pat_sorted_quality_pat.bam [sortorder=queryname]
ERROR   2019-11-19 16:51:40 FilterSamReads  Failed to filter simulate_50X_pat_sorted_read.bam
java.lang.IllegalArgumentException: Alignments added out of order in SAMFileWriterImpl.addAlignment for file:///cluster/work/projects/simulate_50X_pat_sorted_quality_pat.bam. Sort order is queryname. Offending records are at [1-93166-:1-93466--:::::::::::52438MzI4MTAy:1] and [1-102419--:1-102119-:::::::::::199592NzM1MA==:1]
    at htsjdk.samtools.SAMFileWriterImpl.assertPresorted(SAMFileWriterImpl.java:213)
    at htsjdk.samtools.SAMFileWriterImpl.addAlignment(SAMFileWriterImpl.java:200)
    at picard.sam.FilterSamReads.filterReads(FilterSamReads.java:256)
    at picard.sam.FilterSamReads.doWork(FilterSamReads.java:345)
    at picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:282)
    at picard.cmdline.PicardCommandLine.instanceMain(PicardCommandLine.java:103)
    at picard.cmdline.PicardCommandLine.main(PicardCommandLine.java:113)
[Tue Nov 19 16:51:40 CET 2019] picard.sam.FilterSamReads done. Elapsed time: 0.20 minutes.
Runtime.totalMemory()=3706716160

I have tried to remove the above reads from my input list and tried again, however, the same ERROR message appeared with different read names.

I would like to know, what else other than sorting the inputs should be done before running the FilterSamReads tool?

Any help or suggestion is much appreciated.

yfarjoun commented 4 years ago

You could filter with a javascript that will look at the mapping quality, and filter accordingly, instead of extracting the list of reads that have high enough mapping quality and then filtering by read name.....

alternatively, you could also set SORT_ORDER=queryname, or SORT_ORDER=coordinate and rerun your commandline.

Y.

On Tue, Nov 19, 2019 at 6:06 PM Alva Rani James notifications@github.com wrote:

Dear All,

I am using Picard FilterSamReads for filtering a list of sorted reads from a read_name/_id sorted BAM file. I am wanna sort the list of reads which are of certain mapping quality.

Here is what I tried,

java -jar -Xmx4G /path/picard-2.18.4-0/picard.jar FilterSamReads I=simulate_50X_pat_sorted_read.bam O=simulate_50X_pat_sorted_quality_pat.bam READ_LIST_FILE=pat_quality2 FILTER=includeReadList

And the above line is throwing the following error,

INFO 2019-11-19 16:51:40 FilterSamReads Filtering [presorted=true] simulate_50X_pat_sorted_read.bam -> OUTPUT=simulate_50X_pat_sorted_quality_pat.bam [sortorder=queryname] ERROR 2019-11-19 16:51:40 FilterSamReads Failed to filter simulate_50X_pat_sorted_read.bam java.lang.IllegalArgumentException: Alignments added out of order in SAMFileWriterImpl.addAlignment for file:///cluster/work/projects/simulate_50X_pat_sorted_quality_pat.bam. Sort order is queryname. Offending records are at [1-93166-:1-93466--:::::::::::52438MzI4MTAy:1] and [1-102419--:1-102119-:::::::::::199592NzM1MA==:1] at htsjdk.samtools.SAMFileWriterImpl.assertPresorted(SAMFileWriterImpl.java:213) at htsjdk.samtools.SAMFileWriterImpl.addAlignment(SAMFileWriterImpl.java:200) at picard.sam.FilterSamReads.filterReads(FilterSamReads.java:256) at picard.sam.FilterSamReads.doWork(FilterSamReads.java:345) at picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:282) at picard.cmdline.PicardCommandLine.instanceMain(PicardCommandLine.java:103) at picard.cmdline.PicardCommandLine.main(PicardCommandLine.java:113) [Tue Nov 19 16:51:40 CET 2019] picard.sam.FilterSamReads done. Elapsed time: 0.20 minutes. Runtime.totalMemory()=3706716160

I have tried to remove the above reads from my input list and tried again, however, the same ERROR message appeared with different read names.

I would like to know, what else other than sorting the inputs should be done before running the FilterSamReads tool?

Any help or suggestion is much appreciated.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/broadinstitute/picard/issues/1429?email_source=notifications&email_token=AAU6JUVM54WXXUPVGH5VP53QUQFGZA5CNFSM4JPFT5G2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4H2MPRFA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAU6JUUPMMYPMYUM4WXQHF3QUQFGZANCNFSM4JPFT5GQ .

moldach commented 4 years ago

This issue is a duplicate of #1194