<p>We've seen this error before on the GATK forum; if you google "bin field of BAM record does not equal value computed based on alignment start and end" you will find this forum thread: </p>

<p><a href="https://gatkforums.broadinstitute.org/gatk/discussion/4290/sam-bin-field-error-for-the-gatk-run" rel="nofollow noreferrer">https://gatkforums.broadinstitute.org/gatk/discussion/4290/sam-bin-field-error-for-the-gatk-run</a></p>

<p>This part of the last post should help you solve this:</p>

<blockquote>
  <p>The only way I can think of to fix this is to fix the BAM. In order to
  do that, you would need to convert to SAM format, which does not have
  a field for indexing bin, and then back to BAM. That would be the
  safest thing, followed by recreating the BAI. So you can do this with
  GATK tools using the following commands.</p>

<pre><code>gatk SamFormatConverter - to convert Bam to Sam

gatk SamFormatConverter - to convert Sam back to Bam

gatk BuildBamIndex - to create the Bam index file.
</code></pre>
  
  <p>Also, please make sure your Picardtools and GATK versions are up to
  date to the most recent versions.</p>
</blockquote>

CC BY-SA 4.0
2020-04-23T19:37:24.063Z
2020-04-23T19:37:24.063Z
Geraldine_VdAuwera
<p>I am sure I set the path right but whatever I am trying the command not working</p>

<p>Any help please?</p>

<pre><code>[fi1d18@cyan02 fi1d18]<span class="math-container">$ picard MarkDuplicates \
    I=DNA.dupmarked.bam \
    O=DNA.dupmarked1.bam \
    M= marked-dup-metrics.txt 
[Thu Mar 07 17:33:42 GMT 2019] picard.sam.markduplicates.MarkDuplicates INPUT=[/temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked.bam] OUTPUT=/temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked1.bam METRICS_FILE=marked-dup-metrics.txt MAX_SEQUENCES_FOR_DISK_READ_ENDS_MAP=50000 MAX_FILE_HANDLES_FOR_READ_ENDS_MAP=8000 SORTING_COLLECTION_SIZE_RATIO=0.25 REMOVE_SEQUENCING_DUPLICATES=false TAGGING_POLICY=DontTag REMOVE_DUPLICATES=false ASSUME_SORTED=false DUPLICATE_SCORING_STRATEGY=SUM_OF_BASE_QUALITIES PROGRAM_RECORD_ID=MarkDuplicates PROGRAM_GROUP_NAME=MarkDuplicates READ_NAME_REGEX=&lt;optimized capture of last three ':' separated fields as numeric values&gt; OPTICAL_DUPLICATE_PIXEL_DISTANCE=100 VERBOSITY=INFO QUIET=false VALIDATION_STRINGENCY=STRICT COMPRESSION_LEVEL=5 MAX_RECORDS_IN_RAM=500000 CREATE_INDEX=false CREATE_MD5_FILE=false GA4GH_CLIENT_SECRETS=client_secrets.json
[Thu Mar 07 17:33:42 GMT 2019] Executing as fi1d18@cyan02 on Linux 2.6.32-754.el6.x86_64 amd64; Java HotSpot(TM) 64-Bit Server VM 1.8.0_51-b16; Picard version: 2.8.3-SNAPSHOT
INFO 2019-03-07 17:33:42 MarkDuplicates Start of doWork freeMemory: 2012347496; totalMemory: 2027945984; maxMemory: 3817865216
INFO 2019-03-07 17:33:42 MarkDuplicates Reading input file and constructing read end information.
INFO 2019-03-07 17:33:42 MarkDuplicates Will retain up to 14684096 data points before spilling to disk.
WARNING: BAM index file /temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked.bam.bai is older than BAM /temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked.bam
[Thu Mar 07 17:33:42 GMT 2019] picard.sam.markduplicates.MarkDuplicates done. Elapsed time: 0.01 minutes.
Runtime.totalMemory()=2027945984
To get help, see http://broadinstitute.github.io/picard/index.html#GettingHelp
Exception in thread "main" htsjdk.samtools.SAMFormatException: SAM validation error: ERROR: Record 3752, Read name HX3_22030:3:2114:23155:23319, bin field of BAM record does not equal value computed based on alignment start and end, and length of sequence to which read is aligned
at htsjdk.samtools.SAMUtils.processValidationErrors(SAMUtils.java:448)
at htsjdk.samtools.BAMFileReader$</span>BAMFileIterator.advance(BAMFileReader.java:665)
at htsjdk.samtools.BAMFileReader<span class="math-container">$BAMFileIterator.next(BAMFileReader.java:650)
at htsjdk.samtools.BAMFileReader$</span>BAMFileIterator.next(BAMFileReader.java:620)
at htsjdk.samtools.SamReader<span class="math-container">$AssertingIterator.next(SamReader.java:569)
at htsjdk.samtools.SamReader$</span>AssertingIterator.next(SamReader.java:543)
at picard.sam.markduplicates.MarkDuplicates.buildSortedReadEndLists(MarkDuplicates.java:438)
at picard.sam.markduplicates.MarkDuplicates.doWork(MarkDuplicates.java:222)
at picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:205)
at picard.cmdline.PicardCommandLine.instanceMain(PicardCommandLine.java:94)
at picard.cmdline.PicardCommandLine.main(PicardCommandLine.java:104)
[fi1d18@cyan02 fi1d18]$
</code></pre>

