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

bam2wig.pl: Division by zero during rpm normalisation #15

Closed
balwierz opened this issue Jun 25, 2021 · 2 comments
Closed

bam2wig.pl: Division by zero during rpm normalisation #15

balwierz opened this issue Jun 25, 2021 · 2 comments

Comments

@balwierz
Copy link

balwierz commented Jun 25, 2021

Hi,

I bam2wig.pl crashes during normalisation step. Apparently $totals[0] in the line 1805 is an empty string.
I have 9 bam files from the same genome processed in exactly the same way. There are no problems for 3 of them, but the remaining 6 fail. I rerun with -V and checked that all alignments are counted correctly and although some of them have zero alignments the total goes in millions.

Version 1.68
Perl 5.32.1

bam2wig.pl -V --extend --rpm --nope --shift --shiftval $((-50/2 + 4)) --extval 50 --bin $binSize --in f1.mm10.sorted.bam --nogz --bw --out foo.bw
 This program will convert bam alignments to wig data
  Including secondary 0x100 reads
  Including duplicate 0x400 reads
  Including supplementary 0x800 reads
 Recording single-end shifted, extended alignment span
 Writing fixedStep format in 10 bp bins
 Writing temp files to /mnt/scratch/piotr/bam2wig_UpahTh/bam2wigTEMP_gloB
 Processing files ../../Mapped/f1.mm10.sorted.bam...
 Using the Bio::DB::Sam Bam adapter and align wrapper 
 Alignments will be extended by 50 bp
 Forking into 8 children for parallel conversion
  Converted 3,436,700 alignments on chr8 in 29 seconds
  Converted 3,643,578 alignments on chr7 in 31 seconds
  Converted 3,850,668 alignments on chr6 in 32 seconds
  Converted 3,997,847 alignments on chr5 in 34 seconds
  Converted 4,029,221 alignments on chr3 in 34 seconds
  Converted 4,069,201 alignments on chr4 in 35 seconds
  Converted 4,934,754 alignments on chr2 in 42 seconds
  Converted 4,941,632 alignments on chr1 in 42 seconds
  Converted 2,356,301 alignments on chr14 in 20 seconds
  Converted 3,393,314 alignments on chr9 in 29 seconds
  Converted 3,250,935 alignments on chr10 in 27 seconds
  Converted 3,037,476 alignments on chr12 in 26 seconds
  Converted 3,076,095 alignments on chr13 in 26 seconds
  Converted 95,714 alignments on chrY in 2 seconds
  Converted 3,564,766 alignments on chr11 in 30 seconds
  Converted 2,615 alignments on chr1_GL456210_random in 1 seconds
  Converted 2,516,301 alignments on chr16 in 21 seconds
  Converted 2,435 alignments on chr1_GL456212_random in 0 seconds
  Converted 3,538 alignments on chr1_GL456211_random in 0 seconds
  Converted 0 alignments on chr1_GL456213_random in 0 seconds
  Converted 2,019 alignments on chr1_GL456221_random in 0 seconds
  Converted 2,707,038 alignments on chr15 in 23 seconds
  Converted 43 alignments on chr4_JH584292_random in 0 seconds
  Converted 0 alignments on chr4_GL456350_random in 0 seconds
  Converted 1,396 alignments on chr4_GL456216_random in 0 seconds
  Converted 35 alignments on chr4_JH584295_random in 0 seconds
  Converted 0 alignments on chr4_JH584293_random in 0 seconds
  Converted 16 alignments on chr4_JH584294_random in 0 seconds
  Converted 2 alignments on chr5_JH584297_random in 0 seconds
  Converted 2 alignments on chr5_JH584296_random in 0 seconds
  Converted 282 alignments on chr5_GL456354_random in 0 seconds
  Converted 0 alignments on chr7_GL456219_random in 0 seconds
  Converted 0 alignments on chr5_JH584298_random in 0 seconds
  Converted 2,660 alignments on chr5_JH584299_random in 0 seconds
  Converted 0 alignments on chrY_JH584300_random in 0 seconds
  Converted 2 alignments on chrY_JH584301_random in 0 seconds
  Converted 3,801 alignments on chrX_GL456233_random in 0 seconds
  Converted 0 alignments on chrY_JH584302_random in 0 seconds
  Converted 0 alignments on chrY_JH584303_random in 0 seconds
  Converted 2,209 alignments on chrUn_GL456239 in 0 seconds
  Converted 506 alignments on chrUn_GL456359 in 0 seconds
  Converted 742 alignments on chrUn_GL456360 in 0 seconds
  Converted 1,154 alignments on chrUn_GL456366 in 0 seconds
  Converted 1,608,531 alignments on chr19 in 14 seconds
  Converted 509 alignments on chrUn_GL456367 in 0 seconds
  Converted 96 alignments on chrUn_GL456370 in 0 seconds
  Converted 462 alignments on chrUn_GL456372 in 0 seconds
  Converted 1,042 alignments on chrUn_GL456368 in 0 seconds
  Converted 266 alignments on chrUn_GL456382 in 0 seconds
  Converted 278 alignments on chrUn_GL456381 in 0 seconds
  Converted 870 alignments on chrUn_GL456378 in 0 seconds
  Converted 631 alignments on chrUn_GL456379 in 0 seconds
  Converted 431 alignments on chrUn_GL456383 in 0 seconds
  Converted 766 alignments on chrUn_GL456389 in 0 seconds
  Converted 737 alignments on chrUn_GL456385 in 0 seconds
  Converted 1,262 alignments on chrUn_GL456387 in 0 seconds
  Converted 436 alignments on chrUn_GL456390 in 0 seconds
  Converted 548 alignments on chrUn_GL456394 in 0 seconds
  Converted 1,232 alignments on chrUn_GL456392 in 0 seconds
  Converted 2,117 alignments on chrUn_GL456393 in 0 seconds
  Converted 2,463,763 alignments on chr17 in 21 seconds
  Converted 427 alignments on chrUn_GL456396 in 0 seconds
  Converted 57,141 alignments on chrUn_JH584304 in 0 seconds
  Converted 1,952,986 alignments on chrX in 17 seconds
  Converted 2,286,956 alignments on chr18 in 20 seconds
  Converted 3,886,331 alignments on chrM in 31 seconds
Illegal division by zero at /usr/local/bin/bam2wig.pl line 1805.
 Finished converting alignments in 1.567 minutes
 Normalizing depth based on  total counted alignments
@balwierz
Copy link
Author

If I remove --rpmoption then there are lines:

Merging temporary files
0 total alignments

@tjparnell
Copy link
Owner

This is quite a strange, and I'm unable to reproduce the error with your file names and options. I've re-traced the path in the code that should be taken by your options, but can't identify a problem of why an alignment would be processed but not counted.
Each chromosome is processed in a separate fork and written to a separate temp file, with the total number of alignments encoded in the file name as basename.samid.seqid.count.strand.temp.bin. During execution (or if you cancel early), you can list the temp folder contents to confirm that the file name matches the standard out. The app should fail if the number of children files don't equal the number of children spawned for each chromosome and bam file. The count is pulled out from the child file name by regular expression. For some reason, the alignment count isn't being written to the file name.
I've put in a sanity check in the bam2wig script to check for totals equaling zero, but it's not going to help you much – it will still die, and it can't really proceed with RPM normalization without a count.
If you can provide a reproducible example bam file (perhaps just a contig or something?), I might be able to debug further.

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

No branches or pull requests

2 participants