<p>The error message is:</p>

<blockquote>
  <p>Exception in thread "main" htsjdk.samtools.SAMFormatException: validation error: ERROR: Record 3752, Read name HX3_22030:3:2114:23155:23319, bin field of BAM record does not equal value computed based on alignment start and end, and length of sequence to which read is aligned</p>
  
  <p>EDITED</p>
</blockquote>

<pre><code>[fi1d18@cyan02 sambamba]$ samtools view -H /temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked.bam
[W::bam_hdr_read] EOF marker is absent. The input is probably truncated.
@HD     VN:1.5  SO:coordinate
@SQ     SN:1    LN:249250621    AS:NCBI37       M5:1b22b98cdeb4a9304cb5d48026a85128     SP:Human  UR:/lustre/scratch117/core/sciops_repository/references/Homo_sapiens/1000Genomes_hs37d5/all/fasta/hs37d5.fa
@SQ     SN:2    LN:243199373    AS:NCBI37       M5:a0d9851da00400dec1098a9255ac712e     SP:Human  UR:/lustre/scratch117/core/sciops_repository/references/Homo_sapiens/1000Genomes_h
</code></pre>

CC BY-SA 4.0
2019-03-07T15:19:10.543Z
The `java` executable is not on your `PATH`.
user172818
CC BY-SA 4.0
2019-03-07T15:42:26.210Z
Thank you but when I loaded likely related module I got another error in edited post
Zizogolu
CC BY-SA 4.0
2019-03-07T23:17:42.277Z
Can you post what that line of the bam looks like?  Did you try remaking the bam index, since the software complained about it?
swbarnes2
CC BY-SA 4.0
2019-03-07T23:39:16.867Z
Have you considered just using `sambamba` to mark duplicates? It tends to be faster and less picky. There were a couple old versions of samtools that were messing up the bin assigned to some records, so make sure you use the most recent version in the future if you're not already doing so.
Devon Ryan
CC BY-SA 4.0
2019-03-08T10:58:18.020Z
Sorry I pasted a few lines of my bam in my main post please consider
Zizogolu
CC BY-SA 4.0
2019-03-08T11:04:13.833Z
Sorry @Devon sambamba says    [fi1d18@cyan02 sambamba]$ make sambamba-ldmd2-64
make: *** No rule to make target `sambamba-ldmd2-64'.  Stop.
Zizogolu
CC BY-SA 4.0
2019-03-08T11:18:03.677Z
Why would you try to compile programs rather than using conda or downloading the binary?
Devon Ryan
CC BY-SA 4.0
2019-03-08T12:44:13.020Z
Please read error messages thoroughly, the cause is written right in what you posted.
Devon Ryan
CC BY-SA 4.0
2019-03-08T13:01:02.363Z
[fi1d18@cyan03 ~]$ samtools quickcheck file.bam
[fi1d18@cyan03 ~]$
Zizogolu
CC BY-SA 4.0
2019-03-08T14:39:31.377Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/90774/discussion-between-feresh-teh-and-devon-ryan).
Zizogolu
<sam><wgs><picard>
Picard validation error regarding bin field of BAM file
# Picard validation error regarding bin field of BAM file

(Asked by: username_0 on 2019-03-07)

I am sure I set the path right but whatever I am trying the command not working
Any help please?
[fi1d18@cyan02 fi1d18]$ picard MarkDuplicates \
    I=DNA.dupmarked.bam \
    O=DNA.dupmarked1.bam \
    M= marked-dup-metrics.txt 
[Thu Mar 07 17:33:42 GMT 2019] picard.sam.markduplicates.MarkDuplicates INPUT=[/temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked.bam] OUTPUT=/temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked1.bam METRICS_FILE=marked-dup-metrics.txt MAX_SEQUENCES_FOR_DISK_READ_ENDS_MAP=50000 MAX_FILE_HANDLES_FOR_READ_ENDS_MAP=8000 SORTING_COLLECTION_SIZE_RATIO=0.25 REMOVE_SEQUENCING_DUPLICATES=false TAGGING_POLICY=DontTag REMOVE_DUPLICATES=false ASSUME_SORTED=false DUPLICATE_SCORING_STRATEGY=SUM_OF_BASE_QUALITIES PROGRAM_RECORD_ID=MarkDuplicates PROGRAM_GROUP_NAME=MarkDuplicates READ_NAME_REGEX= OPTICAL_DUPLICATE_PIXEL_DISTANCE=100 VERBOSITY=INFO QUIET=false VALIDATION_STRINGENCY=STRICT COMPRESSION_LEVEL=5 MAX_RECORDS_IN_RAM=500000 CREATE_INDEX=false CREATE_MD5_FILE=false GA4GH_CLIENT_SECRETS=client_secrets.json
[Thu Mar 07 17:33:42 GMT 2019] Executing as fi1d18@cyan02 on Linux 2.6.32-754.el6.x86_64 amd64; Java HotSpot(TM) 64-Bit Server VM 1.8.0_51-b16; Picard version: 2.8.3-SNAPSHOT
INFO 2019-03-07 17:33:42 MarkDuplicates Start of doWork freeMemory: 2012347496; totalMemory: 2027945984; maxMemory: 3817865216
INFO 2019-03-07 17:33:42 MarkDuplicates Reading input file and constructing read end information.
INFO 2019-03-07 17:33:42 MarkDuplicates Will retain up to 14684096 data points before spilling to disk.
WARNING: BAM index file /temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked.bam.bai is older than BAM /temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked.bam
[Thu Mar 07 17:33:42 GMT 2019] picard.sam.markduplicates.MarkDuplicates done. Elapsed time: 0.01 minutes.
Runtime.totalMemory()=2027945984
To get help, see http://broadinstitute.github.io/picard/index.html#GettingHelp
Exception in thread "main" htsjdk.samtools.SAMFormatException: SAM validation error: ERROR: Record 3752, Read name HX3_22030:3:2114:23155:23319, bin field of BAM record does not equal value computed based on alignment start and end, and length of sequence to which read is aligned
at htsjdk.samtools.SAMUtils.processValidationErrors(SAMUtils.java:448)
at htsjdk.samtools.BAMFileReader$BAMFileIterator.advance(BAMFileReader.java:665)
at htsjdk.samtools.BAMFileReader$BAMFileIterator.next(BAMFileReader.java:650)
at htsjdk.samtools.BAMFileReader$BAMFileIterator.next(BAMFileReader.java:620)
at htsjdk.samtools.SamReader$AssertingIterator.next(SamReader.java:569)
at htsjdk.samtools.SamReader$AssertingIterator.next(SamReader.java:543)
at picard.sam.markduplicates.MarkDuplicates.buildSortedReadEndLists(MarkDuplicates.java:438)
at picard.sam.markduplicates.MarkDuplicates.doWork(MarkDuplicates.java:222)
at picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:205)
at picard.cmdline.PicardCommandLine.instanceMain(PicardCommandLine.java:94)
at picard.cmdline.PicardCommandLine.main(PicardCommandLine.java:104)
[fi1d18@cyan02 fi1d18]$

The error message is:

Exception in thread "main" htsjdk.samtools.SAMFormatException: validation error: ERROR: Record 3752, Read name HX3_22030:3:2114:23155:23319, bin field of BAM record does not equal value computed based on alignment start and end, and length of sequence to which read is aligned
EDITED

[fi1d18@cyan02 sambamba]$ samtools view -H /temp/hgig/fi1d18/1631_WTSI-OESO_005_a_DNA/mapped_sample/HUMAN_1000Genomes_hs37d5_genomic_WTSI-OESO_005_a_DNA.dupmarked.bam
[W::bam_hdr_read] EOF marker is absent. The input is probably truncated.
@HD     VN:1.5  SO:coordinate
@SQ     SN:1    LN:249250621    AS:NCBI37       M5:1b22b98cdeb4a9304cb5d48026a85128     SP:Human  UR:/lustre/scratch117/core/sciops_repository/references/Homo_sapiens/1000Genomes_hs37d5/all/fasta/hs37d5.fa
@SQ     SN:2    LN:243199373    AS:NCBI37       M5:a0d9851da00400dec1098a9255ac712e     SP:Human  UR:/lustre/scratch117/core/sciops_repository/references/Homo_sapiens/1000Genomes_h

**Tags:** sam, wgs, picard
> **Comments:**
> **username_1**: The `java` executable is not on your `PATH`.  
> **username_0**: Thank you but when I loaded likely related module I got another error in edited post  
> **username_2**: Can you post what that line of the bam looks like?  Did you try remaking the bam index, since the software complained about it?  
> **username_3**: Have you considered just using `sambamba` to mark duplicates? It tends to be faster and less picky. There were a couple old versions of samtools that were messing up the bin assigned to some records, so make sure you use the most recent version in the future if you're not already doing so.  
> **username_0**: Sorry I pasted a few lines of my bam in my main post please consider  
> **username_0**: Sorry @Devon sambamba says    [fi1d18@cyan02 sambamba]$ make sambamba-ldmd2-64 make: *** No rule to make target `sambamba-ldmd2-64'.  Stop.  
> **username_3**: Why would you try to compile programs rather than using conda or downloading the binary?  
> **username_3**: Please read error messages thoroughly, the cause is written right in what you posted.  
> **username_0**: [fi1d18@cyan03 ~]$ samtools quickcheck file.bam [fi1d18@cyan03 ~]$  
> **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/90774/discussion-between-feresh-teh-and-devon-ryan).  

---

## 1 answers

### Answer by username_4 on 2020-04-23. Score: 0 | Accepted answer

We've seen this error before on the GATK forum; if you google "bin field of BAM record does not equal value computed based on alignment start and end" you will find this forum thread: 
https://gatkforums.broadinstitute.org/gatk/discussion/4290/sam-bin-field-error-for-the-gatk-run
This part of the last post should help you solve this:

The only way I can think of to fix this is to fix the BAM. In order to
  do that, you would need to convert to SAM format, which does not have
  a field for indexing bin, and then back to BAM. That would be the
  safest thing, followed by recreating the BAI. So you can do this with
  GATK tools using the following commands.
gatk SamFormatConverter - to convert Bam to Sam

gatk SamFormatConverter - to convert Sam back to Bam

gatk BuildBamIndex - to create the Bam index file.

Also, please make sure your Picardtools and GATK versions are up to
  date to the most recent versions.


---

